From nobody Sat Aug 1 12:19:30 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 4hC2766hslz6mvB2 for ; Sat, 01 Aug 2026 12:19:30 +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 4hC2763y90z49wV for ; Sat, 01 Aug 2026 12:19:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785586770; 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=zelx2FQCwu1w6mH3jW+MeKOKs6BfWaigmBnSH1Ayjv0=; b=DBKyS8s0ML4qXvF/cFz+5OE2mMOy3Qz5sfK2qj1sqkK+E7wpLeGHXZY0gB3aZ69HCdZ0x9 DY+8ophvsXUDkgBrQ+KvdwXPaPriU1a5XQonj0CIUZG8e2AIwVreF5NVtfdvksbHG++wob b/YVgIViSxSzKYFn9lWGrRdvWNj4mWarmLNbD9MPlWqpXiFvImeEoUgz694+AqpG8xwkQJ BOfRB00Uj5KmKaji2MF7IOF4kOuwAzeWx+JFDLqjOoE/Lajxs4zqGVtnqPhR0Dk99b49Bd Ifg8WOApVw8Bg2Mn4fswdzk7UTWjbwT1mS3uiaGi2Ql4dmTN8E8w0ep09gmCeg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785586770; a=rsa-sha256; cv=none; b=WLz/89n9MZyjqVjE8XeB76A4QHdQCxMrqE2q0I0a1H7xmBmtFv/vkkacXeXzczZ5Jt2vA3 2B768BK2FWBehaYD1j2yiIdJCVLrQ9zoHoqUfUAOAjga2EnR9U2zRwPk0x6MYqebIQ2ZLx xpzSgnyJKOHSy6Qtszb4hudQaSLskbJUMePTXgW7ez8HGetKaw8ueH2BiqiKuxJfD8jKdn LoGpI9dkiqF2FKu/QUhSHKdLctwtNqPREzRVrJicFO6LGFrgt+YKjf0w7IJcNc84cbUfc5 6WPYyrgOcFOQPNjDWdDjFZKTFveqdaojKsc/PYiimvaERGKEtrQHOEd2xzGsnA== 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=1785586770; 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=zelx2FQCwu1w6mH3jW+MeKOKs6BfWaigmBnSH1Ayjv0=; b=ZoNtNma09/WCbE1xMnH3Tqm6iPthJvV153yBIUwdqtdglW+JMIC3rvCy/zLq28LBAc8CrD N7WX8n4lKhyVaK7XCnIXJ0pO7rR+E85N5Rl35byPqLR91ZEsOBGd1BITR7DNrqZcYK2R4A GkT8WZpQV0Zf/LQny9Qk4wEddhsGbnTLPqeL8WTKm5Hy1v4//tPCco6YdV3wKc7JCVwFOc S1oOfg6tkb4QLuyKQsDmxMH5IiOqvoY8ywFRR1lp52gsHEq4JciOHm4KEO3tsl2D3pznWl jIFloWHTtuTciSaEy7pnJzl10A14PCRSwRfma0ZBhiA/NW6xt9VncGE7eMaWcQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hC2762P6Qzkvn for ; Sat, 01 Aug 2026 12:19:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1d6b8 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 01 Aug 2026 12:19:30 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 77d6c45afdca - main - 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/main X-Git-Reftype: branch X-Git-Commit: 77d6c45afdca8a524a88edfb3097d4d9dc90b583 Auto-Submitted: auto-generated Date: Sat, 01 Aug 2026 12:19:30 +0000 Message-Id: <6a6de452.1d6b8.b073cf4@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=77d6c45afdca8a524a88edfb3097d4d9dc90b583 commit 77d6c45afdca8a524a88edfb3097d4d9dc90b583 Author: Konstantin Belousov AuthorDate: 2026-07-31 06:55:17 +0000 Commit: Konstantin Belousov CommitDate: 2026-08-01 10:42:04 +0000 tests/sys/capsicum: adjust tests for the new reaping behavior Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D58569 --- 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