Module Name: src
Committed By: christos
Date: Mon Oct 18 19:39:33 UTC 2010
Modified Files:
src/usr.bin/vmstat: vmstat.c
Log Message:
simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.
To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/usr.bin/vmstat/vmstat.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/vmstat/vmstat.c
diff -u src/usr.bin/vmstat/vmstat.c:1.169 src/usr.bin/vmstat/vmstat.c:1.170
--- src/usr.bin/vmstat/vmstat.c:1.169 Wed Jul 7 07:42:18 2010
+++ src/usr.bin/vmstat/vmstat.c Mon Oct 18 15:39:32 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: vmstat.c,v 1.169 2010/07/07 11:42:18 pooka Exp $ */
+/* $NetBSD: vmstat.c,v 1.170 2010/10/18 19:39:32 christos Exp $ */
/*-
* Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
#if 0
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
#else
-__RCSID("$NetBSD: vmstat.c,v 1.169 2010/07/07 11:42:18 pooka Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.170 2010/10/18 19:39:32 christos Exp $");
#endif
#endif /* not lint */
@@ -296,6 +296,9 @@
/* allow old usage [vmstat 1] */
#define BACKWARD_COMPATIBILITY
+static const int vmmeter_mib[] = { CTL_VM, VM_METER };
+static const int uvmexp2_mib[] = { CTL_VM, VM_UVMEXP2 };
+
int
main(int argc, char *argv[])
{
@@ -410,7 +413,9 @@
i != X_TIME_SECOND &&
i != X_TIME) {
if (doexit++ == 0)
- (void)fprintf(stderr, "vmstat: undefined symbols:");
+ (void)fprintf(stderr,
+ "%s: undefined symbols:",
+ getprogname());
(void)fprintf(stderr, " %s",
namelist[i].n_name);
}
@@ -599,7 +604,6 @@
dovmtotal(struct timespec *interval, int reps)
{
struct vmtotal total;
- int mib[2];
size_t size;
(void)signal(SIGCONT, needhdr);
@@ -608,16 +612,13 @@
if (!--hdrcnt)
print_total_hdr();
if (memf != NULL) {
- (void)printf(
- "Unable to get vmtotals from crash dump.\n");
+ warnx("Unable to get vmtotals from crash dump.");
(void)memset(&total, 0, sizeof(total));
} else {
size = sizeof(total);
- mib[0] = CTL_VM;
- mib[1] = VM_METER;
- if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) {
- (void)printf("Can't get vmtotals: %s\n",
- strerror(errno));
+ if (sysctl(vmmeter_mib, __arraycount(vmmeter_mib),
+ &total, &size, NULL, 0) == -1) {
+ warn("Can't get vmtotals");
(void)memset(&total, 0, sizeof(total));
}
}
@@ -650,7 +651,6 @@
{
struct vmtotal total;
time_t uptime, halfuptime;
- int mib[2];
size_t size;
int pagesize = getpagesize();
int ovflw;
@@ -677,16 +677,13 @@
* XXX Can't do this if we're reading a crash
* XXX dump because they're lazily-calculated.
*/
- (void)printf(
- "Unable to get vmtotals from crash dump.\n");
+ warnx("Unable to get vmtotals from crash dump.");
(void)memset(&total, 0, sizeof(total));
} else {
size = sizeof(total);
- mib[0] = CTL_VM;
- mib[1] = VM_METER;
- if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) {
- (void)printf("Can't get vmtotals: %s\n",
- strerror(errno));
+ if (sysctl(vmmeter_mib, __arraycount(vmmeter_mib),
+ &total, &size, NULL, 0) == -1) {
+ warn("Can't get vmtotals");
(void)memset(&total, 0, sizeof(total));
}
}
@@ -784,7 +781,6 @@
{
struct nchstats nchstats;
u_long nchtotal;
- int mib[2];
struct uvmexp_sysctl uvmexp2;
size_t ssize;
int active_kernel;
@@ -799,11 +795,9 @@
active_kernel = (memf == NULL);
if (active_kernel) {
/* only on active kernel */
- mib[0] = CTL_VM;
- mib[1] = VM_UVMEXP2;
- if (sysctl(mib, 2, &uvmexp2, &ssize, NULL, 0) < 0)
- fprintf(stderr, "%s: sysctl vm.uvmexp2 failed: %s",
- getprogname(), strerror(errno));
+ if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), &uvmexp2,
+ &ssize, NULL, 0) == -1)
+ warn("sysctl vm.uvmexp2 failed");
}
kread(namelist, X_UVMEXP, &uvmexp, sizeof(uvmexp));