@@ -23,9 +23,10 @@
#include <spawn.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <wait.h>
#include <sys/param.h>
+#include <support/check.h>
+#include <support/xunistd.h>
/* Nonzero if the program gets called via `exec'. */
@@ -240,22 +241,26 @@ 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. */
+ TEST_VERIFY (xwaitpid (pid, &status, 0) == pid);
+ TEST_VERIFY (WIFEXITED (status));
+ TEST_VERIFY (!WIFSIGNALED (status));
+ TEST_VERIFY (WEXITSTATUS (status) == 0);
+
/* 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. */
+ xwaitpid (-1, &status, 0);
+ TEST_VERIFY (WIFEXITED (status));
+ TEST_VERIFY (!WIFSIGNALED (status));
+ TEST_VERIFY (WEXITSTATUS (status) == 0);
+
/* 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;
}