mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-17 18:02:09 +03:00
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.
This commit is contained in:
1 parent
a977dbbe78
commit
0b1dcf33f5
1 file changed
+19
-6
+19
-6
@@ -317,12 +317,25 @@ main (int argc, char **argv)
|
|||||||
child exits, not on this process receiving a signal. Also we're not
|
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
|
passing WUNTRACED | WCONTINUED to a waitpid() call and so will not get
|
||||||
indication that the child has stopped or continued. */
|
indication that the child has stopped or continued. */
|
||||||
wait (&status);
|
if (wait (&status) == -1)
|
||||||
|
{
|
||||||
if (WIFEXITED (status))
|
/* shouldn't happen. */
|
||||||
status = WEXITSTATUS (status);
|
error (0, errno, _("error waiting for command"));
|
||||||
else if (WIFSIGNALED (status))
|
status = EXIT_CANCELED;
|
||||||
status = WTERMSIG (status) + 128; /* what sh does at least. */
|
}
|
||||||
|
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)
|
if (timed_out)
|
||||||
return EXIT_TIMEDOUT;
|
return EXIT_TIMEDOUT;
|
||||||
|
|||||||
Reference in new issue
Block a user