diff options
author | Ron Yorston <rmy@pobox.com> | 2020-02-08 16:48:40 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-02-08 16:48:40 +0000 |
commit | 8152e92d3abfff0386a672421e164ce163678dcf (patch) | |
tree | 2246535e3516556c7486c5b589d7fe82d6691e55 /shell/shell_common.c | |
parent | 47dbad5047e6bb9fb1f287245791711ceb822c96 (diff) | |
download | busybox-w32-8152e92d3abfff0386a672421e164ce163678dcf.tar.gz busybox-w32-8152e92d3abfff0386a672421e164ce163678dcf.tar.bz2 busybox-w32-8152e92d3abfff0386a672421e164ce163678dcf.zip |
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.
Diffstat (limited to 'shell/shell_common.c')
-rw-r--r-- | shell/shell_common.c | 9 |
1 files changed, 7 insertions, 2 deletions
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) | |||
235 | int64_t key; | 235 | int64_t key; |
236 | 236 | ||
237 | key = read_key(fd, NULL, timeout); | 237 | key = read_key(fd, NULL, timeout); |
238 | if (key == 0x03 || key == -1 || (key == 0x1a && bufpos == 0)) { | 238 | if (key == 0x03) { |
239 | /* ^C, timeout or ^Z at start of buffer */ | 239 | /* ^C pressed */ |
240 | retval = (const char *)(uintptr_t)2; | ||
241 | goto ret; | ||
242 | } | ||
243 | else if (key == -1 || (key == 0x1a && bufpos == 0)) { | ||
244 | /* timeout or ^Z at start of buffer */ | ||
240 | retval = (const char *)(uintptr_t)1; | 245 | retval = (const char *)(uintptr_t)1; |
241 | goto ret; | 246 | goto ret; |
242 | } | 247 | } |