From d065b3eb9ed6785a19dc7d96fb34a0050747c663 Mon Sep 17 00:00:00 2001 From: Maxim Sobolev Date: Mon, 24 Aug 2020 16:45:23 +0000 Subject: [PATCH] In the endless batch mode (-B), terminate if and when stdout is closed. That mode is useful to call gstat from other app, however kinda useless since gstat won't exit and stay running forever when its parent process has long gone. MFC after: 2 weeks --- usr.sbin/gstat/gstat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/usr.sbin/gstat/gstat.c b/usr.sbin/gstat/gstat.c index 1c75fd5bf2d..c2d28720205 100644 --- a/usr.sbin/gstat/gstat.c +++ b/usr.sbin/gstat/gstat.c @@ -517,7 +517,8 @@ main(int argc, char **argv) if (!flag_B) loop = 0; else - fflush(stdout); + if (fflush(stdout) == EOF) + goto out; usleep(flag_I); continue; } @@ -585,7 +586,7 @@ main(int argc, char **argv) } } } - +out: if (!flag_b) { el_end(el); endwin();