Module Name: src
Committed By: simonb
Date: Sat Jul 16 09:32:27 UTC 2022
Modified Files:
src/usr.bin/vmstat: vmstat.c
Log Message:
Move the call to getnlist() to after we check if kvm_openfiles(3) succeeded.
Avoids a coredump when called with "vmstat -M /dev/mem".
To generate a diff of this commit:
cvs rdiff -u -r1.253 -r1.254 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.253 src/usr.bin/vmstat/vmstat.c:1.254
--- src/usr.bin/vmstat/vmstat.c:1.253 Thu May 19 13:57:03 2022
+++ src/usr.bin/vmstat/vmstat.c Sat Jul 16 09:32:27 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: vmstat.c,v 1.253 2022/05/19 13:57:03 simonb Exp $ */
+/* $NetBSD: vmstat.c,v 1.254 2022/07/16 09:32:27 simonb Exp $ */
/*-
* Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020
@@ -71,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
#if 0
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
#else
-__RCSID("$NetBSD: vmstat.c,v 1.253 2022/05/19 13:57:03 simonb Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.254 2022/07/16 09:32:27 simonb Exp $");
#endif
#endif /* not lint */
@@ -422,12 +422,14 @@ main(int argc, char *argv[])
kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
} else {
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
- getnlist(todo);
}
if (kd == NULL)
errx(EXIT_FAILURE, "%s", errbuf);
+ if (memf != NULL)
+ getnlist(todo); /* Only need this if a core is specified. */
+
if (todo & VMSTAT) {
struct winsize winsize;