From owner-freebsd-bugs Mon Oct 29 9: 0:15 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 34B3C37B40A for ; Mon, 29 Oct 2001 09:00:04 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f9TH04n23113; Mon, 29 Oct 2001 09:00:04 -0800 (PST) (envelope-from gnats) Date: Mon, 29 Oct 2001 09:00:04 -0800 (PST) Message-Id: <200110291700.f9TH04n23113@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: David Malone Subject: Re: bin/30939: top(1) behaves badly when it loses terminal Reply-To: David Malone Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/30939; it has been noted by GNATS. From: David Malone 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 #include #include #include @@ -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