summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-06-08 22:31:26 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-06-08 22:31:26 +0000
commit8eba06a381117500d20dc3d4aea1af8f26dc065f (patch)
tree62327bd559a77957200c248e9da175c4d3d496d9
parentbe4ffb2a10c754590ba8e54a20c870c8746bb107 (diff)
Add a flag - KVM_NO_FILES which tells kvm_openfiles to not
open any files, just return an kvm handle that we can use to some of the functions.
-rw-r--r--include/kvm.h8
-rw-r--r--lib/libkvm/kvm.c12
-rw-r--r--lib/libkvm/kvm_open.36
-rw-r--r--lib/libkvm/kvm_private.h5
4 files changed, 25 insertions, 6 deletions
diff --git a/include/kvm.h b/include/kvm.h
index 9ecc806fcd7..fe46715d237 100644
--- a/include/kvm.h
+++ b/include/kvm.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm.h,v 1.4 2002/02/16 21:27:17 millert Exp $ */
+/* $OpenBSD: kvm.h,v 1.5 2002/06/08 22:31:24 art Exp $ */
/* $NetBSD: kvm.h,v 1.7 1996/04/19 12:02:50 leo Exp $ */
/*-
@@ -43,6 +43,12 @@
#define VRS_SYM "_version"
#define VRS_KEY "VERSION"
+/*
+ * Flag for kvm_open* that disables opening of any files. We're just
+ * interested in a handle to run sysctls.
+ */
+#define KVM_NO_FILES 0x80000000
+
#include <nlist.h>
#include <sys/cdefs.h>
#include <stdio.h>
diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c
index 17684922068..4599cc48cfa 100644
--- a/lib/libkvm/kvm.c
+++ b/lib/libkvm/kvm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm.c,v 1.30 2002/03/05 00:15:08 deraadt Exp $ */
+/* $OpenBSD: kvm.c,v 1.31 2002/06/08 22:31:24 art Exp $ */
/* $NetBSD: kvm.c,v 1.43 1996/05/05 04:31:59 gwr Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)kvm.c 8.2 (Berkeley) 2/13/94";
#else
-static char *rcsid = "$OpenBSD: kvm.c,v 1.30 2002/03/05 00:15:08 deraadt Exp $";
+static char *rcsid = "$OpenBSD: kvm.c,v 1.31 2002/06/08 22:31:24 art Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -191,6 +191,7 @@ _kvm_open(kd, uf, mf, sf, flag, errout)
kd->vmfd = -1;
kd->swfd = -1;
kd->nlfd = -1;
+ kd->alive = 0;
kd->procbase = 0;
kd->nbpg = getpagesize();
kd->swapspc = 0;
@@ -204,6 +205,11 @@ _kvm_open(kd, uf, mf, sf, flag, errout)
kd->cpu_data = 0;
kd->dump_off = 0;
+ if (flag & KVM_NO_FILES) {
+ kd->alive = 1;
+ return (kd);
+ }
+
if (uf && strlen(uf) >= MAXPATHLEN) {
_kvm_err(kd, kd->program, "exec file name too long");
goto failed;
@@ -241,6 +247,7 @@ _kvm_open(kd, uf, mf, sf, flag, errout)
_kvm_syserr(kd, kd->program, "%s", _PATH_KMEM);
goto failed;
}
+ kd->alive = 1;
if ((kd->swfd = open(sf, flag, 0)) < 0) {
_kvm_syserr(kd, kd->program, "%s", sf);
goto failed;
@@ -641,6 +648,7 @@ kvm_close(kd)
error |= close(kd->pmfd);
if (kd->vmfd >= 0)
error |= close(kd->vmfd);
+ kd->alive = 0;
if (kd->nlfd >= 0)
error |= close(kd->nlfd);
if (kd->swfd >= 0)
diff --git a/lib/libkvm/kvm_open.3 b/lib/libkvm/kvm_open.3
index e1a694d39cd..c03dcc2bf04 100644
--- a/lib/libkvm/kvm_open.3
+++ b/lib/libkvm/kvm_open.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: kvm_open.3,v 1.6 2000/03/04 15:29:56 aaron Exp $
+.\" $OpenBSD: kvm_open.3,v 1.7 2002/06/08 22:31:24 art Exp $
.\" $NetBSD: kvm_open.3,v 1.2 1996/03/18 22:33:52 thorpej Exp $
.\"
.\" Copyright (c) 1992, 1993
@@ -116,6 +116,10 @@ Only
and
.Dv O_RDWR
are permitted.
+A special value
+.Dv KVM_NO_FILES
+can be specified which will cause no files to be opened and the handle
+can only be used on live kernels on a limited subset of all kvm operations.
.Pp
There are two open routines which differ only with respect to
the error mechanism.
diff --git a/lib/libkvm/kvm_private.h b/lib/libkvm/kvm_private.h
index 2b88a2e8977..2eff0a80071 100644
--- a/lib/libkvm/kvm_private.h
+++ b/lib/libkvm/kvm_private.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_private.h,v 1.6 2002/02/16 21:27:26 millert Exp $ */
+/* $OpenBSD: kvm_private.h,v 1.7 2002/06/08 22:31:25 art Exp $ */
/* $NetBSD: kvm_private.h,v 1.7 1996/05/05 04:32:15 gwr Exp $ */
/*-
@@ -50,7 +50,6 @@ struct __kvm {
char *errp; /* XXX this can probably go away */
char errbuf[_POSIX2_LINE_MAX];
DB *db;
-#define ISALIVE(kd) ((kd)->vmfd >= 0)
int pmfd; /* physical memory file (or crashdump) */
int vmfd; /* virtual memory file (-1 if crashdump) */
int swfd; /* swap file (e.g., /dev/drum) */
@@ -85,6 +84,8 @@ struct __kvm {
*/
struct pglist *vm_page_buckets;
int vm_page_hash_mask;
+ int alive; /* Dead or alive. */
+#define ISALIVE(kd) ((kd)->alive)
};
/*