From nobody Wed Jun 17 22:45:35 2026 X-Original-To: dev-commits-src-main@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 4ggf8J3sr9z6hw5b for ; Wed, 17 Jun 2026 22:45:36 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ggf8J0s3Kz4KHJ for ; Wed, 17 Jun 2026 22:45:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1781736336; 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=zEzuqVLzM/XciUfmIaZlbuHkk3XAP7H2+7/JUqUdrPU=; b=dciV1eDVlovfB3jhkF5NMBSR8ga7iapQaMsVRFhPQoZUeDjB1wR+flItquvpNaWPLNNXw4 ybRp5Y8fHyzxfb9SmoiH6mve3dCz8hHcktZZPrPKdBDf4bxukztOSM1trojEVwgAVQOtnz xgm+j6g5xTjz5SmJepvS/d8H78kzWKCgwygfc4U0lPZ1D+L8RZFCPowuW1mKSOvSi3o7Ii NydU5M8V63tg35r5OodESKFbl16E+4OTCsBFr5d1c0WYiYWY+odrUKaKTTOBHYQR0SBvuq Gd8JBcf/0DalTqubmuYg/OcDB21Qt2uW5N6Y0vAKX8qfkr+BWIdu6iKLQsH5Jw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1781736336; a=rsa-sha256; cv=none; b=B1qw36spXGuX0tt+vDSFljFErXBAgeYsepCjzrdXcoHLdUKAPqxrOApyrO9YLA7AIpvzDd 8D0SsT0Zzkwxnjnx+PxJQE0Z4Fltm14XW3UUUsIz3ujmF2V+afPI1gNszlzZxG03xSGcNq qXZCAsOPNAtSbM+rInAFn0PwVAZLGR3ShegPepUEj/yvYsP9tBcMHkwl7QKPlbZpUJ8TX5 dgIwIrQXsFp+ql1m/OHglqw9KPoq3AzjEKNToESmtpiDZIm5w5v6P7egPdeTgxY7GkB+a4 J4KBXSS7j5Oevup/x1FjxeHCIo+yzDD4l1iqUOdJuzXlM76+0ePsIJiwJzmM/Q== 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=1781736336; 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=zEzuqVLzM/XciUfmIaZlbuHkk3XAP7H2+7/JUqUdrPU=; b=D3zT9LIbF+NR8Hz02P6Yxfa/2VNoS5F7QF7Dk36XAsGoshwxP9Dom7GxYXTK4M64v9F9ST ox+rVojqVrD2MlCjSyVxpM80Om5ju3v6pNCx+MBC0E82EbFRYm2/cDBUiNinBJHU3u+7mU /6iDVTztfyXFs6CcTQsSALjj1NeLozEkpm8pUsDmlofHgAOTbnOv9hPTR7jpX6PrzqObl/ Ol6nTuFz/kdLobnbAchqcecLxLa6jFBenfMnDjzbaotQe2DQhH40I8xsXsAF51qVZl/1Od ol8a4BwMeXetW/wqfS3NwMyuam5mQ6dpu72spUCluv6wnmKTaq8nVOtGFpLWFg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4ggf8H6bl6zY1w for ; Wed, 17 Jun 2026 22:45:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 47105 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 17 Jun 2026 22:45:35 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Aymeric Wibo Subject: git: bb14ba3777bb - main - daemon(3): Note about environment after calling daemon() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: obiwac X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bb14ba3777bb201abd6d4dfbf67d70b81f9c1e97 Auto-Submitted: auto-generated Date: Wed, 17 Jun 2026 22:45:35 +0000 Message-Id: <6a33238f.47105.567c52b0@gitrepo.freebsd.org> The branch main has been updated by obiwac: URL: https://cgit.FreeBSD.org/src/commit/?id=bb14ba3777bb201abd6d4dfbf67d70b81f9c1e97 commit bb14ba3777bb201abd6d4dfbf67d70b81f9c1e97 Author: Aymeric Wibo AuthorDate: 2026-06-17 19:51:39 +0000 Commit: Aymeric Wibo CommitDate: 2026-06-17 22:44:46 +0000 daemon(3): Note about environment after calling daemon() While here, fix missing comma typo. Reviewed by: 0mp, ziaee Approved by: 0mp, ziaee MFC after: 3 days Obtained from: https://github.com/apple-oss-distributions/libc (partially) Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D57384 --- lib/libc/gen/daemon.3 | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/libc/gen/daemon.3 b/lib/libc/gen/daemon.3 index 4619ba3489aa..99a4f685bedb 100644 --- a/lib/libc/gen/daemon.3 +++ b/lib/libc/gen/daemon.3 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd February 27, 2023 +.Dd June 1, 2026 .Dt DAEMON 3 .Os .Sh NAME @@ -44,6 +44,13 @@ The .Fn daemon function is for programs wishing to detach themselves from the controlling terminal and run in the background as system daemons. +The +.Xr fork 2 +system call is used; see +.Sx CAVEATS +below about the environment after a +.Fn fork +.Pq without a corresponding call to one of the exec routines . .Pp If the argument .Fa nochdir @@ -89,7 +96,7 @@ and function may fail and set .Va errno for any of the errors specified for the library functions -.Xr fork 2 +.Xr fork 2 , .Xr open 2 , and .Xr setsid 2 . @@ -107,6 +114,21 @@ The function first appeared in .Fx 12.0 . .Sh CAVEATS +In multithreaded programs, the child process after +.Fn fork +inherits copies of all mutexes and other synchronization state, but only the +calling thread survives. +Any locks held by other threads at the time of the call will remain permanently +acquired in the child, causing deadlocks in any code that attempts to +acquire them. +Until one of the +.Xr exec 3 +functions is called, the child should restrict itself to async-signal safe +operations +.Po see +.Xr sigaction 2 +.Pc . +.Pp Unless the .Fa noclose argument is non-zero,