diff options
author | Pádraig Brady <P@draigBrady.com> | 2009-08-31 19:18:27 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2009-09-01 11:02:18 +0100 |
commit | 0b1dcf33f5b9d0102b852a361135462708408a71 (patch) | |
tree | b61a3f7badfafc4467da89bc7da31621a4107515 /src | |
parent | a977dbbe78f4dcb64e008f41c8a46c4972af834b (diff) | |
download | coreutils-0b1dcf33f5b9d0102b852a361135462708408a71.tar.xz |
timeout: defensive handling of all wait() errors
* src/timeout.c (main): Handle all possible cases of unexpected
failures from wait(). This was prompted by the clang tool reporting
the possible non-initialization of the status variable.
Diffstat (limited to 'src')
-rw-r--r-- | src/timeout.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/timeout.c b/src/timeout.c index 20efdddc0..62f3d4b6e 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -317,12 +317,25 @@ main (int argc, char **argv) child exits, not on this process receiving a signal. Also we're not passing WUNTRACED | WCONTINUED to a waitpid() call and so will not get indication that the child has stopped or continued. */ - wait (&status); - - if (WIFEXITED (status)) - status = WEXITSTATUS (status); - else if (WIFSIGNALED (status)) - status = WTERMSIG (status) + 128; /* what sh does at least. */ + if (wait (&status) == -1) + { + /* shouldn't happen. */ + error (0, errno, _("error waiting for command")); + status = EXIT_CANCELED; + } + else + { + if (WIFEXITED (status)) + status = WEXITSTATUS (status); + else if (WIFSIGNALED (status)) + status = WTERMSIG (status) + 128; /* what sh does at least. */ + else + { + /* shouldn't happen. */ + error (0, 0, _("unknown status from command (0x%X)"), status); + status = EXIT_FAILURE; + } + } if (timed_out) return EXIT_TIMEDOUT; |