[glibc] posix: Use unique PID file in tst-spawn3 and tst-spawn3-pidfd
Florian Weimer via Glibc-cvs <[email protected]> Thu, 9 Jul 2026 15:23:12 +0000 (GMT)
| Newsgroups | gmane.comp.lib.glibc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=980089ebab2a05af6d675d614bb2ec84c58b6615 commit 980089ebab2a05af6d675d614bb2ec84c58b6615 Author: Florian Weimer <[email protected]> Date: Thu Jul 9 17:09:32 2026 +0200 posix: Use unique PID file in tst-spawn3 and tst-spawn3-pidfd The test sources are built twice and the two tests may run in parallel. They cannot use the same PID file. Reviewed-by: Sam James <[email protected]> Diff: --- posix/tst-spawn3.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/posix/tst-spawn3.c b/posix/tst-spawn3.c index 70a5a8ba49..8b946cbb4d 100644 --- a/posix/tst-spawn3.c +++ b/posix/tst-spawn3.c @@ -30,6 +30,7 @@ #include <intprops.h> #include <support/check.h> +#include <support/support.h> #include <support/temp_file.h> #include <support/xunistd.h> #include <tst-spawn.h> @@ -84,8 +85,12 @@ do_test (void) posix_spawn_file_actions_t a; TEST_COMPARE (posix_spawn_file_actions_init (&a), 0); - /* Executes a /bin/sh echo $$ 2>&1 > ${objpfx}tst-spawn3.pid . */ - const char pidfile[] = OBJPFX "tst-spawn3.pid"; + /* Executes a /bin/sh echo $$ 2>&1 > ${objpfx}tst-spawn3-$$.pid . + Embed this PID into the path because the test is built multiple + times and can run in parallel. */ + char *pidfile = xasprintf ("%s/tst-spawn3-%d.pid", + OBJPFX, (int) getpid ()); + add_temp_file (pidfile); TEST_COMPARE (posix_spawn_file_actions_addopen (&a, STDOUT_FILENO, pidfile, O_WRONLY| O_CREAT | O_TRUNC, 0644), @@ -145,7 +150,7 @@ do_test (void) ssize_t n = read (pidfd, buf, sizeof (buf)); TEST_VERIFY (n < sizeof buf && n >= 0); - xunlink (pidfile); + free (pidfile); /* We only expect to read the PID. */ char *endp;