diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_sysctl.c | 20 | ||||
-rw-r--r-- | sys/sys/sysctl.h | 28 |
2 files changed, 34 insertions, 14 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index e577f6b1e35..c6b9cf784f3 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.219 2012/04/10 15:50:52 guenther Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.220 2012/04/12 14:59:19 pirofti Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -1458,8 +1458,20 @@ again: goto err; } + if ((p->p_flag & P_THREAD) == 0) { + if (buflen >= elem_size && elem_count > 0) { + fill_kproc(p, kproc, 0); + error = copyout(kproc, dp, elem_size); + if (error) + goto err; + dp += elem_size; + buflen -= elem_size; + elem_count--; + } + needed += elem_size; + } if (buflen >= elem_size && elem_count > 0) { - fill_kproc(p, kproc); + fill_kproc(p, kproc, 1); error = copyout(kproc, dp, elem_size); if (error) goto err; @@ -1494,7 +1506,7 @@ err: * Fill in a kproc structure for the specified process. */ void -fill_kproc(struct proc *p, struct kinfo_proc *ki) +fill_kproc(struct proc *p, struct kinfo_proc *ki, int isthread) { struct process *pr = p->p_p; struct session *s = pr->ps_session; @@ -1502,7 +1514,7 @@ fill_kproc(struct proc *p, struct kinfo_proc *ki) struct timeval ut, st; FILL_KPROC(ki, strlcpy, p, pr, p->p_cred, p->p_ucred, pr->ps_pgrp, - p, pr, s, p->p_vmspace, pr->ps_limit, p->p_sigacts); + p, pr, s, p->p_vmspace, pr->ps_limit, p->p_sigacts, isthread); /* stuff that's too painful to generalize into the macros */ ki->p_pid = pr->ps_pid; diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 598ef417e16..0dfa6bb1441 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.123 2012/04/12 10:11:41 mikeb Exp $ */ +/* $OpenBSD: sysctl.h,v 1.124 2012/04/12 14:59:18 pirofti Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -466,7 +466,7 @@ struct kinfo_proc { #define PTRTOINT64(_x) ((u_int64_t)(u_long)(_x)) -#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, lim, sa) \ +#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, lim, sa, isthread) \ do { \ memset((kp), 0, sizeof(*(kp))); \ \ @@ -498,15 +498,24 @@ do { \ (kp)->p_jobc = (pg)->pg_jobc; \ \ (kp)->p_estcpu = (p)->p_estcpu; \ - (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec; \ - (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_usec; \ + if (isthread) { \ + (kp)->p_rtime_sec = (p)->p_tu.tu_runtime.tv_sec; \ + (kp)->p_rtime_usec = (p)->p_tu.tu_runtime.tv_usec; \ + (kp)->p_tid = (p)->p_pid + THREAD_PID_OFFSET; \ + (kp)->p_uticks = (p)->p_tu.tu_uticks; \ + (kp)->p_sticks = (p)->p_tu.tu_sticks; \ + (kp)->p_iticks = (p)->p_tu.tu_iticks; \ + } else { \ + (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec; \ + (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_usec; \ + (kp)->p_tid = -1; \ + (kp)->p_uticks = (pr)->ps_tu.tu_uticks; \ + (kp)->p_sticks = (pr)->ps_tu.tu_sticks; \ + (kp)->p_iticks = (pr)->ps_tu.tu_iticks; \ + } \ (kp)->p_cpticks = (p)->p_cpticks; \ (kp)->p_pctcpu = (p)->p_pctcpu; \ \ - (kp)->p_uticks = (p)->p_uticks; \ - (kp)->p_sticks = (p)->p_sticks; \ - (kp)->p_iticks = (p)->p_iticks; \ - \ (kp)->p_tracep = PTRTOINT64((pr)->ps_tracevp); \ (kp)->p_traceflag = (pr)->ps_traceflag; \ \ @@ -587,7 +596,6 @@ do { \ } \ \ (kp)->p_cpuid = KI_NOCPU; \ - (kp)->p_tid = (p)->p_pid + THREAD_PID_OFFSET; \ (kp)->p_rtableid = (pr)->ps_rtableid; \ } while (0) @@ -933,7 +941,7 @@ int sysctl_dopool(int *, u_int, char *, size_t *); void fill_file2(struct kinfo_file2 *, struct file *, struct filedesc *, int, struct vnode *, struct proc *, struct proc *); -void fill_kproc(struct proc *, struct kinfo_proc *); +void fill_kproc(struct proc *, struct kinfo_proc *, int); int kern_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *); |