1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
Commit Graph

81 Commits

Author SHA1 Message Date
Benjamin Valentin
c0a4acf32d sys/shell_lock: lock shell on EOF 2023-05-26 15:04:36 +02:00
Marian Buschsieweke
2825f5f2ae
sys/shell: use flash_utils 2023-02-27 12:31:03 +01:00
Hendrik van Essen
ccc795133f sys/shell: add pseudomodule shell_lock_auto_locking
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.
2022-06-08 12:53:48 +02:00
Hendrik van Essen
2284f87fdb sys/shell: add module shell_lock
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.
2022-06-08 12:53:48 +02:00
Marian Buschsieweke
5ea582b3dd
sys/shell_commands: convert to SHELL_COMMAND()
Make use of XFA for shell commands
2022-06-07 09:25:04 +02:00
b8fef54724 sys/shell: drop _builtin_cmds define 2022-05-09 15:24:34 +02:00
3eaa1beb56 sys/shell: initial XFA support 2021-03-02 14:57:29 +01:00
Leandro Lanzieri
67f36d78a9
sys/shell: document configs and add to Kconfig 2021-02-04 09:19:43 +01:00
Hendrik van Essen
aead3162ec sys/shell: terminate shell on Ctrl-D
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.
2020-10-21 17:40:44 +02:00
Keith Packard
e215261ced picolibc: Use most NEWLIB code with picolibc
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>
2020-08-24 08:26:16 -07:00
MrKevinWeiss
04630d20ba sys/shell: Add optional hooks for shell commands
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.
2020-07-07 17:00:38 +02:00
Hendrik van Essen
cc759ebcca sys/shell: further refactor tokenizer (part 2/2)
Code now correctly handles quotes within PARSE_UNQUOTED
and tabs are now considered a BLANK just like a space.
2020-06-23 13:47:04 +02:00
Hendrik van Essen
0782b493ed sys/shell: simplify array traversal code
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>
2020-06-23 13:46:51 +02:00
Hendrik van Essen
37cff93254 sys/shell: further refactor tokenizer (part 1/2)
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>
2020-06-23 13:46:40 +02:00
Hendrik van Essen
86f60357cf sys/shell: refactor tokenizer code
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>
2020-05-18 14:31:46 +02:00
Hendrik van Essen
a0a3e6c3a1 sys/shell: refactor readline function
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>
2020-04-14 15:38:56 +02:00
Hendrik van Essen
45f898563a sys/shell: remove ifdefs in the middle of code
ifdefs in the middle of code reduce the readability
and debugability and should be avoided.

Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>
2020-04-14 15:38:54 +02:00
Hendrik van Essen
268d1b2305 sys/shell: remove useless "inline prevention"
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>
2020-04-14 14:34:58 +02:00
Hendrik van Essen
3860355380
sys/shell: rephrase/reformat some comments 2020-03-30 12:26:20 +02:00
Juan Carrano
2810637306
sys/shell: correctly detect and handle long lines
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>
2020-03-30 12:26:20 +02:00
Martine S. Lenders
2c1a2863ce shell: make shell_run run shell forever
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
2019-09-19 10:26:31 +02:00
Juan Carrano
fa9337d73c sys/shell: cancel current line on CTRL-C.
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.
2019-08-15 17:13:42 +02:00
Benjamin Valentin
0c98b79e2f sys/shell: reduce scope of variable 'entry' 2019-08-06 19:43:54 +02:00
Benjamin Valentin
e8dc1119b8 sys: make use of ARRAY_SIZE macro 2019-08-06 19:43:54 +02:00
Juan Carrano
b34dc3a565 sys/shell: ensure character is flushed when echoing.
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.)
2018-12-19 12:08:54 +01:00
Lucas Jenss
62cecc9496 Do not try to continue reading shell commands if input source is closed
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
2018-10-30 19:06:42 +01:00
Vincent Dupont
669a6922f3 sys/shell: fix build when SHELL_NO_ECHO is defined
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.
2017-05-04 15:49:22 +02:00
0c4b760f11 sys/shell: fix build issue when deactivating shell echo (iotlab) 2016-05-29 14:21:11 +02:00
fdf12d01b3 sys/shell: adding definition for deactiving prompt and/or echo in shell 2016-05-26 09:36:23 +02:00
d7b9053e23 sys: shell: work around inlined putchar 2015-09-04 19:38:16 +02:00
13995e878f sys: shell: get rid of some parameters 2015-09-03 13:33:18 +02:00
Cenk Gündoğan
4deb0213b9 sys/shell/shell.c: command not found in one line 2015-08-12 13:16:37 +02:00
adabd8c930 shell: let readline return an error on empty line so prompt gets print again 2015-07-06 11:33:44 +02:00
2d7642b8c1 shell: flush stdout after printing prompt 2015-07-06 09:53:29 +02:00
Hauke Petersen
1eec484a30 sys/shell: changed signature of put_char pointer
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.
2015-06-14 17:02:57 +02:00
Hauke Petersen
2323c08d32 sys/shell: fixed and unified doxygen headers
- changed doxygen group name to sys_shell
- added some missing fields
- unified the doxygen header format
2015-03-03 18:10:06 +01:00
René Kijewski
5f262be568 Merge pull request #1653 from medicalwei/shell_backspace
Add backspace functionality in shell
2014-09-29 21:21:41 +02:00
Yao Wei
b5d3c65672 Add 0x7f as backspace key in shell 2014-09-24 15:40:21 +08:00
Yao Wei
208f889a4a add backspace functionality in shell 2014-09-11 21:27:20 +08:00
Ludwig Ortmann
3ca4f18479 doc: use lgplv2.1-short license header instead of lgpl-short-riot 2014-07-31 22:57:20 +02:00
Ludwig Ortmann
b6846e31fc doc: fix most occurences of FU as an author
.. but only if there are other authors as well
2014-07-29 17:23:11 +02:00
Oleg Hahm
36b9f7e7d7 Merge pull request #1257 from Kijewski/shell-fix-newline
shell: fix newlines
2014-06-22 23:56:36 +02:00
René Kijewski
94bb326fc0 shell: fix newlines 2014-05-30 21:10:05 +02:00
René Kijewski
638666c34a shell: print command if not found 2014-05-12 22:07:35 +02:00
René Kijewski
97593e9f05 shell: add myself to authors 2014-03-10 18:17:05 +01:00
René Kijewski
a1df6a86bb shell: don't ignore IO errors 2014-03-10 13:48:00 +01:00
René Kijewski
3f289760bf shell: accept UTF8 input 2014-03-10 13:47:33 +01:00
René Kijewski
03e174ed96 Allow escaped characters in shell
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.
2014-02-26 18:09:46 +01:00
René Kijewski
28c4ef45f7 Do not skip over the null terminator 2014-02-26 13:21:25 +01:00
René Kijewski
829966ee32 Print error message on any quoting error 2014-02-25 17:54:17 +01:00