From efc5ed3263008bddbe8223e021ddf845aec070ec Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sat, 11 Jul 2020 15:10:39 +0200 Subject: [PATCH] Use line buffering for stdout. fixes #179 --- CHANGELOG.md | 1 + src/fping.c | 9 +-------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6befa12..bb12f71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ UNRELEASED - Macos build fix (#174, thanks @tycho) - Fix xmt stats in Netdata output (#172, thanks @vlvkobal) - Only increase num_alive if response is not a duplicate (#151, thanks @brownowski) +- Use line buffering for stdout (#179, thanks @bg6cq) fping 4.2 (2019-02-19) ====================== diff --git a/src/fping.c b/src/fping.c index a335d97..214a3ed 100644 --- a/src/fping.c +++ b/src/fping.c @@ -1031,6 +1031,7 @@ int main(int argc, char** argv) signal(SIGINT, finish); signal(SIGQUIT, sigstatus); + setlinebuf(stdout); gettimeofday(&start_time, NULL); current_time = start_time; @@ -1430,8 +1431,6 @@ void print_per_system_stats(void) HOST_ENTRY* h; int resp; - fflush(stdout); - if (verbose_flag || per_recv_flag) fprintf(stderr, "\n"); @@ -1511,8 +1510,6 @@ void print_netdata(void) int i, avg; HOST_ENTRY* h; - fflush(stdout); - for (i = 0; i < num_hosts; i++) { h = table[i]; @@ -1594,8 +1591,6 @@ void print_per_system_splits(void) HOST_ENTRY* h; struct tm* curr_tm; - fflush(stdout); - if (verbose_flag || per_recv_flag) fprintf(stderr, "\n"); @@ -1659,7 +1654,6 @@ void print_per_system_splits(void) void print_global_stats(void) { - fflush(stdout); fprintf(stderr, "\n"); fprintf(stderr, " %7d targets\n", num_hosts); fprintf(stderr, " %7d alive\n", num_alive); @@ -2299,7 +2293,6 @@ int wait_for_reply(long wait_time) remove_job(h); } - fflush(stdout); return num_jobs; }