diff options
author | mjg <mjg@FreeBSD.org> | 2014-08-28 08:41:11 +0000 |
---|---|---|
committer | mjg <mjg@FreeBSD.org> | 2014-08-28 08:41:11 +0000 |
commit | ec92f2e61c40e5b3a519a14ea47a142d9047a75a (patch) | |
tree | 8b47cb5fe2bdf03c237daa6e7bf34f23a0e3a915 | |
parent | a3bb3db4bfc2cbf2451d297879c706700876f778 (diff) | |
download | FreeBSD-src-ec92f2e61c40e5b3a519a14ea47a142d9047a75a.zip FreeBSD-src-ec92f2e61c40e5b3a519a14ea47a142d9047a75a.tar.gz |
Return real parent pid in kinfo (used by e.g. ps)
Add a separate field which exports tracer pid and add a new keyword
("tracer") for ps to display it.
This is a follow up to r270444.
Reviewed by: kib
MFC after: 1 week
Relnotes: yes
-rw-r--r-- | bin/ps/keyword.c | 1 | ||||
-rw-r--r-- | bin/ps/ps.1 | 4 | ||||
-rw-r--r-- | sys/compat/freebsd32/freebsd32.h | 1 | ||||
-rw-r--r-- | sys/kern/kern_proc.c | 17 | ||||
-rw-r--r-- | sys/sys/user.h | 3 |
5 files changed, 20 insertions, 6 deletions
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index 3a0c323..38a9934 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -157,6 +157,7 @@ static VAR var[] = { {"tdnam", "TDNAM", NULL, LJUST, tdnam, 0, CHAR, NULL, 0}, {"time", "TIME", NULL, USER, cputime, 0, CHAR, NULL, 0}, {"tpgid", "TPGID", NULL, 0, kvar, KOFF(ki_tpgid), UINT, PIDFMT, 0}, + {"tracer", "TRACER", NULL, 0, kvar, KOFF(ki_tracer), UINT, PIDFMT, 0}, {"tsid", "TSID", NULL, 0, kvar, KOFF(ki_tsid), UINT, PIDFMT, 0}, {"tsiz", "TSIZ", NULL, 0, kvar, KOFF(ki_tsize), PGTOK, "ld", 0}, {"tt", "TT ", NULL, 0, tname, 0, CHAR, NULL, 0}, diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index d8e56fb..294ecf9 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -29,7 +29,7 @@ .\" @(#)ps.1 8.3 (Berkeley) 4/18/94 .\" $FreeBSD$ .\" -.Dd August 7, 2014 +.Dd August 27, 2014 .Dt PS 1 .Os .Sh NAME @@ -665,6 +665,8 @@ accumulated CPU time, user + system (alias .Cm cputime ) .It Cm tpgid control terminal process group ID +.It Cm tracer +tracer process ID .\".It Cm trss .\"text resident set size (in Kbytes) .It Cm tsid diff --git a/sys/compat/freebsd32/freebsd32.h b/sys/compat/freebsd32/freebsd32.h index 94f886e..155612b 100644 --- a/sys/compat/freebsd32/freebsd32.h +++ b/sys/compat/freebsd32/freebsd32.h @@ -343,6 +343,7 @@ struct kinfo_proc32 { char ki_loginclass[LOGINCLASSLEN+1]; char ki_sparestrings[50]; int ki_spareints[KI_NSPARE_INT]; + int ki_tracer; int ki_flag2; int ki_fibnum; u_int ki_cr_flags; diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 6689186..740c4a6 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -791,6 +791,8 @@ fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp) struct ucred *cred; struct sigacts *ps; + /* For proc_realparent. */ + sx_assert(&proctree_lock, SX_LOCKED); PROC_LOCK_ASSERT(p, MA_OWNED); bzero(kp, sizeof(*kp)); @@ -920,7 +922,9 @@ fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp) kp->ki_acflag = p->p_acflag; kp->ki_lock = p->p_lock; if (p->p_pptr) - kp->ki_ppid = p->p_pptr->p_pid; + kp->ki_ppid = proc_realparent(p)->p_pid; + if (p->p_flag & P_TRACED) + kp->ki_tracer = p->p_pptr->p_pid; } /* @@ -1166,6 +1170,7 @@ freebsd32_kinfo_proc_out(const struct kinfo_proc *ki, struct kinfo_proc32 *ki32) bcopy(ki->ki_comm, ki32->ki_comm, COMMLEN + 1); bcopy(ki->ki_emul, ki32->ki_emul, KI_EMULNAMELEN + 1); bcopy(ki->ki_loginclass, ki32->ki_loginclass, LOGINCLASSLEN + 1); + CP(*ki, *ki32, ki_tracer); CP(*ki, *ki32, ki_flag2); CP(*ki, *ki32, ki_fibnum); CP(*ki, *ki32, ki_cr_flags); @@ -1287,10 +1292,11 @@ sysctl_kern_proc(SYSCTL_HANDLER_ARGS) error = sysctl_wire_old_buffer(req, 0); if (error) return (error); + sx_slock(&proctree_lock); error = pget((pid_t)name[0], PGET_CANSEE, &p); - if (error != 0) - return (error); - error = sysctl_out_proc(p, req, flags, 0); + if (error == 0) + error = sysctl_out_proc(p, req, flags, 0); + sx_sunlock(&proctree_lock); return (error); } @@ -1318,6 +1324,7 @@ sysctl_kern_proc(SYSCTL_HANDLER_ARGS) error = sysctl_wire_old_buffer(req, 0); if (error != 0) return (error); + sx_slock(&proctree_lock); sx_slock(&allproc_lock); for (doingzomb=0 ; doingzomb < 2 ; doingzomb++) { if (!doingzomb) @@ -1422,11 +1429,13 @@ sysctl_kern_proc(SYSCTL_HANDLER_ARGS) error = sysctl_out_proc(p, req, flags, doingzomb); if (error) { sx_sunlock(&allproc_lock); + sx_sunlock(&proctree_lock); return (error); } } } sx_sunlock(&allproc_lock); + sx_sunlock(&proctree_lock); return (0); } diff --git a/sys/sys/user.h b/sys/sys/user.h index f7b18df..6775ff7 100644 --- a/sys/sys/user.h +++ b/sys/sys/user.h @@ -84,7 +84,7 @@ * it in two places: function fill_kinfo_proc in sys/kern/kern_proc.c and * function kvm_proclist in lib/libkvm/kvm_proc.c . */ -#define KI_NSPARE_INT 7 +#define KI_NSPARE_INT 6 #define KI_NSPARE_LONG 12 #define KI_NSPARE_PTR 6 @@ -187,6 +187,7 @@ struct kinfo_proc { */ char ki_sparestrings[50]; /* spare string space */ int ki_spareints[KI_NSPARE_INT]; /* spare room for growth */ + int ki_tracer; /* Pid of tracing process */ int ki_flag2; /* P2_* flags */ int ki_fibnum; /* Default FIB number */ u_int ki_cr_flags; /* Credential flags */ |