diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2015-12-15 22:59:38 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2015-12-15 23:04:25 +0100 |
commit | 22f7d9bc5cb66411cf2e3108356b1bdc8157f437 (patch) | |
tree | 15e42823f61f9fbfd9a892ea7c19d2d1add0678c | |
parent | e40413a8dc74f42db1b2568d3c2a05ed73324804 (diff) |
handle the zombies
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r-- | multi_auth.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/multi_auth.c b/multi_auth.c index 1160491..9140036 100644 --- a/multi_auth.c +++ b/multi_auth.c @@ -102,24 +102,23 @@ static int perform_auth(void) #undef STACK_SIZE } - for (int i = 0; i < countof(modules_g); ++i) { - int status; - - do { - waitpid(-1, &status, 0); + siginfo_t infos; - } while (!WIFEXITED(status) && !WIFSIGNALED(status)); + /* wait for a first child to exit or be killed */ + waitid(P_ALL, 0, &infos, WEXITED); - if (WIFEXITED(status)) { - for (int j = 0; j < countof(modules_g); ++j) { - kill(modules_g[j].pid, SIGKILL); - } + int ret = infos.si_status; - return (WEXITSTATUS(status) == 0) ? PAM_SUCCESS : PAM_AUTH_ERR; + for (int i = 0; i < countof(modules_g); ++i) { + if (modules_g[i].pid == infos.si_pid) { + continue; } + + kill(modules_g[i].pid, SIGKILL); + waitpid(modules_g[i].pid, NULL, 0); } - return PAM_AUTH_ERR; + return ret; } PAM_EXTERN |