diff options
author | jh <jh@FreeBSD.org> | 2009-10-11 12:32:25 +0000 |
---|---|---|
committer | jh <jh@FreeBSD.org> | 2009-10-11 12:32:25 +0000 |
commit | 5abd9242cb6059fa0ae38155f28a39256d862ec3 (patch) | |
tree | 75dd00a6dd710c0f0a87381d10e3cf769a725993 | |
parent | 6e9ccb9f7aabc7ed6deb0119ea5eaa3bb5a4d0a2 (diff) | |
download | FreeBSD-src-5abd9242cb6059fa0ae38155f28a39256d862ec3.zip FreeBSD-src-5abd9242cb6059fa0ae38155f28a39256d862ec3.tar.gz |
- Catch SIGHUP to perform cleanup before exiting.
- Exit if getch() returns with an error other than EINTR. Otherwise
systat(1) may get stuck in an infinite loop if it doesn't receive
SIGHUP when terminal closes. [1]
- Remove attempt to clear stdio error indicators. getch() doesn't use
stdio, making it useless. [2]
- Remove unneeded masking of getch() return value. [2]
PR: bin/107171
Reviewed by: bde
Approved by: trasz (mentor)
Obtained from: OpenBSD [1]
Suggested by: bde [2]
MFC after: 1 month
-rw-r--r-- | usr.bin/systat/keyboard.c | 11 | ||||
-rw-r--r-- | usr.bin/systat/main.c | 1 |
2 files changed, 8 insertions, 4 deletions
diff --git a/usr.bin/systat/keyboard.c b/usr.bin/systat/keyboard.c index 7784f5b..0ab28eb 100644 --- a/usr.bin/systat/keyboard.c +++ b/usr.bin/systat/keyboard.c @@ -39,8 +39,10 @@ __FBSDID("$FreeBSD$"); static const char sccsid[] = "@(#)keyboard.c 8.1 (Berkeley) 6/6/93"; #endif +#include <errno.h> #include <ctype.h> #include <signal.h> +#include <stdlib.h> #include <termios.h> #include "systat.h" @@ -57,10 +59,11 @@ keyboard(void) move(CMDLINE, 0); do { refresh(); - ch = getch() & 0177; - if (ch == 0177 && ferror(stdin)) { - clearerr(stdin); - continue; + ch = getch(); + if (ch == ERR) { + if (errno == EINTR) + continue; + exit(1); } if (ch >= 'A' && ch <= 'Z') ch += 'a' - 'A'; diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c index 28673e5..6f6b994 100644 --- a/usr.bin/systat/main.c +++ b/usr.bin/systat/main.c @@ -133,6 +133,7 @@ main(int argc, char **argv) exit(1); } } + signal(SIGHUP, die); signal(SIGINT, die); signal(SIGQUIT, die); signal(SIGTERM, die); |