Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/shell: native: stop RIOT when the shell reads EOF #13675

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions sys/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,28 @@
#define SHELL_H

#include <stdint.h>
#include "periph/pm.h"

#include "kernel_defines.h"

#ifdef __cplusplus
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
fjmolinas marked this conversation as resolved.
Show resolved Hide resolved
# endif
#endif

/**
* @brief Default shell buffer size (maximum line length shell can handle)
*/
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
}
}

Expand Down