[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: timeout.c warning about returning undefined value
From: |
Pádraig Brady |
Subject: |
Re: timeout.c warning about returning undefined value |
Date: |
Tue, 1 Sep 2009 04:15:47 +0100 |
User-agent: |
Thunderbird 2.0.0.6 (X11/20071008) |
I'll check in the attached later on today
unless there are objections.
cheers,
Pádraig.
>From 9fd105fed6c317d12c949a1f8b66b0c0aacc77b3 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= <address@hidden>
Date: Mon, 31 Aug 2009 19:18:27 +0100
Subject: [PATCH] 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.
---
src/timeout.c | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/timeout.c b/src/timeout.c
index 20efddd..62f3d4b 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;
--
1.6.2.5