From 775b00744050ad3fa8bc63a93087d578c9ef36f3 Mon Sep 17 00:00:00 2001 From: Guido van Rooij Date: Wed, 26 Sep 2001 19:35:03 +0000 Subject: [PATCH] Redo patch in 1.22 such that the header printing is reset when the process gets a SIGCONT Reviewed by: kris@freebs.org MFC after: 2 weeks --- usr.sbin/iostat/iostat.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/usr.sbin/iostat/iostat.c b/usr.sbin/iostat/iostat.c index 672c468629a2..d11909ac719f 100644 --- a/usr.sbin/iostat/iostat.c +++ b/usr.sbin/iostat/iostat.c @@ -109,7 +109,6 @@ #include #include #include -#include #include #include #include @@ -135,13 +134,13 @@ struct statinfo cur, last; int num_devices; struct device_selection *dev_select; int maxshowdevs; +volatile sig_atomic_t headercount; int dflag = 0, Iflag = 0, Cflag = 0, Tflag = 0, oflag = 0, Kflag = 0; -volatile sig_atomic_t phdr_flag = 0; /* local function declarations */ static void usage(void); -static void phdr(int signo); -static void do_phdr(); +static void needhdr(int signo); +static void phdr(void); static void devstats(int perf_select, long double etime, int havelast); static void cpustats(void); static int readvar(kvm_t *kd, const char *name, int nlid, void *ptr, @@ -173,7 +172,6 @@ main(int argc, char **argv) int num_matches = 0; char errbuf[_POSIX2_LINE_MAX]; kvm_t *kd = NULL; - int headercount; long generation; int num_devices_specified; int num_selected, num_selections; @@ -419,7 +417,7 @@ main(int argc, char **argv) * If the user stops the program (control-Z) and then resumes it, * print out the header again. */ - (void)signal(SIGCONT, phdr); + (void)signal(SIGCONT, needhdr); for (headercount = 1;;) { struct devinfo *tmp_dinfo; @@ -436,11 +434,6 @@ main(int argc, char **argv) } } - if (phdr_flag) { - phdr_flag = 0; - do_phdr(); - } - if (Cflag > 0) { if (readvar(kd, "kern.cp_time", X_CP_TIME, &cur.cp_time, sizeof(cur.cp_time)) != 0) { @@ -450,7 +443,7 @@ main(int argc, char **argv) } if (!--headercount) { - do_phdr(); + phdr(); headercount = 20; } @@ -492,7 +485,7 @@ main(int argc, char **argv) errx(1, "%s", devstat_errbuf); break; case 1: - do_phdr(); + phdr(); headercount = 20; break; default: @@ -527,7 +520,7 @@ main(int argc, char **argv) errx(1,"%s", devstat_errbuf); break; case 1: - do_phdr(); + phdr(); headercount = 20; break; default: @@ -577,15 +570,18 @@ main(int argc, char **argv) exit(0); } -static void -phdr(int signo) +/* + * Force a header to be prepended to the next output. + */ +void +needhdr(int signo) { - - phdr_flag = 1; + + headercount = 1; } static void -do_phdr() +phdr(void) { register int i; int printed; @@ -637,6 +633,7 @@ do_phdr() (void)printf(" us ni sy in id\n"); else printf("\n"); + } static void