aboutsummaryrefslogtreecommitdiff
path: root/shell/shell_common.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2025-07-01 09:16:20 +0100
committerRon Yorston <rmy@pobox.com>2025-07-01 09:16:20 +0100
commit4835252c89966d694b919b10deb28b3851648657 (patch)
tree7eaad177e73809948b4540f1d62d822ece4751f6 /shell/shell_common.c
parentd319b435a49e52a51162ab456cde9a1b103ec299 (diff)
downloadbusybox-w32-4835252c89966d694b919b10deb28b3851648657.tar.gz
busybox-w32-4835252c89966d694b919b10deb28b3851648657.tar.bz2
busybox-w32-4835252c89966d694b919b10deb28b3851648657.zip
ash: don't mistake errors for timeouts in read built-in
Commit e07a73a15 (ash: bring 'read' built-in closer to bash) added code to treat a timeout differently from an error returned by poll(2). This falsely assumed that only an EINTR error was relevant. We must allow for other errors. Adds 16 bytes. (GitHub issue #502)
Diffstat (limited to 'shell/shell_common.c')
-rw-r--r--shell/shell_common.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/shell/shell_common.c b/shell/shell_common.c
index 2a876acac..6ea08ad74 100644
--- a/shell/shell_common.c
+++ b/shell/shell_common.c
@@ -227,20 +227,23 @@ shell_builtin_read(struct builtin_read_params *params)
227 pfd[0].events = POLLIN; 227 pfd[0].events = POLLIN;
228//TODO race with a signal arriving just before the poll! 228//TODO race with a signal arriving just before the poll!
229#if ENABLE_PLATFORM_MINGW32 229#if ENABLE_PLATFORM_MINGW32
230 /* Don't poll if timeout is -1, it hurts performance. */ 230 /* Don't poll if timeout is -1, it hurts performance. The
231 * caution above about interrupts isn't relevant on Windows
232 * where Ctrl-C causes an event, not a signal.
233 */
231 if (timeout >= 0) 234 if (timeout >= 0)
232#endif 235#endif
233 if (poll(pfd, 1, timeout) <= 0) { 236 if (poll(pfd, 1, timeout) <= 0) {
234 /* timed out, or EINTR */ 237 /* timed out, or EINTR */
235 err = errno; 238 err = errno;
236#if ENABLE_PLATFORM_MINGW32 239#if ENABLE_PLATFORM_MINGW32
237 /* Windows poll(2) doesn't do EINTR, we timed out */ 240 if (!err) {
238 retval = (const char *)(uintptr_t)2; 241 retval = (const char *)(uintptr_t)2;
239 break; 242 break;
240#else 243 }
244#endif
241 retval = (const char *)(uintptr_t)1; 245 retval = (const char *)(uintptr_t)1;
242 goto ret; 246 goto ret;
243#endif
244 } 247 }
245#if ENABLE_PLATFORM_MINGW32 248#if ENABLE_PLATFORM_MINGW32
246 if (isatty(fd)) { 249 if (isatty(fd)) {