git: fcba16c23bd5 - stable/12 - kinfo_proc: move job-control related data collection into a new helper.

Konstantin Belousov kib at FreeBSD.org
Tue Feb 9 08:36:51 UTC 2021


The branch stable/12 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=fcba16c23bd56d061d8981d0f82bd6a71c6a2c9d

commit fcba16c23bd56d061d8981d0f82bd6a71c6a2c9d
Author:     Konstantin Belousov <kib at FreeBSD.org>
AuthorDate: 2020-12-31 22:46:20 +0000
Commit:     Konstantin Belousov <kib at FreeBSD.org>
CommitDate: 2021-02-09 08:35:45 +0000

    kinfo_proc: move job-control related data collection into a new helper.
    
    Tested by:      pho
    
    (cherry picked from commit cf4f802e77a3a438bce5335b67c88ac6f0e21a6e)
---
 sys/kern/kern_proc.c | 86 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 51 insertions(+), 35 deletions(-)

diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 739046cca413..9798abe96708 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -1035,22 +1035,18 @@ fill_kinfo_aggregate(struct proc *p, struct kinfo_proc *kp)
 }
 
 /*
- * Clear kinfo_proc and fill in any information that is common
- * to all threads in the process.
+ * Fill in any information that is common to all threads in the process.
  * Must be called with the target process locked.
  */
 static void
 fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp)
 {
 	struct thread *td0;
-	struct tty *tp;
-	struct session *sp;
 	struct ucred *cred;
 	struct sigacts *ps;
 	struct timeval boottime;
 
 	PROC_LOCK_ASSERT(p, MA_OWNED);
-	bzero(kp, sizeof(*kp));
 
 	kp->ki_structsize = sizeof(*kp);
 	kp->ki_paddr = p;
@@ -1142,36 +1138,6 @@ fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp)
 	FOREACH_THREAD_IN_PROC(p, td0)
 		kp->ki_cow += td0->td_cow;
 
-	tp = NULL;
-	if (p->p_pgrp) {
-		kp->ki_pgid = p->p_pgrp->pg_id;
-		kp->ki_jobc = p->p_pgrp->pg_jobc;
-		sp = p->p_pgrp->pg_session;
-
-		if (sp != NULL) {
-			kp->ki_sid = sp->s_sid;
-			SESS_LOCK(sp);
-			strlcpy(kp->ki_login, sp->s_login,
-			    sizeof(kp->ki_login));
-			if (sp->s_ttyvp)
-				kp->ki_kiflag |= KI_CTTY;
-			if (SESS_LEADER(p))
-				kp->ki_kiflag |= KI_SLEADER;
-			/* XXX proctree_lock */
-			tp = sp->s_ttyp;
-			SESS_UNLOCK(sp);
-		}
-	}
-	if ((p->p_flag & P_CONTROLT) && tp != NULL) {
-		kp->ki_tdev = tty_udev(tp);
-		kp->ki_tdev_freebsd11 = kp->ki_tdev; /* truncate */
-		kp->ki_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
-		if (tp->t_session)
-			kp->ki_tsid = tp->t_session->s_sid;
-	} else {
-		kp->ki_tdev = NODEV;
-		kp->ki_tdev_freebsd11 = kp->ki_tdev; /* truncate */
-	}
 	if (p->p_comm[0] != '\0')
 		strlcpy(kp->ki_comm, p->p_comm, sizeof(kp->ki_comm));
 	if (p->p_sysent && p->p_sysent->sv_name != NULL &&
@@ -1188,6 +1154,53 @@ fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp)
 	}
 }
 
+/*
+ * Fill job-related process information.
+ */
+static void
+fill_kinfo_proc_pgrp(struct proc *p, struct kinfo_proc *kp)
+{
+	struct tty *tp;
+	struct session *sp;
+	struct pgrp *pgrp;
+
+	sx_assert(&proctree_lock, SA_LOCKED);
+	PROC_LOCK_ASSERT(p, MA_OWNED);
+
+	pgrp = p->p_pgrp;
+	if (pgrp == NULL)
+		return;
+
+	kp->ki_pgid = pgrp->pg_id;
+	kp->ki_jobc = pgrp->pg_jobc;
+
+	sp = pgrp->pg_session;
+	tp = NULL;
+
+	if (sp != NULL) {
+		kp->ki_sid = sp->s_sid;
+		SESS_LOCK(sp);
+		strlcpy(kp->ki_login, sp->s_login, sizeof(kp->ki_login));
+		if (sp->s_ttyvp)
+			kp->ki_kiflag |= KI_CTTY;
+		if (SESS_LEADER(p))
+			kp->ki_kiflag |= KI_SLEADER;
+		tp = sp->s_ttyp;
+		SESS_UNLOCK(sp);
+	}
+
+	if ((p->p_flag & P_CONTROLT) && tp != NULL) {
+		kp->ki_tdev = tty_udev(tp);
+		kp->ki_tdev_freebsd11 = kp->ki_tdev; /* truncate */
+		kp->ki_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
+		if (tp->t_session)
+			kp->ki_tsid = tp->t_session->s_sid;
+	} else {
+		kp->ki_tdev = NODEV;
+		kp->ki_tdev_freebsd11 = kp->ki_tdev; /* truncate */
+	}
+}
+
 /*
  * Fill in information that is thread specific.  Must be called with
  * target process locked.  If 'preferthread' is set, overwrite certain
@@ -1310,6 +1323,9 @@ fill_kinfo_proc(struct proc *p, struct kinfo_proc *kp)
 
 	MPASS(FIRST_THREAD_IN_PROC(p) != NULL);
 
+	bzero(kp, sizeof(*kp));
+
+	fill_kinfo_proc_pgrp(p,kp);
 	fill_kinfo_proc_only(p, kp);
 	fill_kinfo_thread(FIRST_THREAD_IN_PROC(p), kp, 0);
 	fill_kinfo_aggregate(p, kp);


More information about the dev-commits-src-all mailing list