diff options
author | peter <peter@FreeBSD.org> | 1996-02-24 14:37:30 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1996-02-24 14:37:30 +0000 |
commit | 4223430ef271f2fdfd2e4384dcb69393411e55f8 (patch) | |
tree | 00f5472548be9f315edc7d3c99327c3e16f41c16 /lib/libkvm | |
parent | 427e11b898e376c5200a6077bb0cec0547ea6e28 (diff) | |
download | FreeBSD-src-4223430ef271f2fdfd2e4384dcb69393411e55f8.zip FreeBSD-src-4223430ef271f2fdfd2e4384dcb69393411e55f8.tar.gz |
If the two recently added sysctl variables exist, use those rather than
the statically compiled PS_STRINGS and USRSTACK variables. This prevents
programs using setproctitle from coredumping if the kernel VM is increased,
and stops libkvm users (w, ps, etc) from needing to be recompiled if only
the VM layout changes.
Diffstat (limited to 'lib/libkvm')
-rw-r--r-- | lib/libkvm/kvm_proc.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c index c26e680..47773e7 100644 --- a/lib/libkvm/kvm_proc.c +++ b/lib/libkvm/kvm_proc.c @@ -599,13 +599,23 @@ kvm_doargv(kd, kp, nchr, info) register char **ap; u_long addr; int cnt; - struct ps_strings arginfo; + struct ps_strings arginfo, *ps_strings; + int mib[2]; + 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; /* * Pointers are stored at the top of the user stack. */ if (p->p_stat == SZOMB || - kvm_uread(kd, p, USRSTACK - sizeof(arginfo), (char *)&arginfo, + kvm_uread(kd, p, ps_strings, (char *)&arginfo, sizeof(arginfo)) != sizeof(arginfo)) return (0); @@ -659,6 +669,11 @@ kvm_uread(kd, p, uva, buf, len) ssize_t amount; int fd; + if (!ISALIVE(kd)) { + _kvm_err(kd, kd->program, "cannot read user space from dead kernel"); + return(0); + } + cp = buf; sprintf(procfile, "/proc/%d/mem", p->p_pid); |