diff options
-rw-r--r-- | usr.bin/top/display.c | 13 | ||||
-rw-r--r-- | usr.bin/top/top.c | 31 |
2 files changed, 38 insertions, 6 deletions
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index ef8bb8e00d6..b540bdee4db 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -1,4 +1,4 @@ -/* $OpenBSD: display.c,v 1.16 2003/06/19 22:40:45 millert Exp $ */ +/* $OpenBSD: display.c,v 1.17 2003/11/01 20:20:57 deraadt Exp $ */ /* * Top users/processes display for Unix @@ -50,6 +50,7 @@ #include <ctype.h> #include <stdlib.h> #include <string.h> +#include <signal.h> #include <term.h> #include <time.h> #include <unistd.h> @@ -756,12 +757,20 @@ int readline(char *buffer, int size, int numeric) { char *ptr = buffer, ch, cnt = 0, maxcnt = 0; + extern volatile sig_atomic_t leaveflag; + ssize_t len; /* allow room for null terminator */ size -= 1; /* read loop */ - while ((fflush(stdout), read(0, ptr, 1) > 0)) { + while ((fflush(stdout), (len = read(0, ptr, 1)) > 0)) { + + if (len == 0 || leaveflag) { + end_screen(); + exit(0); + } + /* newline means we are done */ if ((ch = *ptr) == '\n') break; diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index ea4ac0d9a3b..5fc68516e1c 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -1,4 +1,4 @@ -/* $OpenBSD: top.c,v 1.29 2003/09/19 10:32:24 jmc Exp $ */ +/* $OpenBSD: top.c,v 1.30 2003/11/01 20:20:57 deraadt Exp $ */ /* * Top users/processes display for Unix @@ -362,6 +362,7 @@ main(int argc, char *argv[]) sigprocmask(SIG_BLOCK, &mask, &oldmask); init_screen(); (void) signal(SIGINT, leave); + siginterrupt(SIGINT, 1); (void) signal(SIGQUIT, leave); (void) signal(SIGTSTP, tstop); (void) signal(SIGWINCH, winch); @@ -562,6 +563,7 @@ rundisplay(void) */ if (poll(pfd, 1, delay * 1000) > 0) { char *errmsg; + ssize_t len; int newval; clear_message(); @@ -570,7 +572,14 @@ rundisplay(void) * now read it and convert to * command strchr */ - (void) read(0, &ch, 1); + while (1) { + len = read(0, &ch, 1); + if (len == -1 && errno == EINTR) + continue; + if (len == 0) + exit(1); + break; + } if ((iptr = strchr(command_chars, ch)) == NULL) { /* illegal command */ new_message(MT_standout, " Command not understood"); @@ -620,7 +629,14 @@ rundisplay(void) show_help(); standout("Hit any key to continue: "); fflush(stdout); - (void) read(0, &ch, 1); + while (1) { + len = read(0, &ch, 1); + if (len == -1 && errno == EINTR) + continue; + if (len == 0) + exit(1); + break; + } break; case CMD_errors: /* show errors */ @@ -636,7 +652,14 @@ rundisplay(void) show_errors(); standout("Hit any key to continue: "); fflush(stdout); - (void) read(0, &ch, 1); + while (1) { + len = read(0, &ch, 1); + if (len == -1 && errno == EINTR) + continue; + if (len == 0) + exit(1); + break; + } } break; |