diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2026-05-20 02:02:54 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2026-07-07 01:22:20 +0000 |
| commit | 599d021224f2af3fc0befdbd6b804a328dd556f9 (patch) | |
| tree | 456a3bff7592bcd595353f004072b87eed13134d | |
| parent | aa1694e23401762c661da11bbf9016a368d37fbe (diff) | |
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
| -rw-r--r-- | sys/kern/sys_procdesc.c | 36 |
1 files 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; } /* |
