kern/proc: expose reaper PID and subtree root in struct kinfo_proc
Expose process reaper metadata through struct kinfo_proc so userland
can reconstruct reaper hierarchies from kern.proc.all without adding
a new procctl(2) operation.
Two pid_t fields are added by carving 8 bytes from ki_sparestrings
(46 -> 38), restoring KI_NSPARE_INT to 2 and keeping sizeof(struct
kinfo_proc) unchanged:
ki_reaper: PID of the owning reaper process
ki_reapsubtree: PID of the direct child of the reaper that roots
the subtree the process belongs to
fill_kinfo_proc_pgrp() populates both fields under proctree_lock.
kvm_proclist() is updated for crash dump consumers. The freebsd32
compat struct and freebsd32_kinfo_proc_out() are updated accordingly.
PR: 293871
Reviewed by: kib
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D56538
This commit is contained in:
committed by
Konstantin Belousov
parent
5c89d661a0
commit
0f89380a3d
@@ -121,6 +121,7 @@ kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p,
|
||||
struct thread mtd;
|
||||
struct proc proc;
|
||||
struct proc pproc;
|
||||
struct proc rproc;
|
||||
struct sysentvec sysent;
|
||||
char svname[KI_EMULNAMELEN];
|
||||
struct thread *td = NULL;
|
||||
@@ -365,6 +366,13 @@ kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p,
|
||||
kp->ki_xstat = KW_EXITCODE(proc.p_xexit, proc.p_xsig);
|
||||
kp->ki_acflag = proc.p_acflag;
|
||||
kp->ki_lock = proc.p_lock;
|
||||
if (KREAD(kd, (u_long)proc.p_reaper, &rproc)) {
|
||||
_kvm_err(kd, kd->program,
|
||||
"can't read reaper at %p", proc.p_reaper);
|
||||
return (-1);
|
||||
}
|
||||
kp->ki_reaper = rproc.p_pid;
|
||||
kp->ki_reapsubtree = proc.p_reapsubtree;
|
||||
kp->ki_tdev_freebsd11 = kp->ki_tdev; /* truncate */
|
||||
|
||||
/* Per-thread items; iterate as appropriate. */
|
||||
|
||||
@@ -392,8 +392,10 @@ struct kinfo_proc32 {
|
||||
char ki_emul[KI_EMULNAMELEN+1];
|
||||
char ki_loginclass[LOGINCLASSLEN+1];
|
||||
char ki_moretdname[MAXCOMLEN-TDNAMLEN+1];
|
||||
char ki_sparestrings[46];
|
||||
char ki_sparestrings[38];
|
||||
int ki_spareints[KI_NSPARE_INT];
|
||||
pid_t ki_reaper;
|
||||
pid_t ki_reapsubtree;
|
||||
freebsd32_uint64_t ki_tdev;
|
||||
int ki_oncpu;
|
||||
int ki_lastcpu;
|
||||
|
||||
@@ -1235,6 +1235,8 @@ fill_kinfo_proc_pgrp(struct proc *p, struct kinfo_proc *kp)
|
||||
kp->ki_tdev = NODEV;
|
||||
kp->ki_tdev_freebsd11 = kp->ki_tdev; /* truncate */
|
||||
}
|
||||
kp->ki_reaper = p->p_reaper->p_pid;
|
||||
kp->ki_reapsubtree = p->p_reapsubtree;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1494,6 +1496,8 @@ freebsd32_kinfo_proc_out(const struct kinfo_proc *ki, struct kinfo_proc32 *ki32)
|
||||
CP(*ki, *ki32, ki_fibnum);
|
||||
CP(*ki, *ki32, ki_cr_flags);
|
||||
CP(*ki, *ki32, ki_jid);
|
||||
CP(*ki, *ki32, ki_reaper);
|
||||
CP(*ki, *ki32, ki_reapsubtree);
|
||||
CP(*ki, *ki32, ki_numthreads);
|
||||
CP(*ki, *ki32, ki_tid);
|
||||
CP(*ki, *ki32, ki_pri);
|
||||
|
||||
+3
-1
@@ -186,8 +186,10 @@ struct kinfo_proc {
|
||||
* front of ki_sparestrings, and ints from the end of ki_spareints.
|
||||
* That way the spare room from both arrays will remain contiguous.
|
||||
*/
|
||||
char ki_sparestrings[46]; /* spare string space */
|
||||
char ki_sparestrings[38]; /* spare string space */
|
||||
int ki_spareints[KI_NSPARE_INT]; /* spare room for growth */
|
||||
pid_t ki_reaper; /* pid of reaper process */
|
||||
pid_t ki_reapsubtree; /* reaper subtree id */
|
||||
uint64_t ki_tdev; /* controlling tty dev */
|
||||
int ki_oncpu; /* Which cpu we are on */
|
||||
int ki_lastcpu; /* Last cpu we were on */
|
||||
|
||||
Reference in New Issue
Block a user