The branch main has been updated by kib:

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

commit 599d021224f2af3fc0befdbd6b804a328dd556f9
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2026-05-20 02:02:54 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2026-07-07 01:22:20 +0000

    sys_procdesc: extract procdesc_alloc()
    
    Reviewed by:    markj
    Tested by:      pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D57124
---
 sys/kern/sys_procdesc.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c
index 377132af13c3..e6d8ac403dfb 100644
--- a/sys/kern/sys_procdesc.c
+++ b/sys/kern/sys_procdesc.c
@@ -201,23 +201,15 @@ sys_pdgetpid(struct thread *td, struct pdgetpid_args *uap)
        return (error);
 }
 
-/*
- * When a new process is forked by pdfork(), a file descriptor is allocated
- * by the fork code first, then the process is forked, and then we get a
- * chance to set up the process descriptor.  Failure is not permitted at this
- * point, so procdesc_new() must succeed.
- */
-void
-procdesc_new(struct proc *p, int flags)
+static struct procdesc *
+procdesc_alloc(int flags)
 {
        struct procdesc *pd;
 
        pd = malloc(sizeof(*pd), M_PROCDESC, M_WAITOK | M_ZERO);
-       pd->pd_proc = p;
-       pd->pd_pid = p->p_pid;
-       p->p_procdesc = pd;
        pd->pd_flags = 0;
-       if (flags & PD_DAEMON)
+       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);
@@ -227,6 +219,26 @@ procdesc_new(struct proc *p, int flags)
         * struct file, and the other from their struct proc.
         */
        refcount_init(&pd->pd_refcount, 2);
+
+       return (pd);
+}
+
+/*
+ * When a new process is forked by pdfork(), a file descriptor is allocated
+ * by the fork code first, then the process is forked, and then we get a
+ * chance to set up the process descriptor.  Failure is not permitted at this
+ * point, so procdesc_new() must succeed.
+ */
+void
+procdesc_new(struct proc *p, int flags)
+{
+       struct procdesc *pd;
+
+       pd = procdesc_alloc(flags);
+       pd->pd_proc = p;
+       pd->pd_pid = p->p_pid;
+       MPASS(p->p_procdesc == NULL);
+       p->p_procdesc = pd;
 }
 
 /*

Reply via email to