This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] fix posix/tst-spawn test
- From: Szabolcs Nagy <szabolcs dot nagy at arm dot com>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Cc: nd at arm dot com
- Date: Wed, 27 Sep 2017 13:56:26 +0100
- Subject: [PATCH] fix posix/tst-spawn test
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Szabolcs dot Nagy at arm dot com;
- Nodisclaimer: True
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
The test spawns two children but only waited for one.
2017-09-27 Szabolcs Nagy <szabolcs.nagy@arm.com>
* posix/tst-spawn.c (do_test): Wait for both children.
diff --git a/posix/tst-spawn.c b/posix/tst-spawn.c
index 08d92bd7a7afdaf1a1abf2f996b00bb107c1d631..c224e6a563327234b134214c98e6123ed99adbc8 100644
--- a/posix/tst-spawn.c
+++ b/posix/tst-spawn.c
@@ -240,22 +240,30 @@ do_test (int argc, char *argv[])
if (posix_spawn (&pid, argv[1], &actions, NULL, spargv, environ) != 0)
error (EXIT_FAILURE, errno, "posix_spawn");
+ /* Wait for the child. */
+ if (waitpid (pid, &status, 0) != pid)
+ error (EXIT_FAILURE, errno, "wrong child");
+ if (WTERMSIG (status) != 0)
+ error (EXIT_FAILURE, 0, "Child terminated incorrectly");
+ if (WEXITSTATUS (status) != 0)
+ error (EXIT_FAILURE, 0, "Child failed");
+
/* Same test but with a NULL pid argument. */
if (posix_spawn (NULL, argv[1], &actions, NULL, spargv, environ) != 0)
error (EXIT_FAILURE, errno, "posix_spawn");
+ /* Wait for the child. */
+ if (waitpid (-1, &status, 0) == -1)
+ error (EXIT_FAILURE, errno, "waitpid failed");
+ if (WTERMSIG (status) != 0)
+ error (EXIT_FAILURE, 0, "Child terminated incorrectly");
+ if (WEXITSTATUS (status) != 0)
+ error (EXIT_FAILURE, 0, "Child failed");
+
/* Cleanup. */
if (posix_spawn_file_actions_destroy (&actions) != 0)
error (EXIT_FAILURE, errno, "posix_spawn_file_actions_destroy");
free (name3_copy);
- /* Wait for the child. */
- if (waitpid (pid, &status, 0) != pid)
- error (EXIT_FAILURE, errno, "wrong child");
-
- if (WTERMSIG (status) != 0)
- error (EXIT_FAILURE, 0, "Child terminated incorrectly");
- status = WEXITSTATUS (status);
-
- return status;
+ return 0;
}