[dovecot-cvs] dovecot/src/auth passdb-checkpassword.c, 1.18.2.3, 1.18.2.4 passdb-pam.c, 1.37.2.4, 1.37.2.5

cras at dovecot.org cras at dovecot.org
Fri Aug 11 00:59:41 EEST 2006


Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv3752

Modified Files:
      Tag: branch_1_0
	passdb-checkpassword.c passdb-pam.c 
Log Message:
Use SIGCHLD handler to check for killed child processes instead of a timeout
loop.



Index: passdb-checkpassword.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-checkpassword.c,v
retrieving revision 1.18.2.3
retrieving revision 1.18.2.4
diff -u -d -r1.18.2.3 -r1.18.2.4
--- passdb-checkpassword.c	3 Aug 2006 15:27:52 -0000	1.18.2.3
+++ passdb-checkpassword.c	10 Aug 2006 21:59:39 -0000	1.18.2.4
@@ -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 = {

Index: passdb-pam.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-pam.c,v
retrieving revision 1.37.2.4
retrieving revision 1.37.2.5
diff -u -d -r1.37.2.4 -r1.37.2.5
--- passdb-pam.c	16 Jun 2006 09:59:32 -0000	1.37.2.4
+++ passdb-pam.c	10 Aug 2006 21:59:39 -0000	1.37.2.5
@@ -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 = {



More information about the dovecot-cvs mailing list