Mercurial > dovecot > core-2.2
changeset 4564:6012b0978d2c HEAD
Use SIGCHLD handler to check for killed child processes instead of a timeout
loop.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 11 Aug 2006 00:59:40 +0300 |
parents | 5d725c24d5a0 |
children | a54558861acc |
files | src/auth/passdb-checkpassword.c src/auth/passdb-pam.c |
diffstat | 2 files changed, 14 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/src/auth/passdb-checkpassword.c Fri Aug 11 00:48:33 2006 +0300 +++ b/src/auth/passdb-checkpassword.c Fri Aug 11 00:59:40 2006 +0300 @@ -4,6 +4,7 @@ #ifdef PASSDB_CHECKPASSWORD +#include "lib-signals.h" #include "buffer.h" #include "str.h" #include "ioloop.h" @@ -21,7 +22,6 @@ const char *checkpassword_path, *checkpassword_reply_path; struct hash_table *clients; - struct timeout *to_wait; }; struct chkpw_auth_request { @@ -129,7 +129,7 @@ } } -static void wait_timeout(void *context) +static void sigchld_handler(int signo __attr_unused__, void *context) { struct checkpassword_passdb_module *module = context; struct chkpw_auth_request *request; @@ -139,9 +139,7 @@ /* FIXME: if we ever do some other kind of forking, this needs fixing */ while ((pid = waitpid(-1, &status, WNOHANG)) != 0) { if (pid == -1) { - if (errno == ECHILD) - timeout_remove(&module->to_wait); - else if (errno != EINTR) + if (errno != ECHILD && errno != EINTR) i_error("waitpid() failed: %m"); return; } @@ -375,11 +373,6 @@ chkpw_auth_request); hash_insert(module->clients, POINTER_CAST(pid), chkpw_auth_request); - - if (module->to_wait == NULL) { - /* FIXME: we could use SIGCHLD */ - module->to_wait = timeout_add(100, wait_timeout, module); - } } static struct passdb_module * @@ -395,6 +388,8 @@ module->clients = hash_create(default_pool, default_pool, 0, NULL, NULL); + + lib_signals_set_handler(SIGCHLD, TRUE, sigchld_handler, module); return &module->module; } @@ -405,6 +400,8 @@ struct hash_iterate_context *iter; void *key, *value; + lib_signals_unset_handler(SIGCHLD, sigchld_handler, module); + iter = hash_iterate_init(module->clients); while (hash_iterate(iter, &key, &value)) { checkpassword_request_finish(value, @@ -412,9 +409,6 @@ } hash_iterate_deinit(iter); hash_destroy(module->clients); - - if (module->to_wait != NULL) - timeout_remove(&module->to_wait); } struct passdb_module_interface passdb_checkpassword = {
--- a/src/auth/passdb-pam.c Fri Aug 11 00:48:33 2006 +0300 +++ b/src/auth/passdb-pam.c Fri Aug 11 00:59:40 2006 +0300 @@ -11,6 +11,7 @@ #ifdef PASSDB_PAM +#include "lib-signals.h" #include "buffer.h" #include "ioloop.h" #include "network.h" @@ -63,7 +64,6 @@ bool pam_setcred, pam_session; const char *service_name, *pam_cache_key; - struct timeout *to_wait; }; struct pam_auth_request { @@ -360,18 +360,16 @@ i_free(request); } -static void wait_timeout(void *context) +static void sigchld_handler(int signo __attr_unused__, + void *context __attr_unused__) { - struct pam_passdb_module *module = context; int status; pid_t pid; /* FIXME: if we ever do some other kind of forking, this needs fixing */ while ((pid = waitpid(-1, &status, WNOHANG)) != 0) { if (pid == -1) { - if (errno == ECHILD) - timeout_remove(&module->to_wait); - else if (errno != EINTR) + if (errno != ECHILD && errno != EINTR) i_error("waitpid() failed: %m"); return; } @@ -430,9 +428,6 @@ pam_auth_request->io = io_add(fd[0], IO_READ, pam_child_input, pam_auth_request); - - if (module->to_wait == NULL) - module->to_wait = timeout_add(1000, wait_timeout, module); } static struct passdb_module * @@ -472,15 +467,13 @@ } t_pop(); + lib_signals_set_handler(SIGCHLD, TRUE, sigchld_handler, NULL); return &module->module; } -static void pam_deinit(struct passdb_module *_module) +static void pam_deinit(struct passdb_module *_module __attr_unused__) { - struct pam_passdb_module *module = (struct pam_passdb_module *)_module; - - if (module->to_wait != NULL) - timeout_remove(&module->to_wait); + lib_signals_unset_handler(SIGCHLD, sigchld_handler, NULL); } struct passdb_module_interface passdb_pam = {