From cb52c77eb8d7c6943caebbd5332184604dd23a03 Mon Sep 17 00:00:00 2001 From: Mohammad Alsaleh Date: Wed, 31 Oct 2012 12:13:26 +0300 Subject: [PATCH] Revert "ping,ping6: Check return value of write(2) for stdout." This reverts commit 8feb586c4c6df32badb159947ed233898891aecd. Until upstream provides a fix. The reverted commit broke "ping -f" in addition to maxing CPU usage and unresponsiveness towards SIGINT. --- ping.c | 10 +++++----- ping6.c | 6 +++--- ping_common.c | 8 ++++---- ping_common.h | 12 ------------ 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/ping.c b/ping.c index 550a039..3ab2ae0 100644 --- a/ping.c +++ b/ping.c @@ -580,7 +580,7 @@ int receive_error_msg() if (options & F_QUIET) goto out; if (options & F_FLOOD) - write_stdout("E", 1); + write(STDOUT_FILENO, "E", 1); else if (e->ee_errno != EMSGSIZE) fprintf(stderr, "ping: local error: %s\n", strerror(e->ee_errno)); else @@ -616,7 +616,7 @@ int receive_error_msg() if (options & F_QUIET) goto out; if (options & F_FLOOD) { - write_stdout("\bE", 2); + write(STDOUT_FILENO, "\bE", 2); } else { print_timestamp(); printf("From %s icmp_seq=%u ", pr_addr(sin->sin_addr.s_addr), ntohs(icmph.un.echo.sequence)); @@ -789,7 +789,7 @@ parse_reply(struct msghdr *msg, int cc, void *addr, struct timeval *tv) return !error_pkt; if (options & F_FLOOD) { if (error_pkt) - write_stdout("\bE", 2); + write(STDOUT_FILENO, "\bE", 2); return !error_pkt; } print_timestamp(); @@ -807,9 +807,9 @@ parse_reply(struct msghdr *msg, int cc, void *addr, struct timeval *tv) } if ((options & F_FLOOD) && !(options & (F_VERBOSE|F_QUIET))) { if (!csfailed) - write_stdout("!E", 2); + write(STDOUT_FILENO, "!E", 2); else - write_stdout("!EC", 3); + write(STDOUT_FILENO, "!EC", 3); return 0; } if (!(options & F_VERBOSE) || uid) diff --git a/ping6.c b/ping6.c index 81417f1..d7bc645 100644 --- a/ping6.c +++ b/ping6.c @@ -1077,7 +1077,7 @@ int receive_error_msg() if (options & F_QUIET) goto out; if (options & F_FLOOD) - write_stdout("E", 1); + write(STDOUT_FILENO, "E", 1); else if (e->ee_errno != EMSGSIZE) fprintf(stderr, "ping: local error: %s\n", strerror(e->ee_errno)); else @@ -1100,7 +1100,7 @@ int receive_error_msg() if (options & F_QUIET) goto out; if (options & F_FLOOD) { - write_stdout("\bE", 2); + write(STDOUT_FILENO, "\bE", 2); } else { print_timestamp(); printf("From %s icmp_seq=%u ", pr_addr(&sin6->sin6_addr), ntohs(icmph.icmp6_seq)); @@ -1448,7 +1448,7 @@ parse_reply(struct msghdr *msg, int cc, void *addr, struct timeval *tv) return 0; nerrors++; if (options & F_FLOOD) { - write_stdout("\bE", 2); + write(STDOUT_FILENO, "\bE", 2); return 0; } print_timestamp(); diff --git a/ping_common.c b/ping_common.c index 9e133c5..287d0e6 100644 --- a/ping_common.c +++ b/ping_common.c @@ -371,7 +371,7 @@ resend: * high preload or pipe size is very confusing. */ if ((preload < screen_width && pipesize < screen_width) || in_flight() < screen_width) - write_stdout(".", 1); + write(STDOUT_FILENO, ".", 1); } return interval - tokens; } @@ -424,7 +424,7 @@ resend: if (i == 0 && !(options & F_QUIET)) { if (options & F_FLOOD) - write_stdout("E", 1); + write(STDOUT_FILENO, "E", 1); else perror("ping: sendmsg"); } @@ -765,9 +765,9 @@ restamp: if (options & F_FLOOD) { if (!csfailed) - write_stdout("\b \b", 3); + write(STDOUT_FILENO, "\b \b", 3); else - write_stdout("\bC", 1); + write(STDOUT_FILENO, "\bC", 1); } else { int i; __u8 *cp, *dp; diff --git a/ping_common.h b/ping_common.h index d2a2b5c..bd61c3b 100644 --- a/ping_common.h +++ b/ping_common.h @@ -130,18 +130,6 @@ case 'D': case 'O': #define COMMON_OPTSTR "h?VQ:I:M:aUc:dfi:w:l:S:np:qrs:vLt:AW:Bm:DO" -/* - * Write to stdout - */ -static inline void write_stdout(const char *str, size_t len) -{ - size_t o = 0; - ssize_t cc; - do { - cc = write(STDOUT_FILENO, str + o, len - o); - o += cc; - } while (len >= o || cc < 0); -} /* * tvsub -- -- 1.8.0