From pavalos@theshell.com  Fri Sep 14 17:32:49 2001
Return-Path: <pavalos@theshell.com>
Received: from theshell.com (arsenic.theshell.com [63.236.138.5])
	by hub.freebsd.org (Postfix) with SMTP id 7DEEC37B40C
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 14 Sep 2001 17:32:49 -0700 (PDT)
Received: (qmail 37697 invoked from network); 15 Sep 2001 00:32:49 -0000
Received: from radium.theshell.com (root@63.236.138.3)
  by arsenic.theshell.com with SMTP; 15 Sep 2001 00:32:49 -0000
Received: (from pavalos@localhost)
	by radium.theshell.com (8.11.6/8.11.6) id f8F0Wnk22482;
	Fri, 14 Sep 2001 17:32:49 -0700 (PDT)
	(envelope-from pavalos)
Message-Id: <200109150032.f8F0Wnk22482@radium.theshell.com>
Date: Fri, 14 Sep 2001 17:32:49 -0700 (PDT)
From: Peter Avalos <pavalos@theshell.com>
Reply-To: Peter Avalos <pavalos@theshell.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: top(1) races when it loses its terminal
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         30581
>Category:       bin
>Synopsis:       top(1) races when it loses its terminal
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 14 17:40:00 PDT 2001
>Closed-Date:    Sun Nov 4 13:08:21 PST 2001
>Last-Modified:  Sun Nov 04 13:11:02 PST 2001
>Originator:     Peter Avalos
>Release:        FreeBSD 4.4-RC i386
>Organization:
none
>Environment:
System: FreeBSD radium.theshell.com 4.4-RC FreeBSD 4.4-RC #0: Tue Aug 21 16:51:12 PDT 2001 pavalos@radium.theshell.com:/usr/obj/usr/src/sys/RADIUM i386


>Description:
	top(1) uses up all the cpu it can when it loses its terminal.
>How-To-Repeat:
	Disconnect from an ssh session while running top as root. I can't
get this to happen when run as a normal user.

	Everything working normally (terminal connected):
root     23936  1.5  0.2  2096 1312  p8  S+    5:22PM   0:00.21 top

	Now disconnect from the ssh session:
root     23936 94.8  0.2  2096 1312  p8- R     5:22PM   3:12.76 top
>Fix:
	I'm not sure. It looks like there's some read(2)'s that don't
get their return values checked throughout the code, but I'm not sure
if that will fix it.
>Release-Note:
>Audit-Trail:

From: Edwin Groothuis <edwin@mavetju.org>
To: freebsd-gnats-submit@FreeBSD.org, pavalos@theshell.com
Cc:  
Subject: bin/30581: top(1) races when it loses its terminal
Date: Fri, 12 Oct 2001 16:21:40 +1000

 A fix for this is this. I've forward this to the author of top
 also, can please somebody in the mean time submit this to the
 FreeBSD source?
 
 --- /usr/src/contrib/top/top.c.old	Fri Oct 12 16:13:52 2001
 +++ /usr/src/contrib/top/top.c	Fri Oct 12 16:16:44 2001
 @@ -721,7 +721,11 @@
  
  		    /* 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)==0) {
 +			/* this happens if the controlling terminal */
 +			/* has disappeared. Maybe due to network problems? */
 +			quit(0);
 +		    }
  		    if ((iptr = strchr(command_chars, ch)) == NULL)
  		    {
  			if (ch != '\r' && ch != '\n')
 
 -- 
 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 
State-Changed-By: dwmalone 
State-Changed-When: Sun Nov 4 13:08:21 PST 2001 
State-Changed-Why:  
I'm abou to commit the patch in PR 30939, which is similar to 
Edwin's patch in this PR. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30581 
>Unformatted:
