diff options
author | 2001-07-27 17:13:42 +0000 | |
---|---|---|
committer | 2001-07-27 17:13:42 +0000 | |
commit | 169dc930eea5bc78225bb2455b171f22b51d30dc (patch) | |
tree | 7494b00297e3c8018fac678ecbe8179e0dfe48e8 | |
parent | sync (diff) | |
download | wireguard-openbsd-169dc930eea5bc78225bb2455b171f22b51d30dc.tar.xz wireguard-openbsd-169dc930eea5bc78225bb2455b171f22b51d30dc.zip |
abort if stdout use ever produces EOF. before, top was one of those nasty
processes that could spin if it's output tty went away in some cases.
-rw-r--r-- | usr.bin/top/display.c | 104 | ||||
-rw-r--r-- | usr.bin/top/screen.c | 18 | ||||
-rw-r--r-- | usr.bin/top/top.c | 35 |
3 files changed, 107 insertions, 50 deletions
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index 93b65b07ee3..05c4f5a87c0 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -1,4 +1,4 @@ -/* $OpenBSD: display.c,v 1.4 1999/03/06 20:27:42 millert Exp $ */ +/* $OpenBSD: display.c,v 1.5 2001/07/27 17:13:42 deraadt Exp $ */ /* * Top users/processes display for Unix @@ -262,13 +262,15 @@ time_t *tod; } else { - fputs(" ", stdout); + if (fputs(" ", stdout) == EOF) + exit(1); } #ifdef DEBUG { char *foo; foo = ctime(tod); - fputs(foo, stdout); + if (fputs(foo, stdout) == EOF) + exit(1); } #endif printf("%-8.8s\n", &(ctime(tod)[11])); @@ -301,12 +303,14 @@ int *brkdn; i = digits(total); while (i++ < 4) { - putchar(' '); + if (putchar(' ') == EOF) + exit(1); } /* format and print the process state summary */ summary_format(procstates_buffer, brkdn, procstate_names); - fputs(procstates_buffer, stdout); + if (fputs(procstates_buffer, stdout) == EOF) + exit(1); /* save the numbers for next time */ memcpy(lprocstates, brkdn, num_procstates * sizeof(int)); @@ -336,12 +340,14 @@ int *brkdn; /* if number of digits differs, rewrite the label */ if (digits(total) != digits(ltotal)) { - fputs(" processes:", stdout); + if (fputs(" processes:", stdout) == EOF) + exit(1); /* put out enough spaces to get to column 15 */ i = digits(total); while (i++ < 4) { - putchar(' '); + if (putchar(' ') == EOF) + exit(1); } /* cursor may end up right where we want it!!! */ } @@ -518,12 +524,14 @@ void i_memory(stats) int *stats; { - fputs("\nMemory: ", stdout); + if (fputs("\nMemory: ", stdout) == EOF) + exit(1); lastline++; /* format and print the memory summary */ summary_format(memory_buffer, stats, memory_names); - fputs(memory_buffer, stdout); + if (fputs(memory_buffer, stdout) == EOF) + exit(1); } void u_memory(stats) @@ -562,7 +570,8 @@ void i_message() { while (lastline < y_message) { - fputc('\n', stdout); + if (fputc('\n', stdout) == EOF) + exit(1); lastline++; } if (next_msg[0] != '\0') @@ -600,8 +609,10 @@ char *text; header_length = strlen(text); if (header_status == ON) { - putchar('\n'); - fputs(text, stdout); + if (putchar('\n') == EOF) + exit(1); + if (fputs(text, stdout) == EOF) + exit(1); lastline++; } else if (header_status == ERASE) @@ -618,7 +629,8 @@ char *text; /* ignored */ { if (header_status == ERASE) { - putchar('\n'); + if (putchar('\n') == EOF) + exit(1); lastline++; clear_eol(header_length); header_status = OFF; @@ -643,7 +655,8 @@ char *thisline; /* make sure we are on the correct line */ while (lastline < y_procs + line) { - putchar('\n'); + if (putchar('\n') == EOF) + exit(1); lastline++; } @@ -651,7 +664,8 @@ char *thisline; thisline[display_width] = '\0'; /* write the line out */ - fputs(thisline, stdout); + if (fputs(thisline, stdout) == EOF) + exit(1); /* copy it in to our buffer */ base = smart_terminal ? screenbuf + lineindex(line) : screenbuf; @@ -684,7 +698,8 @@ char *linebuf; /* get positioned on the correct line */ if (screen_line - lastline == 1) { - putchar('\n'); + if (putchar('\n') == EOF) + exit(1); lastline++; } else @@ -694,7 +709,8 @@ char *linebuf; } /* now write the line */ - fputs(linebuf, stdout); + if (fputs(linebuf, stdout) == EOF) + exit(1); /* copy it in to the buffer */ optr = strecpy(bufferline, linebuf); @@ -729,7 +745,8 @@ register int hi; { while (lastline < screen_line) { - putchar('\n'); + if (putchar('\n') == EOF) + exit(1); lastline++; } } @@ -750,7 +767,8 @@ register int hi; i = hi; while ((void) clear_eol(strlen(&screenbuf[lineindex(i++)])), i < last_hi) { - putchar('\n'); + if (putchar('\n') == EOF) + exit(1); } } } @@ -764,7 +782,8 @@ register int hi; else { /* separate this display from the next with some vertical room */ - fputs("\n\n", stdout); + if (fputs("\n\n", stdout) == EOF) + exit(1); } } @@ -805,8 +824,12 @@ caddr_t a1, a2, a3; i = strlen(next_msg); if ((type & MT_delayed) == 0) { - type & MT_standout ? standout(next_msg) : - fputs(next_msg, stdout); + if (type & MT_standout) + standout(next_msg); + else { + if (fputs(next_msg, stdout) == EOF) + exit(1); + } (void) clear_eol(msglen - i); msglen = i; next_msg[0] = '\0'; @@ -817,7 +840,12 @@ caddr_t a1, a2, a3; { if ((type & MT_delayed) == 0) { - type & MT_standout ? standout(next_msg) : fputs(next_msg, stdout); + if (type & MT_standout) + standout(next_msg); + else { + if (fputs(next_msg, stdout) == EOF) + exit(1); + } msglen = strlen(next_msg); next_msg[0] = '\0'; } @@ -829,7 +857,8 @@ void clear_message() { if (clear_eol(msglen) == 1) { - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); } } @@ -868,7 +897,8 @@ int numeric; /* return null string */ *buffer = '\0'; - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); return(-1); } else if (ch == ch_erase) @@ -877,11 +907,13 @@ int numeric; if (cnt <= 0) { /* none to erase! */ - putchar('\7'); + if (putchar('\7') == EOF) + exit(1); } else { - fputs("\b \b", stdout); + if (fputs("\b \b", stdout) == EOF) + exit(1); ptr--; cnt--; } @@ -891,12 +923,14 @@ int numeric; !isprint(ch)) { /* not legal */ - putchar('\7'); + if (putchar('\7') == EOF) + exit(1); } else { /* echo it and store it in the buffer */ - putchar(ch); + if (putchar(ch) == EOF) + exit(1); ptr++; cnt++; if (cnt > maxcnt) @@ -914,7 +948,8 @@ int numeric; msglen += overstrike ? maxcnt : cnt; /* return either inputted number or string length */ - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); return(cnt == 0 ? -1 : numeric ? atoi(buffer) : cnt); } @@ -1018,14 +1053,16 @@ int line; { if (line - lastline == 1 && start == 0) { - putchar('\n'); + if (putchar('\n') == EOF) + exit(1); } else { Move_to(start, line); } cursor_on_line = Yes; - putchar(ch); + if (putchar(ch) == EOF) + exit(1); *old = ch; lastcol = 1; } @@ -1081,7 +1118,8 @@ int line; else { /* write the new character */ - putchar(ch); + if (putchar(ch) == EOF) + exit(1); } /* put the new character in the screen buffer */ *old = ch; diff --git a/usr.bin/top/screen.c b/usr.bin/top/screen.c index fd297a8746a..44184d2e1b4 100644 --- a/usr.bin/top/screen.c +++ b/usr.bin/top/screen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen.c,v 1.6 1999/04/26 01:34:04 downsj Exp $ */ +/* $OpenBSD: screen.c,v 1.7 2001/07/27 17:13:42 deraadt Exp $ */ /* * Top users/processes display for Unix @@ -283,12 +283,14 @@ char *msg; if (smart_terminal) { putcap(start_standout); - fputs(msg, stdout); + if (fputs(msg, stdout) == EOF) + exit(1); putcap(end_standout); } else { - fputs(msg, stdout); + if (fputs(msg, stdout) == EOF) + exit(1); } } @@ -317,7 +319,8 @@ int len; { while (len-- > 0) { - putchar(' '); + if (putchar(' ') == EOF) + exit(1); } return(1); } @@ -341,6 +344,11 @@ int putstdout(ch) int ch; { - return(putchar(ch)); + int ret; + + ret = putchar(ch); + if (ret == EOF) + exit(1); + return (ret); } diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index c6607ce1dd1..78e99f65090 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -1,4 +1,4 @@ -/* $OpenBSD: top.c,v 1.8 2001/07/17 02:23:58 pvalchev Exp $ */ +/* $OpenBSD: top.c,v 1.9 2001/07/27 17:13:42 deraadt Exp $ */ const char copyright[] = "Copyright (c) 1984 through 1996, William LeFebvre"; @@ -536,7 +536,8 @@ restart: } else { - putchar('\n'); + if (putchar('\n') == EOF) + exit(1); } dostates = Yes; } @@ -687,7 +688,8 @@ restart: { /* illegal command */ new_message(MT_standout, " Command not understood"); - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); no_command = Yes; } else @@ -698,7 +700,8 @@ restart: /* error */ new_message(MT_standout, " Command cannot be handled by this terminal"); - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); no_command = Yes; } else switch(change) @@ -737,7 +740,8 @@ restart: { new_message(MT_standout, " Currently no errors to report."); - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); no_command = Yes; } else @@ -763,7 +767,8 @@ restart: new_message(MT_standout | MT_delayed, " This terminal can only display %d processes.", max_topn); - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); } if (newval == 0) @@ -813,7 +818,8 @@ restart: if ((errmsg = kill_procs(tempbuf2)) != NULL) { new_message(MT_standout, "%s", errmsg); - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); no_command = Yes; } } @@ -830,7 +836,8 @@ restart: if ((errmsg = renice_procs(tempbuf2)) != NULL) { new_message(MT_standout, "%s", errmsg); - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); no_command = Yes; } } @@ -846,7 +853,8 @@ restart: new_message(MT_standout | MT_delayed, " %sisplaying idle processes.", ps.idle ? "D" : "Not d"); - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); break; case CMD_user: @@ -869,7 +877,8 @@ restart: { ps.uid = i; } - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); } else { @@ -893,7 +902,8 @@ restart: { order_index = i; } - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); } else { @@ -904,7 +914,8 @@ restart: default: new_message(MT_standout, " BAD CASE IN SWITCH!"); - putchar('\r'); + if (putchar('\r') == EOF) + exit(1); } } |