aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2014-06-19 13:59:24 +0200
committerDaniel Lezcano <daniel.lezcano@free.fr>2014-06-19 14:15:15 +0200
commit88790b7bc20a8edaa1a5406c8dba1ebec75000ae (patch)
treea6ad9e3af53549b4b2a46964d255ba70fc9b6f2a
parentf5b9bdcb530a8871e6c65a617d41001b39bf4912 (diff)
Fix bad check with waitpid.
With the current code, when the child exits on timeout, waitpid returns -1. The check right after will kill the process without waiting it, so none of the macros after will conclude the process exited correctly leading to the end of the function with a return -1. Kill the process in case of timeout and wait it. We don't care of the other errors because waitpid returns ECHLD, EINVAL. * ECHLD : we won't wait twice our child * EINVAL: we are not passing flag Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r--idlestat.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/idlestat.c b/idlestat.c
index 1fb6f9e..5e8f8d5 100644
--- a/idlestat.c
+++ b/idlestat.c
@@ -1202,9 +1202,9 @@ static int execute(int argc, char *argv[], char *const envp[],
alarm(options->duration);
again:
if (waitpid(pid, &status, 0) < 0) {
- if (errno != EINTR || !sigalrm)
- goto again;
- kill(pid, SIGTERM);
+ if (errno == EINTR && sigalrm)
+ kill(pid, SIGTERM);
+ goto again;
}
if (WIFEXITED(status) && !WEXITSTATUS(status)) {