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
This commit is contained in:
parent
a2866b2ef9
commit
3d08935d6a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=86042
@ -32,6 +32,7 @@ char *copyright =
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -157,6 +158,7 @@ char *argv[];
|
|||||||
int topn = Default_TOPN;
|
int topn = Default_TOPN;
|
||||||
int delay = Default_DELAY;
|
int delay = Default_DELAY;
|
||||||
int displays = 0; /* indicates unspecified */
|
int displays = 0; /* indicates unspecified */
|
||||||
|
int sel_ret = 0;
|
||||||
time_t curr_time;
|
time_t curr_time;
|
||||||
char *(*get_userid)() = username;
|
char *(*get_userid)() = username;
|
||||||
char *uname_field = "USERNAME";
|
char *uname_field = "USERNAME";
|
||||||
@ -711,7 +713,10 @@ Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n",
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* wait for either input or the end of the delay period */
|
/* 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;
|
int newval;
|
||||||
char *errmsg;
|
char *errmsg;
|
||||||
@ -721,7 +726,8 @@ Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n",
|
|||||||
|
|
||||||
/* now read it and convert to command strchr */
|
/* now read it and convert to command strchr */
|
||||||
/* (use "change" as a temporary to hold 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 ((iptr = strchr(command_chars, ch)) == NULL)
|
||||||
{
|
{
|
||||||
if (ch != '\r' && ch != '\n')
|
if (ch != '\r' && ch != '\n')
|
||||||
|
Loading…
Reference in New Issue
Block a user