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
This commit is contained in:
parent
8cb5266728
commit
35e6b695d6
@ -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) {
|
||||
|
@ -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;
|
||||
int i;
|
||||
|
||||
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;
|
||||
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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user