diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-08-04 00:51:02 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-08-04 00:51:02 +0000 |
commit | f4130e9d232b87be57db8c0f5e6eda5802eb45f3 (patch) | |
tree | 2347680d224d514604120bf11dad19db10de5ebd /usr.bin/vmstat | |
parent | 15cbe4c1f4ee6f056e2fccc97d8c6a639d647711 (diff) |
only open kvm once between these two
Diffstat (limited to 'usr.bin/vmstat')
-rw-r--r-- | usr.bin/vmstat/dkstats.c | 15 |
1 files changed, 12 insertions, 3 deletions
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."); |