From cb23d93c6845df3f2733a32caa4194e60ef871a7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 12 Jan 2010 12:29:55 +0100 Subject: [PATCH] *: add/remove safe_, it seems we had a few incorrect uses function old new delta chat_main 1359 1361 +2 microcom_main 712 713 +1 ifplugd_main 1109 1110 +1 arpping 465 466 +1 acpid_main 440 441 +1 script_main 1069 1067 -2 cgi_io_loop_and_exit 594 591 -3 telnet_main 1475 1469 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/3 up/down: 6/-11) Total: -5 bytes Signed-off-by: Denys Vlasenko --- miscutils/microcom.c | 7 ++++--- networking/httpd.c | 6 +++--- networking/telnet.c | 8 ++++---- networking/udhcp/arpping.c | 2 +- util-linux/script.c | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/miscutils/microcom.c b/miscutils/microcom.c index fe6661f00..9a7a41d53 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c @@ -117,8 +117,9 @@ int microcom_main(int argc UNUSED_PARAM, char **argv) bb_got_signal = 0; nfd = 2; - while (!bb_got_signal && safe_poll(pfd, nfd, timeout) > 0) { - if (nfd > 1 && pfd[1].revents) { + // Not safe_poll: we want to exit on signal + while (!bb_got_signal && poll(pfd, nfd, timeout) > 0) { + if (nfd > 1 && (pfd[1].revents & POLLIN)) { char c; // read from stdin -> write to device if (safe_read(STDIN_FILENO, &c, 1) < 1) { @@ -142,7 +143,7 @@ int microcom_main(int argc UNUSED_PARAM, char **argv) safe_poll(pfd, 1, delay); skip_write: ; } - if (pfd[0].revents) { + if (pfd[0].revents & POLLIN) { #define iobuf bb_common_bufsiz1 ssize_t len; // read from device -> write to stdout diff --git a/networking/httpd.c b/networking/httpd.c index 0a8322c88..227803abf 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -1167,7 +1167,7 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post break; } - if (pfd[TO_CGI].revents) { + if (pfd[TO_CGI].revents & POLLOUT) { /* hdr_cnt > 0 here due to the way pfd[TO_CGI].events set */ /* Have data from peer and can write to CGI */ count = safe_write(toCgi_wr, hdr_ptr, hdr_cnt); @@ -1184,7 +1184,7 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post } } - if (pfd[0].revents) { + if (pfd[0].revents & POLLIN) { /* post_len > 0 && hdr_cnt == 0 here */ /* We expect data, prev data portion is eaten by CGI * and there *is* data to read from the peer @@ -1202,7 +1202,7 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post } } - if (pfd[FROM_CGI].revents) { + if (pfd[FROM_CGI].revents & POLLIN) { /* There is something to read from CGI */ char *rbuf = iobuf; diff --git a/networking/telnet.c b/networking/telnet.c index 77e17479d..013d959a1 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -618,12 +618,12 @@ int telnet_main(int argc UNUSED_PARAM, char **argv) default: #ifdef USE_POLL - if (ufds[0].revents) /* well, should check POLLIN, but ... */ + if (ufds[0].revents & POLLIN) #else if (FD_ISSET(STDIN_FILENO, &rfds)) #endif { - len = read(STDIN_FILENO, G.buf, DATABUFSIZE); + len = safe_read(STDIN_FILENO, G.buf, DATABUFSIZE); if (len <= 0) doexit(EXIT_SUCCESS); TRACE(0, ("Read con: %d\n", len)); @@ -631,12 +631,12 @@ int telnet_main(int argc UNUSED_PARAM, char **argv) } #ifdef USE_POLL - if (ufds[1].revents) /* well, should check POLLIN, but ... */ + if (ufds[1].revents & POLLIN) #else if (FD_ISSET(netfd, &rfds)) #endif { - len = read(netfd, G.buf, DATABUFSIZE); + len = safe_read(netfd, G.buf, DATABUFSIZE); if (len <= 0) { write_str(1, "Connection closed by foreign host\r\n"); doexit(EXIT_FAILURE); diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c index 3df0f39b7..4af8534bd 100644 --- a/networking/udhcp/arpping.c +++ b/networking/udhcp/arpping.c @@ -95,7 +95,7 @@ int FAST_FUNC arpping(uint32_t test_nip, if (r < 0) break; if (r) { - r = read(s, &arp, sizeof(arp)); + r = safe_read(s, &arp, sizeof(arp)); if (r < 0) break; diff --git a/util-linux/script.c b/util-linux/script.c index d9a62fbfe..37213eec8 100644 --- a/util-linux/script.c +++ b/util-linux/script.c @@ -119,7 +119,7 @@ int script_main(int argc UNUSED_PARAM, char **argv) * for example, try "script -c true" */ break; } - if (pfd[0].revents) { + if (pfd[0].revents & POLLIN) { errno = 0; count = safe_read(pty, buf, sizeof(buf)); if (count <= 0 && errno != EAGAIN) { @@ -143,7 +143,7 @@ int script_main(int argc UNUSED_PARAM, char **argv) } } } - if (pfd[1].revents) { + if (pfd[1].revents & POLLIN) { count = safe_read(STDIN_FILENO, buf, sizeof(buf)); if (count <= 0) { /* err/eof from stdin: don't read stdin anymore */