Module to lock the shell after a given timeout of time x. When the
shell did not receive any input within time x, then the shell is
locked automatically.
Module to lock the running shell with a password. Shell is proceeded only
when the valid password was entered by the user. After 3 failed attempts,
the input is blocked for a few seconds to slow down brute force attacks.
Does not make use of any cryptographic features yet.
Ctrl-D was not caught in a special case so it was interpreted as
a standard character. Handle it now the same way like EOF and
terminate the shell instance.
In most places, picolibc and newlib are the same, so use
the existing newlib code when compiling with picolibc.
Signed-off-by: Keith Packard <keithp@keithp.com>
Introduce optional user shell_post_readline_hook, shell_pre_command_hook, shell_post_command_hook.
Enable with USEMODULE=shell_hooks.
Calls user implemented *_hook functions if defined.
If implementation does not exist, nothing happens.
The intent is to make profiling of the shell command timings easier.
Test provided in tests/shell with USEMODULE=shell_hooks.
The code for traversing arrays of shell commands (used to print help messages
and to search for commmand handlers) was needlessly complex.
Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>
Factor out common code for quoted and unquoted tokens. This makes the code
slighly less clear, but it also eliminates repetition (which may improve
clarity).
Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>
The tokenizer (the code that breaks up the line given to the shell into
strings to create argv) was quite a messy piece of code. This commit
refactors it into a more traditional state-machine based parser.
This fixes the issues with quote handling exposed by the recently
introduced test.
Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>
This makes the code of `readline()` clearer and shorter. It also fixes a
minor artifact of the long line handling.
Previously it was not possible to recover from a long line. That is, if too
many characters were sent, the line would be invalidated and pressing backspace
would not fix it- the only option was to discard the line. It is now possible
to bring the line back to size. Note that visual effects when deleting characters
will still depend on the host's terminal.
The new code is written in a way that all writes to memory are guarded by
bounds check, so an assertion was removed.
Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>
There was some code added to "prevent putchar from being inlined", which
supposedly enlarged the code size.
Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>
The numeric value for EOF is -1. This caused the shell to return
the same code when EOF was encountered and when the line lenght was
exceeded. Additionally, if the line length is exceeded, the correct
behaviour is to consume the remaining characters until the end of
the line, to prevent the following line from containing (potentially
dangerous) garbage.
Co-authored-by: Hendrik van Essen <hendrik.ve@fu-berlin.de>
This change is in preparation to [PR 10788]. PR 10788 will make the
shell exitable which may lead to unexpected behavior in comparison to
previous usage of the shell.
To prevent this, this PR introduces two "new" functions to the shell's
API: `shell_run_once()` and `shell_run_forever()`.
`shell_run_once()` basically has the same behavior as `shell_run()` in
current master: Start a shell and continue reading lines until EOF is
reached.
`shell_run_forever()` wraps around `shell_run_once()` and restarts the
shell if it exits.
`shell_run()` is re-introduced as a back-porting alias for
`shell_run_forever()`.
As a consequence all current calls to `shell_run()` won't exit even
with [PR 10788] merged (which would add EOT as additional exit
condition for `shell_run_once()`).
[PR 10788]: https://github.com/RIOT-OS/RIOT/pull/10788
CTRL-C cancels the current line, similar to how getty works.
This is useful if one is using a dumb terminal to communicate with
a node, as it saves having to repeatedly type backspace to discard the
current line. It also helps when connecting to an already running node,
as one does not know what is on the line buffer, the safest thing to do
is to begin by sending a ctrl-C.
This is a suggestion of @benemorius.
When using a serial terminal without local echo, the current line
would not get updated as the user typed because the shell module's
readline() was not flushing each character.
This commit fixes that behavior. For additional clarity, fflush is
turned into a macro (flush_if_needed) which expands to either a call
to fflush() or empty, according to the standard library used.
This also fixes the erase/line editing behavior (the delete characters
were not being flushed either.)
In RIOT native, sending CTRL+D to a shell started using shell_run would resulted in and
endless prompt loop. I've been unable to trigger such a behaviour
on actual hardware using a UART connection, but calling `pm_off` seemed
like a better alternative than having an `#ifdef BOARD_NATIVE`.
Fixes#9946
When SHELL_NO_ECHO was defined and not SHELL_NO_PROMPT build was broken
because _putchar was not defined.
This define _putchar when one of SHELL_NO_PROMPT or SHELL_NO_ECHO is not
defined.
changed from void(*put_char)(int) to int(*putchar)(int).
This is beneficial, as now the std-libs putchar can be given as
an argument to shell_init() directly.
Per #708.
This patch allows escaped characters in the shell, and makes the
apostrophe a quotation mark. The escape character is backslash.
The term "escape character" is used liberally in here: if a backslash is
encountered in the command line, the next character will be taken
verbatim. No escape sequences are understood, i.e. `"\n"` is just the
letter `n`, not a new line.