Skip to content

Commit

Permalink
sys/shell: Exit the shell on ctrl-D
Browse files Browse the repository at this point in the history
Right now the only way to exit the shell is if stdin is closed. This
works on native, but on an embedded platform stdin is the uart and thus
is never closed.

This patch causes the shell loop to exit on EOT (ASCII 0x04 / ctrl-D),
also called "End-of-Transmission".
  • Loading branch information
jcarrano committed Feb 12, 2019
1 parent e8ac6a8 commit abc2b84
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "shell_commands.h"

#define ETX '\x03' /** ASCII "End-of-Text", or ctrl-C */
#define EOT '\x04' /** ASCII "End-of-Transmission", or ctrl-D */

#if !defined(SHELL_NO_ECHO) || !defined(SHELL_NO_PROMPT)
#ifdef MODULE_NEWLIB
/* use local copy of putchar, as it seems to be inlined,
Expand Down Expand Up @@ -235,7 +237,7 @@ static int readline(char *buf, size_t size)
}

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

Expand Down

0 comments on commit abc2b84

Please sign in to comment.