summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1998-06-30 21:29:44 +0000
committerphk <phk@FreeBSD.org>1998-06-30 21:29:44 +0000
commit6658078ab314ed6133739f3639793c8fde5b5a71 (patch)
treed11fac9f99243c98cb111f66972d82594c86d5fd
parent107b074e2348937933283de1a7851d864a95ff23 (diff)
downloadFreeBSD-src-6658078ab314ed6133739f3639793c8fde5b5a71.zip
FreeBSD-src-6658078ab314ed6133739f3639793c8fde5b5a71.tar.gz
Allow /dev/null as path for the "/dev/mem" file, and assume that people
know what they're doing if they do that. This will allow ps to use the kvm_proc.c bits without having access to /dev/mem. Fix kvm_proc.c to not need /dev/mem for access to argv/envp
-rw-r--r--lib/libkvm/kvm.c24
-rw-r--r--lib/libkvm/kvm_proc.c44
2 files changed, 38 insertions, 30 deletions
diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c
index a2ea42a..f8aaab5 100644
--- a/lib/libkvm/kvm.c
+++ b/lib/libkvm/kvm.c
@@ -212,18 +212,22 @@ _kvm_open(kd, uf, mf, sf, flag, errout)
* make it work for either /dev/mem or /dev/kmem -- in either
* case you're working with a live kernel.)
*/
- if (strcmp(mf, _PATH_MEM) != 0) { /* XXX */
+ if (strcmp(mf, _PATH_DEVNULL) == 0) {
+ kd->vmfd = open(_PATH_DEVNULL, O_RDONLY);
+ kd->swfd = open(_PATH_DEVNULL, O_RDONLY);
+ } else if (strcmp(mf, _PATH_MEM) != 0) {
_kvm_err(kd, kd->program,
"%s: not physical memory device", mf);
goto failed;
- }
- if ((kd->vmfd = open(_PATH_KMEM, flag)) < 0) {
- _kvm_syserr(kd, kd->program, "%s", _PATH_KMEM);
- goto failed;
- }
- if ((kd->swfd = open(sf, flag, 0)) < 0) {
- _kvm_syserr(kd, kd->program, "%s", sf);
- goto failed;
+ } else {
+ if ((kd->vmfd = open(_PATH_KMEM, flag)) < 0) {
+ _kvm_syserr(kd, kd->program, "%s", _PATH_KMEM);
+ goto failed;
+ }
+ if ((kd->swfd = open(sf, flag, 0)) < 0) {
+ _kvm_syserr(kd, kd->program, "%s", sf);
+ goto failed;
+ }
}
/*
* Open kvm nlist database. We go ahead and do this
@@ -241,7 +245,7 @@ _kvm_open(kd, uf, mf, sf, flag, errout)
} else {
/*
* This is a crash dump.
- * Initalize the virtual address translation machinery,
+ * Initialize the virtual address translation machinery,
* but first setup the namelist fd.
*/
if ((kd->nlfd = open(uf, O_RDONLY, 0)) < 0) {
diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c
index d8a1b8e..674ba28 100644
--- a/lib/libkvm/kvm_proc.c
+++ b/lib/libkvm/kvm_proc.c
@@ -591,17 +591,21 @@ proc_verify(kd, kernp, p)
u_long kernp;
const struct proc *p;
{
- struct proc kernproc;
+ struct kinfo_proc kp;
+ int mib[4], st, len;
- /*
- * Just read in the whole proc. It's not that big relative
- * to the cost of the read system call.
- */
- if (kvm_read(kd, kernp, (char *)&kernproc, sizeof(kernproc)) !=
- sizeof(kernproc))
- return (0);
- return (p->p_pid == kernproc.p_pid &&
- (kernproc.p_stat != SZOMB || p->p_stat == SZOMB));
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_PID;
+ mib[3] = p->p_pid;
+
+ len = sizeof kp;
+
+ st = sysctl(mib, 4, &kp, &len, NULL, 0);
+ if (st < 0)
+ return(0);
+ return (p->p_pid == kp.kp_proc.p_pid &&
+ (kp.kp_proc.p_stat != SZOMB || p->p_stat == SZOMB));
}
static char **
@@ -615,17 +619,17 @@ kvm_doargv(kd, kp, nchr, info)
register char **ap;
u_long addr;
int cnt;
- struct ps_strings arginfo, *ps_strings;
- int mib[2];
+ static struct ps_strings arginfo, *ps_strings;
size_t len;
-
- ps_strings = NULL;
- mib[0] = CTL_KERN;
- mib[1] = KERN_PS_STRINGS;
- len = sizeof(ps_strings);
- if (sysctl(mib, 2, &ps_strings, &len, NULL, 0) < 0 ||
- ps_strings == NULL)
- ps_strings = PS_STRINGS;
+ int i;
+
+ if (ps_strings == NULL) {
+ len = sizeof ps_strings;
+ i = sysctlbyname("kern.ps_strings",
+ &ps_strings, &len, 0, 0);
+ if (i < 0 || ps_strings == NULL)
+ ps_strings = PS_STRINGS;
+ }
/*
* Pointers are stored at the top of the user stack.
OpenPOWER on IntegriCloud