diff options
| author | Ron Yorston <rmy@pobox.com> | 2025-07-01 09:47:14 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2025-07-01 20:21:37 +0200 |
| commit | dcd8df258a402658ad1fdc018a245b06a610ca8d (patch) | |
| tree | f297a609c894cbd1a42492399c9fd29f3819527b /shell/shell_common.c | |
| parent | 4b1f1da358e0cf18bd7c8265ea1a9121c2801a21 (diff) | |
| download | busybox-w32-dcd8df258a402658ad1fdc018a245b06a610ca8d.tar.gz busybox-w32-dcd8df258a402658ad1fdc018a245b06a610ca8d.tar.bz2 busybox-w32-dcd8df258a402658ad1fdc018a245b06a610ca8d.zip | |
shell: improve bash compatibility of read built-in
Make the read built-in more compatible with bash:
- Return an exit code of 142 on timeout.
- When the timeout expires before a newline is detected in the
input bash captures the partial input. This behaviour is new
since bash version 4.4. BusyBox shells had the pre-4.4 behaviour
where the input was lost.
Update the tests to suit and fix a couple of compiler errors in
the testsuite.
function old new delta
builtin_read 154 174 +20
readcmd 213 228 +15
shell_builtin_read 1364 1370 +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 41/0) Total: 41 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/shell_common.c')
| -rw-r--r-- | shell/shell_common.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/shell/shell_common.c b/shell/shell_common.c index e5c2cefb3..9a03f7265 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c | |||
| @@ -204,8 +204,8 @@ shell_builtin_read(struct builtin_read_params *params) | |||
| 204 | * 32-bit unix time wrapped (year 2038+). | 204 | * 32-bit unix time wrapped (year 2038+). |
| 205 | */ | 205 | */ |
| 206 | if (timeout <= 0) { /* already late? */ | 206 | if (timeout <= 0) { /* already late? */ |
| 207 | retval = (const char *)(uintptr_t)1; | 207 | retval = (const char *)(uintptr_t)2; |
| 208 | goto ret; | 208 | break; |
| 209 | } | 209 | } |
| 210 | } | 210 | } |
| 211 | 211 | ||
| @@ -217,8 +217,12 @@ shell_builtin_read(struct builtin_read_params *params) | |||
| 217 | pfd[0].events = POLLIN; | 217 | pfd[0].events = POLLIN; |
| 218 | //TODO race with a signal arriving just before the poll! | 218 | //TODO race with a signal arriving just before the poll! |
| 219 | if (poll(pfd, 1, timeout) <= 0) { | 219 | if (poll(pfd, 1, timeout) <= 0) { |
| 220 | /* timed out, or EINTR */ | 220 | /* timed out, or some error */ |
| 221 | err = errno; | 221 | err = errno; |
| 222 | if (!err) { | ||
| 223 | retval = (const char *)(uintptr_t)2; | ||
| 224 | break; | ||
| 225 | } | ||
| 222 | retval = (const char *)(uintptr_t)1; | 226 | retval = (const char *)(uintptr_t)1; |
| 223 | goto ret; | 227 | goto ret; |
| 224 | } | 228 | } |
