Skip to content

Commit

Permalink
Merge pull request #10105 from x3ro/fix-shell-prompt-infinite-loop
Browse files Browse the repository at this point in the history
Do not try to continue reading shell commands if input source is closed
  • Loading branch information
x3ro authored Oct 30, 2018
2 parents 365d82e + 62cecc9 commit 6ed11de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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

0 comments on commit 6ed11de

Please sign in to comment.