| Summary: | top(1) behaves badly when it loses terminal | ||||||
|---|---|---|---|---|---|---|---|
| Product: | Base System | Reporter: | andrew <andrew> | ||||
| Component: | bin | Assignee: | freebsd-bugs (Nobody) <bugs> | ||||
| Status: | Closed FIXED | ||||||
| Severity: | Affects Only Me | ||||||
| Priority: | Normal | ||||||
| Version: | 4.3-RELEASE | ||||||
| Hardware: | Any | ||||||
| OS: | Any | ||||||
| Attachments: |
|
||||||
|
Description
andrew
2001-09-30 20:30:00 UTC
andrew@nas.dgap.mipt.ru <andrew@nas.dgap.mipt.ru> wrote: > > >Number: 30939 > >Category: bin > >Synopsis: top(1) behaves badly when it loses terminal This looks like a duplicate of PR bin/30581. The old PR does not contain a lot of information though, so perhaps bin/30581 should be closed ? I'll test the patch of this PR (bin/30939) later tonight, and see what happens... -giorgos 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')
On Mon, Oct 29, 2001 at 09:00:04AM -0800, David Malone wrote: > 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 See also pr bin/30581: top(1) races when it loses its terminal That one can be closed afterwards too. Edwin -- Edwin Groothuis | Personal website: http://www.MavEtJu.org edwin@mavetju.org | Interested in MUDs? Visit Fatal Dimensions: ------------------+ http://www.FatalDimensions.org/ State Changed From-To: open->closed Fixed in -current and -stable. Thanks. |