diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2019-06-28 13:35:06 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2019-06-28 13:35:06 +0000 |
commit | 61656abc7ff84215165af1bd464bc053b3b66158 (patch) | |
tree | c7eabb0c4fa9faa024e724e99c240c40da07ca42 /usr.bin/vmstat | |
parent | 18603ebf99fbb890ae9666cb0c4aa9f879e7edaa (diff) |
When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.
Diffstat (limited to 'usr.bin/vmstat')
-rw-r--r-- | usr.bin/vmstat/dkstats.c | 24 | ||||
-rw-r--r-- | usr.bin/vmstat/vmstat.c | 45 |
2 files changed, 35 insertions, 34 deletions
diff --git a/usr.bin/vmstat/dkstats.c b/usr.bin/vmstat/dkstats.c index d55231087be..df4e8d50b41 100644 --- a/usr.bin/vmstat/dkstats.c +++ b/usr.bin/vmstat/dkstats.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dkstats.c,v 1.40 2017/05/30 05:57:46 tedu Exp $ */ +/* $OpenBSD: dkstats.c,v 1.41 2019/06/28 13:35:05 deraadt Exp $ */ /* $NetBSD: dkstats.c,v 1.1 1996/05/10 23:19:27 thorpej Exp $ */ /* @@ -176,7 +176,7 @@ dkreadstats(void) mib[0] = CTL_HW; mib[1] = HW_DISKCOUNT; size = sizeof(dk_ndrive); - if (sysctl(mib, 2, &dk_ndrive, &size, NULL, 0) < 0 ) { + if (sysctl(mib, 2, &dk_ndrive, &size, NULL, 0) == -1 ) { warn("could not read hw.diskcount"); dk_ndrive = 0; } @@ -189,12 +189,12 @@ dkreadstats(void) mib[0] = CTL_HW; mib[1] = HW_DISKNAMES; size = 0; - if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) + if (sysctl(mib, 2, NULL, &size, NULL, 0) == -1) err(1, "can't get hw.disknames"); disknames = malloc(size); if (disknames == NULL) err(1, NULL); - if (sysctl(mib, 2, disknames, &size, NULL, 0) < 0) + if (sysctl(mib, 2, disknames, &size, NULL, 0) == -1) err(1, "can't get hw.disknames"); bufpp = disknames; for (i = 0; i < dk_ndrive && @@ -357,7 +357,7 @@ dkreadstats(void) q = malloc(size); if (q == NULL) err(1, NULL); - if (sysctl(mib, 2, q, &size, NULL, 0) < 0) { + if (sysctl(mib, 2, q, &size, NULL, 0) == -1) { #ifdef DEBUG warn("could not read hw.diskstats"); #endif /* DEBUG */ @@ -377,7 +377,7 @@ dkreadstats(void) size = sizeof(cur.cp_time); mib[0] = CTL_KERN; mib[1] = KERN_CPTIME; - if (sysctl(mib, 2, cur.cp_time, &size, NULL, 0) < 0) { + if (sysctl(mib, 2, cur.cp_time, &size, NULL, 0) == -1) { warn("could not read kern.cp_time"); memset(cur.cp_time, 0, sizeof(cur.cp_time)); } @@ -385,7 +385,7 @@ dkreadstats(void) mib[0] = CTL_KERN; mib[1] = KERN_TTY; mib[2] = KERN_TTY_TKNIN; - if (sysctl(mib, 3, &cur.tk_nin, &size, NULL, 0) < 0) { + if (sysctl(mib, 3, &cur.tk_nin, &size, NULL, 0) == -1) { warn("could not read kern.tty.tk_nin"); cur.tk_nin = 0; } @@ -393,7 +393,7 @@ dkreadstats(void) mib[0] = CTL_KERN; mib[1] = KERN_TTY; mib[2] = KERN_TTY_TKNOUT; - if (sysctl(mib, 3, &cur.tk_nout, &size, NULL, 0) < 0) { + if (sysctl(mib, 3, &cur.tk_nout, &size, NULL, 0) == -1) { warn("could not read kern.tty.tk_nout"); cur.tk_nout = 0; } @@ -472,7 +472,7 @@ dkinit(int sel) mib[0] = CTL_HW; mib[1] = HW_DISKCOUNT; size = sizeof(cur.dk_ndrive); - if (sysctl(mib, 2, &cur.dk_ndrive, &size, NULL, 0) < 0 ) { + if (sysctl(mib, 2, &cur.dk_ndrive, &size, NULL, 0) == -1 ) { warn("could not read hw.diskcount"); cur.dk_ndrive = 0; } @@ -481,7 +481,7 @@ dkinit(int sel) mib[0] = CTL_KERN; mib[1] = KERN_CLOCKRATE; size = sizeof(clkinfo); - if (sysctl(mib, 2, &clkinfo, &size, NULL, 0) < 0) { + if (sysctl(mib, 2, &clkinfo, &size, NULL, 0) == -1) { warn("could not read kern.clockrate"); hz = 0; } else @@ -521,12 +521,12 @@ dkinit(int sel) mib[0] = CTL_HW; mib[1] = HW_DISKNAMES; size = 0; - if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) + if (sysctl(mib, 2, NULL, &size, NULL, 0) == -1) err(1, "can't get hw.disknames"); disknames = malloc(size); if (disknames == NULL) err(1, NULL); - if (sysctl(mib, 2, disknames, &size, NULL, 0) < 0) + if (sysctl(mib, 2, disknames, &size, NULL, 0) == -1) err(1, "can't get hw.disknames"); bufpp = disknames; for (i = 0; i < dk_ndrive && (name = strsep(&bufpp, ",")) != NULL; i++) { diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index 0031f375ea0..703818a920f 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.145 2018/06/19 22:35:07 krw Exp $ */ +/* $OpenBSD: vmstat.c,v 1.146 2019/06/28 13:35:05 deraadt Exp $ */ /* * Copyright (c) 1980, 1986, 1991, 1993 @@ -214,9 +214,10 @@ 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, &winsize); - if (winsize.ws_row > 0) - winlines = winsize.ws_row; + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize) == 0) { + if (winsize.ws_row > 0) + winlines = winsize.ws_row; + } } @@ -330,7 +331,7 @@ dovmstat(u_int interval, int reps) mib[0] = CTL_KERN; mib[1] = KERN_CLOCKRATE; size = sizeof(clkinfo); - if (sysctl(mib, 2, &clkinfo, &size, NULL, 0) < 0) { + if (sysctl(mib, 2, &clkinfo, &size, NULL, 0) == -1) { warn("could not read kern.clockrate"); return; } @@ -345,7 +346,7 @@ dovmstat(u_int interval, int reps) size = sizeof(struct uvmexp); mib[0] = CTL_VM; mib[1] = VM_UVMEXP; - if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) { + if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) == -1) { warn("could not get vm.uvmexp"); memset(&uvmexp, 0, sizeof(struct uvmexp)); } @@ -355,7 +356,7 @@ dovmstat(u_int interval, int reps) size = sizeof(total); mib[0] = CTL_VM; mib[1] = VM_METER; - if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) { + if (sysctl(mib, 2, &total, &size, NULL, 0) == -1) { warn("could not read vm.vmmeter"); memset(&total, 0, sizeof(total)); } @@ -446,7 +447,7 @@ dotimes(void) size = sizeof(struct uvmexp); mib[0] = CTL_VM; mib[1] = VM_UVMEXP; - if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) { + if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) == -1) { warn("could not read vm.uvmexp"); memset(&uvmexp, 0, sizeof(struct uvmexp)); } @@ -490,7 +491,7 @@ dosum(void) size = sizeof(struct uvmexp); mib[0] = CTL_VM; mib[1] = VM_UVMEXP; - if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) { + if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) == -1) { warn("could not read vm.uvmexp"); memset(&uvmexp, 0, sizeof(struct uvmexp)); } @@ -547,7 +548,7 @@ dosum(void) size = sizeof(nchstats); mib[0] = CTL_KERN; mib[1] = KERN_NCHSTATS; - if (sysctl(mib, 2, &nchstats, &size, NULL, 0) < 0) { + if (sysctl(mib, 2, &nchstats, &size, NULL, 0) == -1) { warn("could not read kern.nchstats"); memset(&nchstats, 0, sizeof(nchstats)); } @@ -573,7 +574,7 @@ dosum(void) size = sizeof(nselcoll); mib[0] = CTL_KERN; mib[1] = KERN_NSELCOLL; - if (sysctl(mib, 2, &nselcoll, &size, NULL, 0) < 0) { + if (sysctl(mib, 2, &nselcoll, &size, NULL, 0) == -1) { warn("could not read kern.nselcoll"); nselcoll = 0; } @@ -594,7 +595,7 @@ doforkst(void) size = sizeof(struct forkstat); mib[0] = CTL_KERN; mib[1] = KERN_FORKSTAT; - if (sysctl(mib, 2, &fks, &size, NULL, 0) < 0) { + if (sysctl(mib, 2, &fks, &size, NULL, 0) == -1) { warn("could not read kern.forkstat"); memset(&fks, 0, sizeof(struct forkstat)); } @@ -676,7 +677,7 @@ dointr(void) mib[1] = KERN_INTRCNT; mib[2] = KERN_INTRCNT_NUM; siz = sizeof(nintr); - if (sysctl(mib, 3, &nintr, &siz, NULL, 0) < 0) { + if (sysctl(mib, 3, &nintr, &siz, NULL, 0) == -1) { warnx("could not read kern.intrcnt.nintrcnt"); return; } @@ -694,7 +695,7 @@ dointr(void) mib[2] = KERN_INTRCNT_NAME; mib[3] = i; siz = sizeof(name); - if (sysctl(mib, 4, name, &siz, NULL, 0) < 0) { + if (sysctl(mib, 4, name, &siz, NULL, 0) == -1) { warnx("could not read kern.intrcnt.name.%d", i); return; } @@ -704,7 +705,7 @@ dointr(void) mib[2] = KERN_INTRCNT_VECTOR; mib[3] = i; siz = sizeof(vector); - if (sysctl(mib, 4, &vector, &siz, NULL, 0) < 0) { + if (sysctl(mib, 4, &vector, &siz, NULL, 0) == -1) { strlcpy(intrname, name, sizeof(intrname)); } else { snprintf(intrname, sizeof(intrname), "irq%d/%s", @@ -716,7 +717,7 @@ dointr(void) mib[2] = KERN_INTRCNT_CNT; mib[3] = i; siz = sizeof(cnt); - if (sysctl(mib, 4, &cnt, &siz, NULL, 0) < 0) { + if (sysctl(mib, 4, &cnt, &siz, NULL, 0) == -1) { warnx("could not read kern.intrcnt.cnt.%d", i); return; } @@ -753,7 +754,7 @@ domem(void) mib[1] = KERN_MALLOCSTATS; mib[2] = KERN_MALLOC_BUCKETS; siz = sizeof(buf); - if (sysctl(mib, 3, buf, &siz, NULL, 0) < 0) { + if (sysctl(mib, 3, buf, &siz, NULL, 0) == -1) { warnx("could not read kern.malloc.buckets"); return; } @@ -772,7 +773,7 @@ domem(void) } if (sysctl(mib, 4, &buckets[MINBUCKET + i], &siz, - NULL, 0) < 0) { + NULL, 0) == -1) { warn("could not read kern.malloc.bucket.%d", mib[3]); return; } @@ -825,7 +826,7 @@ domem(void) * Skip errors -- these are presumed to be unallocated * entries. */ - if (sysctl(mib, 4, &kmemstats[i], &siz, NULL, 0) < 0) + if (sysctl(mib, 4, &kmemstats[i], &siz, NULL, 0) == -1) continue; } } else { @@ -983,7 +984,7 @@ dopool_sysctl(void) mib[1] = KERN_POOL; mib[2] = KERN_POOL_NPOOLS; size = sizeof(npools); - if (sysctl(mib, 3, &npools, &size, NULL, 0) < 0) { + if (sysctl(mib, 3, &npools, &size, NULL, 0) == -1) { warn("can't figure out number of pools in kernel"); return; } @@ -996,7 +997,7 @@ dopool_sysctl(void) mib[2] = KERN_POOL_POOL; mib[3] = i; size = sizeof(pool); - if (sysctl(mib, 4, &pool, &size, NULL, 0) < 0) { + if (sysctl(mib, 4, &pool, &size, NULL, 0) == -1) { if (errno == ENOENT) continue; warn("error getting pool"); @@ -1005,7 +1006,7 @@ dopool_sysctl(void) npools--; mib[2] = KERN_POOL_NAME; size = sizeof(name); - if (sysctl(mib, 4, &name, &size, NULL, 0) < 0) { + if (sysctl(mib, 4, &name, &size, NULL, 0) == -1) { warn("error getting pool name"); return; } |