aboutsummaryrefslogtreecommitdiff
path: root/shell/shell_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/shell_common.c')
-rw-r--r--shell/shell_common.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/shell/shell_common.c b/shell/shell_common.c
index e5c2cefb3..754fef34b 100644
--- a/shell/shell_common.c
+++ b/shell/shell_common.c
@@ -55,7 +55,7 @@ const char* FAST_FUNC
55shell_builtin_read(struct builtin_read_params *params) 55shell_builtin_read(struct builtin_read_params *params)
56{ 56{
57 struct pollfd pfd[1]; 57 struct pollfd pfd[1];
58#define fd (pfd[0].fd) /* -u FD */ 58#define fd (pfd->fd) /* -u FD */
59 unsigned err; 59 unsigned err;
60 unsigned end_ms; /* -t TIMEOUT */ 60 unsigned end_ms; /* -t TIMEOUT */
61 int nchars; /* -n NUM */ 61 int nchars; /* -n NUM */
@@ -142,7 +142,7 @@ shell_builtin_read(struct builtin_read_params *params)
142 * bash seems to ignore -p PROMPT for this use case. 142 * bash seems to ignore -p PROMPT for this use case.
143 */ 143 */
144 int r; 144 int r;
145 pfd[0].events = POLLIN; 145 pfd->events = POLLIN;
146 r = poll(pfd, 1, /*timeout:*/ 0); 146 r = poll(pfd, 1, /*timeout:*/ 0);
147 /* Return 0 only if poll returns 1 ("one fd ready"), else return 1: */ 147 /* Return 0 only if poll returns 1 ("one fd ready"), else return 1: */
148 return (const char *)(uintptr_t)(r <= 0); 148 return (const char *)(uintptr_t)(r <= 0);
@@ -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
@@ -214,11 +214,16 @@ shell_builtin_read(struct builtin_read_params *params)
214 * regardless of SA_RESTART-ness of that signal! 214 * regardless of SA_RESTART-ness of that signal!
215 */ 215 */
216 errno = 0; 216 errno = 0;
217 pfd[0].events = POLLIN; 217 pfd->events = POLLIN;
218//TODO race with a signal arriving just before the poll! 218
219 if (poll(pfd, 1, timeout) <= 0) { 219 /* test bb_got_signal, then poll(), atomically wrt signals */
220 /* timed out, or EINTR */ 220 if (check_got_signal_and_poll(pfd, timeout) <= 0) {
221 /* timed out, or some error */
221 err = errno; 222 err = errno;
223 if (!err) { /* timed out */
224 retval = (const char *)(uintptr_t)2;
225 break;
226 }
222 retval = (const char *)(uintptr_t)1; 227 retval = (const char *)(uintptr_t)1;
223 goto ret; 228 goto ret;
224 } 229 }