Often, when I want to type "systat vmstat" I get confused and type
"vmstat systat". To my surprise, this actually works.
Two things to fix. First, if a drive name is not found, stop and print
an error. Don't ignore it. Second, finish converting atoi to strtonum.
Index: vmstat.c
===================================================================
RCS file: /cvs/src/usr.bin/vmstat/vmstat.c,v
retrieving revision 1.136
diff -u -p -r1.136 vmstat.c
--- vmstat.c 16 Jan 2015 06:40:14 -0000 1.136
+++ vmstat.c 30 Jan 2015 05:05:32 -0000
@@ -136,7 +136,9 @@ main(int argc, char *argv[])
while ((c = getopt(argc, argv, "c:fiM:mN:stw:vz")) != -1) {
switch (c) {
case 'c':
- reps = atoi(optarg);
+ reps = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr)
+ errx(1, "-c %s: %s", optarg, errstr);
break;
case 'f':
todo |= FORKSTAT;
@@ -222,10 +224,13 @@ main(int argc, char *argv[])
if (*argv) {
interval = (u_int)strtonum(*argv, 0, 1000, &errstr);
if (errstr)
- errx(1, "%s: %s", *argv, errstr);
+ errx(1, "interval %s: %s", *argv, errstr);
- if (*++argv)
- reps = atoi(*argv);
+ if (*++argv) {
+ reps = strtonum(*argv, 0, INT_MAX, &errstr);
+ if (errstr)
+ errx(1, "reps %s: %s", *argv, errstr);
+ }
}
#endif
@@ -276,6 +281,8 @@ choosedrives(char **argv)
++ndrives;
break;
}
+ if (i == dk_ndrive)
+ errx(1, "invalid interval or drive name: %s", *argv);
}
for (i = 0; i < dk_ndrive && ndrives < 2; i++) {
if (dk_select[i])