Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/vmstat Move the call to getnlist() to after we check...



details:   https://anonhg.NetBSD.org/src/rev/b4ea97fa19ea
branches:  trunk
changeset: 368502:b4ea97fa19ea
user:      simonb <simonb%NetBSD.org@localhost>
date:      Sat Jul 16 09:32:27 2022 +0000

description:
Move the call to getnlist() to after we check if kvm_openfiles(3) succeeded.
Avoids a coredump when called with "vmstat -M /dev/mem".

diffstat:

 usr.bin/vmstat/vmstat.c |  8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diffs (34 lines):

diff -r f0124daf102c -r b4ea97fa19ea usr.bin/vmstat/vmstat.c
--- a/usr.bin/vmstat/vmstat.c   Sat Jul 16 07:28:39 2022 +0000
+++ b/usr.bin/vmstat/vmstat.c   Sat Jul 16 09:32:27 2022 +0000
@@ -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 @@
 #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 @@
                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;
 



Home | Main Index | Thread Index | Old Index