aboutsummaryrefslogtreecommitdiff
path: root/shell/shell_common.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--shell/shell_common.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/shell/shell_common.c b/shell/shell_common.c
index 2702ef98a..657f0df8f 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 */
@@ -144,7 +144,7 @@ shell_builtin_read(struct builtin_read_params *params)
144 * bash seems to ignore -p PROMPT for this use case. 144 * bash seems to ignore -p PROMPT for this use case.
145 */ 145 */
146 int r; 146 int r;
147 pfd[0].events = POLLIN; 147 pfd->events = POLLIN;
148 r = poll(pfd, 1, /*timeout:*/ 0); 148 r = poll(pfd, 1, /*timeout:*/ 0);
149 /* Return 0 only if poll returns 1 ("one fd ready"), else return 1: */ 149 /* Return 0 only if poll returns 1 ("one fd ready"), else return 1: */
150 return (const char *)(uintptr_t)(r <= 0); 150 return (const char *)(uintptr_t)(r <= 0);
@@ -209,13 +209,8 @@ shell_builtin_read(struct builtin_read_params *params)
209 * 32-bit unix time wrapped (year 2038+). 209 * 32-bit unix time wrapped (year 2038+).
210 */ 210 */
211 if (timeout <= 0) { /* already late? */ 211 if (timeout <= 0) { /* already late? */
212#if ENABLE_PLATFORM_MINGW32
213 retval = (const char *)(uintptr_t)2; 212 retval = (const char *)(uintptr_t)2;
214 break; 213 break;
215#else
216 retval = (const char *)(uintptr_t)1;
217 goto ret;
218#endif
219 } 214 }
220 } 215 }
221 216
@@ -224,8 +219,8 @@ shell_builtin_read(struct builtin_read_params *params)
224 * regardless of SA_RESTART-ness of that signal! 219 * regardless of SA_RESTART-ness of that signal!
225 */ 220 */
226 errno = 0; 221 errno = 0;
227 pfd[0].events = POLLIN; 222 pfd->events = POLLIN;
228//TODO race with a signal arriving just before the poll! 223
229#if ENABLE_PLATFORM_MINGW32 224#if ENABLE_PLATFORM_MINGW32
230 /* Don't poll if timeout is -1, it hurts performance. The 225 /* Don't poll if timeout is -1, it hurts performance. The
231 * caution above about interrupts isn't relevant on Windows 226 * caution above about interrupts isn't relevant on Windows
@@ -233,15 +228,14 @@ shell_builtin_read(struct builtin_read_params *params)
233 */ 228 */
234 if (timeout >= 0) 229 if (timeout >= 0)
235#endif 230#endif
236 if (poll(pfd, 1, timeout) <= 0) { 231 /* test bb_got_signal, then poll(), atomically wrt signals */
237 /* timed out, or EINTR */ 232 if (check_got_signal_and_poll(pfd, timeout) <= 0) {
233 /* timed out, or some error */
238 err = errno; 234 err = errno;
239#if ENABLE_PLATFORM_MINGW32 235 if (!err) { /* timed out */
240 if (!err) {
241 retval = (const char *)(uintptr_t)2; 236 retval = (const char *)(uintptr_t)2;
242 break; 237 break;
243 } 238 }
244#endif
245 retval = (const char *)(uintptr_t)1; 239 retval = (const char *)(uintptr_t)1;
246 goto ret; 240 goto ret;
247 } 241 }