diff --git a/contrib/top/top.c b/contrib/top/top.c index 9b9b2b2b917c..1b8804142dd4 100644 --- a/contrib/top/top.c +++ b/contrib/top/top.c @@ -9,7 +9,9 @@ char *copyright = * but this entire comment MUST remain intact. * * Copyright (c) 1984, 1989, William LeFebvre, Rice University - * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University + * Copyright (c) 1989 - 1994, William LeFebvre, Northwestern University + * Copyright (c) 1994, 1995, William LeFebvre, Argonne National Laboratory + * Copyright (c) 1996, William LeFebvre, Group sys Consulting * * $FreeBSD$ */ @@ -56,9 +58,6 @@ char stdoutbuf[Buffersize]; /* build Signal masks */ #define Smask(s) (1 << ((s) - 1)) -/* for system errors */ -extern int errno; - /* for getopt: */ extern int optind; extern char *optarg; @@ -188,7 +187,7 @@ char *argv[]; /* FD_SET and friends are not present: fake it */ typedef int fd_set; #define FD_ZERO(x) (*(x) = 0) -#define FD_SET(f, x) (*(x) = f) +#define FD_SET(f, x) (*(x) = 1< topn) { active_procs = topn; @@ -620,7 +627,13 @@ Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n", u_endscreen(i); /* now, flush the output buffer */ - fflush(stdout); + if (fflush(stdout) != 0) + { + new_message(MT_standout, " Write error on stdout"); + putchar('\r'); + quit(1); + /*NOTREACHED*/ + } /* only do the rest if we have more displays to show */ if (displays) @@ -662,7 +675,7 @@ Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n", /* set up arguments for select with timeout */ FD_ZERO(&readfds); - FD_SET(1, &readfds); /* for standard input */ + FD_SET(0, &readfds); /* for standard input */ timeout.tv_sec = delay; timeout.tv_usec = 0; @@ -727,7 +740,13 @@ Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n", /* now read it and convert to command strchr */ /* (use "change" as a temporary to hold strchr) */ if (read(0, &ch, 1) != 1) - quit(0); + { + /* read error: either 0 or -1 */ + new_message(MT_standout, " Read error on stdin"); + putchar('\r'); + quit(1); + /*NOTREACHED*/ + } if ((iptr = strchr(command_chars, ch)) == NULL) { if (ch != '\r' && ch != '\n') @@ -833,7 +852,10 @@ Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n", new_message(MT_standout, "Seconds to delay: "); if ((i = readline(tempbuf1, 8, Yes)) > -1) { - delay = i; + if ((delay = i) == 0 && getuid() != 0) + { + delay = 1; + } } clear_message(); break; @@ -971,6 +993,9 @@ Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n", } } +#ifdef DEBUG + fclose(debug); +#endif quit(0); /*NOTREACHED*/ }