diff options
-rw-r--r-- | usr.bin/vmstat/dkstats.c | 38 | ||||
-rw-r--r-- | usr.bin/vmstat/vmstat.c | 78 |
2 files changed, 58 insertions, 58 deletions
diff --git a/usr.bin/vmstat/dkstats.c b/usr.bin/vmstat/dkstats.c index c2d80435ce5..e566f930934 100644 --- a/usr.bin/vmstat/dkstats.c +++ b/usr.bin/vmstat/dkstats.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dkstats.c,v 1.28 2006/03/13 19:29:26 otto Exp $ */ +/* $OpenBSD: dkstats.c,v 1.29 2006/03/31 04:06:13 deraadt Exp $ */ /* $NetBSD: dkstats.c,v 1.1 1996/05/10 23:19:27 thorpej Exp $ */ /* @@ -143,7 +143,11 @@ dkswap(void) timerset(&tmp_timer, &(last.dk_time[i])); } for (i = 0; i < CPUSTATES; i++) { - SWAP(cp_time[i]); + long ltmp; + + ltmp = cur.cp_time[i]; + cur.cp_time[i] -= last.cp_time[i]; + last.cp_time[i] = ltmp; } SWAP(tk_nin); SWAP(tk_nout); @@ -180,7 +184,7 @@ dkreadstats(void) if (cur.dk_ndrive != dk_ndrive) { /* Re-read the disk names. */ - dk_name = calloc(dk_ndrive, sizeof(char *)); + dk_name = calloc((size_t)dk_ndrive, sizeof(char *)); if (dk_name == NULL) err(1, NULL); mib[0] = CTL_HW; @@ -472,20 +476,20 @@ dkinit(int sel) } /* allocate space for the statistics */ - cur.dk_time = calloc(cur.dk_ndrive, sizeof(struct timeval)); - cur.dk_rxfer = calloc(cur.dk_ndrive, sizeof(u_int64_t)); - cur.dk_wxfer = calloc(cur.dk_ndrive, sizeof(u_int64_t)); - cur.dk_seek = calloc(cur.dk_ndrive, sizeof(u_int64_t)); - cur.dk_rbytes = calloc(cur.dk_ndrive, sizeof(u_int64_t)); - cur.dk_wbytes = calloc(cur.dk_ndrive, sizeof(u_int64_t)); - last.dk_time = calloc(cur.dk_ndrive, sizeof(struct timeval)); - last.dk_rxfer = calloc(cur.dk_ndrive, sizeof(u_int64_t)); - last.dk_wxfer = calloc(cur.dk_ndrive, sizeof(u_int64_t)); - last.dk_seek = calloc(cur.dk_ndrive, sizeof(u_int64_t)); - last.dk_rbytes = calloc(cur.dk_ndrive, sizeof(u_int64_t)); - last.dk_wbytes = calloc(cur.dk_ndrive, sizeof(u_int64_t)); - cur.dk_select = calloc(cur.dk_ndrive, sizeof(int)); - cur.dk_name = calloc(cur.dk_ndrive, sizeof(char *)); + cur.dk_time = calloc((size_t)cur.dk_ndrive, sizeof(struct timeval)); + cur.dk_rxfer = calloc((size_t)cur.dk_ndrive, sizeof(u_int64_t)); + cur.dk_wxfer = calloc((size_t)cur.dk_ndrive, sizeof(u_int64_t)); + cur.dk_seek = calloc((size_t)cur.dk_ndrive, sizeof(u_int64_t)); + cur.dk_rbytes = calloc((size_t)cur.dk_ndrive, sizeof(u_int64_t)); + cur.dk_wbytes = calloc((size_t)cur.dk_ndrive, sizeof(u_int64_t)); + last.dk_time = calloc((size_t)cur.dk_ndrive, sizeof(struct timeval)); + last.dk_rxfer = calloc((size_t)cur.dk_ndrive, sizeof(u_int64_t)); + last.dk_wxfer = calloc((size_t)cur.dk_ndrive, sizeof(u_int64_t)); + last.dk_seek = calloc((size_t)cur.dk_ndrive, sizeof(u_int64_t)); + last.dk_rbytes = calloc((size_t)cur.dk_ndrive, sizeof(u_int64_t)); + last.dk_wbytes = calloc((size_t)cur.dk_ndrive, sizeof(u_int64_t)); + cur.dk_select = calloc((size_t)cur.dk_ndrive, sizeof(int)); + cur.dk_name = calloc((size_t)cur.dk_ndrive, sizeof(char *)); if (!cur.dk_time || !cur.dk_rxfer || !cur.dk_wxfer || !cur.dk_seek || !cur.dk_rbytes || !cur.dk_wbytes || !last.dk_time || diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index 2b51c8ddc02..6e6c09a6ce9 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -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 @@ static char copyright[] = #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 ncpu; 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 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) #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 @@ choosedrives(char **argv) 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 @@ int hz, hdrcnt; 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 @@ dovmstat(u_int interval, int reps) (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 @@ void 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 @@ dotimes(void) int pct(long top, long bot) { - long ans; + int ans; if (bot == 0) return(0); @@ -529,9 +532,9 @@ void 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 @@ dkstats(void) void cpustats(void) { - int state; double percent, total; + int state; total = 0; for (state = 0; state < CPUSTATES; ++state) @@ -709,13 +712,11 @@ cpustats(void) 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 @@ const char *kmemnames[] = INITKMEMNAMES; 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 @@ static void 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 @@ dopool(void) 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 @@ dopool_sysctl(void) 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 @@ dopool_kvm(void) 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 @@ dopool_kvm(void) 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; |