dovecot-2.1: lib-master: Set service/client limits already in ma...

dovecot at dovecot.org dovecot at dovecot.org
Fri Nov 18 21:37:47 EET 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/c6f5203bf59f
changeset: 13726:c6f5203bf59f
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Nov 18 21:35:52 2011 +0200
description:
lib-master: Set service/client limits already in master_service_init()

diffstat:

 src/lib-master/master-service.c |  85 +++++++++++++++++++---------------------
 1 files changed, 41 insertions(+), 44 deletions(-)

diffs (134 lines):

diff -r 700e92b43c74 -r c6f5203bf59f src/lib-master/master-service.c
--- a/src/lib-master/master-service.c	Fri Nov 18 21:31:15 2011 +0200
+++ b/src/lib-master/master-service.c	Fri Nov 18 21:35:52 2011 +0200
@@ -101,7 +101,8 @@
 		    int *argc, char **argv[], const char *getopt_str)
 {
 	struct master_service *service;
-	const char *str;
+	const char *value;
+	unsigned int count;
 
 	i_assert(name != NULL);
 
@@ -110,8 +111,8 @@
 	    (flags & MASTER_SERVICE_FLAG_STANDALONE) == 0) {
 		int count;
 
-		str = getenv("SOCKET_COUNT");
-		count = str == NULL ? 0 : atoi(str);
+		value = getenv("SOCKET_COUNT");
+		count = value == NULL ? 0 : atoi(value);
 		fd_debug_verify_leaks(MASTER_LISTEN_FD_FIRST + count, 1024);
 	}
 #endif
@@ -165,12 +166,12 @@
 	} else {
 		service->version_string = PACKAGE_VERSION;
 	}
-	str = getenv("SOCKET_COUNT");
-	if (str != NULL)
-		service->socket_count = atoi(str);
-	str = getenv("SSL_SOCKET_COUNT");
-	if (str != NULL)
-		service->ssl_socket_count = atoi(str);
+	value = getenv("SOCKET_COUNT");
+	if (value != NULL)
+		service->socket_count = atoi(value);
+	value = getenv("SSL_SOCKET_COUNT");
+	if (value != NULL)
+		service->ssl_socket_count = atoi(value);
 
 	/* set up some kind of logging until we know exactly how and where
 	   we want to log */
@@ -183,6 +184,37 @@
 		i_set_failure_prefix(t_strdup_printf("%s: ", name));
 	}
 
+	if ((flags & MASTER_SERVICE_FLAG_STANDALONE) == 0) {
+		/* initialize master_status structure */
+		value = getenv(MASTER_UID_ENV);
+		if (value == NULL ||
+		    str_to_uint(value, &service->master_status.uid) < 0)
+			i_fatal(MASTER_UID_ENV" missing");
+		service->master_status.pid = getpid();
+
+		/* set the default limit */
+		value = getenv(MASTER_CLIENT_LIMIT_ENV);
+		if (value == NULL || str_to_uint(value, &count) < 0 ||
+		    count == 0)
+			i_fatal(MASTER_CLIENT_LIMIT_ENV" missing");
+		master_service_set_client_limit(service, count);
+
+		/* seve the process limit */
+		value = getenv(MASTER_PROCESS_LIMIT_ENV);
+		if (value != NULL && str_to_uint(value, &count) == 0 &&
+		    count > 0)
+			service->process_limit = count;
+
+		/* set the default service count */
+		value = getenv(MASTER_SERVICE_COUNT_ENV);
+		if (value != NULL && str_to_uint(value, &count) == 0 &&
+		    count > 0)
+			master_service_set_service_count(service, count);
+	} else {
+		master_service_set_client_limit(service, 1);
+		master_service_set_service_count(service, 1);
+	}
+
 	master_service_verify_version_string(service);
 	return service;
 }
@@ -346,11 +378,6 @@
 {
 	enum libsig_flags sigint_flags = LIBSIG_FLAG_DELAYED;
 	struct stat st;
-	const char *value;
-	unsigned int count;
-
-	i_assert(service->total_available_count == 0);
-	i_assert(service->service_count_left == (unsigned int)-1);
 
 	/* set default signal handlers */
 	lib_signals_init();
@@ -367,40 +394,10 @@
 		if (fstat(MASTER_STATUS_FD, &st) < 0 || !S_ISFIFO(st.st_mode))
 			i_fatal("Must be started by dovecot master process");
 
-		/* initialize master_status structure */
-		value = getenv(MASTER_UID_ENV);
-		if (value == NULL ||
-		    str_to_uint(value, &service->master_status.uid) < 0)
-			i_fatal(MASTER_UID_ENV" missing");
-		service->master_status.pid = getpid();
-
-		/* set the default limit */
-		value = getenv(MASTER_CLIENT_LIMIT_ENV);
-		if (value == NULL || str_to_uint(value, &count) < 0 ||
-		    count == 0)
-			i_fatal(MASTER_CLIENT_LIMIT_ENV" missing");
-		master_service_set_client_limit(service, count);
-
-		/* seve the process limit */
-		value = getenv(MASTER_PROCESS_LIMIT_ENV);
-		if (value != NULL && str_to_uint(value, &count) == 0 &&
-		    count > 0)
-			service->process_limit = count;
-
-		/* set the default service count */
-		value = getenv(MASTER_SERVICE_COUNT_ENV);
-		if (value != NULL && str_to_uint(value, &count) == 0 &&
-		    count > 0)
-			master_service_set_service_count(service, count);
-
 		/* start listening errors for status fd, it means master died */
 		service->io_status_error = io_add(MASTER_DEAD_FD, IO_ERROR,
 						  master_status_error, service);
-	} else {
-		master_service_set_client_limit(service, 1);
-		master_service_set_service_count(service, 1);
 	}
-
 	master_service_io_listeners_add(service);
 
 	if ((service->flags & MASTER_SERVICE_FLAG_STD_CLIENT) != 0) {


More information about the dovecot-cvs mailing list