From nobody Sun Aug 16 02:47:14 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 4hN0jv1jLpz6pHLQ for ; Sun, 16 Aug 2026 02:47:15 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hN0jt6Wjgz3fcm for ; Sun, 16 Aug 2026 02:47:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786848434; 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=2r/9fxraqAQV/tbeNTiWoXJWqXAnknP8dvFKon1gn8g=; b=r9jPKthWVIG8AOdWYyGRLMYsB2H/eVy7Z7AOKdySAmpNWJhTiW3SAX4LHEFL0r1iF0W5DI fg4ksCvjOLTsPUYuCxH0RoCasIXw0xY9HWXnBbL5eSSdeQ6s6x5zI2MbKcnJW2ceEE0Is+ PaC6P+lnXL5si8EXCbA71qkGVpvHX3ncFHYzN/otXQukCEIpK0nro3idjTMsw9zjxMtzmI a42lUc5ww0/CXhdQasEx3XYJPSyQCSpwJGdqPYUFtvNx374EyIOdl6lzfwMaqNTTZRzKXW t/quFfIXCm9GWmG6fx5jLiaiJKL71WIXOgp5jFv2EwuVqohQwU1UWaqAEk7d0w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786848434; a=rsa-sha256; cv=none; b=TuPfNK+UB8TqcI2Zbq+Irvz3eji989REg8SxIcX8fdvxPo7Aa51qcNYR3hzX1M2TFJPhpu umugSmKb4263gJ5RCvik5mCVnNwGBI0/odfHxbBKm4icr1xz2m8o933Zw4nZj+XErM/VJA 2kjeL2jh7EfFuSuMIsURFY3VVaXYI2W0kzfgeIu+mv7Ai1SqwRG29FQj/qO9jeaL53iqBN zOkj5aDhW2KDGTxcJ664B2C1qaMNlf1T2K3XQJF2oTAWW6o+AfqNbwwQ4w8pOF/g866k6b CTt9S6YixwAuDSCgU6Rt7KTH+dndnYAnfu789ss3QP5zYh81V60JzWM1H8iUog== 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=1786848434; 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=2r/9fxraqAQV/tbeNTiWoXJWqXAnknP8dvFKon1gn8g=; b=AbBrUmjXFFgFWKAekkWK+Cedv+mynu8PYwj1qSGkzNh+WSxS/PaSgKmd9JBeNKaeRYk7Pq A2vU++Mf2sZQj98ubve4Y7MwTIZ0Cy83ABpn/LKVliWbtYHqC2vBrGoh18NFVh3WV9D7M9 JkAYE31THkfOljDE0/O8LGgo02rKURQwAf69tklUhbdjko2F4qVsoA3i4sz1vCs+14lNJ5 At9w+E715vsoDS81Fr3tqsa8i5adR6ZxrFs9d0JE5fp0+xQLZNg8EwSvAAI6aPtxPMxoJX bGCBeVhMSzrUxCnZi7Ls87ZOv+OmC5pcnogPawdI4VEUmxoMIjA7P548W/AxAw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hN0jt5Swrz17xs for ; Sun, 16 Aug 2026 02:47:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 44266 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 16 Aug 2026 02:47:14 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: c20ccfc06ade - stable/15 - pdwait(2), wait(2): document interaction between pdopenpid() and waitpid() 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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: c20ccfc06adecb0a9316ad574e34e875ad3f3552 Auto-Submitted: auto-generated Date: Sun, 16 Aug 2026 02:47:14 +0000 Message-Id: <6a8124b2.44266.31882f0@gitrepo.freebsd.org> The branch stable/15 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=c20ccfc06adecb0a9316ad574e34e875ad3f3552 commit c20ccfc06adecb0a9316ad574e34e875ad3f3552 Author: Konstantin Belousov AuthorDate: 2026-07-21 20:03:46 +0000 Commit: Konstantin Belousov CommitDate: 2026-08-16 02:41:36 +0000 pdwait(2), wait(2): document interaction between pdopenpid() and waitpid() (cherry picked from commit c49198534a9b823c18c8b9e67e3b16a2d0fa27ad) --- lib/libsys/pdfork.2 | 61 +++++++++++++++++++++++++++++++++++++++++++++++++---- lib/libsys/wait.2 | 9 -------- 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/lib/libsys/pdfork.2 b/lib/libsys/pdfork.2 index 1b99157203c1..6f577427a716 100644 --- a/lib/libsys/pdfork.2 +++ b/lib/libsys/pdfork.2 @@ -103,6 +103,9 @@ specifying the flag, closing that descriptor kills the process. .It Dv PD_CLOEXEC Set close-on-exec on process descriptor. +.It Dv PD_NOWAITPID +The parent cannot obtain the child's status with +.Xr waitpid 2 . .El .Pp The @@ -149,9 +152,6 @@ to succeed. Zombie processes cannot be opened. .Pp There might be more that one file descriptor referencing the process. -But only one caller of -.Fn pdwait -gets the exit status. After the zombie is reaped, calls to .Fn pdwait specifying any file descriptors for the same process fail with the @@ -176,7 +176,7 @@ the status information on the process referenced by the .Fa fd process descriptor. See the description of the -.Xr wait6 +.Xr wait6 2 system call for the behavior specification. .Pp The @@ -197,6 +197,59 @@ The argument is reserved and must be zero. Certain file descriptor types cannot be copied this way, namely kqueues. +.Sh INTERACTION OF PROCESS DESCRIPTORS AND Xr WAITPID 2 +.Pp +The +.Fn pdwait +system call may be called on a process descriptor +an unlimited number of times. +In particular, it does not reap the target process, +even if that process has exited. +Each time, it returns the same status. +.Bl -dash +.It +If the process was forked with +.Fn pdfork , +and the +.Dv PD_NOWAITPID +flag was specified, then the process is automatically reaped after the +last process descriptor referencing that process is closed. +No +.Xr waitpid 2 +call +.Pq or a call from the same family of the wait functions which operate on PIDs +are needed to reap the zombie process. +.It +If the process was created by +.Fn pdfork , +and the +.Dv PD_NOWAITPID +flag was not specified, then after exiting, +the process will not be reaped until the parent or reaper has called +.Xr waitpid 2 +and all process descriptors referencing the process are closed. +.It +If the process was created by the +.Xr fork 2 +system call +.Pq which does not allocate a process descriptor for the child , +and later the process was opened by +.Fn pdopenpid , +then a +.Xr waitpid 2 +call from the parent is needed to reap the exited child. +.El +.Pp +In any case, the PID of the process is not reused until its zombie +is reaped, and all its process descriptors are closed. +.Pp +A debugger attached by +.Xr ptrace 2 +can execute the +.Fn waitpid +calls against the alive target regardless of the way +the target process was forked. +.Sh INTERACTION OF PROCESS DESCRIPTORS WITH OTHER SYSTEM CALLS .Pp The following system calls also have effects specific to process descriptors: .Pp diff --git a/lib/libsys/wait.2 b/lib/libsys/wait.2 index ca289c69f188..f018ab3d4d37 100644 --- a/lib/libsys/wait.2 +++ b/lib/libsys/wait.2 @@ -607,15 +607,6 @@ fields of .Fa infop must be checked against zero to determine if a process reported status. .Pp -The -.Fn wait -family of functions will only return a child process created with -.Xr pdfork 2 -if the calling process is not in -.Xr capsicum 4 -capability mode, and -.Nm -has been explicitly given the child's process ID. .Sh ERRORS The .Fn wait