=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/vmstat/vmstat.c,v retrieving revision 1.101 retrieving revision 1.102 diff -u -r1.101 -r1.102 --- src/usr.bin/vmstat/vmstat.c 2006/03/13 19:29:26 1.101 +++ src/usr.bin/vmstat/vmstat.c 2006/03/31 04:06:13 1.102 @@ -1,5 +1,5 @@ /* $NetBSD: vmstat.c,v 1.29.4.1 1996/06/05 00:21:05 cgd Exp $ */ -/* $OpenBSD: vmstat.c,v 1.101 2006/03/13 19:29:26 otto Exp $ */ +/* $OpenBSD: vmstat.c,v 1.102 2006/03/31 04:06:13 deraadt Exp $ */ /* * Copyright (c) 1980, 1986, 1991, 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: vmstat.c,v 1.101 2006/03/13 19:29:26 otto Exp $"; +static const char rcsid[] = "$OpenBSD: vmstat.c,v 1.102 2006/03/31 04:06:13 deraadt Exp $"; #endif #endif /* not lint */ @@ -151,15 +151,13 @@ int main(int argc, char *argv[]) { - int mib[2]; - size_t size; - int c, todo; - u_int interval; - int reps; char errbuf[_POSIX2_LINE_MAX]; + int c, todo = 0, reps = 0, mib[2]; + const char *errstr; + u_int interval = 0; + size_t size; gid_t gid; - interval = reps = todo = 0; while ((c = getopt(argc, argv, "c:fiM:mN:stw:vz")) != -1) { switch (c) { case 'c': @@ -187,7 +185,9 @@ todo |= TIMESTAT; break; case 'w': - interval = atoi(optarg); + interval = (u_int)strtonum(optarg, 0, 1000, &errstr); + if (errstr) + err(1, "-w %s: %s\n", optarg, errstr); break; case 'v': verbose = 1; @@ -259,7 +259,7 @@ dkinit(0); /* Initialize disk stats, no disks selected. */ argv = choosedrives(argv); /* Select disks. */ winsize.ws_row = 0; - (void) ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&winsize); + (void) ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize); if (winsize.ws_row > 0) winlines = winsize.ws_row; @@ -268,7 +268,10 @@ #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { - interval = atoi(*argv); + interval = (u_int)strtonum(*argv, 0, 1000, &errstr); + if (errstr) + err(1, "-w %s: %s\n", optarg, errstr); + if (*++argv) reps = atoi(*argv); } @@ -334,11 +337,11 @@ time_t getuptime(void) { - static time_t now; static struct timeval boottime; + static time_t now; time_t uptime; - int mib[2]; size_t size; + int mib[2]; if (boottime.tv_sec == 0) { if (nlistf == NULL && memf == NULL) { @@ -366,11 +369,11 @@ void dovmstat(u_int interval, int reps) { - struct vmtotal total; time_t uptime, halfuptime; - int mib[2]; struct clockinfo clkinfo; + struct vmtotal total; size_t size; + int mib[2]; uptime = getuptime(); halfuptime = uptime / 2; @@ -411,7 +414,7 @@ (void)printf("%2u%2u%2u", total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw); #define rate(x) (((x) + halfuptime) / uptime) /* round */ -#define pgtok(a) ((a) * ((int)uvmexp.pagesize >> 10)) +#define pgtok(a) ((a) * ((unsigned int)uvmexp.pagesize >> 10)) (void)printf("%7u%7u ", pgtok(total.t_avm), pgtok(total.t_free)); (void)printf("%5u ", rate(uvmexp.faults - ouvmexp.faults)); @@ -480,8 +483,8 @@ dotimes(void) { u_int pgintime, rectime; - int mib[2]; size_t size; + int mib[2]; /* XXX Why are these set to 0 ? This doesn't look right. */ pgintime = 0; @@ -515,7 +518,7 @@ int pct(long top, long bot) { - long ans; + int ans; if (bot == 0) return(0); @@ -529,9 +532,9 @@ dosum(void) { struct nchstats nchstats; + int mib[2], nselcoll; long nchtotal; size_t size; - int mib[2], nselcoll; if (nlistf == NULL && memf == NULL) { size = sizeof(struct uvmexp); @@ -691,8 +694,8 @@ void cpustats(void) { - int state; double percent, total; + int state; total = 0; for (state = 0; state < CPUSTATES; ++state) @@ -709,13 +712,11 @@ void dointr(void) { - time_t uptime; - u_int64_t inttotal; - int nintr; + int nintr, mib[4], i; char intrname[128]; - int mib[4]; + u_int64_t inttotal; + time_t uptime; size_t siz; - int i; if (nlistf != NULL || memf != NULL) { errx(1, @@ -791,18 +792,14 @@ void domem(void) { - struct kmembuckets *kp; - struct kmemstats *ks; - int i, j; - int len, size, first; + struct kmembuckets buckets[MINBUCKET + 16], *kp; + struct kmemstats kmemstats[M_LAST], *ks; + int i, j, len, size, first, mib[4]; u_long totuse = 0, totfree = 0; + char buf[BUFSIZ], *bufp, *ap; quad_t totreq = 0; const char *name; - struct kmemstats kmemstats[M_LAST]; - struct kmembuckets buckets[MINBUCKET + 16]; - int mib[4]; size_t siz; - char buf[BUFSIZ], *bufp, *ap; if (memf == NULL && nlistf == NULL) { mib[0] = CTL_KERN; @@ -948,8 +945,8 @@ print_pool(struct pool *pp, char *name) { static int first = 1; - int ovflw; char maxp[32]; + int ovflw; if (first) { (void)printf("Memory resource pool statistics\n"); @@ -1024,11 +1021,10 @@ void dopool_sysctl(void) { + int mib[4], npools, i, kmfp; long total = 0, inuse = 0; struct pool pool; size_t size; - int mib[4]; - int npools, i, kmfp; mib[0] = CTL_KERN; mib[1] = KERN_POOL; @@ -1077,14 +1073,14 @@ void dopool_kvm(void) { - long addr; - long total = 0, inuse = 0; TAILQ_HEAD(,pool) pool_head; struct pool pool, *pp = &pool; + long total = 0, inuse = 0; + u_long addr; int kmfp; kread(X_POOLHEAD, &pool_head, sizeof(pool_head)); - addr = (long)TAILQ_FIRST(&pool_head); + addr = (u_long)TAILQ_FIRST(&pool_head); while (addr != 0) { char name[32]; @@ -1095,7 +1091,7 @@ kvm_geterr(kd)); exit(1); } - if (kvm_read(kd, (long)pp->pr_wchan, name, sizeof name) < 0) { + if (kvm_read(kd, (u_long)pp->pr_wchan, name, sizeof name) < 0) { (void)fprintf(stderr, "vmstat: pool name trashed: %s\n", kvm_geterr(kd)); @@ -1109,7 +1105,7 @@ inuse += (pp->pr_nget - pp->pr_nput) * pp->pr_size; total += pp->pr_npages * getpagesize(); /* XXX */ - addr = (long)TAILQ_NEXT(pp, pr_poollist); + addr = (u_long)TAILQ_NEXT(pp, pr_poollist); } inuse /= 1024;