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
This commit is contained in:
Mateusz Guzik 2014-08-28 08:41:11 +00:00
parent 18aabe98d0
commit 8b04bbef31
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=270745
5 changed files with 20 additions and 6 deletions

View File

@ -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},

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -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 */