diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-01-25 15:49:54 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-01-25 15:49:54 +0100 |
commit | 6e5db34b2e1c6f53927d03d914fdc3d65cb32b63 (patch) | |
tree | 856cff3cada7636d77b4bde767be81c164fb0764 /Userland/sh.cpp | |
parent | c6fdde37e7ce8c0e58e9e6b25e2d018dbe8120a6 (diff) | |
download | serenity-6e5db34b2e1c6f53927d03d914fdc3d65cb32b63.zip |
sh: Discard the current line on interrupt.
Diffstat (limited to 'Userland/sh.cpp')
-rw-r--r-- | Userland/sh.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Userland/sh.cpp b/Userland/sh.cpp index 8091dee5ca..bac8b67949 100644 --- a/Userland/sh.cpp +++ b/Userland/sh.cpp @@ -20,6 +20,7 @@ struct GlobalState { pid_t sid; uid_t uid; termios termios; + bool was_interrupted { false }; }; static GlobalState* g; @@ -50,7 +51,7 @@ void did_receive_signal(int signum) void handle_sigint(int) { - printf("Interrupt received by sh\n"); + g->was_interrupted = true; } static int sh_busy(int, char**) @@ -409,7 +410,15 @@ int main(int, char**) ssize_t nread = read(0, keybuf, sizeof(keybuf)); if (nread < 0) { if (errno == EINTR) { - // Ignore. :^) + ASSERT(g->was_interrupted); + if (linedx != 0) + printf("^C"); + g->was_interrupted = false; + linebuf[0] = '\0'; + linedx = 0; + putchar('\n'); + prompt(); + continue; } else { perror("read failed"); return 2; |