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

Do not try to continue reading shell commands if input source is closed #10105

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions sys/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ typedef struct shell_command_t {
* @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
*
* @returns This function does not return.
*/
void shell_run(const shell_command_t *commands, char *line_buf, int len) NORETURN;
void shell_run(const shell_command_t *commands, char *line_buf, int len);

#ifdef __cplusplus
}
Expand Down
6 changes: 5 additions & 1 deletion sys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static int readline(char *buf, size_t size)

int c = getchar();
if (c < 0) {
return 1;
return EOF;
}

/* We allow Unix linebreaks (\n), DOS linebreaks (\r\n), and Mac linebreaks (\r). */
Expand Down Expand Up @@ -287,6 +287,10 @@ void shell_run(const shell_command_t *shell_commands, char *line_buf, int len)
while (1) {
int res = readline(line_buf, len);

if (res == EOF) {
break;
}

if (!res) {
handle_input_line(shell_commands, line_buf);
}
Expand Down