From nobody Tue Oct 06 08:11:31 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 4hzTVW5Ky7z6cYFL for ; Tue, 06 Oct 2026 08:11:31 +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 4hzTVW4pZSz4bnx for ; Tue, 06 Oct 2026 08:11:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791274291; 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=C0ikGdyY9hf6lIvrgi8smlia8sCU1KHk3ny+LPkXgUY=; b=hvzNPtwbyMu3GuKln1xohwScyREgPg19si7525FZIsFCauGQZOM5nDTarfzsyTSxg8pDo5 cMBl9hcZBFZpcnZ7kHc2COGBxDKqBycuhHNd/r6wNcFTpW88F+25q5YEqBgM0bof18hYZj 6ipC0hE2zV/BtBbqF675LBhg4kI8KJzBkH92SDlYUonUKUu119C1d3a2MaJvvRXTS+wEQn fWRJDkePg2dD/iexFNLkOBymtuDP12tOuE1EYllcNQpbJh0kaEDyrXIxZIFHZsw24LE9a9 0Jn32RAb4CBbckt/nogC/RDTRni5c91hM2Dtbv/OtxxPCxr+sCfV1xBbP5iqfA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791274291; b=w+T3p63dMxWiSFgFsuanYJkJ4KKAeK527fe8siAPCs3waJSK+GVESAoSbScrvMYEKC4GPu dm/4WIh28dFBDTwB2BcBLCQKOtlUDpqoyVFju2Ax2Tt5H7Vnvk2VfEE49WAHZzS2GcxeJd wXAtuT1/k6H4B0iFybJqMb94LAuMCJVdc+Tyoe5ZRKEk/sn37BtJSvtFNFUvFZ5zBF0q46 7JD+LznXboligzRFmI+T5UBkAgK14l45nAXdfTHKosIyGL4utLR0jNykYnVdx+JWs7kKNe gMDYLsP1om72x4OsGyTu+LxatiDFQw27sdkEbyOwC7YSLC+RAhmb+Nzu6GPPeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791274291; 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=C0ikGdyY9hf6lIvrgi8smlia8sCU1KHk3ny+LPkXgUY=; b=UEXtC7fjlULmYg7ZBtx8/habNDUQ/Pr6sU4ILbcvoNrcyZV8xSqsH3s0ia/g9Chw9EJGmM TH8u0oQMSuMcWaati4W6E17jeUaAEDFFS7KVdAid+5jhS2HeyW1aJIXf9bNNrByAJlzNco VXrQwfx1VSdP/bLuIBbMxYMM8RjLywmRtaTWSFXoktGr3HfMSbBEOlf3iSXEji501sjhBg nXId1ZWYDXqwhYVWHiCen5JaN94UZtTvPWySBc6LSPhYW8ymeM4SPVz78IsIzjjHZxd2RA QTXip2BQI731pyz8lcPMIpB9Vvhwz52giH3SINZ35F99FiqYIAkwA3DgLiJEeQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hzTVW3sQnzySX for ; Tue, 06 Oct 2026 08:11:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 19f5f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 06 Oct 2026 08:11:31 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Xin LI Subject: git: b4e2c9abaf14 - main - libcasper: tolerate kernels without PD_NOWAITPID 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: delphij X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b4e2c9abaf14d6eabbce59656d448c064e0dc40b Auto-Submitted: auto-generated Date: Tue, 06 Oct 2026 08:11:31 +0000 Message-Id: <6ac4ad33.19f5f.8a9063f@gitrepo.freebsd.org> The branch main has been updated by delphij: URL: https://cgit.FreeBSD.org/src/commit/?id=b4e2c9abaf14d6eabbce59656d448c064e0dc40b commit b4e2c9abaf14d6eabbce59656d448c064e0dc40b Author: Xin LI AuthorDate: 2026-10-06 07:17:21 +0000 Commit: Xin LI CommitDate: 2026-10-06 08:10:57 +0000 libcasper: tolerate kernels without PD_NOWAITPID Commit 1a296762b3d0 made libcasper pass PD_NOWAITPID to pdfork(2). Kernels predating the flag (15.1 and earlier, since the flag first ships in 15.2) reject it with EINVAL, which makes cap_init() and every service fork fail when a newer world runs on an older kernel, for example in a poudriere jail. Add casper_pdfork(), which retries without the flag on EINVAL, and use it at both pdfork(2) call sites. The retry is safe because the kernel validates pdfork flags before creating a child. On such kernels the zombie must still be reaped with waitpid(2), as before the flag was introduced. The fallback is compiled out once __FreeBSD_version reaches 1700000, so it disappears from main when stable/16 branches while remaining in the stable/15 and stable/16 branches that need it. Reviewed by: kib MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D60401 --- lib/libcasper/libcasper/libcasper.c | 2 +- lib/libcasper/libcasper/libcasper_impl.h | 23 +++++++++++++++++++++++ lib/libcasper/libcasper/zygote.c | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/libcasper/libcasper/libcasper.c b/lib/libcasper/libcasper/libcasper.c index 8783529d9dc0..9a34b8d7acea 100644 --- a/lib/libcasper/libcasper/libcasper.c +++ b/lib/libcasper/libcasper/libcasper.c @@ -95,7 +95,7 @@ cap_init(void) return (NULL); } - pid = pdfork(&pfd, PD_NOWAITPID); + pid = casper_pdfork(&pfd); if (pid == 0) { /* Child. */ close(sock[0]); diff --git a/lib/libcasper/libcasper/libcasper_impl.h b/lib/libcasper/libcasper/libcasper_impl.h index 43d2495cacf6..682a71fff01c 100644 --- a/lib/libcasper/libcasper/libcasper_impl.h +++ b/lib/libcasper/libcasper/libcasper_impl.h @@ -33,6 +33,10 @@ #ifndef _LIBCASPER_IMPL_H_ #define _LIBCASPER_IMPL_H_ +#include +#include + +#include #include #include "libcasper.h" @@ -44,6 +48,25 @@ struct service_connection; bool fd_is_valid(int fd); void fd_fix_environment(int *fdp); +static inline pid_t +casper_pdfork(int *fdp) +{ + pid_t pid; + + pid = pdfork(fdp, PD_NOWAITPID); +#if __FreeBSD_version < 1700000 + /* + * Kernels predating PD_NOWAITPID (introduced in 15.2) reject the + * flag with EINVAL before creating a child, so retrying without + * it is safe. The child must then be reaped with waitpid(2), as + * before. This fallback is compiled out starting with 17.0. + */ + if (pid == -1 && errno == EINVAL) + pid = pdfork(fdp, 0); +#endif + return (pid); +} + /* Private service functions. */ struct service *service_alloc(const char *name, service_limit_func_t *limitfunc, diff --git a/lib/libcasper/libcasper/zygote.c b/lib/libcasper/libcasper/zygote.c index 8295312b6593..574d80a16b01 100644 --- a/lib/libcasper/libcasper/zygote.c +++ b/lib/libcasper/libcasper/zygote.c @@ -149,7 +149,7 @@ zygote_main(int *sockp) error = errno; goto send; } - pid = pdfork(&procfd, PD_NOWAITPID); + pid = casper_pdfork(&procfd); switch (pid) { case -1: /* Failure. */