From nobody Sun Aug 16 02:47:23 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 4hN0k42PD4z6pHDk for ; Sun, 16 Aug 2026 02:47:24 +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 4hN0k36T72z3g0Q for ; Sun, 16 Aug 2026 02:47:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786848443; 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=se46bGRIQgvUKuqNl5cac2xkrQ2hWD1X5dgsioyVAQY=; b=ECRw0aEpFZqFkxNfunObRA2yPQelh9vFirEY2PqvE5fviy5wzmk9xS4CNG8NYwjCc9Kdw3 mhT3eDDNuNImIhpCeX+FpefVHvcIQwY3EhXAU3BABwKsQ9repHbij9jSrTpbTVJoyTcBak woh8tH9B5lhoxyUqnl+nw3xU26MhQHxQmHO0m4zOTUMU6rWDn6Zc0w34X1eS/aFdsWc7ra zHKq360IwECvGpZWX1ZrvhCaL21qgWUFtBbCs2QqudMZgiDw1oOvYG1bVWLIVy7Z2ub/hY Ego1w55/WlsfLvxXxDUsEgEF2P8mWBUtHquNFMccMaiaR8xyuM6/4M2o8hw1xw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786848443; a=rsa-sha256; cv=none; b=f8QeXtdIxvYm8TCG1ejC0DxaSpSVlqwFqqRIVXoRH8mdJaZ7z94mDxdJqGVyPq7abHQczR obhA++7vTD3s59OAzEbp3eBp0fKadXfl6/RHYg2KbouUrD3BghpJfW4UsNw0hwpmRynn5e 8LwGTd4tkVQJEhRlDb6b+ijoEzG/ro/zbDtjh+3I8rAkkZT209vSAPDjiDiXg5dWubyGbc wZU2ZOb92i5XgYlCzL3gxe5z+xYrqJQeYdhDseLBO9Swd3rLkse144FMQxsofQxPhh2cXr ZiM1QZLlMli6X+cszlnd5SLVcIqHq8AlLq3d7G4PkWhzFaTehbkHihqQIV4NuQ== 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=1786848443; 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=se46bGRIQgvUKuqNl5cac2xkrQ2hWD1X5dgsioyVAQY=; b=kVsYq1AIMEyoTYXmA43yLWR9HXNxvyByIoHqMnNR+g9bW7w85uuG+miELkz+rTaBGlGRUn Moi+uDSfZYv/WAanWC9L7c+gk8/9xv9FwXoUM4+mFsOdPdT/p/QoQFpC4musFZNB8o3nFX TS9LBMaEh9u4TbOB96RDslTbR1OnUAKdrzepBBq9qGPHhtobBdqRhvELoCs7HwlwmKAVh8 HMWl8iQxUy6bc4nL0Gv95bjOZqz01b6H2A6erGPUDbB4kAX9tw9WwuTHdCVhRZ4Hjeflfm fKhbJ+3CHzp1c4i6AP0Km/OFCwcL8Ox2AG0JdpYFh5TIqqYCt/04/EQj2kceWw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hN0k3505Pz17R6 for ; Sun, 16 Aug 2026 02:47:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 447bb by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 16 Aug 2026 02:47:23 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: cfc5ebfeb889 - stable/15 - tests/sys/capsicum: adjust tests for the new reaping behavior 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: cfc5ebfeb889a0e894f94bfe45ee1ba4338ececb Auto-Submitted: auto-generated Date: Sun, 16 Aug 2026 02:47:23 +0000 Message-Id: <6a8124bb.447bb.ade56f2@gitrepo.freebsd.org> The branch stable/15 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=cfc5ebfeb889a0e894f94bfe45ee1ba4338ececb commit cfc5ebfeb889a0e894f94bfe45ee1ba4338ececb Author: Konstantin Belousov AuthorDate: 2026-07-31 06:55:17 +0000 Commit: Konstantin Belousov CommitDate: 2026-08-16 02:41:40 +0000 tests/sys/capsicum: adjust tests for the new reaping behavior (cherry picked from commit 77d6c45afdca8a524a88edfb3097d4d9dc90b583) --- tests/sys/capsicum/procdesc.cc | 90 ++++++++++++++++++------------------------ tests/sys/capsicum/syscalls.h | 1 + 2 files changed, 40 insertions(+), 51 deletions(-) diff --git a/tests/sys/capsicum/procdesc.cc b/tests/sys/capsicum/procdesc.cc index aabc0446553b..f25324e4efc7 100644 --- a/tests/sys/capsicum/procdesc.cc +++ b/tests/sys/capsicum/procdesc.cc @@ -26,6 +26,21 @@ static pid_t pdwait4_(int pd, int *status, int options, struct rusage *ru) { #ifdef HAVE_PDWAIT4 return pdwait4(pd, status, options, ru); +#elif defined(HAVE_PDWAIT) + struct __wrusage wr; + int rc; + pid_t pid = -1; + + options |= WEXITED | WTRAPPED; + rc = pdwait(pd, status, options, &wr, NULL); + if (rc == 0) { + if (ru != NULL) + *ru = wr.wru_self; + rc = pdgetpid(pd, &pid); + if (rc == 0) + return pid; + } + return -1; #else // Simulate pdwait4() with wait4(pdgetpid()); this won't work in capability mode. pid_t pid = -1; @@ -140,14 +155,15 @@ TEST(Pdfork, Simple) { fprintf(stderr, "For pd %d pid %d:\n", pd, pid); print_rusage(stderr, &ru); } - EXPECT_PID_GONE(pid); - // Can only pdwait4(pd) once (as initial call reaps zombie). + // Can pdwait4(pd) as much as wanted. memset(&ru, 0, sizeof(ru)); - EXPECT_EQ(-1, pdwait4_(pd, &status, 0, &ru)); - EXPECT_EQ(ECHILD, errno); + EXPECT_EQ(pid, pdwait4_(pd, &status, 0, &ru)); + /* Reap */ + EXPECT_EQ(pid, waitpid(pid, &status, WEXITED)); EXPECT_OK(close(pd)); + EXPECT_PID_GONE(pid); } TEST(Pdfork, InvalidFlag) { @@ -326,7 +342,7 @@ class PipePdforkBase : public ::testing::Test { waitpid(pid_, NULL, WNOHANG); } // Check signal expectations. - EXPECT_FALSE(had_signal[SIGCHLD]); + //EXPECT_FALSE(had_signal[SIGCHLD]); } int TerminateChild() { // Tell the child to exit. @@ -456,15 +472,15 @@ TEST_F(PipePdfork, MultipleRetrieveExitStatus) { fprintf(stderr, "For pd %d -> pid %d:\n", pd_, pid_); print_rusage(stderr, &ru); } - EXPECT_PID_GONE(pid_); -#ifdef NOTYET // Child has been reaped, so original process descriptor dangles but // still has access to rusage information. memset(&ru, 0, sizeof(ru)); - EXPECT_EQ(0, pdwait4_(pd_, &status, 0, &ru)); -#endif + EXPECT_EQ(pid_, pdwait4_(pd_, &status, 0, &ru)); close(pd_copy); + close(pd_); + waitpid(pid_, &status, 0); + EXPECT_PID_GONE(pid_); } TEST_F(PipePdfork, ChildExit) { @@ -492,8 +508,7 @@ TEST_F(PipePdfork, Close) { EXPECT_PID_DEAD(pid_); #ifdef __FreeBSD__ - EXPECT_EQ(-1, waitpid(pid_, NULL, 0)); - EXPECT_EQ(errno, ECHILD); + EXPECT_EQ(pid_, waitpid(pid_, NULL, 0)); #else // Having closed the process descriptor means that pdwait4(pd) now doesn't work. int rc = pdwait4_(pd_, &status, 0, NULL); @@ -524,13 +539,15 @@ TEST_F(PipePdfork, CloseLast) { EXPECT_EQ(EBADF, errno); // ...but can pdwait4() the still-open process descriptor. errno = 0; - EXPECT_EQ(0, pdwait4_(pd_other, &status, WNOHANG, NULL)); - EXPECT_EQ(0, errno); + EXPECT_EQ(-1, pdwait4_(pd_other, &status, WNOHANG, NULL)); + // process not yet exited + EXPECT_EQ(EWOULDBLOCK, errno); EXPECT_OK(close(pd_other)); + EXPECT_EQ(0, waitpid(pid_, &status, WNOHANG)); EXPECT_PID_DEAD(pid_); - EXPECT_FALSE(had_signal[SIGCHLD]); + EXPECT_TRUE(had_signal[SIGCHLD]); signal(SIGCHLD, original); } @@ -560,27 +577,13 @@ FORK_TEST(Pdfork, OtherUserIfRoot) { // Ideally, we should be able to send signals via a process descriptor even // if it's owned by another user, but this is not implementated on FreeBSD. -#ifdef __FreeBSD__ - // On FreeBSD, pdkill() still performs all the same checks that kill() does - // and therefore cannot be used to send a signal to a process with another - // UID unless we are root. - EXPECT_SYSCALL_FAIL(EBADF, pdkill(pid, SIGKILL)); - EXPECT_PID_ALIVE(pid); - // However, the process will be killed when we close the process descriptor. - EXPECT_OK(close(pd)); - EXPECT_PID_GONE(pid); - // Can't pdwait4() after close() since close() reparents the child to a reaper (init) - EXPECT_SYSCALL_FAIL(EBADF, pdwait4_(pd, &status, WNOHANG, NULL)); -#else // Sending a signal with pdkill() should be permitted though. - EXPECT_OK(pdkill(pd, SIGKILL)); - EXPECT_PID_ZOMBIE(pid); + EXPECT_EQ(-1, pdkill(pd, SIGKILL)); + EXPECT_EQ(EPERM, errno); int rc = pdwait4_(pd, &status, WNOHANG, NULL); - EXPECT_OK(rc); - EXPECT_EQ(pid, rc); - EXPECT_TRUE(WIFSIGNALED(status)); -#endif + EXPECT_EQ(-1, rc); + EXPECT_EQ(EWOULDBLOCK, errno); } TEST_F(PipePdfork, WaitPidThenPd) { @@ -605,9 +608,7 @@ TEST_F(PipePdfork, WaitPdThenPid) { EXPECT_OK(rc); EXPECT_EQ(pid_, rc); - // ...the zombie is reaped and cannot subsequently waitpid(pid). - EXPECT_EQ(-1, waitpid(pid_, &status, 0)); - EXPECT_EQ(ECHILD, errno); + EXPECT_EQ(pid_, waitpid(pid_, &status, 0)); } // Setting PD_DAEMON prevents close() from killing the child. @@ -637,11 +638,6 @@ static void TestPdkill(pid_t pid, int pd) { errno = 0; EXPECT_EQ(0, pdkill(pd, SIGINT)); EXPECT_EQ(0, errno); - - // pdkill() on reaped process gives -ESRCH. - CheckChildFinished(pid, true); - EXPECT_EQ(-1, pdkill(pd, SIGINT)); - EXPECT_EQ(ESRCH, errno); } TEST_F(PipePdfork, Pdkill) { @@ -778,7 +774,7 @@ TEST_F(PipePdfork, NoSigchld) { // Can waitpid() for the specific pid of the pdfork()ed child. EXPECT_EQ(pid_, waitpid(pid_, &rc, 0)); EXPECT_TRUE(WIFEXITED(rc)) << "0x" << std::hex << rc; - EXPECT_FALSE(had_signal[SIGCHLD]); + EXPECT_TRUE(had_signal[SIGCHLD]); signal(SIGCHLD, original); } @@ -791,16 +787,11 @@ TEST_F(PipePdforkDaemon, NoPDSigchld) { EXPECT_OK(close(pd_)); TerminateChild(); -#ifdef __FreeBSD__ - EXPECT_EQ(-1, waitpid(pid_, NULL, 0)); - EXPECT_EQ(errno, ECHILD); -#else int rc = 0; // Can waitpid() for the specific pid of the pdfork()ed child. EXPECT_EQ(pid_, waitpid(pid_, &rc, 0)); EXPECT_TRUE(WIFEXITED(rc)) << "0x" << std::hex << rc; -#endif - EXPECT_FALSE(had_signal[SIGCHLD]); + EXPECT_TRUE(had_signal[SIGCHLD]); signal(SIGCHLD, original); } @@ -825,11 +816,8 @@ TEST_F(PipePdfork, WildcardWait) { TerminateChild(); EXPECT_PID_ZOMBIE(pid_); // Ensure child is truly dead. - // Wildcard waitpid(-1) should not see the pdfork()ed child because - // there is still a process descriptor for it. int rc; - EXPECT_EQ(-1, waitpid(-1, &rc, WNOHANG)); - EXPECT_EQ(ECHILD, errno); + EXPECT_EQ(pid_, waitpid(-1, &rc, WNOHANG)); EXPECT_OK(close(pd_)); pd_ = -1; diff --git a/tests/sys/capsicum/syscalls.h b/tests/sys/capsicum/syscalls.h index 70b49056f11c..2c97d576fc6e 100644 --- a/tests/sys/capsicum/syscalls.h +++ b/tests/sys/capsicum/syscalls.h @@ -119,6 +119,7 @@ inline long ptrace_(int request, pid_t pid, void *addr, void *data) { #define HAVE_F_DUP2FD #define HAVE_PSELECT #define HAVE_SCTP +#define HAVE_PDWAIT /* FreeBSD only allows root to call mlock[all]/munlock[all] */ #define MLOCK_REQUIRES_ROOT 1