Annotation of src/usr.bin/top/top.c, Revision 1.11
1.11 ! deraadt 1: /* $OpenBSD: top.c,v 1.10 2001/09/04 23:35:59 millert Exp $ */
1.1 downsj 2:
1.2 downsj 3: const char copyright[] = "Copyright (c) 1984 through 1996, William LeFebvre";
1.1 downsj 4:
5: /*
6: * Top users/processes display for Unix
7: * Version 3
8: *
9: * This program may be freely redistributed,
10: * but this entire comment MUST remain intact.
11: *
12: * Copyright (c) 1984, 1989, William LeFebvre, Rice University
13: * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
14: */
15:
16: /*
17: * See the file "Changes" for information on version-to-version changes.
18: */
19:
20: /*
21: * This file contains "main" and other high-level routines.
22: */
23:
24: /*
25: * The following preprocessor variables, when defined, are used to
26: * distinguish between different Unix implementations:
27: *
28: * FD_SET - macros FD_SET and FD_ZERO are used when defined
29: */
30:
1.2 downsj 31: #include <sys/types.h>
32: #include <stdio.h>
33: #include <ctype.h>
1.1 downsj 34: #include <signal.h>
35: #include <setjmp.h>
1.2 downsj 36: #include <string.h>
37: #include <stdlib.h>
38: #include <unistd.h>
1.5 deraadt 39: #include <errno.h>
1.1 downsj 40: #include <sys/time.h>
41:
42: /* includes specific to top */
43: #include "display.h" /* interface to display package */
44: #include "screen.h" /* interface to screen package */
45: #include "top.h"
46: #include "top.local.h"
47: #include "boolean.h"
48: #include "machine.h"
49: #include "utils.h"
50:
51: /* Size of the stdio buffer given to stdout */
52: #define Buffersize 2048
53:
54: /* The buffer that stdio will use */
55: char stdoutbuf[Buffersize];
56:
57: /* imported from screen.c */
58: extern int overstrike;
59:
60: /* signal handling routines */
1.2 downsj 61: static void leave __P((int));
62: static void onalrm __P((int));
63: static void tstop __P((int));
1.1 downsj 64: #ifdef SIGWINCH
1.2 downsj 65: static void winch __P((int));
1.1 downsj 66: #endif
67:
1.7 deraadt 68: sig_atomic_t leaveflag;
69: sig_atomic_t tstopflag;
70: sig_atomic_t winchflag;
71:
1.2 downsj 72: static void reset_display __P((void));
1.1 downsj 73:
74: /* values which need to be accessed by signal handlers */
75: static int max_topn; /* maximum displayable processes */
76:
77: /* miscellaneous things */
78: char *myname = "top";
79: jmp_buf jmp_int;
80:
81: /* routines that don't return int */
82:
83: #ifdef ORDER
84: extern int (*proc_compares[])();
85: #else
86: extern int proc_compare();
87: #endif
88: time_t time();
89:
90: caddr_t get_process_info();
91:
92: /* pointers to display routines */
1.2 downsj 93: void (*d_loadave)() = i_loadave;
94: void (*d_procstates)() = i_procstates;
95: void (*d_cpustates)() = i_cpustates;
96: void (*d_memory)() = i_memory;
97: void (*d_message)() = i_message;
98: void (*d_header)() = i_header;
99: void (*d_process)() = i_process;
1.1 downsj 100:
101:
1.2 downsj 102: int main(argc, argv)
1.1 downsj 103:
104: int argc;
105: char *argv[];
106:
107: {
108: register int i;
109: register int active_procs;
110: register int change;
111:
112: struct system_info system_info;
113: struct statics statics;
114: caddr_t processes;
115:
116: static char tempbuf1[50];
117: static char tempbuf2[50];
1.10 millert 118: sigset_t mask, oldmask;
1.1 downsj 119: int topn = Default_TOPN;
120: int delay = Default_DELAY;
121: int displays = 0; /* indicates unspecified */
122: time_t curr_time;
123: char *(*get_userid)() = username;
124: char *uname_field = "USERNAME";
125: char *header_text;
126: char *env_top;
127: char **preset_argv;
128: int preset_argc = 0;
129: char **av;
130: int ac;
131: char dostates = No;
132: char do_unames = Yes;
133: char interactive = Maybe;
134: char warnings = 0;
135: #if Default_TOPN == Infinity
136: char topn_specified = No;
137: #endif
138: char ch;
139: char *iptr;
140: char no_command = 1;
141: struct timeval timeout;
142: struct process_select ps;
143: #ifdef ORDER
144: char *order_name = NULL;
145: int order_index = 0;
146: #endif
147: #ifndef FD_SET
148: /* FD_SET and friends are not present: fake it */
149: typedef int fd_set;
150: #define FD_ZERO(x) (*(x) = 0)
151: #define FD_SET(f, x) (*(x) = f)
152: #endif
153: fd_set readfds;
154:
155: #ifdef ORDER
156: static char command_chars[] = "\f qh?en#sdkriIuo";
157: #else
158: static char command_chars[] = "\f qh?en#sdkriIu";
159: #endif
160: /* these defines enumerate the "strchr"s of the commands in command_chars */
161: #define CMD_redraw 0
162: #define CMD_update 1
163: #define CMD_quit 2
164: #define CMD_help1 3
165: #define CMD_help2 4
166: #define CMD_OSLIMIT 4 /* terminals with OS can only handle commands */
167: #define CMD_errors 5 /* less than or equal to CMD_OSLIMIT */
168: #define CMD_number1 6
169: #define CMD_number2 7
170: #define CMD_delay 8
171: #define CMD_displays 9
172: #define CMD_kill 10
173: #define CMD_renice 11
174: #define CMD_idletog 12
175: #define CMD_idletog2 13
176: #define CMD_user 14
177: #ifdef ORDER
178: #define CMD_order 15
179: #endif
180:
181: /* set the buffer for stdout */
182: #ifdef DEBUG
183: setbuffer(stdout, NULL, 0);
184: #else
185: setbuffer(stdout, stdoutbuf, Buffersize);
186: #endif
187:
188: /* get our name */
189: if (argc > 0)
190: {
191: if ((myname = strrchr(argv[0], '/')) == 0)
192: {
193: myname = argv[0];
194: }
195: else
196: {
197: myname++;
198: }
199: }
200:
201: /* initialize some selection options */
202: ps.idle = Yes;
203: ps.system = No;
204: ps.uid = -1;
205: ps.command = NULL;
206:
207: /* get preset options from the environment */
208: if ((env_top = getenv("TOP")) != NULL)
209: {
210: av = preset_argv = argparse(env_top, &preset_argc);
211: ac = preset_argc;
212:
213: /* set the dummy argument to an explanatory message, in case
214: getopt encounters a bad argument */
215: preset_argv[0] = "while processing environment";
216: }
217:
218: /* process options */
219: do {
220: /* if we're done doing the presets, then process the real arguments */
221: if (preset_argc == 0)
222: {
223: ac = argc;
224: av = argv;
225:
226: /* this should keep getopt happy... */
227: optind = 1;
228: }
229:
1.3 aaron 230: while ((i = getopt(ac, av, "SIbinqus:d:U:o:")) != -1)
1.1 downsj 231: {
232: switch(i)
233: {
234: case 'u': /* toggle uid/username display */
235: do_unames = !do_unames;
236: break;
237:
238: case 'U': /* display only username's processes */
239: if ((ps.uid = userid(optarg)) == -1)
240: {
241: fprintf(stderr, "%s: unknown user\n", optarg);
242: exit(1);
243: }
244: break;
245:
246: case 'S': /* show system processes */
247: ps.system = !ps.system;
248: break;
249:
250: case 'I': /* show idle processes */
251: ps.idle = !ps.idle;
252: break;
253:
254: case 'i': /* go interactive regardless */
255: interactive = Yes;
256: break;
257:
258: case 'n': /* batch, or non-interactive */
259: case 'b':
260: interactive = No;
261: break;
262:
263: case 'd': /* number of displays to show */
264: if ((i = atoiwi(optarg)) == Invalid || i == 0)
265: {
266: fprintf(stderr,
267: "%s: warning: display count should be positive -- option ignored\n",
268: myname);
269: warnings++;
270: }
271: else
272: {
273: displays = i;
274: }
275: break;
276:
277: case 's':
278: {
1.6 deraadt 279: char *endp;
280:
281: delay = strtoul(optarg, &endp, 10);
282: if (delay < 0 || *endp != '\0')
283: {
1.1 downsj 284: fprintf(stderr,
285: "%s: warning: seconds delay should be non-negative -- using default\n",
286: myname);
287: delay = Default_DELAY;
288: warnings++;
1.6 deraadt 289: }
1.1 downsj 290: }
291: break;
292:
293: case 'q': /* be quick about it */
294: /* only allow this if user is really root */
295: if (getuid() == 0)
296: {
297: /* be very un-nice! */
298: (void) nice(-20);
299: }
300: else
301: {
302: fprintf(stderr,
303: "%s: warning: `-q' option can only be used by root\n",
304: myname);
305: warnings++;
306: }
307: break;
308:
309: case 'o': /* select sort order */
310: #ifdef ORDER
311: order_name = optarg;
312: #else
313: fprintf(stderr,
314: "%s: this platform does not support arbitrary ordering. Sorry.\n",
315: myname);
316: warnings++;
317: #endif
318: break;
319:
320: default:
321: fprintf(stderr, "\
322: Top version %s\n\
323: Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n",
324: version_string(), myname);
325: exit(1);
326: }
327: }
328:
329: /* get count of top processes to display (if any) */
330: if (optind < ac)
331: {
332: if ((topn = atoiwi(av[optind])) == Invalid)
333: {
334: fprintf(stderr,
335: "%s: warning: process display count should be non-negative -- using default\n",
336: myname);
337: warnings++;
338: }
339: #if Default_TOPN == Infinity
340: else
341: {
342: topn_specified = Yes;
343: }
344: #endif
345: }
346:
347: /* tricky: remember old value of preset_argc & set preset_argc = 0 */
348: i = preset_argc;
349: preset_argc = 0;
350:
351: /* repeat only if we really did the preset arguments */
352: } while (i != 0);
353:
354: /* set constants for username/uid display correctly */
355: if (!do_unames)
356: {
357: uname_field = " UID ";
358: get_userid = itoa7;
359: }
360:
361: /* initialize the kernel memory interface */
362: if (machine_init(&statics) == -1)
363: {
364: exit(1);
365: }
366:
367: #ifdef ORDER
368: /* determine sorting order index, if necessary */
369: if (order_name != NULL)
370: {
371: if ((order_index = string_index(order_name, statics.order_names)) == -1)
372: {
373: char **pp;
374:
375: fprintf(stderr, "%s: '%s' is not a recognized sorting order.\n",
376: myname, order_name);
377: fprintf(stderr, "\tTry one of these:");
378: pp = statics.order_names;
379: while (*pp != NULL)
380: {
381: fprintf(stderr, " %s", *pp++);
382: }
383: fputc('\n', stderr);
384: exit(1);
385: }
386: }
387: #endif
388:
389: #ifdef no_initialization_needed
390: /* initialize the hashing stuff */
391: if (do_unames)
392: {
393: init_hash();
394: }
395: #endif
396:
397: /* initialize termcap */
398: init_termcap(interactive);
399:
400: /* get the string to use for the process area header */
401: header_text = format_header(uname_field);
402:
403: /* initialize display interface */
404: if ((max_topn = display_init(&statics)) == -1)
405: {
406: fprintf(stderr, "%s: can't allocate sufficient memory\n", myname);
407: exit(4);
408: }
409:
410: /* print warning if user requested more processes than we can display */
411: if (topn > max_topn)
412: {
413: fprintf(stderr,
414: "%s: warning: this terminal can only display %d processes.\n",
415: myname, max_topn);
416: warnings++;
417: }
418:
419: /* adjust for topn == Infinity */
420: if (topn == Infinity)
421: {
422: /*
423: * For smart terminals, infinity really means everything that can
424: * be displayed, or Largest.
425: * On dumb terminals, infinity means every process in the system!
426: * We only really want to do that if it was explicitly specified.
427: * This is always the case when "Default_TOPN != Infinity". But if
428: * topn wasn't explicitly specified and we are on a dumb terminal
429: * and the default is Infinity, then (and only then) we use
430: * "Nominal_TOPN" instead.
431: */
432: #if Default_TOPN == Infinity
433: topn = smart_terminal ? Largest :
434: (topn_specified ? Largest : Nominal_TOPN);
435: #else
436: topn = Largest;
437: #endif
438: }
439:
440: /* set header display accordingly */
441: display_header(topn > 0);
442:
443: /* determine interactive state */
444: if (interactive == Maybe)
445: {
446: interactive = smart_terminal;
447: }
448:
449: /* if # of displays not specified, fill it in */
450: if (displays == 0)
451: {
452: displays = smart_terminal ? Infinity : 1;
453: }
454:
1.10 millert 455: /* block interrupt signals while setting up the screen and the handlers */
456: sigemptyset(&mask);
457: sigaddset(&mask, SIGINT);
458: sigaddset(&mask, SIGQUIT);
459: sigaddset(&mask, SIGTSTP);
460: sigprocmask(SIG_BLOCK, &mask, &oldmask);
1.1 downsj 461: init_screen();
462: (void) signal(SIGINT, leave);
463: (void) signal(SIGQUIT, leave);
464: (void) signal(SIGTSTP, tstop);
465: #ifdef SIGWINCH
466: (void) signal(SIGWINCH, winch);
467: #endif
1.10 millert 468: sigprocmask(SIG_SETMASK, &oldmask, NULL);
1.1 downsj 469: if (warnings)
470: {
471: fputs("....", stderr);
472: fflush(stderr); /* why must I do this? */
473: sleep((unsigned)(3 * warnings));
474: fputc('\n', stderr);
475: }
476:
1.7 deraadt 477: restart:
1.1 downsj 478:
479: /*
480: * main loop -- repeat while display count is positive or while it
481: * indicates infinity (by being -1)
482: */
483:
484: while ((displays == -1) || (displays-- > 0))
485: {
486: /* get the current stats */
487: get_system_info(&system_info);
488:
489: /* get the current set of processes */
490: processes =
491: get_process_info(&system_info,
492: &ps,
493: #ifdef ORDER
494: proc_compares[order_index]);
495: #else
496: proc_compare);
497: #endif
498:
499: /* display the load averages */
500: (*d_loadave)(system_info.last_pid,
501: system_info.load_avg);
502:
503: /* display the current time */
504: /* this method of getting the time SHOULD be fairly portable */
505: time(&curr_time);
506: i_timeofday(&curr_time);
507:
508: /* display process state breakdown */
509: (*d_procstates)(system_info.p_total,
510: system_info.procstates);
511:
512: /* display the cpu state percentage breakdown */
513: if (dostates) /* but not the first time */
514: {
515: (*d_cpustates)(system_info.cpustates);
516: }
517: else
518: {
519: /* we'll do it next time */
520: if (smart_terminal)
521: {
522: z_cpustates();
523: }
524: else
525: {
1.9 deraadt 526: if (putchar('\n') == EOF)
527: exit(1);
1.1 downsj 528: }
529: dostates = Yes;
530: }
531:
532: /* display memory stats */
533: (*d_memory)(system_info.memory);
534:
535: /* handle message area */
536: (*d_message)();
537:
538: /* update the header area */
539: (*d_header)(header_text);
540:
541: if (topn > 0)
542: {
543: /* determine number of processes to actually display */
544: /* this number will be the smallest of: active processes,
545: number user requested, number current screen accomodates */
546: active_procs = system_info.p_active;
547: if (active_procs > topn)
548: {
549: active_procs = topn;
550: }
551: if (active_procs > max_topn)
552: {
553: active_procs = max_topn;
554: }
555:
556: /* now show the top "n" processes. */
557: for (i = 0; i < active_procs; i++)
558: {
559: (*d_process)(i, format_next_process(processes, get_userid));
560: }
561: }
562: else
563: {
564: i = 0;
565: }
566:
567: /* do end-screen processing */
568: u_endscreen(i);
569:
570: /* now, flush the output buffer */
571: fflush(stdout);
572:
573: /* only do the rest if we have more displays to show */
574: if (displays)
575: {
576: /* switch out for new display on smart terminals */
577: if (smart_terminal)
578: {
579: if (overstrike)
580: {
581: reset_display();
582: }
583: else
584: {
585: d_loadave = u_loadave;
586: d_procstates = u_procstates;
587: d_cpustates = u_cpustates;
588: d_memory = u_memory;
589: d_message = u_message;
590: d_header = u_header;
591: d_process = u_process;
592: }
593: }
594:
595: no_command = Yes;
596: if (!interactive)
597: {
598: /* set up alarm */
599: (void) signal(SIGALRM, onalrm);
600: (void) alarm((unsigned)delay);
601:
602: /* wait for the rest of it .... */
603: pause();
604: }
605: else while (no_command)
606: {
607: /* assume valid command unless told otherwise */
608: no_command = No;
609:
610: /* set up arguments for select with timeout */
611: FD_ZERO(&readfds);
1.11 ! deraadt 612: FD_SET(STDIN_FILENO, &readfds); /* for standard input */
1.1 downsj 613: timeout.tv_sec = delay;
614: timeout.tv_usec = 0;
615:
1.7 deraadt 616: if (leaveflag) {
617: end_screen();
618: exit(0);
619: }
620:
621: if (tstopflag) {
622: /* move to the lower left */
623: end_screen();
624: fflush(stdout);
625:
626: /* default the signal handler action */
627: (void) signal(SIGTSTP, SIG_DFL);
628:
629: /* unblock the signal and send ourselves one */
1.10 millert 630: sigemptyset(&mask);
631: sigaddset(&mask, SIGTSTP);
632: sigprocmask(SIG_UNBLOCK, &mask, NULL);
1.7 deraadt 633: (void) kill(0, SIGTSTP);
634:
635: /* reset the signal handler */
636: (void) signal(SIGTSTP, tstop);
637:
638: /* reinit screen */
639: reinit_screen();
640: reset_display();
641: tstopflag = 0;
642: goto restart;
643: }
644:
645: if (winchflag) {
646: /* reascertain the screen dimensions */
647: get_screensize();
648:
649: /* tell display to resize */
650: max_topn = display_resize();
651:
652: /* reset the signal handler */
653: (void) signal(SIGWINCH, winch);
654:
655: reset_display();
656: winchflag = 0;
657: goto restart;
658: }
659:
1.1 downsj 660: /* wait for either input or the end of the delay period */
1.11 ! deraadt 661: if (select(STDIN_FILENO + 1, &readfds, (fd_set *)NULL,
! 662: (fd_set *)NULL, &timeout) > 0)
1.1 downsj 663: {
664: int newval;
665: char *errmsg;
666:
667: /* something to read -- clear the message area first */
668: clear_message();
669:
670: /* now read it and convert to command strchr */
671: /* (use "change" as a temporary to hold strchr) */
672: (void) read(0, &ch, 1);
673: if ((iptr = strchr(command_chars, ch)) == NULL)
674: {
675: /* illegal command */
676: new_message(MT_standout, " Command not understood");
1.9 deraadt 677: if (putchar('\r') == EOF)
678: exit(1);
1.1 downsj 679: no_command = Yes;
680: }
681: else
682: {
683: change = iptr - command_chars;
684: if (overstrike && change > CMD_OSLIMIT)
685: {
686: /* error */
687: new_message(MT_standout,
688: " Command cannot be handled by this terminal");
1.9 deraadt 689: if (putchar('\r') == EOF)
690: exit(1);
1.1 downsj 691: no_command = Yes;
692: }
693: else switch(change)
694: {
695: case CMD_redraw: /* redraw screen */
696: reset_display();
697: break;
698:
699: case CMD_update: /* merely update display */
700: /* is the load average high? */
701: if (system_info.load_avg[0] > LoadMax)
702: {
703: /* yes, go home for visual feedback */
704: go_home();
705: fflush(stdout);
706: }
707: break;
708:
709: case CMD_quit: /* quit */
710: quit(0);
711: /*NOTREACHED*/
712: break;
713:
714: case CMD_help1: /* help */
715: case CMD_help2:
716: reset_display();
717: clear();
718: show_help();
719: standout("Hit any key to continue: ");
720: fflush(stdout);
721: (void) read(0, &ch, 1);
722: break;
723:
724: case CMD_errors: /* show errors */
725: if (error_count() == 0)
726: {
727: new_message(MT_standout,
728: " Currently no errors to report.");
1.9 deraadt 729: if (putchar('\r') == EOF)
730: exit(1);
1.1 downsj 731: no_command = Yes;
732: }
733: else
734: {
735: reset_display();
736: clear();
737: show_errors();
738: standout("Hit any key to continue: ");
739: fflush(stdout);
740: (void) read(0, &ch, 1);
741: }
742: break;
743:
744: case CMD_number1: /* new number */
745: case CMD_number2:
746: new_message(MT_standout,
747: "Number of processes to show: ");
748: newval = readline(tempbuf1, 8, Yes);
749: if (newval > -1)
750: {
751: if (newval > max_topn)
752: {
753: new_message(MT_standout | MT_delayed,
754: " This terminal can only display %d processes.",
755: max_topn);
1.9 deraadt 756: if (putchar('\r') == EOF)
757: exit(1);
1.1 downsj 758: }
759:
760: if (newval == 0)
761: {
762: /* inhibit the header */
763: display_header(No);
764: }
765: else if (newval > topn && topn == 0)
766: {
767: /* redraw the header */
768: display_header(Yes);
769: d_header = i_header;
770: }
771: topn = newval;
772: }
773: break;
774:
775: case CMD_delay: /* new seconds delay */
776: new_message(MT_standout, "Seconds to delay: ");
777: if ((i = readline(tempbuf1, 8, Yes)) > -1)
778: {
779: delay = i;
780: }
781: clear_message();
782: break;
783:
784: case CMD_displays: /* change display count */
785: new_message(MT_standout,
786: "Displays to show (currently %s): ",
787: displays == -1 ? "infinite" :
788: itoa(displays));
789: if ((i = readline(tempbuf1, 10, Yes)) > 0)
790: {
791: displays = i;
792: }
793: else if (i == 0)
794: {
795: quit(0);
796: }
797: clear_message();
798: break;
799:
800: case CMD_kill: /* kill program */
801: new_message(0, "kill ");
802: if (readline(tempbuf2, sizeof(tempbuf2), No) > 0)
803: {
804: if ((errmsg = kill_procs(tempbuf2)) != NULL)
805: {
1.4 millert 806: new_message(MT_standout, "%s", errmsg);
1.9 deraadt 807: if (putchar('\r') == EOF)
808: exit(1);
1.1 downsj 809: no_command = Yes;
810: }
811: }
812: else
813: {
814: clear_message();
815: }
816: break;
817:
818: case CMD_renice: /* renice program */
819: new_message(0, "renice ");
820: if (readline(tempbuf2, sizeof(tempbuf2), No) > 0)
821: {
822: if ((errmsg = renice_procs(tempbuf2)) != NULL)
823: {
1.4 millert 824: new_message(MT_standout, "%s", errmsg);
1.9 deraadt 825: if (putchar('\r') == EOF)
826: exit(1);
1.1 downsj 827: no_command = Yes;
828: }
829: }
830: else
831: {
832: clear_message();
833: }
834: break;
835:
836: case CMD_idletog:
837: case CMD_idletog2:
838: ps.idle = !ps.idle;
839: new_message(MT_standout | MT_delayed,
840: " %sisplaying idle processes.",
841: ps.idle ? "D" : "Not d");
1.9 deraadt 842: if (putchar('\r') == EOF)
843: exit(1);
1.1 downsj 844: break;
845:
846: case CMD_user:
847: new_message(MT_standout,
848: "Username to show: ");
849: if (readline(tempbuf2, sizeof(tempbuf2), No) > 0)
850: {
851: if (tempbuf2[0] == '+' &&
852: tempbuf2[1] == '\0')
853: {
854: ps.uid = -1;
855: }
856: else if ((i = userid(tempbuf2)) == -1)
857: {
858: new_message(MT_standout,
859: " %s: unknown user", tempbuf2);
860: no_command = Yes;
861: }
862: else
863: {
864: ps.uid = i;
865: }
1.9 deraadt 866: if (putchar('\r') == EOF)
867: exit(1);
1.1 downsj 868: }
869: else
870: {
871: clear_message();
872: }
873: break;
874:
875: #ifdef ORDER
876: case CMD_order:
877: new_message(MT_standout,
878: "Order to sort: ");
879: if (readline(tempbuf2, sizeof(tempbuf2), No) > 0)
880: {
881: if ((i = string_index(tempbuf2, statics.order_names)) == -1)
882: {
883: new_message(MT_standout,
884: " %s: unrecognized sorting order", tempbuf2);
885: no_command = Yes;
886: }
887: else
888: {
889: order_index = i;
890: }
1.9 deraadt 891: if (putchar('\r') == EOF)
892: exit(1);
1.1 downsj 893: }
894: else
895: {
896: clear_message();
897: }
898: break;
899: #endif
900:
901: default:
902: new_message(MT_standout, " BAD CASE IN SWITCH!");
1.9 deraadt 903: if (putchar('\r') == EOF)
904: exit(1);
1.1 downsj 905: }
906: }
907:
908: /* flush out stuff that may have been written */
909: fflush(stdout);
910: }
911: }
912: }
913: }
914:
915: quit(0);
916: /*NOTREACHED*/
1.8 pvalchev 917: return(0);
1.1 downsj 918: }
919:
920: /*
921: * reset_display() - reset all the display routine pointers so that entire
922: * screen will get redrawn.
923: */
924:
1.2 downsj 925: static void reset_display()
1.1 downsj 926:
927: {
928: d_loadave = i_loadave;
929: d_procstates = i_procstates;
930: d_cpustates = i_cpustates;
931: d_memory = i_memory;
932: d_message = i_message;
933: d_header = i_header;
934: d_process = i_process;
935: }
936:
937: /*
938: * signal handlers
939: */
940:
1.2 downsj 941: void leave(unused) /* exit under normal conditions -- INT handler */
942:
943: int unused;
1.1 downsj 944:
945: {
1.7 deraadt 946: leaveflag = 1;
1.1 downsj 947: }
948:
1.2 downsj 949: void tstop(i) /* SIGTSTP handler */
1.1 downsj 950:
951: int i;
952:
953: {
1.7 deraadt 954: tstopflag = 1;
1.1 downsj 955: }
956:
957: #ifdef SIGWINCH
1.2 downsj 958: void winch(i) /* SIGWINCH handler */
1.1 downsj 959:
960: int i;
961:
962: {
1.7 deraadt 963: winchflag = 1;
1.1 downsj 964: }
965: #endif
966:
967: void quit(status) /* exit under duress */
968:
969: int status;
970:
971: {
972: end_screen();
973: exit(status);
974: /*NOTREACHED*/
975: }
976:
1.2 downsj 977: void onalrm(unused) /* SIGALRM handler */
978:
979: int unused;
1.1 downsj 980:
981: {
982: /* this is only used in batch mode to break out of the pause() */
983: /* return; */
984: }
985: