summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authordwmalone <dwmalone@FreeBSD.org>2001-11-04 21:15:52 +0000
committerdwmalone <dwmalone@FreeBSD.org>2001-11-04 21:15:52 +0000
commit2650f9ea1495350c4d4c119e172b59ab1af10ad4 (patch)
tree7ca9569b44063a2fb9c8cdf2f870c7664c2df54e /contrib
parent7042915fc3293e8d36347822b638b2f30095de9f (diff)
downloadFreeBSD-src-2650f9ea1495350c4d4c119e172b59ab1af10ad4.zip
FreeBSD-src-2650f9ea1495350c4d4c119e172b59ab1af10ad4.tar.gz
Make top exit if its tty vanishes.
PR: 30939, 30581 Submitted by: Edwin Groothuis <edwin@mavetju.org> Submitted by: Andrew L. Neporada <andr@dgap.mipt.ru> MFC after: 2 weeks
Diffstat (limited to 'contrib')
-rw-r--r--contrib/top/top.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/contrib/top/top.c b/contrib/top/top.c
index ef1d47f..9b9b2b2 100644
--- a/contrib/top/top.c
+++ b/contrib/top/top.c
@@ -32,6 +32,7 @@ char *copyright =
*/
#include "os.h"
+#include <errno.h>
#include <signal.h>
#include <setjmp.h>
#include <ctype.h>
@@ -157,6 +158,7 @@ char *argv[];
int topn = Default_TOPN;
int delay = Default_DELAY;
int displays = 0; /* indicates unspecified */
+ int sel_ret = 0;
time_t curr_time;
char *(*get_userid)() = username;
char *uname_field = "USERNAME";
@@ -711,7 +713,10 @@ restart:
}
/* wait for either input or the end of the delay period */
- if (select(32, &readfds, (fd_set *)NULL, (fd_set *)NULL, &timeout) > 0)
+ sel_ret = select(2, &readfds, NULL, NULL, &timeout);
+ if (sel_ret < 0 && errno != EINTR)
+ quit(0);
+ if (sel_ret > 0)
{
int newval;
char *errmsg;
@@ -721,7 +726,8 @@ restart:
/* now read it and convert to command strchr */
/* (use "change" as a temporary to hold strchr) */
- (void) read(0, &ch, 1);
+ if (read(0, &ch, 1) != 1)
+ quit(0);
if ((iptr = strchr(command_chars, ch)) == NULL)
{
if (ch != '\r' && ch != '\n')
OpenPOWER on IntegriCloud