summaryrefslogtreecommitdiffstats
path: root/lib/libkvm/kvm_proc.c
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 /lib/libkvm/kvm_proc.c
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
Diffstat (limited to 'lib/libkvm/kvm_proc.c')
-rw-r--r--lib/libkvm/kvm_proc.c44
1 files changed, 24 insertions, 20 deletions
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