Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/top if the read() on stdin for a command fails, exit.



details:   https://anonhg.NetBSD.org/src/rev/7c33478b8c82
branches:  trunk
changeset: 508508:7c33478b8c82
user:      abs <abs%NetBSD.org@localhost>
date:      Thu Apr 12 14:10:05 2001 +0000

description:
if the read() on stdin for a command fails, exit.
This stops top ending up in an infinite cpu churning loop if the tty detaches,
or if something similar to 'top < /dev/null' is run.

diffstat:

 usr.bin/top/top.c |  5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diffs (19 lines):

diff -r 793c9496f616 -r 7c33478b8c82 usr.bin/top/top.c
--- a/usr.bin/top/top.c Thu Apr 12 13:37:25 2001 +0000
+++ b/usr.bin/top/top.c Thu Apr 12 14:10:05 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: top.c,v 1.6 2000/10/04 20:09:05 mjl Exp $      */
+/*     $NetBSD: top.c,v 1.7 2001/04/12 14:10:05 abs Exp $      */
 
 char *copyright =
     "Copyright (c) 1984 through 1996, William LeFebvre";
@@ -625,7 +625,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)
                    {
                        /* illegal command */



Home | Main Index | Thread Index | Old Index