Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Sep 2001 23:29:35 +0400 (MSD)
From:      andrew@nas.dgap.mipt.ru
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/30939: top(1) behaves badly when it loses terminal
Message-ID:  <200109301929.f8UJTZS24778@nas.dgap.mipt.ru>

next in thread | raw e-mail | index | archive | help

>Number:         30939
>Category:       bin
>Synopsis:       top(1) behaves badly when it loses terminal
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 30 12:30:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Andrew L. Neporada
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
>Environment:
System: FreeBSD nas.dgap.mipt.ru 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Mon May 7 20:16:53 MSD 2001 root@nas.dgap.mipt.ru:/usr/obj/usr/src/sys/NAS i386

>Description:

After losing its control terminal top(1) eats all available CPU resources
(when running under root privileges).

>How-To-Repeat:

Example session:

andrew@nas > ssh localhost
socket: Protocol not supported
andrew@localhost's password:
.
.
.
andrew@nas > su
Password:
nas# top

Then enter ~. to kill ssh and launch top or ps waux. 


>Fix:

Maybe it is better to just exit() instead of sleep() but anyway ...

--- contrib/top/top.c.orig	Sun Sep 30 21:30:08 2001
+++ contrib/top/top.c	Sun Sep 30 22:51:23 2001
@@ -157,6 +157,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 +712,9 @@
 		}
 
 		/* 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, (fd_set *)NULL, (fd_set *)NULL,
+				 &timeout);
+		if (sel_ret > 0)
 		{
 		    int newval;
 		    char *errmsg;
@@ -721,7 +724,12 @@
 
 		    /* now read it and convert to command strchr */
 		    /* (use "change" as a temporary to hold strchr) */
-		    (void) read(0, &ch, 1);
+		    /* sleep if input from stdin causes error */
+		    if (read(0, &ch, 1) != 1)
+		    {
+			ch = '\r';
+			sleep(delay);
+		    }
 		    if ((iptr = strchr(command_chars, ch)) == NULL)
 		    {
 			if (ch != '\r' && ch != '\n')
@@ -960,6 +968,11 @@
 
 		    /* flush out stuff that may have been written */
 		    fflush(stdout);
+		}
+		/* sleep if input from stdin causes error */
+		if (sel_ret < 0)
+		{
+		    sleep(delay);
 		}
 	    }
 	}
>Release-Note:
>Audit-Trail:
>Unformatted:

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?200109301929.f8UJTZS24778>