diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-11 10:10:15 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-11 10:10:15 +0000 |
commit | 4f95e5aab8d6a2d827d3fe937cf2c72229f6955e (patch) | |
tree | 3985763ee17b6bb2a75c0143f61dc21f1384cf02 | |
parent | f9566d8c29a820e94f194a9ac303c912899e6c8a (diff) | |
download | busybox-w32-4f95e5aab8d6a2d827d3fe937cf2c72229f6955e.tar.gz busybox-w32-4f95e5aab8d6a2d827d3fe937cf2c72229f6955e.tar.bz2 busybox-w32-4f95e5aab8d6a2d827d3fe937cf2c72229f6955e.zip |
vi: don't wait 50 ms before reading ESC sequences
inetd,syslogd: use safe_read instead of open-coded EINTR handling
syslogd: bail out if you see null read from Unix socket
(should never happen, but if it does, spinning forever
and eating 100% CPU is not a good idea)
-rw-r--r-- | editors/vi.c | 19 | ||||
-rw-r--r-- | networking/inetd.c | 3 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 8 |
3 files changed, 12 insertions, 18 deletions
diff --git a/editors/vi.c b/editors/vi.c index 249bf29bf..345a9452d 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -2152,7 +2152,7 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2152 | char c; | 2152 | char c; |
2153 | int n; | 2153 | int n; |
2154 | struct esc_cmds { | 2154 | struct esc_cmds { |
2155 | const char *seq; | 2155 | const char seq[4]; |
2156 | char val; | 2156 | char val; |
2157 | }; | 2157 | }; |
2158 | 2158 | ||
@@ -2178,6 +2178,7 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2178 | {"OQ", VI_K_FUN2}, // Function Key F2 | 2178 | {"OQ", VI_K_FUN2}, // Function Key F2 |
2179 | {"OR", VI_K_FUN3}, // Function Key F3 | 2179 | {"OR", VI_K_FUN3}, // Function Key F3 |
2180 | {"OS", VI_K_FUN4}, // Function Key F4 | 2180 | {"OS", VI_K_FUN4}, // Function Key F4 |
2181 | // careful: these have no terminating NUL! | ||
2181 | {"[15~", VI_K_FUN5}, // Function Key F5 | 2182 | {"[15~", VI_K_FUN5}, // Function Key F5 |
2182 | {"[17~", VI_K_FUN6}, // Function Key F6 | 2183 | {"[17~", VI_K_FUN6}, // Function Key F6 |
2183 | {"[18~", VI_K_FUN7}, // Function Key F7 | 2184 | {"[18~", VI_K_FUN7}, // Function Key F7 |
@@ -2198,12 +2199,9 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2198 | n = readed_for_parse; | 2199 | n = readed_for_parse; |
2199 | // get input from User- are there already input chars in Q? | 2200 | // get input from User- are there already input chars in Q? |
2200 | if (n <= 0) { | 2201 | if (n <= 0) { |
2201 | ri0: | ||
2202 | // the Q is empty, wait for a typed char | 2202 | // the Q is empty, wait for a typed char |
2203 | n = read(0, readbuffer, MAX_LINELEN - 1); | 2203 | n = safe_read(0, readbuffer, MAX_LINELEN - 1); |
2204 | if (n < 0) { | 2204 | if (n < 0) { |
2205 | if (errno == EINTR) | ||
2206 | goto ri0; // interrupted sys call | ||
2207 | if (errno == EBADF || errno == EFAULT || errno == EINVAL | 2205 | if (errno == EBADF || errno == EFAULT || errno == EINVAL |
2208 | || errno == EIO) | 2206 | || errno == EIO) |
2209 | editing = 0; | 2207 | editing = 0; |
@@ -2219,11 +2217,10 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2219 | struct pollfd pfd[1]; | 2217 | struct pollfd pfd[1]; |
2220 | pfd[0].fd = 0; | 2218 | pfd[0].fd = 0; |
2221 | pfd[0].events = POLLIN; | 2219 | pfd[0].events = POLLIN; |
2222 | // Wait 50 ms | ||
2223 | // keep reading while there are input chars and room in buffer | 2220 | // keep reading while there are input chars and room in buffer |
2224 | while (safe_poll(pfd, 1, 50) > 0 && n <= (MAX_LINELEN - 5)) { | 2221 | while (safe_poll(pfd, 1, 0) > 0 && n <= (MAX_LINELEN - 5)) { |
2225 | // read the rest of the ESC string | 2222 | // read the rest of the ESC string |
2226 | int r = read(0, readbuffer + n, MAX_LINELEN - n); | 2223 | int r = safe_read(0, readbuffer + n, MAX_LINELEN - n); |
2227 | if (r > 0) | 2224 | if (r > 0) |
2228 | n += r; | 2225 | n += r; |
2229 | } | 2226 | } |
@@ -2236,7 +2233,7 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2236 | const struct esc_cmds *eindex; | 2233 | const struct esc_cmds *eindex; |
2237 | 2234 | ||
2238 | for (eindex = esccmds; eindex < &esccmds[ESCCMDS_COUNT]; eindex++) { | 2235 | for (eindex = esccmds; eindex < &esccmds[ESCCMDS_COUNT]; eindex++) { |
2239 | int cnt = strlen(eindex->seq); | 2236 | int cnt = strnlen(eindex->seq, 4); |
2240 | 2237 | ||
2241 | if (n <= cnt) | 2238 | if (n <= cnt) |
2242 | continue; | 2239 | continue; |
@@ -2397,7 +2394,7 @@ static int file_insert(const char * fn, char *p | |||
2397 | p = text_hole_make(p, size); | 2394 | p = text_hole_make(p, size); |
2398 | if (p == NULL) | 2395 | if (p == NULL) |
2399 | goto fi0; | 2396 | goto fi0; |
2400 | cnt = read(fd, p, size); | 2397 | cnt = safe_read(fd, p, size); |
2401 | if (cnt < 0) { | 2398 | if (cnt < 0) { |
2402 | psbs("\"%s\" %s", fn, strerror(errno)); | 2399 | psbs("\"%s\" %s", fn, strerror(errno)); |
2403 | p = text_hole_delete(p, p + size - 1); // un-do buffer insert | 2400 | p = text_hole_delete(p, p + size - 1); // un-do buffer insert |
@@ -3961,7 +3958,7 @@ static void crash_test() | |||
3961 | printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s", | 3958 | printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s", |
3962 | totalcmds, last_input_char, msg, SOs, SOn); | 3959 | totalcmds, last_input_char, msg, SOs, SOn); |
3963 | fflush(stdout); | 3960 | fflush(stdout); |
3964 | while (read(0, d, 1) > 0) { | 3961 | while (safe_read(0, d, 1) > 0) { |
3965 | if (d[0] == '\n' || d[0] == '\r') | 3962 | if (d[0] == '\n' || d[0] == '\r') |
3966 | break; | 3963 | break; |
3967 | } | 3964 | } |
diff --git a/networking/inetd.c b/networking/inetd.c index 9ea7f9cc1..8dca8fc3c 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -1638,8 +1638,7 @@ discard_stream(int s, servtab_t *sep) | |||
1638 | 1638 | ||
1639 | inetd_setproctitle(sep->se_service, s); | 1639 | inetd_setproctitle(sep->se_service, s); |
1640 | while (1) { | 1640 | while (1) { |
1641 | errno = 0; | 1641 | if (safe_read(s, buffer, sizeof(buffer)) <= 0) |
1642 | if (read(s, buffer, sizeof(buffer)) <= 0 && errno != EINTR) | ||
1643 | exit(0); | 1642 | exit(0); |
1644 | } | 1643 | } |
1645 | } | 1644 | } |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 284e5743c..ba46792b6 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -527,12 +527,10 @@ static void do_syslogd(void) | |||
527 | for (;;) { | 527 | for (;;) { |
528 | size_t sz; | 528 | size_t sz; |
529 | 529 | ||
530 | sz = read(sock_fd, G.recvbuf, MAX_READ - 1); | 530 | sz = safe_read(sock_fd, G.recvbuf, MAX_READ - 1); |
531 | if (sz <= 0) { | 531 | if (sz <= 0) { |
532 | if (sz == 0) | 532 | //if (sz == 0) |
533 | continue; /* EOF from unix socket??? */ | 533 | // continue; /* EOF from unix socket??? */ |
534 | if (errno == EINTR) /* alarm may have happened */ | ||
535 | continue; | ||
536 | bb_perror_msg_and_die("read from /dev/log"); | 534 | bb_perror_msg_and_die("read from /dev/log"); |
537 | } | 535 | } |
538 | 536 | ||