diff options
author | Denys Vlasenko | 2011-05-11 11:49:21 +0200 |
---|---|---|
committer | Denys Vlasenko | 2011-05-11 11:49:21 +0200 |
commit | 10c0131a8a1b3db7fd6b23b72ebd7b33afc7b018 (patch) | |
tree | 88b6afcd3614a43db767780f48a288d868cf2289 /shell/shell_common.c | |
parent | 12bc152b31420c3e3d441c87a995fe7b65dd23fe (diff) | |
download | busybox-10c0131a8a1b3db7fd6b23b72ebd7b33afc7b018.zip busybox-10c0131a8a1b3db7fd6b23b72ebd7b33afc7b018.tar.gz |
hush: use SA_RESTARTed signal handlers across read.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/shell_common.c')
-rw-r--r-- | shell/shell_common.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/shell/shell_common.c b/shell/shell_common.c index a5c455c..bbc22ed 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -159,32 +159,40 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val), bufpos = 0; do { char c; + struct pollfd pfd[1]; + int timeout; - errno = 0; + if ((bufpos & 0xff) == 0) + buffer = xrealloc(buffer, bufpos + 0x100); + timeout = -1; if (end_ms) { - int timeout; - struct pollfd pfd[1]; - - pfd[0].fd = fd; - pfd[0].events = POLLIN; timeout = end_ms - (unsigned)monotonic_ms(); - if (timeout <= 0 /* already late? */ - || poll(pfd, 1, timeout) != 1 /* no? wait... */ - ) { /* timed out! */ - err = errno; + if (timeout <= 0) { /* already late? */ retval = (const char *)(uintptr_t)1; goto ret; } } - if ((bufpos & 0xff) == 0) - buffer = xrealloc(buffer, bufpos + 0x100); - if (nonblock_immune_read(fd, &buffer[bufpos], 1, /*loop_on_EINTR:*/ 0) != 1) { + /* We must poll even if timeout is -1: + * we want to be interrupted if signal arrives, + * regardless of SA_RESTART-ness of that signal! + */ + errno = 0; + pfd[0].fd = fd; + pfd[0].events = POLLIN; + if (poll(pfd, 1, timeout) != 1) { + /* timed out, or EINTR */ + err = errno; + retval = (const char *)(uintptr_t)1; + goto ret; + } + if (read(fd, &buffer[bufpos], 1) != 1) { err = errno; retval = (const char *)(uintptr_t)1; break; } + c = buffer[bufpos]; if (c == '\0') continue; |