diff options
author | Peter Valchev <pvalchev@cvs.openbsd.org> | 2001-12-07 07:57:37 +0000 |
---|---|---|
committer | Peter Valchev <pvalchev@cvs.openbsd.org> | 2001-12-07 07:57:37 +0000 |
commit | 682a9f58ff9b22f31d9c8a39ef0588efb6dc8b6f (patch) | |
tree | ca2436d1c78bd021525b94ef7c25f67f04f31773 /usr.bin/systat | |
parent | 1759f3f7346ef1dda87d5f3dd4ac6e91032d3488 (diff) |
back out latest changes which cause problems on alpha/sparc64 until
they are fixed
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 | 106 |
16 files changed, 342 insertions, 345 deletions
diff --git a/usr.bin/systat/cmds.c b/usr.bin/systat/cmds.c index 2e46aa1a6a3..878babaa1e3 100644 --- a/usr.bin/systat/cmds.c +++ b/usr.bin/systat/cmds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmds.c,v 1.8 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: cmds.c,v 1.9 2001/12/07 07:57:35 pvalchev 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.8 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: cmds.c,v 1.9 2001/12/07 07:57:35 pvalchev Exp $"; #endif /* not lint */ #include <stdlib.h> @@ -51,36 +51,36 @@ static char rcsid[] = "$OpenBSD: cmds.c,v 1.8 2001/11/23 22:20:06 deraadt 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(); + if (strcmp(cmd, "quit") == 0 || strcmp(cmd, "q") == 0) + die(0); 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(); - status(); + alarm(0); + naptime = interval; + display(0); + 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(); - status(); + display(0); + 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 d4d52dd91ab..4bcf75f699f 100644 --- a/usr.bin/systat/cmdtab.c +++ b/usr.bin/systat/cmdtab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmdtab.c,v 1.3 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: cmdtab.c,v 1.4 2001/12/07 07:57:35 pvalchev Exp $ */ /* $NetBSD: cmdtab.c,v 1.2 1995/01/20 08:51:51 jtc Exp $ */ /*- @@ -38,34 +38,31 @@ #if 0 static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.3 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.4 2001/12/07 07:57:35 pvalchev 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 4093e3efe34..44123aa7a5d 100644 --- a/usr.bin/systat/disks.c +++ b/usr.bin/systat/disks.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disks.c,v 1.10 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: disks.c,v 1.11 2001/12/07 07:57:35 pvalchev Exp $ */ /* $NetBSD: disks.c,v 1.4 1996/05/10 23:16:33 thorpej Exp $ */ /*- @@ -38,12 +38,11 @@ #if 0 static char sccsid[] = "@(#)disks.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: disks.c,v 1.10 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: disks.c,v 1.11 2001/12/07 07:57:35 pvalchev 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 03f25e0e2cc..45fb4486a73 100644 --- a/usr.bin/systat/extern.h +++ b/usr.bin/systat/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.7 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.8 2001/12/07 07:57:35 pvalchev Exp $ */ /* $NetBSD: extern.h,v 1.3 1996/05/10 23:16:34 thorpej Exp $ */ /*- @@ -75,10 +75,8 @@ int cmdkre __P((char *, char *)); int cmdnetstat __P((char *, char *)); struct cmdtab *lookup __P((char *)); void command __P((char *)); -void sigdie __P((int)); -void die __P((void)); -void sigdisplay __P((int)); -void display __P((void)); +void die __P((int)); +void display __P((int)); int dkinit __P((int)); int dkcmd __P((char *, char *)); void error __P((const char *fmt, ...)); @@ -113,7 +111,7 @@ WINDOW *opennetstat __P((void)); WINDOW *openpigs __P((void)); WINDOW *openswap __P((void)); int prefix __P((char *, char *)); -void sigwinch __P((int)); +void resize __P((int)); void showiostat __P((void)); void showkre __P((void)); void showmbufs __P((void)); @@ -122,11 +120,3 @@ 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 ba747f97597..445fdf1f203 100644 --- a/usr.bin/systat/fetch.c +++ b/usr.bin/systat/fetch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.3 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: fetch.c,v 1.4 2001/12/07 07:57:35 pvalchev Exp $ */ /* $NetBSD: fetch.c,v 1.2 1995/01/20 08:51:56 jtc Exp $ */ /*- @@ -38,11 +38,10 @@ #if 0 static char sccsid[] = "@(#)fetch.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: fetch.c,v 1.3 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: fetch.c,v 1.4 2001/12/07 07:57:35 pvalchev Exp $"; #endif /* not lint */ #include <sys/types.h> -#include <signal.h> #include "systat.h" #include "extern.h" @@ -55,6 +54,7 @@ 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 1e97a5af2d6..532cbe70ca2 100644 --- a/usr.bin/systat/iostat.c +++ b/usr.bin/systat/iostat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iostat.c,v 1.14 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: iostat.c,v 1.15 2001/12/07 07:57:35 pvalchev 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.14 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: iostat.c,v 1.15 2001/12/07 07:57:35 pvalchev Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -48,6 +48,7 @@ static char rcsid[] = "$OpenBSD: iostat.c,v 1.14 2001/11/23 22:20:06 deraadt Exp #include <string.h> #include <stdlib.h> +#include <nlist.h> #include <paths.h> #include "systat.h" #include "extern.h" @@ -209,7 +210,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 0140cbd5ecb..4d8f58448fa 100644 --- a/usr.bin/systat/keyboard.c +++ b/usr.bin/systat/keyboard.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keyboard.c,v 1.8 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: keyboard.c,v 1.9 2001/12/07 07:57:35 pvalchev Exp $ */ /* $NetBSD: keyboard.c,v 1.2 1995/01/20 08:51:59 jtc Exp $ */ /*- @@ -38,13 +38,12 @@ #if 0 static char sccsid[] = "@(#)keyboard.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: keyboard.c,v 1.8 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: keyboard.c,v 1.9 2001/12/07 07:57:35 pvalchev Exp $"; #endif /* not lint */ #include <ctype.h> #include <signal.h> #include <termios.h> -#include <errno.h> #include "systat.h" #include "extern.h" @@ -52,40 +51,24 @@ static char rcsid[] = "$OpenBSD: keyboard.c,v 1.8 2001/11/23 22:20:06 deraadt Ex void keyboard() { - char ch, line[80]; + char ch, line[80]; sigset_t mask, omask; - 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; + for (;;) { + col = 0; + move(CMDLINE, 0); + do { + refresh(); + if ((ch = getch()) == ERR) 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'): @@ -97,57 +80,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 3638d46cf58..e763488e959 100644 --- a/usr.bin/systat/main.c +++ b/usr.bin/systat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.19 2001/11/28 20:28:08 ericj Exp $ */ +/* $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,11 +44,10 @@ 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.19 2001/11/28 20:28:08 ericj Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.20 2001/12/07 07:57:35 pvalchev Exp $"; #endif /* not lint */ #include <sys/param.h> -#include <sys/sysctl.h> #include <err.h> #include <nlist.h> @@ -63,24 +62,32 @@ static char rcsid[] = "$OpenBSD: main.c,v 1.19 2001/11/28 20:28:08 ericj Exp $"; #include "systat.h" #include "extern.h" -double dellave; - -kvm_t *kd; -char *nlistf = NULL; +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; +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; -WINDOW *wload; /* one line window for load average */ +static WINDOW *wload; /* one line window for load average */ static void usage __P((void)); @@ -89,20 +96,35 @@ main(argc, argv) int argc; char **argv; { - int ch; + int ch, ret; char errbuf[_POSIX2_LINE_MAX]; - while ((ch = getopt(argc, argv, "w:")) != -1) + while ((ch = getopt(argc, argv, "M:N:w:")) != -1) switch(ch) { - case 'w': - if ((naptime = atoi(optarg)) <= 0) - errx(1, "interval <= 0."); - break; - default: - usage(); - } - argc -= optind; - argv += optind; + 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,21 +141,24 @@ main(argc, argv) errx(1, "unknown request: %s", &argv[0][0]); curcmd = p; } - argc--; - argv++; + argc--, argv++; } - kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); + kd = kvm_openfiles(nlistf, memf, 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); + 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 @@ -151,47 +176,31 @@ main(argc, argv) wnd = (*curcmd->c_open)(); if (wnd == NULL) { warnx("couldn't initialize display"); - die(); + die(0); } wload = newwin(1, 0, 3, 20); if (wload == NULL) { warnx("couldn't set up load average window"); - die(); + die(0); } gethostname(hostname, sizeof (hostname)); - gethz(); + NREAD(X_HZ, &hz, LONG); + NREAD(X_STATHZ, &stathz, LONG); (*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; + signal(SIGALRM, display); + signal(SIGWINCH, resize); + display(0); 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() { @@ -218,15 +227,9 @@ labels() } void -sigdisplay(signo) +display(signo) int signo; { - gotdisplay = 1; -} - -void -display(void) -{ int i, j; /* Get the load average over the last minute. */ @@ -244,8 +247,7 @@ display(void) 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) @@ -270,20 +272,10 @@ load() clrtoeol(); } -volatile sig_atomic_t gotdie; -volatile sig_atomic_t gotdisplay; -volatile sig_atomic_t gotwinch; - void -sigdie(signo) +die(signo) int signo; { - gotdie = 1; -} - -void -die() -{ if (wnd) { move(CMDLINE, 0); clrtoeol(); @@ -294,10 +286,17 @@ die() } void -sigwinch(signo) +resize(signo) int signo; { - gotwinch = 1; + sigset_t mask, oldmask; + + sigemptyset(&mask); + sigaddset(&mask, SIGALRM); + sigprocmask(SIG_BLOCK, &mask, &oldmask); + clearok(curscr, TRUE); + wrefresh(curscr); + sigprocmask(SIG_SETMASK, &oldmask, NULL); } diff --git a/usr.bin/systat/mbufs.c b/usr.bin/systat/mbufs.c index ec3521e5b7e..72f71cebafc 100644 --- a/usr.bin/systat/mbufs.c +++ b/usr.bin/systat/mbufs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbufs.c,v 1.7 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: mbufs.c,v 1.8 2001/12/07 07:57:35 pvalchev 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.7 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mbufs.c,v 1.8 2001/12/07 07:57:35 pvalchev Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -48,7 +48,6 @@ static char rcsid[] = "$OpenBSD: mbufs.c,v 1.7 2001/11/23 22:20:06 deraadt Exp $ #include <stdlib.h> #include <string.h> #include <nlist.h> -#include <err.h> #include <paths.h> #include "systat.h" #include "extern.h" @@ -108,7 +107,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 c299e0b4311..58aa82f8156 100644 --- a/usr.bin/systat/netcmds.c +++ b/usr.bin/systat/netcmds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcmds.c,v 1.7 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: netcmds.c,v 1.8 2001/12/07 07:57:35 pvalchev 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.7 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: netcmds.c,v 1.8 2001/12/07 07:57:35 pvalchev 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) - strlcpy(hbuf, "(invalid)", sizeof hbuf); + strcpy(hbuf, "(invalid)"); if (!p->onoff) addch('!'); printw("%s ", hbuf); diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c index e8ee5dc9893..e3dc7654b2b 100644 --- a/usr.bin/systat/netstat.c +++ b/usr.bin/systat/netstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.c,v 1.18 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: netstat.c,v 1.19 2001/12/07 07:57:35 pvalchev 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.18 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: netstat.c,v 1.19 2001/12/07 07:57:35 pvalchev 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,12 +195,14 @@ 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; } @@ -227,12 +229,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 } @@ -320,7 +322,8 @@ 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; @@ -354,7 +357,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 @@ -440,14 +443,13 @@ 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)) { @@ -518,7 +520,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 * @@ -553,7 +555,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); } @@ -578,7 +580,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 7ab1c7882af..b17c9d8ab3e 100644 --- a/usr.bin/systat/pigs.c +++ b/usr.bin/systat/pigs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pigs.c,v 1.10 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: pigs.c,v 1.11 2001/12/07 07:57:35 pvalchev 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.10 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: pigs.c,v 1.11 2001/12/07 07:57:35 pvalchev Exp $"; #endif /* not lint */ /* @@ -47,7 +47,6 @@ static char rcsid[] = "$OpenBSD: pigs.c,v 1.10 2001/11/23 22:20:06 deraadt 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> @@ -55,6 +54,7 @@ static char rcsid[] = "$OpenBSD: pigs.c,v 1.10 2001/11/23 22:20:06 deraadt Exp $ #include <curses.h> #include <math.h> +#include <nlist.h> #include <pwd.h> #include <err.h> #include <stdlib.h> @@ -72,6 +72,7 @@ static struct p_times { } *pt; static long stime[CPUSTATES]; +static int fscale; static double lccpu; WINDOW * @@ -114,7 +115,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) @@ -123,7 +124,8 @@ 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; @@ -140,27 +142,38 @@ showpigs() wmove(wnd, y, 0); wclrtobot(wnd); } -struct loadavg sysload; +static struct nlist namelist[] = { +#define X_FIRST 0 +#define X_CPTIME 0 + { "_cp_time" }, +#define X_CCPU 1 + { "_ccpu" }, +#define X_FSCALE 2 + { "_fscale" }, + + { "" } +}; 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; - - 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); + 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); return(1); } @@ -168,17 +181,17 @@ initpigs() void fetchpigs() { - static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME }; - static int lastnproc = 0; - struct kinfo_proc *kpp; - long ctime[CPUSTATES]; - float time; - double t; int i; - size_t size; + float time; struct proc *pp; float *pctp; + struct kinfo_proc *kpp; + long ctime[CPUSTATES]; + double t; + static int lastnproc = 0; + 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) @@ -190,7 +203,7 @@ fetchpigs() if ((pt = malloc((nproc + 1) * sizeof(struct p_times))) == NULL) { error("Out of memory"); - die(); + die(0); } } lastnproc = nproc; @@ -205,15 +218,13 @@ fetchpigs() if (time == 0 || (pp->p_flag & P_INMEM) == 0) *pctp = 0; else - *pctp = ((double) pp->p_pctcpu / - sysload.fscale) / (1.0 - exp(time * lccpu)); + *pctp = ((double) pp->p_pctcpu / + fscale) / (1.0 - exp(time * lccpu)); } /* * and for the imaginary "idle" process */ - size = sizeof(ctime); - (void) sysctl(cp_time_mib, 2, &ctime, &size, NULL, 0); - + KREAD(NPTR(X_CPTIME), ctime, sizeof (ctime)); 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 d4f86875727..c11869324ec 100644 --- a/usr.bin/systat/swap.c +++ b/usr.bin/systat/swap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: swap.c,v 1.12 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: swap.c,v 1.13 2001/12/07 07:57:36 pvalchev Exp $ */ /* $NetBSD: swap.c,v 1.9 1998/12/26 07:05:08 marc Exp $ */ /*- @@ -39,9 +39,10 @@ #if 0 static char sccsid[] = "@(#)swap.c 8.3 (Berkeley) 4/29/95"; #endif -static char rcsid[] = "$OpenBSD: swap.c,v 1.12 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: swap.c,v 1.13 2001/12/07 07:57:36 pvalchev 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 4d41f06b26e..878fdec6f40 100644 --- a/usr.bin/systat/systat.1 +++ b/usr.bin/systat/systat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: systat.1,v 1.23 2001/11/23 22:20:06 deraadt Exp $ +.\" $OpenBSD: systat.1,v 1.24 2001/12/07 07:57:36 pvalchev Exp $ .\" $NetBSD: systat.1,v 1.6 1996/05/10 23:16:39 thorpej Exp $ .\" .\" Copyright (c) 1985, 1990, 1993 @@ -42,6 +42,8 @@ .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 @@ -86,6 +88,14 @@ 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 @@ -354,7 +364,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 36394819d33..3eb7bd0f1e6 100644 --- a/usr.bin/systat/systat.h +++ b/usr.bin/systat/systat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systat.h,v 1.4 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: systat.h,v 1.5 2001/12/07 07:57:36 pvalchev Exp $ */ /* $NetBSD: systat.h,v 1.2 1995/01/20 08:52:14 jtc Exp $ */ /*- @@ -60,3 +60,4 @@ 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 8202e8fb31f..617c2395ee3 100644 --- a/usr.bin/systat/vmstat.c +++ b/usr.bin/systat/vmstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmstat.c,v 1.29 2001/11/23 22:20:06 deraadt Exp $ */ +/* $OpenBSD: vmstat.c,v 1.30 2001/12/07 07:57:36 pvalchev 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.29 2001/11/23 22:20:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: vmstat.c,v 1.30 2001/12/07 07:57:36 pvalchev Exp $"; #endif /* not lint */ /* @@ -88,6 +88,7 @@ static struct Info { #include "dkstats.h" extern struct _disk cur; + #define cnt s.Cnt #define oldcnt s1.Cnt #define total s.Total @@ -117,6 +118,7 @@ static int nextintsrow; struct utmp utmp; + WINDOW * openkre() { @@ -141,16 +143,22 @@ closekre(w) static struct nlist namelist[] = { -#define X_INTRNAMES 0 +#define X_CPTIME 0 + { "_cp_time" }, +#define X_UVMEXP 1 + { "_uvmexp" }, +#define X_NCHSTATS 2 + { "_nchstats" }, +#define X_INTRNAMES 3 { "_intrnames" }, -#define X_EINTRNAMES 1 +#define X_EINTRNAMES 4 { "_eintrnames" }, -#define X_INTRCNT 2 +#define X_INTRCNT 5 { "_intrcnt" }, -#define X_EINTRCNT 3 +#define X_EINTRCNT 6 { "_eintrcnt" }, #if defined(__i386__) -#define X_INTRHAND 4 +#define X_INTRHAND 7 { "_intrhand" }, #endif { "" }, @@ -193,6 +201,7 @@ initkre() { char *intrnamebuf, *cp; int i, ret; + static int once = 0; if (namelist[0].n_type == 0) { if ((ret = kvm_nlist(kd, namelist)) == -1) @@ -205,8 +214,17 @@ 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; @@ -232,7 +250,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; @@ -240,11 +258,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) @@ -257,7 +275,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; @@ -326,15 +344,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"); @@ -344,7 +362,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++) { @@ -374,6 +392,7 @@ showkre() int i, l, c; static int failcnt = 0; + if (state == TIME) dkswap(); etime = 0; @@ -405,7 +424,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); @@ -423,7 +442,7 @@ showkre() psiz = 0; f2 = 0.0; - /* + /* * Last CPU state not calculated yet. */ for (c = 0; c < CPUSTATES - 1; c++) { @@ -435,7 +454,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) @@ -457,7 +476,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 */ @@ -509,21 +528,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 } @@ -633,17 +652,18 @@ getinfo(s, st) struct Info *s; enum state st; { - 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 }; + int mib[2]; 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++) { @@ -655,29 +675,13 @@ getinfo(s, st) } } #else - NREAD(X_INTRCNT, s->intrcnt, nintr * sizeof(long)); + NREAD(X_INTRCNT, s->intrcnt, nintr * 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); - if (sysctl(vmtotal_mib, 2, &s->Total, &size, NULL, 0) < 0) { - error("Can't get VM_METER: %s\n", strerror(errno)); + 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)); bzero(&s->Total, sizeof(s->Total)); } } @@ -713,7 +717,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 */ |