diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-12-07 09:18:09 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-12-07 09:18:09 +0000 |
commit | 66d8c8126639e28dfc19a3fbdb04994a9688ae66 (patch) | |
tree | fa039ad83f7310baed2e929a4b4bdec6bdb55269 /usr.bin/systat | |
parent | d3d53550233ff51d54223f0038313c8832f83f95 (diff) |
move back. pvalchev -- the bug was quite obscure
Diffstat (limited to 'usr.bin/systat')
-rw-r--r-- | usr.bin/systat/cmds.c | 80 | ||||
-rw-r--r-- | usr.bin/systat/cmdtab.c | 21 | ||||
-rw-r--r-- | usr.bin/systat/disks.c | 5 | ||||
-rw-r--r-- | usr.bin/systat/extern.h | 18 | ||||
-rw-r--r-- | usr.bin/systat/fetch.c | 8 | ||||
-rw-r--r-- | usr.bin/systat/iostat.c | 7 | ||||
-rw-r--r-- | usr.bin/systat/keyboard.c | 127 | ||||
-rw-r--r-- | usr.bin/systat/main.c | 153 | ||||
-rw-r--r-- | usr.bin/systat/mbufs.c | 7 | ||||
-rw-r--r-- | usr.bin/systat/netcmds.c | 14 | ||||
-rw-r--r-- | usr.bin/systat/netstat.c | 40 | ||||
-rw-r--r-- | usr.bin/systat/pigs.c | 79 | ||||
-rw-r--r-- | usr.bin/systat/swap.c | 5 | ||||
-rw-r--r-- | usr.bin/systat/systat.1 | 14 | ||||
-rw-r--r-- | usr.bin/systat/systat.h | 3 | ||||
-rw-r--r-- | usr.bin/systat/vmstat.c | 108 |
16 files changed, 347 insertions, 342 deletions
diff --git a/usr.bin/systat/cmds.c b/usr.bin/systat/cmds.c index 878babaa1e3..dd79bd471c8 100644 --- a/usr.bin/systat/cmds.c +++ b/usr.bin/systat/cmds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmds.c,v 1.9 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: cmds.c,v 1.10 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: cmds.c,v 1.4 1996/05/10 23:16:32 thorpej Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cmds.c 8.2 (Berkeley) 4/29/95"; #endif -static char rcsid[] = "$OpenBSD: cmds.c,v 1.9 2001/12/07 07:57:35 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: cmds.c,v 1.10 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ #include <stdlib.h> @@ -51,36 +51,36 @@ static char rcsid[] = "$OpenBSD: cmds.c,v 1.9 2001/12/07 07:57:35 pvalchev Exp $ void command(cmd) - char *cmd; + char *cmd; { - struct cmdtab *p; - char *cp; + struct cmdtab *p; + char *cp; int interval; sigset_t mask, omask; sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigprocmask(SIG_BLOCK, &mask, &omask); - for (cp = cmd; *cp && !isspace(*cp); cp++) - ; - if (*cp) - *cp++ = '\0'; + for (cp = cmd; *cp && !isspace(*cp); cp++) + ; + if (*cp) + *cp++ = '\0'; if (*cmd == '\0') return; for (; *cp && isspace(*cp); cp++) ; - if (strcmp(cmd, "quit") == 0 || strcmp(cmd, "q") == 0) - die(0); + if (strcmp(cmd, "quit") == 0 || strcmp(cmd, "q") == 0) + die(); if (strcmp(cmd, "load") == 0) { load(); goto done; } - if (strcmp(cmd, "stop") == 0) { - alarm(0); - mvaddstr(CMDLINE, 0, "Refresh disabled."); - clrtoeol(); + if (strcmp(cmd, "stop") == 0) { + alarm(0); + mvaddstr(CMDLINE, 0, "Refresh disabled."); + clrtoeol(); goto done; - } + } if (strcmp(cmd, "help") == 0) { int col, len; @@ -97,30 +97,30 @@ command(cmd) goto done; } interval = atoi(cmd); - if (interval <= 0 && + if (interval <= 0 && (strcmp(cmd, "start") == 0 || strcmp(cmd, "interval") == 0)) { interval = *cp ? atoi(cp) : naptime; - if (interval <= 0) { + if (interval <= 0) { error("%d: bad interval.", interval); goto done; - } + } } if (interval > 0) { - alarm(0); - naptime = interval; - display(0); - status(); + alarm(0); + naptime = interval; + display(); + status(); goto done; - } + } p = lookup(cmd); if (p == (struct cmdtab *)-1) { error("%s: Ambiguous command.", cmd); goto done; } - if (p) { - if (curcmd == p) + if (p) { + if (curcmd == p) goto done; - alarm(0); + alarm(0); (*curcmd->c_close)(wnd); wnd = (*p->c_open)(); if (wnd == 0) { @@ -138,12 +138,12 @@ command(cmd) else goto done; } - curcmd = p; + curcmd = p; labels(); - display(0); - status(); + display(); + status(); goto done; - } + } if (curcmd->c_cmd == 0 || !(*curcmd->c_cmd)(cmd, cp)) error("%s: Unknown command.", cmd); done: @@ -183,19 +183,19 @@ void status() { - error("Showing %s, refresh every %d seconds.", - curcmd->c_name, naptime); + error("Showing %s, refresh every %d seconds.", + curcmd->c_name, naptime); } int prefix(s1, s2) - char *s1, *s2; + char *s1, *s2; { - while (*s1 == *s2) { - if (*s1 == '\0') - return (1); - s1++, s2++; - } - return (*s1 == '\0'); + while (*s1 == *s2) { + if (*s1 == '\0') + return (1); + s1++, s2++; + } + return (*s1 == '\0'); } diff --git a/usr.bin/systat/cmdtab.c b/usr.bin/systat/cmdtab.c index 4bcf75f699f..fcd9c868d5e 100644 --- a/usr.bin/systat/cmdtab.c +++ b/usr.bin/systat/cmdtab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmdtab.c,v 1.4 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: cmdtab.c,v 1.5 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: cmdtab.c,v 1.2 1995/01/20 08:51:51 jtc Exp $ */ /*- @@ -38,31 +38,34 @@ #if 0 static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.4 2001/12/07 07:57:35 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.5 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ +#include <sys/types.h> +#include <signal.h> + #include "systat.h" #include "extern.h" struct cmdtab cmdtab[] = { - { "pigs", showpigs, fetchpigs, labelpigs, + { "pigs", showpigs, fetchpigs, labelpigs, initpigs, openpigs, closepigs, 0, CF_LOADAV }, - { "swap", showswap, fetchswap, labelswap, + { "swap", showswap, fetchswap, labelswap, initswap, openswap, closeswap, 0, CF_LOADAV }, - { "mbufs", showmbufs, fetchmbufs, labelmbufs, + { "mbufs", showmbufs, fetchmbufs, labelmbufs, initmbufs, openmbufs, closembufs, 0, CF_LOADAV }, - { "iostat", showiostat, fetchiostat, labeliostat, + { "iostat", showiostat, fetchiostat, labeliostat, initiostat, openiostat, closeiostat, cmdiostat, CF_LOADAV }, - { "vmstat", showkre, fetchkre, labelkre, + { "vmstat", showkre, fetchkre, labelkre, initkre, openkre, closekre, cmdkre, 0 }, - { "netstat", shownetstat, fetchnetstat, labelnetstat, + { "netstat", shownetstat, fetchnetstat, labelnetstat, initnetstat, opennetstat, closenetstat, cmdnetstat, CF_LOADAV }, - { 0 } + { 0 } }; struct cmdtab *curcmd = &cmdtab[0]; diff --git a/usr.bin/systat/disks.c b/usr.bin/systat/disks.c index 44123aa7a5d..8c8fa8a8d5e 100644 --- a/usr.bin/systat/disks.c +++ b/usr.bin/systat/disks.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disks.c,v 1.11 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: disks.c,v 1.12 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: disks.c,v 1.4 1996/05/10 23:16:33 thorpej Exp $ */ /*- @@ -38,11 +38,12 @@ #if 0 static char sccsid[] = "@(#)disks.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: disks.c,v 1.11 2001/12/07 07:57:35 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: disks.c,v 1.12 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ #include <string.h> #include <ctype.h> +#include <signal.h> #include "systat.h" #include "extern.h" static void dkselect(char *args, int truefalse, int selections[]); diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h index 45fb4486a73..b944833121c 100644 --- a/usr.bin/systat/extern.h +++ b/usr.bin/systat/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.8 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: extern.h,v 1.9 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: extern.h,v 1.3 1996/05/10 23:16:34 thorpej Exp $ */ /*- @@ -75,8 +75,10 @@ int cmdkre __P((char *, char *)); int cmdnetstat __P((char *, char *)); struct cmdtab *lookup __P((char *)); void command __P((char *)); -void die __P((int)); -void display __P((int)); +void sigdie __P((int)); +void die __P((void)); +void sigdisplay __P((int)); +void display __P((void)); int dkinit __P((int)); int dkcmd __P((char *, char *)); void error __P((const char *fmt, ...)); @@ -111,7 +113,7 @@ WINDOW *opennetstat __P((void)); WINDOW *openpigs __P((void)); WINDOW *openswap __P((void)); int prefix __P((char *, char *)); -void resize __P((int)); +void sigwinch __P((int)); void showiostat __P((void)); void showkre __P((void)); void showmbufs __P((void)); @@ -120,3 +122,11 @@ void showpigs __P((void)); void showswap __P((void)); void status __P((void)); void suspend __P((int)); +void gethz __P((void)); + +extern volatile sig_atomic_t gotdie; +extern volatile sig_atomic_t gotdisplay; +extern volatile sig_atomic_t gotwinch; + +extern double dellave; +extern WINDOW *wload; diff --git a/usr.bin/systat/fetch.c b/usr.bin/systat/fetch.c index 445fdf1f203..5999d07a363 100644 --- a/usr.bin/systat/fetch.c +++ b/usr.bin/systat/fetch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.4 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: fetch.c,v 1.5 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: fetch.c,v 1.2 1995/01/20 08:51:56 jtc Exp $ */ /*- @@ -38,10 +38,11 @@ #if 0 static char sccsid[] = "@(#)fetch.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: fetch.c,v 1.4 2001/12/07 07:57:35 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: fetch.c,v 1.5 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ #include <sys/types.h> +#include <signal.h> #include "systat.h" #include "extern.h" @@ -54,7 +55,6 @@ kvm_ckread(a, b, l) if (verbose) error("error reading kmem at %x\n", a); return (0); - } - else + } else return (1); } diff --git a/usr.bin/systat/iostat.c b/usr.bin/systat/iostat.c index 532cbe70ca2..74c1d286c8c 100644 --- a/usr.bin/systat/iostat.c +++ b/usr.bin/systat/iostat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iostat.c,v 1.15 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: iostat.c,v 1.16 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: iostat.c,v 1.5 1996/05/10 23:16:35 thorpej Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)iostat.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: iostat.c,v 1.15 2001/12/07 07:57:35 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: iostat.c,v 1.16 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -48,7 +48,6 @@ static char rcsid[] = "$OpenBSD: iostat.c,v 1.15 2001/12/07 07:57:35 pvalchev Ex #include <string.h> #include <stdlib.h> -#include <nlist.h> #include <paths.h> #include "systat.h" #include "extern.h" @@ -210,7 +209,7 @@ showiostat() /* * Interrupt CPU state not calculated yet. - */ + */ for (i = 0; i < CPUSTATES; i++) stat1(row++, i); diff --git a/usr.bin/systat/keyboard.c b/usr.bin/systat/keyboard.c index 4d8f58448fa..e90c38a49d6 100644 --- a/usr.bin/systat/keyboard.c +++ b/usr.bin/systat/keyboard.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keyboard.c,v 1.9 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: keyboard.c,v 1.10 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: keyboard.c,v 1.2 1995/01/20 08:51:59 jtc Exp $ */ /*- @@ -38,12 +38,13 @@ #if 0 static char sccsid[] = "@(#)keyboard.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: keyboard.c,v 1.9 2001/12/07 07:57:35 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: keyboard.c,v 1.10 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ #include <ctype.h> #include <signal.h> #include <termios.h> +#include <errno.h> #include "systat.h" #include "extern.h" @@ -51,24 +52,40 @@ static char rcsid[] = "$OpenBSD: keyboard.c,v 1.9 2001/12/07 07:57:35 pvalchev E void keyboard() { - char ch, line[80]; + char ch, line[80]; sigset_t mask, omask; - for (;;) { - col = 0; - move(CMDLINE, 0); - do { - refresh(); - if ((ch = getch()) == ERR) + for (;;) { + col = 0; + move(CMDLINE, 0); + do { + if (gotdisplay) { + display(); + gotdisplay = 0; + } + if (gotdie) { + die(); + } + if (gotwinch) { + clearok(curscr, TRUE); + wrefresh(curscr); + gotwinch = 0; + } + + refresh(); + if ((ch = getch()) == ERR) { + if (errno == EINTR) + continue; exit(1); - ch &= 0177; - if (ch == 0177 && ferror(stdin)) { - clearerr(stdin); - continue; - } - if (ch >= 'A' && ch <= 'Z') - ch += 'a' - 'A'; - if (col == 0) { + } + ch &= 0177; + if (ch == 0177 && ferror(stdin)) { + clearerr(stdin); + continue; + } + if (ch >= 'A' && ch <= 'Z') + ch += 'a' - 'A'; + if (col == 0) { switch (ch) { case CTRL('l'): case CTRL('g'): @@ -80,57 +97,57 @@ keyboard() else status(); sigprocmask(SIG_SETMASK, &omask, NULL); - continue; + continue; case ':': break; default: continue; } - move(CMDLINE, 0); - clrtoeol(); - } - if (ch == erasechar() && col > 0) { - if (col == 1 && line[0] == ':') - continue; - col--; - goto doerase; - } - if (ch == CTRL('w') && col > 0) { - while (--col >= 0 && isspace(line[col])) - ; - col++; - while (--col >= 0 && !isspace(line[col])) - if (col == 0 && line[0] == ':') - break; - col++; - goto doerase; - } - if (ch == killchar() && col > 0) { - col = 0; - if (line[0] == ':') - col++; - doerase: - move(CMDLINE, col); - clrtoeol(); - continue; - } + move(CMDLINE, 0); + clrtoeol(); + } + if (ch == erasechar() && col > 0) { + if (col == 1 && line[0] == ':') + continue; + col--; + goto doerase; + } + if (ch == CTRL('w') && col > 0) { + while (--col >= 0 && isspace(line[col])) + ; + col++; + while (--col >= 0 && !isspace(line[col])) + if (col == 0 && line[0] == ':') + break; + col++; + goto doerase; + } + if (ch == killchar() && col > 0) { + col = 0; + if (line[0] == ':') + col++; + doerase: + move(CMDLINE, col); + clrtoeol(); + continue; + } if (col >= sizeof(line) - 1) { /* line too long */ beep(); continue; } - if (isprint(ch) || ch == ' ') { - line[col] = ch; - mvaddch(CMDLINE, col, ch); - col++; - } - } while (col == 0 || (ch != '\r' && ch != '\n')); - line[col] = '\0'; + if (isprint(ch) || ch == ' ') { + line[col] = ch; + mvaddch(CMDLINE, col, ch); + col++; + } + } while (col == 0 || (ch != '\r' && ch != '\n')); + line[col] = '\0'; sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigprocmask(SIG_BLOCK, &mask, &omask); - command(line + 1); + command(line + 1); sigprocmask(SIG_SETMASK, &omask, NULL); - } + } /*NOTREACHED*/ } diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c index e763488e959..363240cd79a 100644 --- a/usr.bin/systat/main.c +++ b/usr.bin/systat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.20 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: main.c,v 1.21 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: main.c,v 1.8 1996/05/10 23:16:36 thorpej Exp $ */ /*- @@ -44,10 +44,11 @@ static char copyright[] = #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 $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.21 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> +#include <sys/sysctl.h> #include <err.h> #include <nlist.h> @@ -62,32 +63,24 @@ static char rcsid[] = "$OpenBSD: main.c,v 1.20 2001/12/07 07:57:35 pvalchev Exp #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; +double dellave; + +kvm_t *kd; char *nlistf = NULL; +char *memf = NULL; sig_t sigtstpdfl; -double avenrun[3]; -int col; +double avenrun[3]; +int col; int naptime = 5; -int verbose = 1; /* to report kvm read errs */ -int hz, stathz; +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 */ +WINDOW *wload; /* one line window for load average */ static void usage __P((void)); @@ -96,35 +89,20 @@ main(argc, argv) int argc; char **argv; { - int ch, ret; + int ch; char errbuf[_POSIX2_LINE_MAX]; - while ((ch = getopt(argc, argv, "M:N:w:")) != -1) + while ((ch = getopt(argc, argv, "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()); - } + 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])) { @@ -141,24 +119,21 @@ main(argc, argv) errx(1, "unknown request: %s", &argv[0][0]); curcmd = p; } - argc--, argv++; + argc--; + argv++; } - kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); + kd = kvm_openfiles(NULL, NULL, 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); + 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 @@ -176,31 +151,47 @@ main(argc, argv) wnd = (*curcmd->c_open)(); if (wnd == NULL) { warnx("couldn't initialize display"); - die(0); + die(); } wload = newwin(1, 0, 3, 20); if (wload == NULL) { warnx("couldn't set up load average window"); - die(0); + die(); } gethostname(hostname, sizeof (hostname)); - NREAD(X_HZ, &hz, LONG); - NREAD(X_STATHZ, &stathz, LONG); + gethz(); (*curcmd->c_init)(); curcmd->c_flags |= CF_INIT; labels(); dellave = 0.0; - signal(SIGALRM, display); - signal(SIGWINCH, resize); - display(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() { @@ -227,9 +218,15 @@ labels() } void -display(signo) +sigdisplay(signo) int signo; { + gotdisplay = 1; +} + +void +display(void) +{ int i, j; /* Get the load average over the last minute. */ @@ -247,7 +244,8 @@ display(signo) if (dellave < 0.05) c = '|'; dellave = avenrun[0]; - wmove(wload, 0, 0); wclrtoeol(wload); + wmove(wload, 0, 0); + wclrtoeol(wload); for (i = (j > 50) ? 50 : j; i > 0; i--) waddch(wload, c); if (j > 50) @@ -272,10 +270,20 @@ load() clrtoeol(); } +volatile sig_atomic_t gotdie; +volatile sig_atomic_t gotdisplay; +volatile sig_atomic_t gotwinch; + void -die(signo) +sigdie(signo) int signo; { + gotdie = 1; +} + +void +die() +{ if (wnd) { move(CMDLINE, 0); clrtoeol(); @@ -286,17 +294,10 @@ die(signo) } void -resize(signo) +sigwinch(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); + gotwinch = 1; } diff --git a/usr.bin/systat/mbufs.c b/usr.bin/systat/mbufs.c index 72f71cebafc..dbdb6c1d272 100644 --- a/usr.bin/systat/mbufs.c +++ b/usr.bin/systat/mbufs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbufs.c,v 1.8 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: mbufs.c,v 1.9 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: mbufs.c,v 1.2 1995/01/20 08:52:02 jtc Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: mbufs.c,v 1.8 2001/12/07 07:57:35 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: mbufs.c,v 1.9 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -48,6 +48,7 @@ static char rcsid[] = "$OpenBSD: mbufs.c,v 1.8 2001/12/07 07:57:35 pvalchev Exp #include <stdlib.h> #include <string.h> #include <nlist.h> +#include <err.h> #include <paths.h> #include "systat.h" #include "extern.h" @@ -107,7 +108,7 @@ showmbufs() if (mb == 0) return; for (j = 0; j < wnd->_maxy; j++) { - max = 0, index = -1; + max = 0, index = -1; for (i = 0; i < wnd->_maxy; i++) if (mb->m_mtypes[i] > max) { max = mb->m_mtypes[i]; diff --git a/usr.bin/systat/netcmds.c b/usr.bin/systat/netcmds.c index 58aa82f8156..978063cccf1 100644 --- a/usr.bin/systat/netcmds.c +++ b/usr.bin/systat/netcmds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcmds.c,v 1.8 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: netcmds.c,v 1.9 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: netcmds.c,v 1.4 1995/05/21 17:14:38 mycroft Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)netcmds.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: netcmds.c,v 1.8 2001/12/07 07:57:35 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: netcmds.c,v 1.9 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ /* @@ -327,8 +327,8 @@ checkhost(inp) if (hosts) for (p = hosts; p < hosts+nhosts; p++) { - if (((struct sockaddr *)&p->addr)->sa_family == AF_INET - && !(inp->inp_flags & INP_IPV6)) { + if (((struct sockaddr *)&p->addr)->sa_family == AF_INET && + !(inp->inp_flags & INP_IPV6)) { struct sockaddr_in *sin; sin = (struct sockaddr_in *)&p->addr; if (sin->sin_addr.s_addr == inp->inp_laddr.s_addr || @@ -336,8 +336,8 @@ checkhost(inp) return (p->onoff); } #ifdef INET6 - if (((struct sockaddr *)&p->addr)->sa_family == AF_INET6 - && (inp->inp_flags & INP_IPV6)) { + if (((struct sockaddr *)&p->addr)->sa_family == AF_INET6 && + (inp->inp_flags & INP_IPV6)) { struct sockaddr_in6 *sin6; sin6 = (struct sockaddr_in6 *)&p->addr; if (IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &inp->inp_laddr6) || @@ -366,7 +366,7 @@ showhosts() sa = (struct sockaddr *)&p->addr; if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0, flags) != 0) - strcpy(hbuf, "(invalid)"); + strlcpy(hbuf, "(invalid)", sizeof hbuf); if (!p->onoff) addch('!'); printw("%s ", hbuf); diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c index e3dc7654b2b..309a86d8af2 100644 --- a/usr.bin/systat/netstat.c +++ b/usr.bin/systat/netstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.c,v 1.19 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: netstat.c,v 1.20 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: netstat.c,v 1.3 1995/06/18 23:53:07 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)netstat.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: netstat.c,v 1.19 2001/12/07 07:57:35 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: netstat.c,v 1.20 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ /* @@ -132,7 +132,7 @@ static int lastrow = 1; void closenetstat(w) - WINDOW *w; + WINDOW *w; { struct netinfo *p; @@ -145,7 +145,7 @@ closenetstat(w) p->nif_line = -1; p = p->nif_forw; } - if (w != NULL) { + if (w != NULL) { wclear(w); wrefresh(w); delwin(w); @@ -195,14 +195,12 @@ fetchnetstat() for (p = netcb.nif_forw; p != (struct netinfo *)&netcb; p = p->nif_forw) p->nif_seen = 0; if (protos&TCP) { - off = NPTR(X_TCBTABLE); + off = NPTR(X_TCBTABLE); istcp = 1; - } - else if (protos&UDP) { - off = NPTR(X_UDBTABLE); + } else if (protos&UDP) { + off = NPTR(X_UDBTABLE); istcp = 0; - } - else { + } else { error("No protocols to display"); return; } @@ -229,12 +227,12 @@ printf("prev = %p, head = %p, next = %p, inpcb...prev = %p\n", prev, head, next, #endif if (!aflag) { - if (!(inpcb.inp_flags & INP_IPV6) - && inet_lnaof(inpcb.inp_laddr) == INADDR_ANY) + if (!(inpcb.inp_flags & INP_IPV6) && + inet_lnaof(inpcb.inp_laddr) == INADDR_ANY) continue; #ifdef INET6 - if ((inpcb.inp_flags & INP_IPV6) - && IN6_IS_ADDR_UNSPECIFIED(&inpcb.inp_laddr6)) + if ((inpcb.inp_flags & INP_IPV6) && + IN6_IS_ADDR_UNSPECIFIED(&inpcb.inp_laddr6)) continue; #endif } @@ -322,8 +320,7 @@ enter(inp, so, state, proto) p->nif_laddr6 = inp->inp_laddr6; p->nif_faddr6 = inp->inp_faddr6; p->nif_family = AF_INET6; - } - else + } else #endif { p->nif_laddr = inp->inp_laddr; @@ -357,7 +354,7 @@ labelnetstat() mvwaddstr(wnd, 0, PROTO, "Proto"); mvwaddstr(wnd, 0, RCVCC, "Recv-Q"); mvwaddstr(wnd, 0, SNDCC, "Send-Q"); - mvwaddstr(wnd, 0, STATE, "(state)"); + mvwaddstr(wnd, 0, STATE, "(state)"); } void @@ -443,13 +440,14 @@ shownetstat() #endif mvwprintw(wnd, p->nif_line, RCVCC, "%6d", p->nif_rcvcc); mvwprintw(wnd, p->nif_line, SNDCC, "%6d", p->nif_sndcc); - if (streq(p->nif_proto, "tcp")) + if (streq(p->nif_proto, "tcp")) { if (p->nif_state < 0 || p->nif_state >= TCP_NSTATES) mvwprintw(wnd, p->nif_line, STATE, "%d", p->nif_state); else mvwaddstr(wnd, p->nif_line, STATE, tcpstates[p->nif_state]); + } wclrtoeol(wnd); } if (lastrow < YMAX(wnd)) { @@ -520,7 +518,7 @@ inet6print(in6, port, proto) /* * Construct an Internet address representation. - * If the nflag has been supplied, give + * If the nflag has been supplied, give * numeric value, otherwise try for symbolic name. */ static const char * @@ -555,7 +553,7 @@ inetname(in) in.s_addr = ntohl(in.s_addr); #define C(x) ((x) & 0xff) snprintf(line, sizeof line, "%u.%u.%u.%u", C(in.s_addr >> 24), - C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr)); + C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr)); } return (line); } @@ -580,7 +578,7 @@ inet6name(in6) sin6.sin6_len = sizeof(struct sockaddr_in6); sin6.sin6_addr = *in6; if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, - line, sizeof(line), NULL, 0, flags) == 0) + line, sizeof(line), NULL, 0, flags) == 0) return line; return "?"; } diff --git a/usr.bin/systat/pigs.c b/usr.bin/systat/pigs.c index b17c9d8ab3e..ba8f7ce65b3 100644 --- a/usr.bin/systat/pigs.c +++ b/usr.bin/systat/pigs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pigs.c,v 1.11 2001/12/07 07:57:35 pvalchev Exp $ */ +/* $OpenBSD: pigs.c,v 1.12 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: pigs.c,v 1.3 1995/04/29 05:54:50 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)pigs.c 8.2 (Berkeley) 9/23/93"; #endif -static char rcsid[] = "$OpenBSD: pigs.c,v 1.11 2001/12/07 07:57:35 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: pigs.c,v 1.12 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ /* @@ -47,6 +47,7 @@ static char rcsid[] = "$OpenBSD: pigs.c,v 1.11 2001/12/07 07:57:35 pvalchev Exp #include <sys/param.h> #include <sys/dkstat.h> +#include <sys/resource.h> #include <sys/dir.h> #include <sys/time.h> #include <sys/proc.h> @@ -54,7 +55,6 @@ static char rcsid[] = "$OpenBSD: pigs.c,v 1.11 2001/12/07 07:57:35 pvalchev Exp #include <curses.h> #include <math.h> -#include <nlist.h> #include <pwd.h> #include <err.h> #include <stdlib.h> @@ -72,7 +72,6 @@ static struct p_times { } *pt; static long stime[CPUSTATES]; -static int fscale; static double lccpu; WINDOW * @@ -115,7 +114,7 @@ showpigs() total = 1.0; factor = 50.0/total; - qsort(pt, nproc + 1, sizeof (struct p_times), compar); + qsort(pt, nproc + 1, sizeof (struct p_times), compar); y = 1; i = nproc + 1; if (i > wnd->_maxy-1) @@ -124,8 +123,7 @@ showpigs() if (pt[k].pt_kp == NULL) { uname = ""; pname = "<idle>"; - } - else { + } else { ep = &pt[k].pt_kp->kp_eproc; uname = user_from_uid(ep->e_ucred.cr_uid, 0); pname = pt[k].pt_kp->kp_proc.p_comm; @@ -142,38 +140,27 @@ showpigs() wmove(wnd, y, 0); wclrtobot(wnd); } -static struct nlist namelist[] = { -#define X_FIRST 0 -#define X_CPTIME 0 - { "_cp_time" }, -#define X_CCPU 1 - { "_ccpu" }, -#define X_FSCALE 2 - { "_fscale" }, - - { "" } -}; +struct loadavg sysload; int initpigs() { + static int sysload_mib[] = {CTL_VM, VM_LOADAVG}; + static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME }; + static int ccpu_mib[] = { CTL_KERN, KERN_CCPU }; + size_t size; fixpt_t ccpu; - int ret; - - if (namelist[X_FIRST].n_type == 0) { - 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) { - error("namelist failed"); - return(0); - } - } - KREAD(NPTR(X_CPTIME), stime, sizeof (stime)); - NREAD(X_CCPU, &ccpu, LONG); - NREAD(X_FSCALE, &fscale, LONG); - lccpu = log((double) ccpu / fscale); + + size = sizeof(stime); + (void) sysctl(cp_time_mib, 2, &stime, &size, NULL, 0); + + size = sizeof(sysload); + (void) sysctl(sysload_mib, 2, &sysload, &size, NULL, 0); + + size = sizeof(ccpu); + (void) sysctl(ccpu_mib, 2, &ccpu, &size, NULL, 0); + + lccpu = log((double) ccpu / sysload.fscale); return(1); } @@ -181,17 +168,17 @@ initpigs() void fetchpigs() { - int i; - float time; - struct proc *pp; - float *pctp; + static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME }; + static int lastnproc = 0; struct kinfo_proc *kpp; long ctime[CPUSTATES]; + float time; double t; - static int lastnproc = 0; + int i; + size_t size; + struct proc *pp; + float *pctp; - if (namelist[X_FIRST].n_type == 0) - return; if ((kpp = kvm_getprocs(kd, KERN_PROC_KTHREAD, 0, &nproc)) == NULL) { error("%s", kvm_geterr(kd)); if (pt) @@ -203,7 +190,7 @@ fetchpigs() if ((pt = malloc((nproc + 1) * sizeof(struct p_times))) == NULL) { error("Out of memory"); - die(0); + die(); } } lastnproc = nproc; @@ -218,13 +205,15 @@ fetchpigs() if (time == 0 || (pp->p_flag & P_INMEM) == 0) *pctp = 0; else - *pctp = ((double) pp->p_pctcpu / - fscale) / (1.0 - exp(time * lccpu)); + *pctp = ((double) pp->p_pctcpu / + sysload.fscale) / (1.0 - exp(time * lccpu)); } /* * and for the imaginary "idle" process */ - KREAD(NPTR(X_CPTIME), ctime, sizeof (ctime)); + size = sizeof(ctime); + (void) sysctl(cp_time_mib, 2, &ctime, &size, NULL, 0); + t = 0; for (i = 0; i < CPUSTATES; i++) t += ctime[i] - stime[i]; diff --git a/usr.bin/systat/swap.c b/usr.bin/systat/swap.c index c11869324ec..6e23d5e5d6d 100644 --- a/usr.bin/systat/swap.c +++ b/usr.bin/systat/swap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: swap.c,v 1.13 2001/12/07 07:57:36 pvalchev Exp $ */ +/* $OpenBSD: swap.c,v 1.14 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: swap.c,v 1.9 1998/12/26 07:05:08 marc Exp $ */ /*- @@ -39,10 +39,9 @@ #if 0 static char sccsid[] = "@(#)swap.c 8.3 (Berkeley) 4/29/95"; #endif -static char rcsid[] = "$OpenBSD: swap.c,v 1.13 2001/12/07 07:57:36 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: swap.c,v 1.14 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ - #include <sys/cdefs.h> #include <sys/param.h> #include <sys/buf.h> diff --git a/usr.bin/systat/systat.1 b/usr.bin/systat/systat.1 index 878fdec6f40..6e0bbfdc18a 100644 --- a/usr.bin/systat/systat.1 +++ b/usr.bin/systat/systat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: systat.1,v 1.24 2001/12/07 07:57:36 pvalchev Exp $ +.\" $OpenBSD: systat.1,v 1.25 2001/12/07 09:18:08 deraadt Exp $ .\" $NetBSD: systat.1,v 1.6 1996/05/10 23:16:39 thorpej Exp $ .\" .\" Copyright (c) 1985, 1990, 1993 @@ -42,8 +42,6 @@ .Nd display system statistics on a crt .Sh SYNOPSIS .Nm systat -.Op Fl M Ar core -.Op Fl N Ar system .Op Fl w Ar wait .Op Ar display .Op Ar refresh-interval @@ -88,14 +86,6 @@ This allows each display to have certain display-specific commands. .Pp The options are as follows: .Bl -tag -width Ds -.It Fl M Ar core -Extract values associated with the name list from -.Ar core -instead of the running kernel. -.It Fl N Ar system -Extract the name list from -.Ar system -instead of the running kernel. .It Ar display The .Ar display @@ -364,7 +354,7 @@ target number of free pages target number of inactive pages .It wired wired pages -.It pdfre +.It pdfre pages daemon freed since boot .It pdscn pages daemon scanned since boot diff --git a/usr.bin/systat/systat.h b/usr.bin/systat/systat.h index 3eb7bd0f1e6..62e898adf36 100644 --- a/usr.bin/systat/systat.h +++ b/usr.bin/systat/systat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systat.h,v 1.5 2001/12/07 07:57:36 pvalchev Exp $ */ +/* $OpenBSD: systat.h,v 1.6 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: systat.h,v 1.2 1995/01/20 08:52:14 jtc Exp $ */ /*- @@ -60,4 +60,3 @@ struct cmdtab { #define NVAL(indx) namelist[(indx)].n_value #define NPTR(indx) (void *)NVAL((indx)) #define NREAD(indx, buf, len) kvm_ckread(NPTR((indx)), (buf), (len)) -#define LONG (sizeof (long)) diff --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c index 617c2395ee3..2274f5b4418 100644 --- a/usr.bin/systat/vmstat.c +++ b/usr.bin/systat/vmstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmstat.c,v 1.30 2001/12/07 07:57:36 pvalchev Exp $ */ +/* $OpenBSD: vmstat.c,v 1.31 2001/12/07 09:18:08 deraadt Exp $ */ /* $NetBSD: vmstat.c,v 1.5 1996/05/10 23:16:40 thorpej Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94"; #endif -static char rcsid[] = "$OpenBSD: vmstat.c,v 1.30 2001/12/07 07:57:36 pvalchev Exp $"; +static char rcsid[] = "$OpenBSD: vmstat.c,v 1.31 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ /* @@ -88,7 +88,6 @@ static struct Info { #include "dkstats.h" extern struct _disk cur; - #define cnt s.Cnt #define oldcnt s1.Cnt #define total s.Total @@ -118,7 +117,6 @@ static int nextintsrow; struct utmp utmp; - WINDOW * openkre() { @@ -143,22 +141,18 @@ closekre(w) static struct nlist namelist[] = { -#define X_CPTIME 0 - { "_cp_time" }, -#define X_UVMEXP 1 - { "_uvmexp" }, -#define X_NCHSTATS 2 - { "_nchstats" }, -#define X_INTRNAMES 3 +#define X_HZ 0 + { "_hz" }, +#define X_INTRNAMES 1 { "_intrnames" }, -#define X_EINTRNAMES 4 +#define X_EINTRNAMES 2 { "_eintrnames" }, -#define X_INTRCNT 5 +#define X_INTRCNT 3 { "_intrcnt" }, -#define X_EINTRCNT 6 +#define X_EINTRCNT 4 { "_eintrcnt" }, #if defined(__i386__) -#define X_INTRHAND 7 +#define X_INTRHAND 5 { "_intrhand" }, #endif { "" }, @@ -201,7 +195,6 @@ initkre() { char *intrnamebuf, *cp; int i, ret; - static int once = 0; if (namelist[0].n_type == 0) { if ((ret = kvm_nlist(kd, namelist)) == -1) @@ -214,17 +207,8 @@ initkre() } } hertz = stathz ? stathz : hz; - if (! dkinit(1)) + if (!dkinit(1)) return(0); - if (dk_ndrive && !once) { -#define allocate(e, t) \ - s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \ - s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \ - s2./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \ - z./**/e = (t *)calloc(dk_ndrive, sizeof (t)); - once = 1; -#undef allocate - } if (nintr == 0) { #if defined(__i386__) struct intrhand *intrhand[16], *ihp, ih; @@ -250,7 +234,7 @@ initkre() while (ihp) { KREAD(ihp, &ih, sizeof(ih)); KREAD(ih.ih_what, iname, 16); - /* XXX strcpy is safe, sized & malloc'd buffer */ + /* XXX strcpy is safe, sized & malloc'd buffer */ strcpy(intrname[n++] = intrnamebuf + namelen, iname); namelen += 1 + strlen(iname); ihp = ih.ih_next; @@ -258,11 +242,11 @@ initkre() } #else nintr = (namelist[X_EINTRCNT].n_value - - namelist[X_INTRCNT].n_value) / sizeof (long); + namelist[X_INTRCNT].n_value) / sizeof (long); intrloc = calloc(nintr, sizeof (long)); intrname = calloc(nintr, sizeof (long)); intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value - - namelist[X_INTRNAMES].n_value); + namelist[X_INTRNAMES].n_value); if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) { error("Out of memory\n"); if (intrnamebuf) @@ -275,7 +259,7 @@ initkre() return(0); } NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) - - NVAL(X_INTRNAMES)); + NVAL(X_INTRNAMES)); for (cp = intrnamebuf, i = 0; i < nintr; i++) { intrname[i] = cp; cp += strlen(cp) + 1; @@ -344,15 +328,15 @@ labelkre() mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt"); mvprintw(GRAPHROW, GRAPHCOL, - " . %% Sys . %% User . %% Nice . %% Idle"); + " . %% Sys . %% User . %% Nice . %% Idle"); mvprintw(PROCSROW, PROCSCOL, "Proc:r d s w"); mvprintw(GRAPHROW + 1, GRAPHCOL, - "| | | | | | | | | | |"); + "| | | | | | | | | | |"); mvprintw(NAMEIROW, NAMEICOL, - "Namei Sys-cache Proc-cache No-cache"); + "Namei Sys-cache Proc-cache No-cache"); mvprintw(NAMEIROW + 1, NAMEICOL, - " Calls hits %% hits %% miss %%"); + " Calls hits %% hits %% miss %%"); mvprintw(DISKROW, DISKCOL, "Discs"); mvprintw(DISKROW + 1, DISKCOL, "seeks"); mvprintw(DISKROW + 2, DISKCOL, "xfers"); @@ -362,7 +346,7 @@ labelkre() for (i = 0; i < dk_ndrive && j < MAXDRIVES; i++) if (dk_select[i]) { mvprintw(DISKROW, DISKCOL + 5 + 5 * j, - " %4.4s", dr_name[j]); + " %4.4s", dr_name[j]); j++; } for (i = 0; i < nintr; i++) { @@ -392,7 +376,6 @@ showkre() int i, l, c; static int failcnt = 0; - if (state == TIME) dkswap(); etime = 0; @@ -424,7 +407,7 @@ showkre() continue; intrloc[i] = nextintsrow++; mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s", - intrname[i]); + intrname[i]); } X(intrcnt); l = (int)((float)s.intrcnt[i]/etime + 0.5); @@ -442,7 +425,7 @@ showkre() psiz = 0; f2 = 0.0; - /* + /* * Last CPU state not calculated yet. */ for (c = 0; c < CPUSTATES - 1; c++) { @@ -454,7 +437,7 @@ showkre() putfloat(f1, GRAPHROW, GRAPHCOL + 1, 5, 1, 0); else putfloat(f1, GRAPHROW, GRAPHCOL + 12 * c, - 5, 1, 0); + 5, 1, 0); move(GRAPHROW + 2, psiz); psiz += l; while (l-- > 0) @@ -476,7 +459,7 @@ showkre() putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0); putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0); mvaddstr(STATROW, STATCOL + 53, buf); -#define pgtokb(pg) ((pg) * s.uvmexp.pagesize / 1024) +#define pgtokb(pg) ((pg) * s.uvmexp.pagesize / 1024) putint(pgtokb(s.uvmexp.active), MEMROW + 2, MEMCOL + 6, 7); putint(pgtokb(s.uvmexp.active + s.uvmexp.swpginuse), /* XXX */ @@ -528,21 +511,21 @@ showkre() for (i = 0, c = 0; i < dk_ndrive && c < MAXDRIVES; i++) if (dk_select[i]) { mvprintw(DISKROW, DISKCOL + 5 + 5 * c, - " %4.4s", dr_name[i]); + " %4.4s", dr_name[i]); dinfo(i, ++c); } putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9); putint(nchtotal.ncs_goodhits, NAMEIROW + 2, NAMEICOL + 10, 8); #define nz(x) ((x) ? (x) : 1) putfloat(nchtotal.ncs_goodhits * 100.0 / nz(s.nchcount), - NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1); + NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1); putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 24, 7); putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount), - NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1); + NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1); putint(nchtotal.ncs_miss - nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 38, 7); putfloat((nchtotal.ncs_miss - nchtotal.ncs_pass2) * - 100.0 / nz(s.nchcount), NAMEIROW + 2, NAMEICOL + 45, 4, 0, 1); + 100.0 / nz(s.nchcount), NAMEIROW + 2, NAMEICOL + 45, 4, 0, 1); #undef nz } @@ -652,18 +635,17 @@ getinfo(s, st) struct Info *s; enum state st; { - int mib[2]; + static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME }; + static int nchstats_mib[2] = { CTL_KERN, KERN_NCHSTATS }; + static int uvmexp_mib[2] = { CTL_VM, VM_UVMEXP }; + static int vmtotal_mib[2] = { CTL_VM, VM_METER }; size_t size; - extern int errno; #if defined(__i386__) struct intrhand *intrhand[16], *ihp, ih; int i, n; #endif dkreadstats(); - NREAD(X_CPTIME, s->time, sizeof s->time); - NREAD(X_UVMEXP, &s->uvmexp, sizeof s->uvmexp); - NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats); #if defined(__i386__) NREAD(X_INTRHAND, intrhand, sizeof(intrhand)); for (i = 0, n = 0; i < 16; i++) { @@ -675,13 +657,29 @@ getinfo(s, st) } } #else - NREAD(X_INTRCNT, s->intrcnt, nintr * LONG); + NREAD(X_INTRCNT, s->intrcnt, nintr * sizeof(long)); #endif + size = sizeof(s->time); + if (sysctl(cp_time_mib, 2, &s->time, &size, NULL, 0) < 0) { + error("Can't get KERN_CPTIME: %s\n", strerror(errno)); + bzero(&s->time, sizeof(s->time)); + } + + size = sizeof(s->nchstats); + if (sysctl(nchstats_mib, 2, &s->nchstats, &size, NULL, 0) < 0) { + error("Can't get KERN_NCHSTATS: %s\n", strerror(errno)); + bzero(&s->nchstats, sizeof(s->nchstats)); + } + + size = sizeof(s->uvmexp); + if (sysctl(uvmexp_mib, 2, &s->uvmexp, &size, NULL, 0) < 0) { + error("Can't get VM_UVMEXP: %s\n", strerror(errno)); + bzero(&s->uvmexp, sizeof(s->uvmexp)); + } + size = sizeof(s->Total); - mib[0] = CTL_VM; - mib[1] = VM_METER; - if (sysctl(mib, 2, &s->Total, &size, NULL, 0) < 0) { - error("Can't get kernel info: %s\n", strerror(errno)); + if (sysctl(vmtotal_mib, 2, &s->Total, &size, NULL, 0) < 0) { + error("Can't get VM_METER: %s\n", strerror(errno)); bzero(&s->Total, sizeof(s->Total)); } } @@ -717,7 +715,7 @@ dinfo(dn, c) /* time busy in disk activity */ atime = (double)cur.dk_time[dn].tv_sec + - ((double)cur.dk_time[dn].tv_usec / (double)1000000); + ((double)cur.dk_time[dn].tv_usec / (double)1000000); words = cur.dk_bytes[dn] / 1024.0; /* # of K transferred */ |