git: 886aadb63941 - stable/15 - procdesc: make PD_DAEMON per-file
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 16 Aug 2026 02:46:35 UTC
The branch stable/15 has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=886aadb639415308a696a49a35066e536cdc1caf
commit 886aadb639415308a696a49a35066e536cdc1caf
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-05-25 17:48:03 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-16 02:41:21 +0000
procdesc: make PD_DAEMON per-file
(cherry picked from commit c0e1201aaba8860bdcfd754e35024a85ceb1580a)
---
sys/kern/sys_procdesc.c | 26 +++++++++++++++++---------
sys/sys/file.h | 1 +
sys/sys/procdesc.h | 7 ++++++-
3 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c
index a3e234be7e39..c4df1f30989b 100644
--- a/sys/kern/sys_procdesc.c
+++ b/sys/kern/sys_procdesc.c
@@ -209,8 +209,6 @@ procdesc_alloc(int flags)
pd = malloc(sizeof(*pd), M_PROCDESC, M_WAITOK | M_ZERO);
pd->pd_flags = 0;
pd->pd_pid = -1;
- if ((flags & PD_DAEMON) != 0)
- pd->pd_flags |= PDF_DAEMON;
PROCDESC_LOCK_INIT(pd);
knlist_init_mtx(&pd->pd_selinfo.si_note, &pd->pd_lock);
@@ -260,7 +258,12 @@ int
procdesc_falloc(struct thread *td, struct file **resultfp, int *resultfd,
int flags, struct filecaps *fcaps)
{
- return (falloc_caps(td, resultfp, resultfd, pdtofdflags(flags), fcaps));
+ int error;
+
+ error = falloc_caps(td, resultfp, resultfd, pdtofdflags(flags), fcaps);
+ if (error == 0 && (flags & PD_DAEMON) != 0)
+ (*resultfp)->f_pdflags |= F_PD_NOKILL;
+ return (error);
}
/*
@@ -369,6 +372,15 @@ procdesc_reap(struct proc *p)
procdesc_free(pd);
}
+static void
+procdesc_close_tail(struct file *fp, struct proc *p)
+{
+ if ((fp->f_pdflags & F_PD_NOKILL) == 0)
+ kern_psignal(p, SIGKILL);
+ PROC_UNLOCK(p);
+ sx_xunlock(&proctree_lock);
+}
+
/*
* procdesc_close() - last close on a process descriptor. If the process is
* still running, terminate with SIGKILL (unless PDF_DAEMON is set) and let
@@ -436,13 +448,9 @@ procdesc_close(struct file *fp, struct thread *td)
p->p_oppid = p->p_reaper->p_pid;
proc_add_orphan(p, p->p_reaper);
}
- if ((pd->pd_flags & PDF_DAEMON) == 0)
- kern_psignal(p, SIGKILL);
- PROC_UNLOCK(p);
- sx_xunlock(&proctree_lock);
+ procdesc_close_tail(fp, p);
} else {
- PROC_UNLOCK(p);
- sx_xunlock(&proctree_lock);
+ procdesc_close_tail(fp, p);
}
}
diff --git a/sys/sys/file.h b/sys/sys/file.h
index 87cfdb8eed20..bc529df82048 100644
--- a/sys/sys/file.h
+++ b/sys/sys/file.h
@@ -213,6 +213,7 @@ struct file {
union {
int16_t f_seqcount[2]; /* (a) Count of seq. reads and writes. */
int f_pipegen;
+ int f_pdflags; /* Per-file flags for procdesc. */
};
off_t f_nextoff[2]; /* next expected read/write offset. */
union {
diff --git a/sys/sys/procdesc.h b/sys/sys/procdesc.h
index 08b563828b95..5fbd43f1ac84 100644
--- a/sys/sys/procdesc.h
+++ b/sys/sys/procdesc.h
@@ -89,7 +89,12 @@ struct procdesc {
* Flags for the pd_flags field.
*/
#define PDF_EXITED 0x00000004 /* Process exited. */
-#define PDF_DAEMON 0x00000008 /* Don't exit when procdesc closes. */
+
+/*
+ * Flags for file f_pdflags.
+ */
+#define F_PD_NOKILL 0x00000001 /* Opened with PD_DAEMON. Don't send
+ SIGKILL when file closes. */
/*
* In-kernel interfaces to process descriptors.