Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Oct 2001 09:00:04 -0800 (PST)
From:      David Malone <dwmalone@maths.tcd.ie>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/30939: top(1) behaves badly when it loses terminal
Message-ID:  <200110291700.f9TH04n23113@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/30939; it has been noted by GNATS.

From: David Malone <dwmalone@maths.tcd.ie>
To: freebsd-gnats-submit@FreeBSD.org
Cc: andr@dgap.mipt.ru, charon@labs.gr
Subject: Re: bin/30939: top(1) behaves badly when it loses terminal
Date: Mon, 29 Oct 2001 16:57:03 +0000

 Here is a version of Andrew's patch which calls top's quit function
 instead of sleeping. It also checks for EINTR after selecting,
 which means that top doesn't quit when you press ^Z.
 
 I've tested this by running top in an xterm and then revoking the
 tty it is running on. Without the patch both top and xterm chew
 CPU time. With the patch they both exit nicely.
 
 I think this file is off the vendor branch already, so I'll commit
 this fix later in the week.
 
 	David.
 
 Index: top.c
 ===================================================================
 RCS file: /cvs/FreeBSD-CVS/src/contrib/top/top.c,v
 retrieving revision 1.7
 diff -u -r1.7 top.c
 --- top.c	6 Aug 2001 03:19:22 -0000	1.7
 +++ top.c	29 Oct 2001 16:06:33 -0000
 @@ -32,6 +32,7 @@
   */
  
  #include "os.h"
 +#include <errno.h>
  #include <signal.h>
  #include <setjmp.h>
  #include <ctype.h>
 @@ -157,6 +158,7 @@
      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 @@
  		}
  
  		/* 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 @@
  
  		    /* 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')

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200110291700.f9TH04n23113>