diff options
author | Daniel Lezcano <daniel.lezcano@linaro.org> | 2014-06-19 13:59:24 +0200 |
---|---|---|
committer | Daniel Lezcano <daniel.lezcano@free.fr> | 2014-06-19 14:15:15 +0200 |
commit | 88790b7bc20a8edaa1a5406c8dba1ebec75000ae (patch) | |
tree | a6ad9e3af53549b4b2a46964d255ba70fc9b6f2a | |
parent | f5b9bdcb530a8871e6c65a617d41001b39bf4912 (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.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -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)) { |