summaryrefslogtreecommitdiff
path: root/usr.bin/top/display.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-11-01 20:20:58 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-11-01 20:20:58 +0000
commitc70122c4a86c06a4084c199b961034a4d9f71423 (patch)
tree52b03f20b9beb90e689f402a83ef554277146b4b /usr.bin/top/display.c
parent40d744ca66751391cbefc0f7df8a8b14f45b6172 (diff)
process signals at the right time. also handle stdin failure better;
millert looked at it..
Diffstat (limited to 'usr.bin/top/display.c')
-rw-r--r--usr.bin/top/display.c13
1 files changed, 11 insertions, 2 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;