From f4130e9d232b87be57db8c0f5e6eda5802eb45f3 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sun, 4 Aug 2002 00:51:02 +0000 Subject: only open kvm once between these two --- usr.bin/vmstat/dkstats.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/vmstat/dkstats.c b/usr.bin/vmstat/dkstats.c index 631138b1960..22af0ffb2a7 100644 --- a/usr.bin/vmstat/dkstats.c +++ b/usr.bin/vmstat/dkstats.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dkstats.c,v 1.19 2002/06/28 22:40:53 deraadt Exp $ */ +/* $OpenBSD: dkstats.c,v 1.20 2002/08/04 00:51:01 deraadt Exp $ */ /* $NetBSD: dkstats.c,v 1.1 1996/05/10 23:19:27 thorpej Exp $ */ /* @@ -87,7 +87,7 @@ struct _disk cur, last; /* Kernel pointers: nlistf and memf defined in calling program. */ #if !defined(NOKVM) -static kvm_t *kd = NULL; +extern kvm_t *kd; #endif extern char *nlistf; extern char *memf; @@ -250,11 +250,20 @@ int select; if (nlistf != NULL || memf != NULL) { #if !defined(NOKVM) + if (memf != NULL) { + setegid(getgid()); + setgid(getgid()); + } + /* Open the kernel. */ - if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, + if (kd == NULL && + (kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf)) == NULL) errx(1, "kvm_openfiles: %s", errbuf); + setegid(getgid()); + setgid(getgid()); + /* Obtain the namelist symbols from the kernel. */ if (kvm_nlist(kd, namelist)) KVM_ERROR("kvm_nlist failed to read symbols."); -- cgit v1.2.3