diff options
author | Philipp Wollermann <philwo@google.com> | 2015-10-22 19:58:12 +0000 |
---|---|---|
committer | John Field <jfield@google.com> | 2015-10-23 14:55:08 +0000 |
commit | d6722d63bb0ac8769f7fed4868620cf9a74c8005 (patch) | |
tree | 07be00315cf14aa0b81da4055b45891477c3e815 /src | |
parent | 916370ec6195d7fc13812e64a65c2cd6ef9e36c9 (diff) |
Print the name of the execvp'd file for easier debugging in case the call fails.
--
MOS_MIGRATED_REVID=106083151
Diffstat (limited to 'src')
-rw-r--r-- | src/main/tools/process-tools.c | 3 | ||||
-rw-r--r-- | src/main/tools/process-tools.h | 10 | ||||
-rw-r--r-- | src/main/tools/process-wrapper.c | 4 | ||||
-rwxr-xr-x | src/test/shell/bazel/process-wrapper_test.sh | 9 |
4 files changed, 16 insertions, 10 deletions
diff --git a/src/main/tools/process-tools.c b/src/main/tools/process-tools.c index 045be73920..b0067f8eb1 100644 --- a/src/main/tools/process-tools.c +++ b/src/main/tools/process-tools.c @@ -51,8 +51,7 @@ void Redirect(const char *target_path, int fd, const char *name) { if (target_path != NULL && strcmp(target_path, "-") != 0) { int fd_out; const int flags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND; - CHECK_CALL(fd_out = open(target_path, flags, 0666), - "Could not open %s for redirection of %s", target_path, name); + CHECK_CALL(fd_out = open(target_path, flags, 0666)); CHECK_CALL(dup2(fd_out, fd)); CHECK_CALL(close(fd_out)); } diff --git a/src/main/tools/process-tools.h b/src/main/tools/process-tools.h index 00a7e9df2b..a0ba38816d 100644 --- a/src/main/tools/process-tools.h +++ b/src/main/tools/process-tools.h @@ -30,11 +30,11 @@ exit(EXIT_FAILURE); \ } -#define CHECK_CALL(x, ...) \ - if ((x) == -1) { \ - fprintf(stderr, __FILE__ ":" S__LINE__ ": " __VA_ARGS__); \ - perror(#x); \ - exit(EXIT_FAILURE); \ +#define CHECK_CALL(x) \ + if ((x) == -1) { \ + fprintf(stderr, __FILE__ ":" S__LINE__ ": "); \ + perror(#x); \ + exit(EXIT_FAILURE); \ } #define CHECK_NOT_NULL(x) \ diff --git a/src/main/tools/process-wrapper.c b/src/main/tools/process-wrapper.c index f118d0aa47..36fa59e157 100644 --- a/src/main/tools/process-wrapper.c +++ b/src/main/tools/process-wrapper.c @@ -24,6 +24,7 @@ #define _GNU_SOURCE +#include <err.h> #include <errno.h> #include <signal.h> #include <stdbool.h> @@ -116,7 +117,8 @@ static void SpawnCommand(char *const *argv, double timeout_secs) { umask(022); // Does not return unless something went wrong. - CHECK_CALL(execvp(argv[0], argv)); + execvp(argv[0], argv); + err(EXIT_FAILURE, "execvp(\"%s\", ...)", argv[0]); } else { // In parent. diff --git a/src/test/shell/bazel/process-wrapper_test.sh b/src/test/shell/bazel/process-wrapper_test.sh index dba3120f9c..77467a2e53 100755 --- a/src/test/shell/bazel/process-wrapper_test.sh +++ b/src/test/shell/bazel/process-wrapper_test.sh @@ -63,13 +63,11 @@ function test_signal_death() { } function test_signal_catcher() { - set -x local code=0 $WRAPPER 1 2 $OUT $ERR /bin/bash -c \ 'trap "echo later; exit 0" SIGINT SIGTERM SIGALRM; sleep 10' &> $TEST_log || code=$? assert_equals 142 "$code" # SIGNAL_BASE + SIGALRM = 128 + 14 assert_stdout "later" - set +x } function test_basic_timeout() { @@ -95,4 +93,11 @@ function test_timeout_kill() { assert_stdout "before" } +function test_execvp_error_message() { + local code=0 + $WRAPPER -1 0 $OUT $ERR /bin/notexisting &> $TEST_log || code=$? + assert_equals 1 "$code" + assert_contains "execvp(\"/bin/notexisting\", ...): No such file or directory" "$ERR" +} + run_suite "process-wrapper" |