diff options
author | charnier <charnier@FreeBSD.org> | 1997-10-09 07:22:08 +0000 |
---|---|---|
committer | charnier <charnier@FreeBSD.org> | 1997-10-09 07:22:08 +0000 |
commit | 1c136192c4b9680d373694ac6796dd80a42697ae (patch) | |
tree | 6a430db3f0db38a96ab032e083753bec4d3677db /usr.sbin/pstat/pstat.c | |
parent | 6d64125af79075a334fc10b542f72059b668de3d (diff) | |
download | FreeBSD-src-1c136192c4b9680d373694ac6796dd80a42697ae.zip FreeBSD-src-1c136192c4b9680d373694ac6796dd80a42697ae.tar.gz |
Use err(3). Add usage().
Default source of tables (-M) is /dev/mem, not /dev/kmem.
Diffstat (limited to 'usr.sbin/pstat/pstat.c')
-rw-r--r-- | usr.sbin/pstat/pstat.c | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c index 576199b..83b6d21 100644 --- a/usr.sbin/pstat/pstat.c +++ b/usr.sbin/pstat/pstat.c @@ -32,13 +32,17 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1980, 1991, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)pstat.c 8.16 (Berkeley) 5/9/95"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include <sys/param.h> @@ -162,7 +166,7 @@ char *nlistf = NULL; char *memf = NULL; kvm_t *kd; -char *usage; +char *usagestr; struct { int m_flag; @@ -231,6 +235,7 @@ void ufs_header __P((void)); int ufs_print __P((struct vnode *)); void union_header __P((void)); int union_print __P((struct vnode *)); +static void usage __P((void)); void vnode_header __P((void)); void vnode_print __P((struct vnode *, struct vnode *)); void vnodemode __P((void)); @@ -240,8 +245,6 @@ main(argc, argv) int argc; char *argv[]; { - extern char *optarg; - extern int optind; int ch, i, quit, ret; int fileflag, swapflag, ttyflag, vnodeflag; char buf[_POSIX2_LINE_MAX],*opts; @@ -257,10 +260,10 @@ main(argc, argv) if (!strcmp(opts,"swapinfo")) { swapflag = 1; opts = "kM:N:"; - usage = "usage: swapinfo [-k] [-M core] [-N system]\n"; + usagestr = "swapinfo [-k] [-M core] [-N system]"; } else { opts = "TM:N:fiknstv"; - usage = "usage: pstat [-Tfknstv] [-M core] [-N system]\n"; + usagestr = "pstat [-Tfknstv] [-M core] [-N system]"; } while ((ch = getopt(argc, argv, opts)) != -1) @@ -294,8 +297,7 @@ main(argc, argv) vnodeflag = 1; break; default: - (void)fprintf(stderr, usage); - exit(1); + usage(); } argc -= optind; argv += optind; @@ -315,15 +317,13 @@ main(argc, argv) for (i = quit = 0; i <= NLMANDATORY; i++) if (!nl[i].n_value) { quit = 1; - warnx("undefined symbol: %s\n", nl[i].n_name); + warnx("undefined symbol: %s", nl[i].n_name); } if (quit) exit(1); } - if (!(fileflag | vnodeflag | ttyflag | swapflag | totalflag)) { - (void)fprintf(stderr, usage); - exit(1); - } + if (!(fileflag | vnodeflag | ttyflag | swapflag | totalflag)) + usage(); if (fileflag || totalflag) filemode(); if (vnodeflag || totalflag) @@ -335,6 +335,13 @@ main(argc, argv) exit (0); } +static void +usage() +{ + fprintf(stderr, "usage: %s\n", usagestr); + exit (1); +} + struct e_vnode { struct vnode *avnode; struct vnode vnode; @@ -603,7 +610,7 @@ getmnt(maddr) if (maddr == mt->maddr) return (&mt->mount); if ((mt = malloc(sizeof(struct mtab))) == NULL) - err(1, NULL); + errx(1, "malloc"); KGETRET(maddr, &mt->mount, sizeof(struct mount), "mount table"); mt->maddr = maddr; mt->next = mhead; @@ -621,7 +628,7 @@ mount_print(mp) #define ST mp->mnt_stat (void)printf("*** MOUNT %s %s on %s", ST.f_fstypename, ST.f_mntfromname, ST.f_mntonname); - if (flags = mp->mnt_flag) { + if ((flags = mp->mnt_flag)) { int i; const char *sep = " ("; @@ -659,7 +666,7 @@ loadvnodes(avnodes) if (sysctl(mib, 2, NULL, ©size, NULL, 0) == -1) err(1, "sysctl: KERN_VNODE"); if ((vnodebase = malloc(copysize)) == NULL) - err(1, NULL); + errx(1, "malloc"); if (sysctl(mib, 2, vnodebase, ©size, NULL, 0) == -1) err(1, "sysctl: KERN_VNODE"); if (copysize % sizeof(struct e_vnode)) @@ -687,7 +694,7 @@ kinfo_vnodes(avnodes) KGET(V_NUMV, numvnodes); if ((vbuf = malloc((numvnodes + 20) * (VPTRSZ + VNODESZ))) == NULL) - err(1, NULL); + errx(1, "malloc"); bp = vbuf; evbuf = vbuf + (numvnodes + 20) * (VPTRSZ + VNODESZ); KGET(V_MOUNTLIST, mountlist); @@ -723,7 +730,7 @@ ttymode() struct tty *tty; if ((tty = malloc(ttyspace * sizeof(*tty))) == NULL) - err(1, NULL); + errx(1, "malloc"); #if !defined(hp300) && !defined(mips) if (nl[SCONS].n_type != 0) { (void)printf("1 console\n"); @@ -799,7 +806,7 @@ ttytype(tty, name, type, number, indir) if (ntty > ttyspace) { ttyspace = ntty; if ((tty = realloc(tty, ttyspace * sizeof(*tty))) == 0) - err(1, NULL); + errx(1, "realloc"); } if (indir) { KGET(type, ttyaddr); @@ -990,7 +997,7 @@ getfiles(abuf, alen) * Add emulation of KINFO_FILE here. */ if (memf != NULL) - errx(1, "files on dead kernel, not implemented\n"); + errx(1, "files on dead kernel, not implemented"); mib[0] = CTL_KERN; mib[1] = KERN_FILE; @@ -999,7 +1006,7 @@ getfiles(abuf, alen) return (-1); } if ((buf = malloc(len)) == NULL) - err(1, NULL); + errx(1, "malloc"); if (sysctl(mib, 2, buf, &len, NULL, 0) == -1) { warn("sysctl: KERN_FILE"); return (-1); @@ -1032,7 +1039,7 @@ swapmode() KGET1(VM_SWAPLIST, &swaplist, sizeof swaplist, "swaplist"); if ((sw = malloc(nswdev * sizeof(*sw))) == NULL || (perdev = malloc(nswdev * sizeof(*perdev))) == NULL) - err(1, "malloc"); + errx(1, "malloc"); KGET1(VM_SWDEVT, &ptr, sizeof ptr, "swdevt"); KGET2(ptr, sw, nswdev * sizeof(*sw), "*swdevt"); |