git: 547751e4efce - stable/15 - procdesc: add NOTE_PDSIGCHLD

Konstantin Belousov <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src,gmane.os.freebsd.devel.stable.scm
Message-ID <[email protected]>
The branch stable/15 has been updated by kib:

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

commit 547751e4efcef869344d4ea8d4906f3b7817ff4f
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2026-07-09 11:08:45 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2026-08-16 02:41:29 +0000

    procdesc: add NOTE_PDSIGCHLD
    
    (cherry picked from commit 2a5e58c59694bc719d7ab82abb1c65ee2045329d)
---
 sys/kern/kern_sig.c     |  2 ++
 sys/kern/sys_procdesc.c | 23 ++++++++++++++++++++---
 sys/sys/event.h         |  4 +++-
 sys/sys/procdesc.h      |  1 +
 4 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index defba6848409..c2561b490f78 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -2315,6 +2315,7 @@ tdsendsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi)
 
 	ps = p->p_sigacts;
 	KNOTE_LOCKED(p->p_klist, NOTE_SIGNAL | sig);
+	procdesc_jobstate(p);
 	prop = sigprop(sig);
 
 	if (td == NULL) {
@@ -3682,6 +3683,7 @@ childproc_jobstate(struct proc *p, int reason, int sig)
 	 */
 	p->p_pptr->p_flag |= P_STATCHILD;
 	wakeup(p->p_pptr);
+	procdesc_jobstate(p);
 
 	ps = p->p_pptr->p_sigacts;
 	mtx_lock(&ps->ps_mtx);
diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c
index 71e8f6797d47..0c6b430b7f39 100644
--- a/sys/kern/sys_procdesc.c
+++ b/sys/kern/sys_procdesc.c
@@ -64,6 +64,7 @@
 
 #include <sys/param.h>
 #include <sys/capsicum.h>
+#include <sys/event.h>
 #include <sys/fcntl.h>
 #include <sys/file.h>
 #include <sys/filedesc.h>
@@ -347,7 +348,7 @@ procdesc_exit(struct proc *p)
 		return (1);
 	}
 	selwakeup(&pd->pd_selinfo);
-	KNOTE_LOCKED(&pd->pd_selinfo.si_note, NOTE_EXIT);
+	KNOTE_LOCKED(&pd->pd_selinfo.si_note, NOTE_EXIT | NOTE_PDSIGCHLD);
 	PROCDESC_UNLOCK(pd);
 
 	/* Wakeup all waiters for this procdesc' process exit. */
@@ -355,6 +356,21 @@ procdesc_exit(struct proc *p)
 	return (0);
 }
 
+void
+procdesc_jobstate(struct proc *p)
+{
+	struct procdesc *pd;
+
+	PROC_LOCK_ASSERT(p, MA_OWNED);
+	pd = p->p_procdesc;
+	if (pd == NULL)
+		return;
+
+	PROCDESC_LOCK(pd);
+	KNOTE_LOCKED(&pd->pd_selinfo.si_note, NOTE_PDSIGCHLD);
+	PROCDESC_UNLOCK(pd);
+}
+
 /*
  * When a process descriptor is reaped, perhaps as a result of close(), release
  * the process's reference on the process descriptor.
@@ -502,10 +518,11 @@ procdesc_kqops_event(struct knote *kn, long hint)
 	pd = kn->kn_fp->f_data;
 	if (hint == 0) {
 		/*
-		 * Initial test after registration. Generate a NOTE_EXIT in
+		 * Initial test after registration.  Generate notes in
 		 * case the process already terminated before registration.
 		 */
-		event = pd->pd_flags & PDF_EXITED ? NOTE_EXIT : 0;
+		event = (pd->pd_flags & PDF_EXITED) != 0 ? (NOTE_EXIT |
+		    NOTE_PDSIGCHLD) : 0;
 	} else {
 		/* Mask off extra data. */
 		event = (u_int)hint & NOTE_PCTRLMASK;
diff --git a/sys/sys/event.h b/sys/sys/event.h
index 16fc829fc8ea..dfba8bc83032 100644
--- a/sys/sys/event.h
+++ b/sys/sys/event.h
@@ -205,10 +205,12 @@ struct freebsd11_kevent32 {
 #define	NOTE_EXIT	0x80000000		/* process exited */
 #define	NOTE_FORK	0x40000000		/* process forked */
 #define	NOTE_EXEC	0x20000000		/* process exec'd */
+#define	NOTE_PDSIGCHLD	0x10000000		/* procdesc: pdwait() info
+						   available */
 #define	NOTE_SIGNAL	0x08000000		/* process received a signal,
 						   shared with EVFIL_SIGNAL */
 #define	NOTE_REAP	0x04000000		/* process reaped */
-#define	NOTE_PCTRLMASK	0xec000000		/* mask for hint bits */
+#define	NOTE_PCTRLMASK	0xfc000000		/* mask for hint bits */
 #define	NOTE_PDATAMASK	0x000fffff		/* mask for pid */
 
 /* additional flags for EVFILT_PROC */
diff --git a/sys/sys/procdesc.h b/sys/sys/procdesc.h
index b332f73744de..dafa3326384d 100644
--- a/sys/sys/procdesc.h
+++ b/sys/sys/procdesc.h
@@ -104,6 +104,7 @@ struct procdesc {
 int	 procdesc_exit(struct proc *);
 int	 procdesc_find(struct thread *, int fd, const cap_rights_t *,
 	    struct proc **);
+void	 procdesc_jobstate(struct proc *p);
 int	 kern_pdgetpid(struct thread *, int fd, const cap_rights_t *,
 	    pid_t *pidp);
 void	 procdesc_new(struct proc *, int);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.