Shell: When shellGetLine fails the last line cmd is executed again Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Mbroek635
Posts: 3
Joined: Thu Oct 06, 2022 10:21 am
Been thanked: 3 times

Shell: When shellGetLine fails the last line cmd is executed again  Topic is solved

Postby Mbroek635 » Thu Dec 08, 2022 2:52 pm

Hello,

I'm using ChibiOS 21.11 on an STM32L496.
I'm using the serial_usb module to create a virtual com port over USB.
This virtual com port is used as the BaseSequentialStream for the shell.
When a certain command is entered the serial USB device is disabled and the USB is used for a mass storage device.
Let's call this command 'do_switch_msd'.
When the MSD is ejected the serial USB device is started again.

I noticed that when the USB device is disabled, the shell executes the 'do_switch_msd' command is called again.
After closer inspection I've noticed that:
  • When shellGetLine fails (due to the stream being closed), and
  • SHELL_CMD_EXIT_ENABLED is FALSE
the line variable will be interpreted again. This causes my 'do_switch_msd' function to be called again.

Here's a diff of how I'd solve this issue:

Code: Select all

diff --git a/os/various/shell/shell.c b/os/various/shell/shell.c
index a7cd30849..62594223f 100644
--- a/os/various/shell/shell.c
+++ b/os/various/shell/shell.c
@@ -375,6 +375,7 @@ THD_FUNCTION(shellThread, p) {
       /* Putting a delay in order to avoid an endless loop trying to read
          an unavailable stream.*/
       osalThreadSleepMilliseconds(100);
+      continue;
 #endif
     }
     lp = parse_arguments(line, &tokp);


I don't know if anyone or anything is counting on this behavior, but I consider this a bug.

Cheers

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Shell: When shellGetLine fails the last line cmd is executed again

Postby Giovanni » Thu Dec 08, 2022 3:22 pm

Hi,

Thanks, I will look into this.

Giovanni

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

Re: Shell: When shellGetLine fails the last line cmd is executed again

Postby FXCoder » Fri Dec 09, 2022 10:49 am

In my modified version of shell.c i have this...

Code: Select all

#else
      /* Putting a delay in order to avoid an endless loop trying to read
         an unavailable stream.*/
      osalThreadSleepMilliseconds(100);
#endif
    }
    if (*line == 0)
      continue;
    lp = parse_arguments(line, &tokp);
   


And at the end of ShellGetLine(...) this...

Code: Select all

    if (c < 0x20)
      continue;
    if (p < line + size - 1) {
      streamPut(chp, c);
      *p++ = (char)c;
    }
    else {
      /* Input buffer overflow. Discard input line. Get new prompt. */
      *line = 0;
      chprintf(chp, SHELL_INPUT_ERROR_ALERT);
      return false;
    }
   

--
Bob

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Shell: When shellGetLine fails the last line cmd is executed again

Postby Giovanni » Sun Dec 18, 2022 10:11 am

Hi,

Added that "continue", not doing other changes because the shell needs a global rework, better implement new behaviors in that context.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 11 guests