=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/systat/main.c,v retrieving revision 1.19 retrieving revision 1.20 diff -c -r1.19 -r1.20 *** src/usr.bin/systat/main.c 2001/11/28 20:28:08 1.19 --- src/usr.bin/systat/main.c 2001/12/07 07:57:35 1.20 *************** *** 1,4 **** ! /* $OpenBSD: main.c,v 1.19 2001/11/28 20:28:08 ericj Exp $ */ /* $NetBSD: main.c,v 1.8 1996/05/10 23:16:36 thorpej Exp $ */ /*- --- 1,4 ---- ! /* $OpenBSD: main.c,v 1.20 2001/12/07 07:57:35 pvalchev Exp $ */ /* $NetBSD: main.c,v 1.8 1996/05/10 23:16:36 thorpej Exp $ */ /*- *************** *** 44,54 **** #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #endif ! static char rcsid[] = "$OpenBSD: main.c,v 1.19 2001/11/28 20:28:08 ericj Exp $"; #endif /* not lint */ #include - #include #include #include --- 44,53 ---- #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #endif ! static char rcsid[] = "$OpenBSD: main.c,v 1.20 2001/12/07 07:57:35 pvalchev Exp $"; #endif /* not lint */ #include #include #include *************** *** 63,86 **** #include "systat.h" #include "extern.h" ! double dellave; ! kvm_t *kd; ! char *nlistf = NULL; char *memf = NULL; sig_t sigtstpdfl; ! double avenrun[3]; ! int col; int naptime = 5; ! int verbose = 1; /* to report kvm read errs */ ! int hz, stathz; char c; char *namp; char hostname[MAXHOSTNAMELEN]; WINDOW *wnd; long CMDLINE; ! WINDOW *wload; /* one line window for load average */ static void usage __P((void)); --- 62,93 ---- #include "systat.h" #include "extern.h" ! static struct nlist namelist[] = { ! #define X_FIRST 0 ! #define X_HZ 0 ! { "_hz" }, ! #define X_STATHZ 1 ! { "_stathz" }, ! { "" } ! }; ! static double dellave; ! kvm_t *kd; char *memf = NULL; + char *nlistf = NULL; sig_t sigtstpdfl; ! double avenrun[3]; ! int col; int naptime = 5; ! int verbose = 1; /* to report kvm read errs */ ! int hz, stathz; char c; char *namp; char hostname[MAXHOSTNAMELEN]; WINDOW *wnd; long CMDLINE; ! static WINDOW *wload; /* one line window for load average */ static void usage __P((void)); *************** *** 89,108 **** int argc; char **argv; { ! int ch; char errbuf[_POSIX2_LINE_MAX]; ! while ((ch = getopt(argc, argv, "w:")) != -1) switch(ch) { ! case 'w': ! if ((naptime = atoi(optarg)) <= 0) ! errx(1, "interval <= 0."); ! break; ! default: ! usage(); ! } ! argc -= optind; ! argv += optind; while (argc > 0) { if (isdigit(argv[0][0])) { --- 96,130 ---- int argc; char **argv; { ! int ch, ret; char errbuf[_POSIX2_LINE_MAX]; ! while ((ch = getopt(argc, argv, "M:N:w:")) != -1) switch(ch) { ! case 'M': ! memf = optarg; ! break; ! case 'N': ! nlistf = optarg; ! break; ! case 'w': ! if ((naptime = atoi(optarg)) <= 0) ! errx(1, "interval <= 0."); ! break; ! case '?': ! default: ! usage(); ! } ! argc -= optind; ! argv += optind; ! /* ! * Discard setgid privileges if not the running kernel so that bad ! * guys can't print interesting stuff from kernel memory. ! */ ! if (nlistf != NULL || memf != NULL) { ! setegid(getgid()); ! setgid(getgid()); ! } while (argc > 0) { if (isdigit(argv[0][0])) { *************** *** 119,140 **** errx(1, "unknown request: %s", &argv[0][0]); curcmd = p; } ! argc--; ! argv++; } ! kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); if (kd == NULL) { error("%s", errbuf); exit(1); } ! signal(SIGINT, sigdie); ! siginterrupt(SIGINT, 1); ! signal(SIGQUIT, sigdie); ! siginterrupt(SIGQUIT, 1); ! signal(SIGTERM, sigdie); ! siginterrupt(SIGTERM, 1); /* * Initialize display. Load average appears in a one line * window of its own. Current command's display appears in --- 141,165 ---- errx(1, "unknown request: %s", &argv[0][0]); curcmd = p; } ! argc--, argv++; } ! kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); if (kd == NULL) { error("%s", errbuf); exit(1); } ! if ((ret = kvm_nlist(kd, namelist)) == -1) ! errx(1, "%s", kvm_geterr(kd)); ! else if (ret) ! nlisterr(namelist); + if (namelist[X_FIRST].n_type == 0) + errx(1, "couldn't read namelist"); + signal(SIGINT, die); + signal(SIGQUIT, die); + signal(SIGTERM, die); + /* * Initialize display. Load average appears in a one line * window of its own. Current command's display appears in *************** *** 151,197 **** wnd = (*curcmd->c_open)(); if (wnd == NULL) { warnx("couldn't initialize display"); ! die(); } wload = newwin(1, 0, 3, 20); if (wload == NULL) { warnx("couldn't set up load average window"); ! die(); } gethostname(hostname, sizeof (hostname)); ! gethz(); (*curcmd->c_init)(); curcmd->c_flags |= CF_INIT; labels(); dellave = 0.0; ! signal(SIGALRM, sigdisplay); ! siginterrupt(SIGALRM, 1); ! signal(SIGWINCH, sigwinch); ! siginterrupt(SIGWINCH, 1); ! gotdisplay = 1; noecho(); crmode(); keyboard(); /*NOTREACHED*/ } - void - gethz() - { - struct clockinfo cinf; - size_t size = sizeof(cinf); - int mib[2]; - - mib[0] = CTL_KERN; - mib[1] = KERN_CLOCKRATE; - if (sysctl(mib, 2, &cinf, &size, NULL, 0) == -1) - return; - stathz = cinf.stathz; - hz = cinf.hz; - } - static void usage() { --- 176,206 ---- wnd = (*curcmd->c_open)(); if (wnd == NULL) { warnx("couldn't initialize display"); ! die(0); } wload = newwin(1, 0, 3, 20); if (wload == NULL) { warnx("couldn't set up load average window"); ! die(0); } gethostname(hostname, sizeof (hostname)); ! NREAD(X_HZ, &hz, LONG); ! NREAD(X_STATHZ, &stathz, LONG); (*curcmd->c_init)(); curcmd->c_flags |= CF_INIT; labels(); dellave = 0.0; ! signal(SIGALRM, display); ! signal(SIGWINCH, resize); ! display(0); noecho(); crmode(); keyboard(); /*NOTREACHED*/ } static void usage() { *************** *** 218,232 **** } void ! sigdisplay(signo) int signo; { - gotdisplay = 1; - } - - void - display(void) - { int i, j; /* Get the load average over the last minute. */ --- 227,235 ---- } void ! display(signo) int signo; { int i, j; /* Get the load average over the last minute. */ *************** *** 244,251 **** if (dellave < 0.05) c = '|'; dellave = avenrun[0]; ! wmove(wload, 0, 0); ! wclrtoeol(wload); for (i = (j > 50) ? 50 : j; i > 0; i--) waddch(wload, c); if (j > 50) --- 247,253 ---- if (dellave < 0.05) c = '|'; dellave = avenrun[0]; ! wmove(wload, 0, 0); wclrtoeol(wload); for (i = (j > 50) ? 50 : j; i > 0; i--) waddch(wload, c); if (j > 50) *************** *** 270,289 **** clrtoeol(); } - volatile sig_atomic_t gotdie; - volatile sig_atomic_t gotdisplay; - volatile sig_atomic_t gotwinch; - void ! sigdie(signo) int signo; { - gotdie = 1; - } - - void - die() - { if (wnd) { move(CMDLINE, 0); clrtoeol(); --- 272,281 ---- clrtoeol(); } void ! die(signo) int signo; { if (wnd) { move(CMDLINE, 0); clrtoeol(); *************** *** 294,303 **** } void ! sigwinch(signo) int signo; { ! gotwinch = 1; } --- 286,302 ---- } void ! resize(signo) int signo; { ! sigset_t mask, oldmask; ! ! sigemptyset(&mask); ! sigaddset(&mask, SIGALRM); ! sigprocmask(SIG_BLOCK, &mask, &oldmask); ! clearok(curscr, TRUE); ! wrefresh(curscr); ! sigprocmask(SIG_SETMASK, &oldmask, NULL); }