changeset 925:2e649dec0f09 HEAD

Auth and login processes send an "we're ok" reply at the end of initialization. If the process dies before master receives that reply, it shutdowns itself. Usually this is because of some configuration error and it's not nice to start spamming the log files.
author Timo Sirainen <tss@iki.fi>
date Wed, 08 Jan 2003 23:13:05 +0200
parents 4f697dde0fca
children 274c722acc35
files src/auth/main.c src/auth/master.c src/login/main.c src/login/master.c src/master/auth-process.c src/master/login-process.c
diffstat 6 files changed, 42 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/main.c	Wed Jan 08 22:49:51 2003 +0200
+++ b/src/auth/main.c	Wed Jan 08 23:13:05 2003 +0200
@@ -72,11 +72,13 @@
 	auth_init();
 	cookies_init();
 	login_connections_init();
-	master_init();
 	userinfo_init();
 
 	io_listen = io_add_priority(LOGIN_LISTEN_FD, IO_PRIORITY_LOW,
 				    IO_READ, auth_accept, NULL);
+
+	/* initialize master last - it sends the "we're ok" notification */
+	master_init();
 }
 
 static void main_deinit(void)
--- a/src/auth/master.c	Wed Jan 08 22:49:51 2003 +0200
+++ b/src/auth/master.c	Wed Jan 08 23:13:05 2003 +0200
@@ -77,6 +77,10 @@
 				      MAX_OUTBUF_SIZE, IO_PRIORITY_DEFAULT,
 				      FALSE);
 	io_master = io_add(MASTER_SOCKET_FD, IO_READ, master_input, NULL);
+
+	/* just a note to master that we're ok. if we die before,
+	   master should shutdown itself. */
+	o_stream_send(output, "O", 1);
 }
 
 void master_deinit(void)
--- a/src/login/main.c	Wed Jan 08 22:49:51 2003 +0200
+++ b/src/login/main.c	Wed Jan 08 23:13:05 2003 +0200
@@ -169,7 +169,6 @@
 	main_refcount = 0;
 
 	auth_connection_init();
-	master_init();
 	clients_init();
 
 	io_imap = io_imaps = NULL;
@@ -192,6 +191,9 @@
 		io_imaps = io_add(LOGIN_IMAPS_LISTEN_FD, IO_READ,
 				  login_accept_ssl, NULL);
 	}
+
+	/* initialize master last - it sends the "we're ok" notification */
+	master_init();
 }
 
 static void main_deinit(void)
--- a/src/login/master.c	Wed Jan 08 22:49:51 2003 +0200
+++ b/src/login/master.c	Wed Jan 08 23:13:05 2003 +0200
@@ -151,6 +151,10 @@
 
         master_pos = 0;
 	io_master = io_add(LOGIN_MASTER_SOCKET_FD, IO_READ, master_input, NULL);
+
+	/* just a note to master that we're ok. if we die before,
+	   master should shutdown itself. */
+        master_notify_finished();
 }
 
 void master_deinit(void)
--- a/src/master/auth-process.c	Wed Jan 08 22:49:51 2003 +0200
+++ b/src/master/auth-process.c	Wed Jan 08 23:13:05 2003 +0200
@@ -29,6 +29,8 @@
 	char reply_buf[sizeof(struct auth_cookie_reply_data)];
 
 	struct waiting_request *requests, **next_request;
+
+	unsigned int initialized:1;
 };
 
 struct waiting_request {
@@ -109,6 +111,18 @@
 		return;
 	}
 
+	if (!p->initialized) {
+		if (p->reply_buf[0] != 'O') {
+			i_fatal("Auth process sent invalid initialization "
+				"notification");
+		}
+
+		p->initialized = TRUE;
+
+		ret--;
+		memmove(p->reply_buf, p->reply_buf + 1, ret);
+	}
+
 	p->reply_pos += ret;
 	if (p->reply_pos < sizeof(p->reply_buf))
 		return;
@@ -146,6 +160,9 @@
 	struct auth_process **pos;
 	struct waiting_request *next;
 
+	if (!p->initialized)
+		i_fatal("Auth process died too early - shutting down");
+
 	for (pos = &processes; *pos != NULL; pos = &(*pos)->next) {
 		if (*pos == p) {
 			*pos = p->next;
--- a/src/master/login-process.c	Wed Jan 08 22:49:51 2003 +0200
+++ b/src/master/login-process.c	Wed Jan 08 23:13:05 2003 +0200
@@ -24,6 +24,7 @@
 	int fd;
 	struct io *io;
 	struct ostream *output;
+	unsigned int initialized:1;
 	unsigned int listening:1;
 	unsigned int destroyed:1;
 };
@@ -131,9 +132,14 @@
 	}
 
 	if (client_fd == -1) {
-		/* just a notification that the login process isn't
-		   listening for new connections anymore */
-		login_process_mark_nonlistening(p);
+		/* just a notification that the login process */
+		if (!p->initialized) {
+			/* initialization notify */
+			p->initialized = TRUE;;
+		} else {
+			/* not listening for new connections anymore */
+			login_process_mark_nonlistening(p);
+		}
 		return;
 	}
 
@@ -210,6 +216,8 @@
 		return;
 	p->destroyed = TRUE;
 
+	if (!p->initialized)
+		i_fatal("Login process died too early - shutting down");
 	if (p->listening)
 		listening_processes--;