From: Sebastien GODARD Date: Sat, 31 Oct 2020 13:58:51 +0000 (+0100) Subject: Fix #253: Make sure setbuf() is the first operation on stream X-Git-Tag: v12.5.1~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=121aba7042b92b83833cba45bdc876963daa419c;p=sysstat Fix #253: Make sure setbuf() is the first operation on stream Required by musl-c. Signed-off-by: Sebastien GODARD --- diff --git a/cifsiostat.c b/cifsiostat.c index 62488d1..52e9cab 100644 --- a/cifsiostat.c +++ b/cifsiostat.c @@ -449,9 +449,6 @@ void rw_io_stat_loop(long int count, struct tm *rectime) sigaction(SIGALRM, &alrm_act, NULL); alarm(interval); - /* Don't buffer data if redirected to a pipe */ - setbuf(stdout, NULL); - do { /* Every device is potentially nonexistent */ set_cifs_nonexistent(cifs_list); @@ -605,6 +602,13 @@ int main(int argc, char **argv) get_localtime(&rectime, 0); + /* + * Don't buffer data if redirected to a pipe. + * Note: With musl-c, the behavior of this function is undefined except + * when it is the first operation on the stream. + */ + setbuf(stdout, NULL); + /* Get system name, release number and hostname */ __uname(&header); if (print_gal_header(&rectime, header.sysname, header.release, diff --git a/iostat.c b/iostat.c index f90a387..6eb5ce5 100644 --- a/iostat.c +++ b/iostat.c @@ -1938,9 +1938,6 @@ void rw_io_stat_loop(long int count, struct tm *rectime) int_act.sa_handler = int_handler; sigaction(SIGINT, &int_act, NULL); - /* Don't buffer data if redirected to a pipe */ - setbuf(stdout, NULL); - do { /* Every device is potentially nonexistent */ set_devices_nonexistent(dev_list); @@ -2332,6 +2329,13 @@ int main(int argc, char **argv) get_localtime(&rectime, 0); + /* + * Don't buffer data if redirected to a pipe. + * Note: With musl-c, the behavior of this function is undefined except + * when it is the first operation on the stream. + */ + setbuf(stdout, NULL); + /* Get system name, release number and hostname */ __uname(&header); if (print_gal_header(&rectime, header.sysname, header.release, diff --git a/mpstat.c b/mpstat.c index 9071d51..bcef52c 100644 --- a/mpstat.c +++ b/mpstat.c @@ -1889,9 +1889,6 @@ void rw_mpstat_loop(int dis_hdr, int rows) int curr = 1, dis = 1; unsigned long lines = rows; - /* Dont buffer data if redirected to a pipe */ - setbuf(stdout, NULL); - /* Read system uptime and CPU stats */ read_uptime(&(uptime_cs[0])); read_stat_cpu(st_cpu[0], cpu_nr + 1); @@ -2313,6 +2310,13 @@ int main(int argc, char **argv) /* Get time */ get_localtime(&(mp_tstamp[0]), 0); + /* + * Don't buffer data if redirected to a pipe. + * Note: With musl-c, the behavior of this function is undefined except + * when it is the first operation on the stream. + */ + setbuf(stdout, NULL); + /* Get system name, release number and hostname */ __uname(&header); print_gal_header(&(mp_tstamp[0]), header.sysname, header.release, diff --git a/pidstat.c b/pidstat.c index 3e326f4..799a1fc 100644 --- a/pidstat.c +++ b/pidstat.c @@ -2354,9 +2354,6 @@ void rw_pidstat_loop(int dis_hdr, int rows) unsigned long lines = rows; struct st_pid *plist; - /* Don't buffer data if redirected to a pipe */ - setbuf(stdout, NULL); - /* Read system uptime */ read_uptime(&uptime_cs[0]); read_stats(0); @@ -2801,6 +2798,13 @@ int main(int argc, char **argv) /* Get time */ get_localtime(&(ps_tstamp[0]), 0); + /* + * Don't buffer data if redirected to a pipe. + * Note: With musl-c, the behavior of this function is undefined except + * when it is the first operation on the stream. + */ + setbuf(stdout, NULL); + /* Get system name, release number and hostname */ __uname(&header); print_gal_header(&(ps_tstamp[0]), header.sysname, header.release, diff --git a/tapestat.c b/tapestat.c index f3e7c17..3d5795e 100644 --- a/tapestat.c +++ b/tapestat.c @@ -559,9 +559,6 @@ void rw_tape_stat_loop(long int count, struct tm *rectime) skip = 1; } - /* Don't buffer data if redirected to a pipe */ - setbuf(stdout, NULL); - do { if (tape_new_stats == NULL) { @@ -703,6 +700,13 @@ int main(int argc, char **argv) get_localtime(&rectime, 0); + /* + * Don't buffer data if redirected to a pipe. + * Note: With musl-c, the behavior of this function is undefined except + * when it is the first operation on the stream. + */ + setbuf(stdout, NULL); + /* Get system name, release number and hostname */ __uname(&header); if (print_gal_header(&rectime, header.sysname, header.release,