Merge pull request #13675 from benpicco/native_eof_exit

sys/shell: native: stop RIOT when the shell reads EOF
This commit is contained in:
Francisco 2020-06-30 15:29:52 +02:00 committed by GitHub
commit 960cca77b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}
}
}