Skip to content

Commit

Permalink
Do not try to continue reading shell commands if input source is close
Browse files Browse the repository at this point in the history
In RIOT native, sending CTRL+D to a shell started using shell_run would resulted in and
endless prompt loop. I've been unable to trigger such a behaviour
on actual hardware using a UART connection, but calling `pm_off` seemed
like a better alternative than having an `#ifdef BOARD_NATIVE`.

Fixes #9946
  • Loading branch information
x3ro committed Oct 2, 2018
1 parent 99e7594 commit 4622f85
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <stdlib.h>
#include "shell.h"
#include "shell_commands.h"
#include "periph/pm.h"

#if !defined(SHELL_NO_ECHO) || !defined(SHELL_NO_PROMPT)
#ifdef MODULE_NEWLIB
Expand Down Expand Up @@ -228,7 +229,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 +288,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) {
pm_off();
}

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

0 comments on commit 4622f85

Please sign in to comment.