summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Price <anprice@redhat.com>2014-03-28 01:42:47 +0000
committerChris Mason <clm@fb.com>2014-09-24 12:02:09 -0700
commit6061d941fc91e079edf76402bab2056063637d96 (patch)
tree2da95f37b1a96b821db8bbc51d430d2113525d46
parentc1ab63ed17189cacf1247751e8633f589c977a00 (diff)
downloadblktrace-6061d941fc91e079edf76402bab2056063637d96.tar.gz
blktrace-6061d941fc91e079edf76402bab2056063637d96.tar.bz2
iowatcher: Check program exit code properly
The return value of posix_spawnp() was being checked but the exit status of the child process was being ignored. This adds checks and error reporting based on the status that waitpid returns. Signed-off-by: Andrew Price <anprice@redhat.com>
-rw-r--r--iowatcher/tracers.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/iowatcher/tracers.c b/iowatcher/tracers.c
index 8f96372..ed5efa1 100644
--- a/iowatcher/tracers.c
+++ b/iowatcher/tracers.c
@@ -182,6 +182,7 @@ int run_program2(int argc, char **argv)
{
int i;
int err;
+ int status;
pid_t pid;
fprintf(stderr, "running");
@@ -191,11 +192,21 @@ int run_program2(int argc, char **argv)
err = posix_spawnp(&pid, argv[0], NULL, NULL, argv, environ);
if (err != 0) {
- fprintf(stderr, "%s failed with exit code %d\n", argv[0], err);
- return err;
+ fprintf(stderr, "Could not run '%s': %s\n", argv[0], strerror(err));
+ return -err;
}
- waitpid(pid, NULL, 0);
- return 0;
+ waitpid(pid, &status, 0);
+ if (WIFEXITED(status)) {
+ err = WEXITSTATUS(status);
+ if (err == 127) /* spawnp failed after forking */
+ fprintf(stderr, "Failed to run '%s'\n", argv[0]);
+ else if (err)
+ fprintf(stderr, "'%s' failed with exit status %d\n", argv[0], err);
+ } else if (WIFSIGNALED(status)) {
+ fprintf(stderr, "'%s' killed by signal %d\n", argv[0], WTERMSIG(status));
+ return 1;
+ }
+ return err;
}
int wait_for_tracers(void)