diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2013-04-21 00:40:09 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2013-04-21 00:40:09 +0000 |
commit | da8fe8148c7e08997756a8ca51e7e8246e595dcb (patch) | |
tree | 6aba0f035a378ac17257c71b3715c8f13b3a42b9 | |
parent | 32a1279aec9ed8eeb6977bf350ba7dc581a97c17 (diff) |
revert 1.45. it depended on a kernel change we will not be making, and
the old code was cleaner
-rw-r--r-- | usr.sbin/procmap/procmap.c | 68 |
1 files changed, 21 insertions, 47 deletions
diff --git a/usr.sbin/procmap/procmap.c b/usr.sbin/procmap/procmap.c index 9094ee8b71e..d13348cca26 100644 --- a/usr.sbin/procmap/procmap.c +++ b/usr.sbin/procmap/procmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: procmap.c,v 1.46 2013/03/26 08:58:00 tedu Exp $ */ +/* $OpenBSD: procmap.c,v 1.47 2013/04/21 00:40:08 tedu Exp $ */ /* $NetBSD: pmap.c,v 1.1 2002/09/01 20:32:44 atatat Exp $ */ /* @@ -198,14 +198,12 @@ int main(int argc, char *argv[]) { char errbuf[_POSIX2_LINE_MAX], *kmem = NULL, *kernel = NULL; - struct kinfo_proc *kprocs, *kproc; + struct kinfo_proc *kproc; struct sum total_sum; - int many, ch, rc, i, nprocs; + int many, ch, rc; kvm_t *kd; pid_t pid = -1; gid_t gid; - int mib[2]; - size_t len; while ((ch = getopt(argc, argv, "AaD:dlmM:N:p:Prsvx")) != -1) { switch (ch) { @@ -277,26 +275,22 @@ main(int argc, char *argv[]) /* start by opening libkvm */ kd = kvm_openfiles(kernel, kmem, NULL, O_RDONLY, errbuf); + if (kernel == NULL && kmem == NULL) + if (setresgid(gid, gid, gid) == -1) + err(1, "setresgid"); + if (kd == NULL) errx(1, "%s", errbuf); + /* get "bootstrap" addresses from kernel */ + load_symbols(kd); + + memset(&total_sum, 0, sizeof(total_sum)); - nprocs = 0; - mib[0] = CTL_KERN; - mib[1] = KERN_NPROCS; - len = sizeof(nprocs); - sysctl(mib, 2, &nprocs, &len, NULL, 0); - kprocs = calloc(nprocs, sizeof(struct kinfo_proc)); - if (!kprocs) - err(1, "calloc"); - /* - * we need to do this to get secret pointers via sysctl - * before we drop the kmem group - */ - i = 0; do { - if (i == nprocs) - errx(1, "too many procs at once"); + struct sum sum; + + memset(&sum, 0, sizeof(sum)); if (pid == -1) { if (argc == 0) @@ -309,7 +303,9 @@ main(int argc, char *argv[]) } /* find the process id */ - if (pid != 0) { + if (pid == 0) + kproc = NULL; + else { kproc = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &rc); if (kproc == NULL || rc == 0) { @@ -318,43 +314,21 @@ main(int argc, char *argv[]) pid = -1; continue; } - memcpy(&kprocs[i], kproc, sizeof(struct kinfo_proc)); } - pid = -1; - - i++; - } while (argc > 0); - - nprocs = i; - - if (kernel == NULL && kmem == NULL) - if (setresgid(gid, gid, gid) == -1) - err(1, "setresgid"); - - /* get "bootstrap" addresses from kernel */ - load_symbols(kd); - - memset(&total_sum, 0, sizeof(total_sum)); - - for (i = 0; i < nprocs; i++) { - struct sum sum; - - memset(&sum, 0, sizeof(sum)); - - kproc = &kprocs[i]; /* dump it */ if (many) { if (kproc) - printf("process %d:\n", kproc->p_pid); + printf("process %d:\n", pid); else printf("kernel:\n"); } - process_map(kd, kproc ? kproc->p_pid : 0, kproc, &sum); + process_map(kd, pid, kproc, &sum); if (print_amap) print_sum(&sum, &total_sum); - } + pid = -1; + } while (argc > 0); if (print_amap) print_sum(&total_sum, NULL); |