From nobody Sun Feb 1 21:41:00 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4f438Y1XVVz6QjMk for ; Sun, 01 Feb 2026 21:41:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4f438X6Rjyz3Fyl for ; Sun, 01 Feb 2026 21:41:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769982061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LcUN77cwVmqBIzUsmMspmpLWgU7BfnnQqC+54mOyMus=; b=d0KLs8cTzZnfSIGlXCU4citdBq1mFrwJuuwHnjU3rcyqRUa+uQmpHqzOUPcres0iOdueOu rVLcwBZPMq4m2NQeCVQZ5L/LpLuOMBt1W27eyk8dhSm70lbltABDKNx+InRYHceneXogym LpfjVLwFL1DBMEOuBFCV89WN2hqncgi6Wwo3sBmAPyNIp3Q/i7D7JQcx3NaYysulppjK+9 HGbEdNSENf3e5CofFncP9Tz7bYdoKf6Hw5Dz+C1wE20Gz+4EtiZ6FvVrfgAPd7VJi9CxBh XNCN8NafRZbk1Umr4YGtAms//bR3sv6m8XY4lk675/8JpHS2iET/aU89i0cOBg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1769982061; a=rsa-sha256; cv=none; b=YfliqLbKT5xHk138kLI/9lvPASjlciIa4qgaCfwM6JqTqDk9CWGX7DK6N4u0mW3vLVYkrS 0pJpjzvaC+NuJ4A2OiaHt5JaCSI6MfQD6lTo/aAfiRxjsrtkVLpi6dml/+8VrgXQCFvQnK ulgibC4x6jmao3p3WYGAD0avgGp+X0ICTrjNaMhGJPH4JcCg2nedPoI61TEyDAUsTmCcEK R5sTRyp/4kEyWXy3uAogrd0Ie7pBilGIRHslxJejfkkueWat113EfSiNCsIauf9y8PDWOh irdkzQMwalmC5QRK+a+a1HfVVS4JsXjCHz1Gvobi5If/Xw6kZ9LT6LtPpejJQQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769982061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LcUN77cwVmqBIzUsmMspmpLWgU7BfnnQqC+54mOyMus=; b=PWAVBZhJmizauvS+UH55ra7m0N6aNf6UtuWduqhKORoZ/9IF5mZyoYNl2q4G3vXb/sowk6 4e6Uebo895dG+idoALjp+g5pVKtRohKeiFSGkcVLlm7HIWpKzSoBBaw2XTp844CuW75iv8 g9i9/Q0dki6ktXePfuHlbQMEboWwyTn72vWaPqr2Om8WOKuaQ3y0PYjtlJSke1rz1eDs/U lgxQhEPPjMRvyqsz89ZbeWi32xKuWaOSNQrNfG3FfYLM8Qa7RxqXtnFmWj2KRpCcS7PG2C uZVEZRiu6bkqIsoMGWYZno877n8MU3d9iegn2UcwdvqvUFlYbDdbpVRidrTzmQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f438X5Z6tzy3J for ; Sun, 01 Feb 2026 21:41:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3c361 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 01 Feb 2026 21:41:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 758de6465572 - stable/15 - Add pdwait(2) List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 758de64655720316cf1803209bb7f4c5eadde453 Auto-Submitted: auto-generated Date: Sun, 01 Feb 2026 21:41:00 +0000 Message-Id: <697fc86c.3c361.71218532@gitrepo.freebsd.org> The branch stable/15 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=758de64655720316cf1803209bb7f4c5eadde453 commit 758de64655720316cf1803209bb7f4c5eadde453 Author: Konstantin Belousov AuthorDate: 2026-01-08 03:37:42 +0000 Commit: Konstantin Belousov CommitDate: 2026-02-01 21:38:49 +0000 Add pdwait(2) (cherry picked from commit 4d707825bf62ee73a32b615846eff9c4a9bda538) --- sys/compat/freebsd32/freebsd32_misc.c | 31 ++++++++++ sys/kern/kern_exit.c | 105 ++++++++++++++++++++++++++++++++++ sys/kern/sys_procdesc.c | 4 ++ sys/kern/syscalls.master | 10 ++++ sys/sys/syscallsubr.h | 2 + 5 files changed, 152 insertions(+) diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c index 8a2c179926d8..c76c9d5c1838 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -281,6 +281,37 @@ freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap) return (error); } +int +freebsd32_pdwait(struct thread *td, struct freebsd32_pdwait_args *uap) +{ + struct __wrusage32 wru32; + struct __wrusage wru, *wrup; + struct __siginfo32 si32; + struct __siginfo si, *sip; + int error, status; + + wrup = uap->wrusage != NULL ? &wru : NULL; + if (uap->info != NULL) { + sip = &si; + bzero(sip, sizeof(*sip)); + } else { + sip = NULL; + } + error = kern_pdwait(td, uap->fd, &status, uap->options, wrup, sip); + if (uap->status != NULL && error == 0) + error = copyout(&status, uap->status, sizeof(status)); + if (uap->wrusage != NULL && error == 0) { + freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self); + freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children); + error = copyout(&wru32, uap->wrusage, sizeof(wru32)); + } + if (uap->info != NULL && error == 0) { + siginfo_to_siginfo32 (&si, &si32); + error = copyout(&si32, uap->info, sizeof(si32)); + } + return (error); +} + #ifdef COMPAT_FREEBSD4 static void copy_statfs(struct statfs *in, struct ostatfs32 *out) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 7dfcb8df7fe3..f27eecc8a8e6 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -906,6 +906,33 @@ sys_wait6(struct thread *td, struct wait6_args *uap) return (error); } +int +sys_pdwait(struct thread *td, struct pdwait_args *uap) +{ + struct __wrusage wru, *wrup; + siginfo_t si, *sip; + int error, status; + + wrup = uap->wrusage != NULL ? &wru : NULL; + + if (uap->info != NULL) { + sip = &si; + bzero(sip, sizeof(*sip)); + } else { + sip = NULL; + } + + error = kern_pdwait(td, uap->fd, &status, uap->options, wrup, sip); + + if (uap->status != NULL && error == 0) + error = copyout(&status, uap->status, sizeof(status)); + if (uap->wrusage != NULL && error == 0) + error = copyout(&wru, uap->wrusage, sizeof(wru)); + if (uap->info != NULL && error == 0) + error = copyout(&si, uap->info, sizeof(si)); + return (error); +} + /* * Reap the remains of a zombie process and optionally return status and * rusage. Asserts and will release both the proctree_lock and the process @@ -1476,6 +1503,84 @@ loop_locked: goto loop; } +int +kern_pdwait(struct thread *td, int fd, int *status, + int options, struct __wrusage *wrusage, siginfo_t *siginfo) +{ + struct proc *p; + struct file *fp; + struct procdesc *pd; + int error; + + AUDIT_ARG_FD(fd); + AUDIT_ARG_VALUE(options); + + error = wait6_checkopt(options); + if (error != 0) + return (error); + + error = fget(td, fd, &cap_pdwait_rights, &fp); + if (error != 0) + return (error); + if (fp->f_type != DTYPE_PROCDESC) { + error = EINVAL; + goto exit_unlocked; + } + pd = fp->f_data; + + for (;;) { + /* We own a reference on the procdesc file. */ + KASSERT((pd->pd_flags & PDF_CLOSED) == 0, + ("PDF_CLOSED proc %p procdesc %p pd flags %#x", + p, pd, pd->pd_flags)); + + sx_xlock(&proctree_lock); + p = pd->pd_proc; + if (p == NULL) { + error = ESRCH; + goto exit_tree_locked; + } + PROC_LOCK(p); + + error = p_canwait(td, p); + if (error != 0) + break; + if ((options & WEXITED) == 0 && p->p_state == PRS_ZOMBIE) { + error = ESRCH; + break; + } + + wait_fill_siginfo(p, siginfo); + wait_fill_wrusage(p, wrusage); + + if (p->p_state == PRS_ZOMBIE) { + proc_reap(td, p, status, options); + goto exit_unlocked; + } + + if (wait6_check_alive(td, options, p, status, siginfo)) + goto exit_unlocked; + + if ((options & WNOHANG) != 0) { + error = EWOULDBLOCK; + break; + } + + PROC_UNLOCK(p); + error = sx_sleep(&p->p_procdesc, &proctree_lock, + PWAIT | PCATCH | PDROP, "pdwait", 0); + if (error != 0) + goto exit_unlocked; + } + + PROC_UNLOCK(p); +exit_tree_locked: + sx_xunlock(&proctree_lock); +exit_unlocked: + fdrop(fp, td); + return (error); +} + void proc_add_orphan(struct proc *child, struct proc *parent) { diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c index 4f5b08003735..ec3b37f96148 100644 --- a/sys/kern/sys_procdesc.c +++ b/sys/kern/sys_procdesc.c @@ -75,6 +75,7 @@ #include #include #include +#include #include #include #include @@ -321,6 +322,9 @@ procdesc_exit(struct proc *p) } KNOTE_LOCKED(&pd->pd_selinfo.si_note, NOTE_EXIT); PROCDESC_UNLOCK(pd); + + /* Wakeup all waiters for this procdesc' process exit. */ + wakeup(&p->p_procdesc); return (0); } diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index 3a6e3cb7266e..d711f21bee4d 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -3404,4 +3404,14 @@ ); } +601 AUE_PDWAIT STD|CAPENABLED { + int pdwait( + int fd, + _Out_opt_ int *status, + int options, + _Out_opt_ _Contains_long_ struct __wrusage *wrusage, + _Out_opt_ _Contains_long_ptr_ struct __siginfo *info + ); + } + ; vim: syntax=off diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index 5acce75e3302..d169481fe13b 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -285,6 +285,8 @@ int kern_posix_fallocate(struct thread *td, int fd, off_t offset, off_t len); int kern_fspacectl(struct thread *td, int fd, int cmd, const struct spacectl_range *, int flags, struct spacectl_range *); +int kern_pdwait(struct thread *td, int fd, int *status, + int options, struct __wrusage *wrusage, siginfo_t *sip); int kern_procctl(struct thread *td, enum idtype idtype, id_t id, int com, void *data); int kern_pread(struct thread *td, int fd, void *buf, size_t nbyte,