dovecot-2.0: lib-master: Added support for keeping config connec...

dovecot at dovecot.org dovecot at dovecot.org
Fri May 15 01:53:01 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/6bb773332683
changeset: 9282:6bb773332683
user:      Timo Sirainen <tss at iki.fi>
date:      Thu May 14 18:52:54 2009 -0400
description:
lib-master: Added support for keeping config connection open and reusing it for later requests.

diffstat:

4 files changed, 35 insertions(+), 18 deletions(-)
src/lib-master/master-service-private.h  |    3 +-
src/lib-master/master-service-settings.c |   44 +++++++++++++++++++-----------
src/lib-master/master-service.c          |    1 
src/lib-master/master-service.h          |    5 ++-

diffs (101 lines):

diff -r 11e974e40f7b -r 6bb773332683 src/lib-master/master-service-private.h
--- a/src/lib-master/master-service-private.h	Thu May 14 18:52:01 2009 -0400
+++ b/src/lib-master/master-service-private.h	Thu May 14 18:52:54 2009 -0400
@@ -22,8 +22,9 @@ struct master_service {
 
 	const char *version_string;
 	const char *config_path;
+	ARRAY_TYPE(const_string) config_overrides;
+	int config_fd;
 	int syslog_facility;
-	ARRAY_TYPE(const_string) config_overrides;
 
 	unsigned int socket_count, ssl_socket_count;
         struct master_service_listener *listeners;
diff -r 11e974e40f7b -r 6bb773332683 src/lib-master/master-service-settings.c
--- a/src/lib-master/master-service-settings.c	Thu May 14 18:52:01 2009 -0400
+++ b/src/lib-master/master-service-settings.c	Thu May 14 18:52:54 2009 -0400
@@ -106,19 +106,24 @@ master_service_read_config(struct master
 	int fd, ret;
 
 	path = master_service_get_config_path(service);
-	fd = net_connect_unix(path);
-	if (fd < 0) {
-		*error_r = t_strdup_printf("net_connect_unix(%s) failed: %m",
-					   path);
-
-		if (stat(path, &st) == 0 && !S_ISFIFO(st.st_mode)) {
-			/* it's a file, not a socket */
-			master_service_exec_config(service,
-						   input->preserve_home);
-		}
-		return -1;
-	}
-	net_set_nonblock(fd, FALSE);
+	if (service->config_fd != -1) {
+		fd = service->config_fd;
+		service->config_fd = -1;
+	} else {
+		fd = net_connect_unix(path);
+		if (fd < 0) {
+			*error_r = t_strdup_printf(
+				"net_connect_unix(%s) failed: %m", path);
+
+			if (stat(path, &st) == 0 && !S_ISFIFO(st.st_mode)) {
+				/* it's a file, not a socket */
+				master_service_exec_config(service,
+							   input->preserve_home);
+			}
+			return -1;
+		}
+		net_set_nonblock(fd, FALSE);
+	}
 
 	T_BEGIN {
 		string_t *str;
@@ -221,9 +226,16 @@ int master_service_settings_read(struct 
 		i_assert(ret <= 0);
 		if (ret < 0) {
 			*error_r = settings_parser_get_error(parser);
-			return -1;
-		}
-	}
+			(void)close(fd);
+			return -1;
+		}
+	}
+
+	if ((service->flags & MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN) == 0)
+		(void)close(fd);
+	else
+		service->config_fd = fd;
+
 	/* let environment override settings. especially useful for the
 	   settings from userdb. */
 	if (settings_parse_environ(parser) < 0) {
diff -r 11e974e40f7b -r 6bb773332683 src/lib-master/master-service.c
--- a/src/lib-master/master-service.c	Thu May 14 18:52:01 2009 -0400
+++ b/src/lib-master/master-service.c	Thu May 14 18:52:54 2009 -0400
@@ -96,6 +96,7 @@ master_service_init(const char *name, en
 	service->flags = flags;
 	service->ioloop = io_loop_create();
 	service->service_count_left = (unsigned int)-1;
+	service->config_fd = -1;
 
 	service->config_path = getenv(MASTER_CONFIG_FILE_ENV);
 	if (service->config_path == NULL)
diff -r 11e974e40f7b -r 6bb773332683 src/lib-master/master-service.h
--- a/src/lib-master/master-service.h	Thu May 14 18:52:01 2009 -0400
+++ b/src/lib-master/master-service.h	Thu May 14 18:52:54 2009 -0400
@@ -9,7 +9,10 @@ enum master_service_flags {
 	/* this process is currently running standalone without a master */
 	MASTER_SERVICE_FLAG_STANDALONE		= 0x02,
 	/* Log to stderr instead of the configured log file */
-	MASTER_SERVICE_FLAG_LOG_TO_STDERR	= 0x04
+	MASTER_SERVICE_FLAG_LOG_TO_STDERR	= 0x04,
+	/* Service is going to do multiple configuration lookups,
+	   keep the connection to config service open. */
+	MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN	= 0x08
 };
 
 struct master_service_connection {


More information about the dovecot-cvs mailing list