=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/systat/main.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- src/usr.bin/systat/main.c 1996/04/21 23:44:05 1.2 +++ src/usr.bin/systat/main.c 1996/05/22 11:35:35 1.3 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.7 1996/03/21 18:04:25 jtc Exp $ */ +/* $NetBSD: main.c,v 1.8 1996/05/10 23:16:36 thorpej Exp $ */ /*- * Copyright (c) 1980, 1992, 1993 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$NetBSD: main.c,v 1.7 1996/03/21 18:04:25 jtc Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.8 1996/05/10 23:16:36 thorpej Exp $"; #endif /* not lint */ #include @@ -53,6 +53,7 @@ #include #include #include +#include #include "systat.h" #include "extern.h" @@ -68,6 +69,8 @@ static int dellave; kvm_t *kd; +char *memf = NULL; +char *nlistf = NULL; sig_t sigtstpdfl; double avenrun[3]; int col; @@ -82,32 +85,59 @@ static WINDOW *wload; /* one line window for load average */ +static void usage(); + int main(argc, argv) int argc; char **argv; { + int ch; char errbuf[80]; - argc--, argv++; + while ((ch = getopt(argc, argv, "M:N:w:")) != EOF) + 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) + setgid(getgid()); + while (argc > 0) { - if (argv[0][0] == '-') { + if (isdigit(argv[0][0])) { + naptime = atoi(argv[0]); + if (naptime <= 0) + naptime = 5; + } else { struct cmdtab *p; - p = lookup(&argv[0][1]); + p = lookup(&argv[0][0]); if (p == (struct cmdtab *)-1) - errx(1, "ambiguous request: %s", &argv[0][1]); + errx(1, "ambiguous request: %s", &argv[0][0]); if (p == 0) - errx(1, "unknown request: %s", &argv[0][1]); + errx(1, "unknown request: %s", &argv[0][0]); curcmd = p; - } else { - naptime = atoi(argv[0]); - if (naptime <= 0) - naptime = 5; } 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); @@ -161,6 +191,14 @@ keyboard(); /*NOTREACHED*/ } + +static void +usage() +{ + fprintf(stderr, "usage: systat [-M core] [-N system] [-w wait]\n"); + exit(1); +} + void labels()