git: dd1252e30063 - stable/15 - tests/procdesc: Fix race in pdopenpid_pdwait_only_one
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 16 Aug 2026 02:47:18 UTC
The branch stable/15 has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=dd1252e300636b40cc10473cda8d93032e26e12c
commit dd1252e300636b40cc10473cda8d93032e26e12c
Author: Olivier Cochard <olivier@FreeBSD.org>
AuthorDate: 2026-07-30 14:28:42 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-08-16 02:41:38 +0000
tests/procdesc: Fix race in pdopenpid_pdwait_only_one
(cherry picked from commit 727a83e90098e1c0fc4acdcf9b8099a70e6ea2b2)
---
tests/sys/kern/procdesc.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/tests/sys/kern/procdesc.c b/tests/sys/kern/procdesc.c
index 541f15b49338..1feaef34e2cb 100644
--- a/tests/sys/kern/procdesc.c
+++ b/tests/sys/kern/procdesc.c
@@ -519,16 +519,29 @@ ATF_TC_WITHOUT_HEAD(pdopenpid_pdwait_only_one);
ATF_TC_BODY(pdopenpid_pdwait_only_one, tc)
{
pid_t child;
- int fd1, fd2, status;
+ int fd1, fd2, pip[2], status;
+
+ ATF_REQUIRE_EQ(pipe(pip), 0);
child = pdfork(&fd1, PD_DAEMON);
ATF_REQUIRE_MSG(child >= 0, "pdfork: %s", strerror(errno));
- if (child == 0)
+ if (child == 0) {
+ char c;
+
+ close(pip[1]);
+ /* Block until the parent has opened the second fd. */
+ (void)read(pip[0], &c, 1);
_exit(42);
+ }
+ ATF_REQUIRE(close(pip[0]) == 0);
+ /* Open the second fd while the child is still alive. */
fd2 = pdopenpid(child, 0);
ATF_REQUIRE_MSG(fd2 >= 0, "pdopenpid: %s", strerror(errno));
+ /* Release the child so that it exits. */
+ ATF_REQUIRE(close(pip[1]) == 0);
+
/* Collect via the first fd. */
ATF_REQUIRE_MSG(pdwait(fd1, &status, WEXITED, NULL, NULL) == 0,
"pdwait(fd1): %s", strerror(errno));