mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
sys/shell: native: stop RIOT when the shell reads EOF
Currently when the shell receives EOF on `native`, sending EOF (ctrl + D) closes the stdin file descriptor, leading to all consecutive reads to also return EOF. The result is that `shell_run_forever()` will re-start the shell forever in a loop, filling up the terminal with > > > > > > > > > > > > > > > > > > > > > > … until the user hits ctrl + C. This is annoying. Instead, cleanly shutdown RIOT when receiving EOF on native, which should match the expected behaviour of most users.
This commit is contained in:
parent
d191b9c38a
commit
a6ca535955
@ -21,6 +21,7 @@
|
||||
#define SHELL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "periph/pm.h"
|
||||
|
||||
#include "kernel_defines.h"
|
||||
|
||||
@ -28,6 +29,20 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Shutdown RIOT on shell exit
|
||||
*/
|
||||
#ifndef CONFIG_SHELL_SHUTDOWN_ON_EXIT
|
||||
/* Some systems (e.g Ubuntu 20.04) close stdin on CTRL-D / EOF
|
||||
* That means we can't just re-start the shell.
|
||||
* Instead terminate RIOT, which is also the behavior a user would
|
||||
* expect from a CLI application.
|
||||
*/
|
||||
# ifdef CPU_NATIVE
|
||||
# define CONFIG_SHELL_SHUTDOWN_ON_EXIT 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Default shell buffer size (maximum line length shell can handle)
|
||||
*/
|
||||
@ -75,6 +90,9 @@ void shell_run_once(const shell_command_t *commands, char *line_buf, int len);
|
||||
/**
|
||||
* @brief Start a shell and restart it if it exits
|
||||
*
|
||||
* If `CONFIG_SHELL_SHUTDOWN_ON_EXIT` is set (e.g. on native)
|
||||
* the shell will instead shut down RIOT once EOF is reached.
|
||||
*
|
||||
* @param[in] commands ptr to array of command structs
|
||||
* @param[in] line_buf Buffer that will be used for reading a line
|
||||
* @param[in] len nr of bytes that fit in line_buf
|
||||
@ -84,6 +102,10 @@ static inline void shell_run_forever(const shell_command_t *commands,
|
||||
{
|
||||
while (1) {
|
||||
shell_run_once(commands, line_buf, len);
|
||||
|
||||
if (IS_ACTIVE(CONFIG_SHELL_SHUTDOWN_ON_EXIT)) {
|
||||
pm_off();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user