From 5f9f79547658271f3f469b6423a176831fef7683 Mon Sep 17 00:00:00 2001 From: stas Date: Thu, 12 May 2011 10:11:39 +0000 Subject: - Commit work from libprocstat project. These patches add support for runtime file and processes information retrieval from the running kernel via sysctl in the form of new library, libprocstat. The library also supports KVM backend for analyzing memory crash dumps. Both procstat(1) and fstat(1) utilities have been modified to take advantage of the library (as the bonus point the fstat(1) utility no longer need superuser privileges to operate), and the procstat(1) utility is now able to display information from memory dumps as well. The newly introduced fuser(1) utility also uses this library and able to operate via sysctl and kvm backends. The library is by no means complete (e.g. KVM backend is missing vnode name resolution routines, and there're no manpages for the library itself) so I plan to improve it further. I'm commiting it so it will get wider exposure and review. We won't be able to MFC this work as it relies on changes in HEAD, which was introduced some time ago, that break kernel ABI. OTOH we may be able to merge the library with KVM backend if we really need it there. Discussed with: rwatson --- usr.bin/procstat/procstat_kstack.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'usr.bin/procstat/procstat_kstack.c') diff --git a/usr.bin/procstat/procstat_kstack.c b/usr.bin/procstat/procstat_kstack.c index 9d5f71e..fd2b9ab 100644 --- a/usr.bin/procstat/procstat_kstack.c +++ b/usr.bin/procstat/procstat_kstack.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -124,7 +125,7 @@ kinfo_kstack_sort(struct kinfo_kstack *kkstp, int count) void -procstat_kstack(pid_t pid, struct kinfo_proc *kipp, int kflag) +procstat_kstack(struct kinfo_proc *kipp, int kflag) { struct kinfo_kstack *kkstp, *kkstp_free; struct kinfo_proc *kip, *kip_free; @@ -140,12 +141,12 @@ procstat_kstack(pid_t pid, struct kinfo_proc *kipp, int kflag) name[0] = CTL_KERN; name[1] = KERN_PROC; name[2] = KERN_PROC_KSTACK; - name[3] = pid; + name[3] = kipp->ki_pid; kstk_len = 0; error = sysctl(name, 4, NULL, &kstk_len, NULL, 0); if (error < 0 && errno != ESRCH && errno != EPERM && errno != ENOENT) { - warn("sysctl: kern.proc.kstack: %d", pid); + warn("sysctl: kern.proc.kstack: %d", kipp->ki_pid); return; } if (error < 0 && errno == ENOENT) { @@ -160,7 +161,7 @@ procstat_kstack(pid_t pid, struct kinfo_proc *kipp, int kflag) err(-1, "malloc"); if (sysctl(name, 4, kkstp, &kstk_len, NULL, 0) < 0) { - warn("sysctl: kern.proc.pid: %d", pid); + warn("sysctl: kern.proc.pid: %d", kipp->ki_pid); free(kkstp); return; } @@ -171,12 +172,12 @@ procstat_kstack(pid_t pid, struct kinfo_proc *kipp, int kflag) name[0] = CTL_KERN; name[1] = KERN_PROC; name[2] = KERN_PROC_PID | KERN_PROC_INC_THREAD; - name[3] = pid; + name[3] = kipp->ki_pid; kip_len = 0; error = sysctl(name, 4, NULL, &kip_len, NULL, 0); if (error < 0 && errno != ESRCH) { - warn("sysctl: kern.proc.pid: %d", pid); + warn("sysctl: kern.proc.pid: %d", kipp->ki_pid); return; } if (error < 0) @@ -187,7 +188,7 @@ procstat_kstack(pid_t pid, struct kinfo_proc *kipp, int kflag) err(-1, "malloc"); if (sysctl(name, 4, kip, &kip_len, NULL, 0) < 0) { - warn("sysctl: kern.proc.pid: %d", pid); + warn("sysctl: kern.proc.pid: %d", kipp->ki_pid); free(kip); return; } @@ -209,7 +210,7 @@ procstat_kstack(pid_t pid, struct kinfo_proc *kipp, int kflag) if (kipp == NULL) continue; - printf("%5d ", pid); + printf("%5d ", kipp->ki_pid); printf("%6d ", kkstp->kkst_tid); printf("%-16s ", kipp->ki_comm); printf("%-16s ", (strlen(kipp->ki_ocomm) && -- cgit v1.1