From 8152e92d3abfff0386a672421e164ce163678dcf Mon Sep 17 00:00:00 2001 From: Ron Yorston <rmy@pobox.com> Date: Sat, 8 Feb 2020 16:48:40 +0000 Subject: ash: fixes to handling of ctrl-C in read builtin Consider this script: while read -r; do echo $REPLY; done echo hello There are currently two problems with this when the read is interrupted by ctrl-C: - The error return code is 0 when it should be 130; - The echo command is executed. Fix these issues by propagating the control event to the process that would have caught it if the read builtin hadn't grabbed keyboard input. --- shell/shell_common.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'shell/shell_common.c') diff --git a/shell/shell_common.c b/shell/shell_common.c index 320cd88fd..9092a8e2b 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -235,8 +235,13 @@ shell_builtin_read(struct builtin_read_params *params) int64_t key; key = read_key(fd, NULL, timeout); - if (key == 0x03 || key == -1 || (key == 0x1a && bufpos == 0)) { - /* ^C, timeout or ^Z at start of buffer */ + if (key == 0x03) { + /* ^C pressed */ + retval = (const char *)(uintptr_t)2; + goto ret; + } + else if (key == -1 || (key == 0x1a && bufpos == 0)) { + /* timeout or ^Z at start of buffer */ retval = (const char *)(uintptr_t)1; goto ret; } -- cgit v1.2.3-55-g6feb