dovecot-2.1: auth: Make idle_kill work with auth worker processes.

dovecot at dovecot.org dovecot at dovecot.org
Fri Jan 20 18:28:46 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/58556a90259f
changeset: 13970:58556a90259f
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jan 20 18:28:40 2012 +0200
description:
auth: Make idle_kill work with auth worker processes.

diffstat:

 src/auth/auth-common.h        |   2 +-
 src/auth/auth-worker-client.c |  30 ++++++++++++++++++++++++++++--
 src/auth/auth-worker-client.h |   3 +--
 src/auth/auth-worker-server.c |   9 ++++++++-
 src/auth/main.c               |   9 +++++++--
 src/auth/passdb-pam.c         |   2 +-
 6 files changed, 46 insertions(+), 9 deletions(-)

diffs (179 lines):

diff -r 3963862a4086 -r 58556a90259f src/auth/auth-common.h
--- a/src/auth/auth-common.h	Fri Jan 20 18:27:44 2012 +0200
+++ b/src/auth/auth-common.h	Fri Jan 20 18:28:40 2012 +0200
@@ -4,7 +4,7 @@
 #include "lib.h"
 #include "auth.h"
 
-extern bool worker, shutdown_request;
+extern bool worker, worker_restart_request;
 extern time_t process_start_time;
 extern struct auth_penalty *auth_penalty;
 
diff -r 3963862a4086 -r 58556a90259f src/auth/auth-worker-client.c
--- a/src/auth/auth-worker-client.c	Fri Jan 20 18:27:44 2012 +0200
+++ b/src/auth/auth-worker-client.c	Fri Jan 20 18:28:40 2012 +0200
@@ -28,6 +28,7 @@
 	struct io *io;
 	struct istream *input;
 	struct ostream *output;
+	struct timeout *to_idle;
 
 	unsigned int version_received:1;
 	unsigned int dbhash_received:1;
@@ -99,8 +100,8 @@
 static void auth_worker_send_reply(struct auth_worker_client *client,
 				   string_t *str)
 {
-	if (shutdown_request)
-		o_stream_send_str(client->output, "SHUTDOWN\n");
+	if (worker_restart_request)
+		o_stream_send_str(client->output, "RESTART\n");
 	o_stream_send(client->output, str_data(str), str_len(str));
 }
 
@@ -594,6 +595,9 @@
 	char *line;
 	bool ret;
 
+	if (client->to_idle != NULL)
+		timeout_reset(client->to_idle);
+
 	switch (i_stream_read(client->input)) {
 	case 0:
 		return;
@@ -670,10 +674,17 @@
 	return 1;
 }
 
+static void
+auth_worker_client_idle_kill(struct auth_worker_client *client ATTR_UNUSED)
+{
+	auth_worker_client_send_shutdown();
+}
+
 struct auth_worker_client *
 auth_worker_client_create(struct auth *auth, int fd)
 {
         struct auth_worker_client *client;
+	unsigned int idle_kill_secs;
 
 	client = i_new(struct auth_worker_client, 1);
 	client->refcount = 1;
@@ -687,6 +698,13 @@
 	client->io = io_add(fd, IO_READ, auth_worker_input, client);
 	auth_worker_refresh_proctitle(CLIENT_STATE_HANDSHAKE);
 
+	idle_kill_secs = master_service_get_idle_kill_secs(master_service);
+	if (idle_kill_secs > 0) {
+		client->to_idle = timeout_add(idle_kill_secs * 1000,
+					      auth_worker_client_idle_kill,
+					      client);
+	}
+
 	auth_worker_client = client;
 	if (auth_worker_client_error)
 		auth_worker_client_send_error();
@@ -704,6 +722,8 @@
 	i_stream_close(client->input);
 	o_stream_close(client->output);
 
+	if (client->to_idle != NULL)
+		timeout_remove(&client->to_idle);
 	if (client->io != NULL)
 		io_remove(&client->io);
 
@@ -751,3 +771,9 @@
 	}
 	auth_worker_refresh_proctitle(CLIENT_STATE_IDLE);
 }
+
+void auth_worker_client_send_shutdown(void)
+{
+	if (auth_worker_client != NULL)
+		o_stream_send_str(auth_worker_client->output, "SHUTDOWN\n");
+}
diff -r 3963862a4086 -r 58556a90259f src/auth/auth-worker-client.h
--- a/src/auth/auth-worker-client.h	Fri Jan 20 18:27:44 2012 +0200
+++ b/src/auth/auth-worker-client.h	Fri Jan 20 18:28:40 2012 +0200
@@ -13,7 +13,6 @@
 
 void auth_worker_client_send_error(void);
 void auth_worker_client_send_success(void);
-
-const char *auth_worker_client_get_state(struct auth_worker_client *client);
+void auth_worker_client_send_shutdown(void);
 
 #endif
diff -r 3963862a4086 -r 58556a90259f src/auth/auth-worker-server.c
--- a/src/auth/auth-worker-server.c	Fri Jan 20 18:27:44 2012 +0200
+++ b/src/auth/auth-worker-server.c	Fri Jan 20 18:28:40 2012 +0200
@@ -42,6 +42,7 @@
 	unsigned int id_counter;
 
 	unsigned int received_error:1;
+	unsigned int restart:1;
 	unsigned int shutdown:1;
 };
 
@@ -335,6 +336,10 @@
 	}
 
 	while ((line = i_stream_next_line(conn->input)) != NULL) {
+		if (strcmp(line, "RESTART") == 0) {
+			conn->restart = TRUE;
+			continue;
+		}
 		if (strcmp(line, "SHUTDOWN") == 0) {
 			conn->shutdown = TRUE;
 			continue;
@@ -372,8 +377,10 @@
 
 	if (conn->request != NULL) {
 		/* there's still a pending request */
-	} else if (conn->shutdown)
+	} else if (conn->restart)
 		auth_worker_destroy(&conn, "Max requests limit", TRUE);
+	else if (conn->shutdown)
+		auth_worker_destroy(&conn, "Idle kill", FALSE);
 	else
 		auth_worker_request_send_next(conn);
 }
diff -r 3963862a4086 -r 58556a90259f src/auth/main.c
--- a/src/auth/main.c	Fri Jan 20 18:27:44 2012 +0200
+++ b/src/auth/main.c	Fri Jan 20 18:28:40 2012 +0200
@@ -48,7 +48,7 @@
 	char *path;
 };
 
-bool worker = FALSE, shutdown_request = FALSE;
+bool worker = FALSE, worker_restart_request = FALSE;
 time_t process_start_time;
 struct auth_penalty *auth_penalty;
 
@@ -339,7 +339,12 @@
 
 static void auth_die(void)
 {
-	/* do nothing. auth clients should disconnect soon. */
+	if (!worker) {
+		/* do nothing. auth clients should disconnect soon. */
+	} else {
+		/* ask auth master to disconnect us */
+		auth_worker_client_send_shutdown();
+	}
 }
 
 int main(int argc, char *argv[])
diff -r 3963862a4086 -r 58556a90259f src/auth/passdb-pam.c
--- a/src/auth/passdb-pam.c	Fri Jan 20 18:27:44 2012 +0200
+++ b/src/auth/passdb-pam.c	Fri Jan 20 18:28:40 2012 +0200
@@ -312,7 +312,7 @@
 
 	if (module->requests_left > 0) {
 		if (--module->requests_left == 0)
-			shutdown_request = TRUE;
+			worker_restart_request = TRUE;
 	}
 
 	expanded_service = t_str_new(64);


More information about the dovecot-cvs mailing list