summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-09-12 00:12:28 -0400
committerTavian Barnes <tavianator@tavianator.com>2018-09-12 00:24:39 -0400
commit727562e99082e9ed808b5ff6e02b65b9cf5b65c3 (patch)
treea790a7407b2ee84ca260e58c33f8b512997d251c
parentfc76667077c0b6f769501d1bb25b1b41d5c38bf5 (diff)
downloadbfs-727562e99082e9ed808b5ff6e02b65b9cf5b65c3.tar.xz
exec: Don't leave zombies around if the child fails to exec()
-rw-r--r--exec.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/exec.c b/exec.c
index 87bb5e6..3cb05f4 100644
--- a/exec.c
+++ b/exec.c
@@ -355,12 +355,14 @@ static int bfs_exec_spawn(const struct bfs_exec *execbuf) {
// Parent
close(pipefd[1]);
- int error;
+ int ret, error;
ssize_t nbytes = read(pipefd[0], &error, sizeof(error));
close(pipefd[0]);
if (nbytes == sizeof(error)) {
- errno = error;
- return -1;
+ ret = -1;
+ } else {
+ ret = 0;
+ error = 0;
}
int wstatus;
@@ -368,23 +370,22 @@ static int bfs_exec_spawn(const struct bfs_exec *execbuf) {
return -1;
}
- int ret = -1;
-
if (WIFEXITED(wstatus)) {
int status = WEXITSTATUS(wstatus);
- if (status == EXIT_SUCCESS) {
- ret = 0;
- } else {
+ if (status != EXIT_SUCCESS) {
bfs_exec_debug(execbuf, "Command '%s' failed with status %d\n", execbuf->argv[0], status);
+ ret = -1;
}
} else if (WIFSIGNALED(wstatus)) {
int sig = WTERMSIG(wstatus);
bfs_exec_debug(execbuf, "Command '%s' terminated by signal %d\n", execbuf->argv[0], sig);
+ ret = -1;
} else {
bfs_exec_debug(execbuf, "Command '%s' terminated abnormally\n", execbuf->argv[0]);
+ ret = -1;
}
- errno = 0;
+ errno = error;
return ret;
} else {
// Child
@@ -407,7 +408,6 @@ static int bfs_exec_spawn(const struct bfs_exec *execbuf) {
close(pipefd[1]);
_Exit(EXIT_FAILURE);
}
-
}
/** exec() a command for a single file. */