From owner-freebsd-bugs Sun Sep 30 12:30:10 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 5A4AD37B40A for ; Sun, 30 Sep 2001 12:30:00 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f8UJU0c34714; Sun, 30 Sep 2001 12:30:00 -0700 (PDT) (envelope-from gnats) Received: from nas.dgap.mipt.ru (nas.dgap.mipt.ru [194.85.81.203]) by hub.freebsd.org (Postfix) with ESMTP id 9DA0A37B406 for ; Sun, 30 Sep 2001 12:29:37 -0700 (PDT) Received: (from andrew@localhost) by nas.dgap.mipt.ru (8.11.3/8.11.3) id f8UJTZS24778; Sun, 30 Sep 2001 23:29:35 +0400 (MSD) (envelope-from andrew) Message-Id: <200109301929.f8UJTZS24778@nas.dgap.mipt.ru> Date: Sun, 30 Sep 2001 23:29:35 +0400 (MSD) From: andrew@nas.dgap.mipt.ru Reply-To: andr@dgap.mipt.ru To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: bin/30939: top(1) behaves badly when it loses terminal 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 >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