From: Timo Sirainen Date: Fri, 27 Oct 2017 13:20:15 +0000 (+0300) Subject: director: Support multiple proxy-notify connections X-Git-Tag: 2.3.0.rc1~502 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=57d65ae19a2339d1303a522e680c30ee1ef68d6d;p=thirdparty%2Fdovecot%2Fcore.git director: Support multiple proxy-notify connections --- diff --git a/src/director/main.c b/src/director/main.c index 09b4023e7f..306dc982ed 100644 --- a/src/director/main.c +++ b/src/director/main.c @@ -36,7 +36,6 @@ enum director_socket_type { }; 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; @@ -176,12 +175,8 @@ static void client_connected(struct master_service_connection *conn) 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; } @@ -292,8 +287,7 @@ static void main_preinit(void) static void main_deinit(void) { timeout_remove(&to_proctitle_refresh); - if (notify_conn != NULL) - notify_connection_deinit(¬ify_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(); diff --git a/src/director/notify-connection.c b/src/director/notify-connection.c index 74607bab0f..f04818f75a 100644 --- a/src/director/notify-connection.c +++ b/src/director/notify-connection.c @@ -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 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) { @@ -59,8 +66,7 @@ static void notify_connection_input(struct notify_connection *conn) } } -struct notify_connection * -notify_connection_init(struct director *dir, int fd) +void notify_connection_init(struct director *dir, int fd) { struct notify_connection *conn; @@ -69,18 +75,27 @@ notify_connection_init(struct director *dir, int fd) conn->dir = dir; conn->input = i_stream_create_fd(conn->fd, 1024); conn->io = io_add(conn->fd, IO_READ, notify_connection_input, conn); - return conn; + DLLIST_PREPEND(¬ify_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(¬ify_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); + } +} diff --git a/src/director/notify-connection.h b/src/director/notify-connection.h index cb6217015e..1a0d09e628 100644 --- a/src/director/notify-connection.h +++ b/src/director/notify-connection.h @@ -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