From nobody Wed Jun 17 22:45:35 2026 X-Original-To: dev-commits-src-all@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 4ggf8P4vJQz6hwGr for ; Wed, 17 Jun 2026 22:45:41 +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 4ggf8P3zK9z4KfK for ; Wed, 17 Jun 2026 22:45:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1781736341; 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=JIgXNLP8f0jtsAfwLkCyib6FLi6HzlOHJT3cyefYbfEmZwEcbuujyj+q1zT46gZWO9v+Gi BI1EECSxHS19llo9VjDPO24myQtlhJ9nUqqUcMuid+SVOlVNa53vRQbK+kAk7c16nDyQQ8 X/R1KSwdw4qLhMN19uGwJkBmR9FD7MlLy4f1Dh1aOFsfZ+9Fp+VJvp7jqFQdrsITngi2oD 9gkazR3ZIwYvw+GHnYZJsoIJgh6hQY6y0uhijMyr2OpxL0UcvlN3xZ+DqiWv0CdKyNAJWc VQlKBQboKyYpHGlmEic3gRJFhR51t7bz48TjGg0MnJ/6t4jdF2KVx/P8OIAClg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1781736341; a=rsa-sha256; cv=none; b=Er7kBAOOs5jQ8cCAeipmPk8Oshvx5MA/IZNdQE0eo44SJhyNpSoX/4tnIw8H3bVwbmbv3M hbbXigk1g1FZivGlfnbjxhv/0E99Zc4RtWoX7xApS0JfW4pocHfnb9LaOSLY/n/ruCRQD/ szynNjJbPkMl0uixG2aw9D6kYItNfqsTErMAl+QiymPFbUZR85mC1OCsNOyVBa45BcLqUE gMsA2LY8HEBfs7ENBZtstcJyMurFfosQzhY+vIispsxGL6Wl1q/M36hAmWmszVYYvonz+h /rxMf/Tzp+Ire4xUMvMVCwKJr1N0ONDrB+mUrAYOxYP9peIHWOefKZIzCm7sCQ== 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=1781736341; 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=FvIojtPbs01UnQ99ewhSaX5Kr7WPQM0A8rDiF7IlqfHUfE4XpcxyFegMDqPZ81m1ta9LCj oVyuOTEZLIbgHKf69SpYM4EWSGUZWcpwP0n7vK11tCMHc1I68zFlp3f4Ub68bC48LMonMv +OdXhNjBbtcGTr1OWnlJ68tudDkLWFzptN8nXehVWmK4t4kLLIuLeHxtd8AAWbhDljgusx /nrcGixH+Lo0/A/7wexhdkg1/dL6MmqG5uN6x5TxecLqxdUGPbY7SI0+wshLOywUUWU4AX D7MLdeNh5COZZkeWQBYCpRl1xvOlfUohqjYTepThoJM4Ok79H2ZladLsCUeG9g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4ggf8P1RvvzY1T for ; Wed, 17 Jun 2026 22:45:41 +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 all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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,