From 9caf477f12e730af5181587656f34c316152a2a6 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 8 Jul 2018 14:23:03 -0400 Subject: exec: Add some debugging info about failed commands --- exec.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'exec.c') diff --git a/exec.c b/exec.c index d383935..43ffad0 100644 --- a/exec.c +++ b/exec.c @@ -363,17 +363,28 @@ static int bfs_exec_spawn(const struct bfs_exec *execbuf) { return -1; } - int status; - if (waitpid(pid, &status, 0) < 0) { + int wstatus; + if (waitpid(pid, &wstatus, 0) < 0) { return -1; } errno = 0; - if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) { - return 0; + + if (WIFEXITED(wstatus)) { + int status = WEXITSTATUS(wstatus); + if (status == EXIT_SUCCESS) { + return 0; + } else { + bfs_exec_debug(execbuf, "Command '%s' failed with status %d\n", execbuf->argv[0], status); + } + } else if (WIFSIGNALED(wstatus)) { + int sig = WTERMSIG(wstatus); + bfs_exec_debug(execbuf, "Command '%s' terminated by signal %d\n", execbuf->argv[0], sig); } else { - return -1; + bfs_exec_debug(execbuf, "Command '%s' terminated abnormally\n", execbuf->argv[0]); } + + return -1; } else { // Child close(pipefd[0]); @@ -601,6 +612,9 @@ int bfs_exec_finish(struct bfs_exec *execbuf) { while (bfs_exec_args_remain(execbuf)) { execbuf->ret |= bfs_exec_flush(execbuf); } + if (execbuf->ret != 0) { + bfs_exec_debug(execbuf, "One or more executions of '%s' failed\n", execbuf->argv[0]); + } } return execbuf->ret; } -- cgit v1.2.3