Module Name: src
Committed By: riastradh
Date: Sat Mar 15 12:09:41 UTC 2025
Modified Files:
src/tests/lib/libc/gen/posix_spawn: t_spawn.c
Log Message:
t_spawn: Add missing dup2 in t_spawn_sig.
Matches what h_execsig expects, and what t_execve_sig arranges: stdin
is a pipe that the parent will write a single byte to after it has
delivered SIGTERM.
Now this should have a higher chance of provoking the bug (though it
was already good enough in cursory testing!).
PR kern/58091: after fork/execve or posix_spawn, parent kill(child,
SIGTERM) has race condition making it unreliable
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libc/gen/posix_spawn/t_spawn.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/lib/libc/gen/posix_spawn/t_spawn.c
diff -u src/tests/lib/libc/gen/posix_spawn/t_spawn.c:1.10 src/tests/lib/libc/gen/posix_spawn/t_spawn.c:1.11
--- src/tests/lib/libc/gen/posix_spawn/t_spawn.c:1.10 Thu Mar 13 12:48:22 2025
+++ src/tests/lib/libc/gen/posix_spawn/t_spawn.c Sat Mar 15 12:09:41 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: t_spawn.c,v 1.10 2025/03/13 12:48:22 riastradh Exp $ */
+/* $NetBSD: t_spawn.c,v 1.11 2025/03/15 12:09:41 riastradh Exp $ */
/*-
* Copyright (c) 2012, 2021 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_spawn.c,v 1.10 2025/03/13 12:48:22 riastradh Exp $");
+__RCSID("$NetBSD: t_spawn.c,v 1.11 2025/03/15 12:09:41 riastradh Exp $");
#include <atf-c.h>
@@ -605,11 +605,14 @@ ATF_TC_BODY(t_spawn_sig, tc)
for (start = time(NULL); time(NULL) - start <= 10;) {
int fd[2];
char *const argv[] = {h_execsig, NULL};
+ posix_spawn_file_actions_t fa;
pid_t pid;
int status;
- RL(pipe(fd));
- RZ(posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL));
+ RL(pipe2(fd, O_CLOEXEC));
+ RZ(posix_spawn_file_actions_init(&fa));
+ RZ(posix_spawn_file_actions_adddup2(&fa, fd[0], STDIN_FILENO));
+ RZ(posix_spawn(&pid, argv[0], &fa, NULL, argv, NULL));
RL(close(fd[0]));
RL(kill(pid, SIGTERM));
if (write(fd[1], (char[]){0}, 1) == -1 && errno != EPIPE)
@@ -621,6 +624,7 @@ ATF_TC_BODY(t_spawn_sig, tc)
"child exited on signal %d (%s)",
WTERMSIG(status), strsignal(WTERMSIG(status)));
RL(close(fd[1]));
+ RZ(posix_spawn_file_actions_destroy(&fa));
}
}