changeset 22657:98408dc06937

director: Support multiple proxy-notify connections
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 27 Oct 2017 16:20:15 +0300
parents 1789bf2a1e01
children ff99e7bff132
files src/director/main.c src/director/notify-connection.c src/director/notify-connection.h
diffstat 3 files changed, 23 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/director/main.c	Sun Nov 05 23:51:56 2017 +0200
+++ b/src/director/main.c	Fri Oct 27 16:20:15 2017 +0300
@@ -36,7 +36,6 @@
 };
 
 static struct director *director;
-static struct notify_connection *notify_conn;
 static struct timeout *to_proctitle_refresh;
 static ARRAY(enum director_socket_type) listener_socket_types;
 
@@ -181,12 +180,8 @@
 	bool userdb;
 
 	if (conn->fifo) {
-		if (notify_conn != NULL) {
-			i_error("Received another proxy-notify connection");
-			return;
-		}
 		master_service_client_connection_accept(conn);
-		notify_conn = notify_connection_init(director, conn->fd);
+		notify_connection_init(director, conn->fd);
 		return;
 	}
 
@@ -298,8 +293,7 @@
 {
 	if (to_proctitle_refresh != NULL)
 		timeout_remove(&to_proctitle_refresh);
-	if (notify_conn != NULL)
-		notify_connection_deinit(&notify_conn);
+	notify_connections_deinit();
 	/* deinit doveadm connections before director, so it can clean up
 	   its pending work, such as abort user moves. */
 	doveadm_connections_deinit();
--- a/src/director/notify-connection.c	Sun Nov 05 23:51:56 2017 +0200
+++ b/src/director/notify-connection.c	Fri Oct 27 16:20:15 2017 +0300
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
+#include "llist.h"
 #include "ioloop.h"
 #include "istream.h"
 #include "master-service.h"
@@ -12,12 +13,18 @@
 #include <unistd.h>
 
 struct notify_connection {
+	struct notify_connection *prev, *next;
+
 	int fd;
 	struct io *io;
 	struct istream *input;
 	struct director *dir;
 };
 
+static struct notify_connection *notify_connections = NULL;
+
+static void notify_connection_deinit(struct notify_connection **_conn);
+
 static void notify_update_user(struct director *dir, struct mail_tag *tag,
 			       const char *username, unsigned int username_hash)
 {
@@ -58,8 +65,7 @@
 	}
 }
 
-struct notify_connection *
-notify_connection_init(struct director *dir, int fd)
+void notify_connection_init(struct director *dir, int fd)
 {
 	struct notify_connection *conn;
 
@@ -68,18 +74,27 @@
 	conn->dir = dir;
 	conn->input = i_stream_create_fd(conn->fd, 1024, FALSE);
 	conn->io = io_add(conn->fd, IO_READ, notify_connection_input, conn);
-	return conn;
+	DLLIST_PREPEND(&notify_connections, conn);
 }
 
-void notify_connection_deinit(struct notify_connection **_conn)
+static void notify_connection_deinit(struct notify_connection **_conn)
 {
 	struct notify_connection *conn = *_conn;
 
 	*_conn = NULL;
 
+	DLLIST_REMOVE(&notify_connections, conn);
 	io_remove(&conn->io);
 	i_stream_unref(&conn->input);
 	if (close(conn->fd) < 0)
 		i_error("close(notify connection) failed: %m");
 	i_free(conn);
 }
+
+void notify_connections_deinit(void)
+{
+	while (notify_connections != NULL) {
+		struct notify_connection *conn = notify_connections;
+		notify_connection_deinit(&conn);
+	}
+}
--- a/src/director/notify-connection.h	Sun Nov 05 23:51:56 2017 +0200
+++ b/src/director/notify-connection.h	Fri Oct 27 16:20:15 2017 +0300
@@ -3,7 +3,7 @@
 
 struct director;
 
-struct notify_connection *notify_connection_init(struct director *dir, int fd);
-void notify_connection_deinit(struct notify_connection **conn);
+void notify_connection_init(struct director *dir, int fd);
+void notify_connections_deinit(void);
 
 #endif