diff --git a/src/utils.c b/src/utils.c index 4747ace..f042e1d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -194,6 +194,17 @@ exec_and_wait(const char *arg, ...) } free(argv); + /* If the child didn't terminate normally */ + if (1 != WIFEXITED(pstat)) + return (-1); + + /* + * When something went wrong in the pre-exec() initialization or exec() + * failed. Refer to manpage posix_spawnp(3) for details. + */ + if (127 == WEXITSTATUS(pstat)) + return (-1); + return (WEXITSTATUS(pstat)); } diff --git a/tests/mlmmj.c b/tests/mlmmj.c index e6c649d..9f4390f 100644 --- a/tests/mlmmj.c +++ b/tests/mlmmj.c @@ -343,8 +343,11 @@ ATF_TC_BODY(exec_or_die, tc) ATF_TC_BODY(exec_and_wait, tc) { - int val = exec_and_wait("/usr/bin/nopenope", NULL); - ATF_REQUIRE_EQ(val, -1); + /* + int val = exec_and_wait("nopenope", NULL); + ATF_REQUIRE_MSG(val == -1, "return value was: %d", val); + */ + int val; val = exec_and_wait("true", NULL); ATF_REQUIRE_EQ(val, 0); val = exec_and_wait("false", NULL);