changeset 9348:0c587f108916 HEAD

lib-master has now a global master_service variable that all binaries use. There should always be only one of them anyway.
author Timo Sirainen <tss@iki.fi>
date Fri, 22 May 2009 17:26:27 -0400
parents 79174ec42414
children 04cade277134
files src/anvil/main.c src/auth/auth-common.h src/auth/auth-master-connection.c src/auth/auth-worker-client.c src/auth/main.c src/config/doveconf.c src/config/main.c src/imap-login/client.c src/imap/imap-client.c src/imap/imap-common.h src/imap/main.c src/lda/main.c src/lib-master/master-service.c src/lib-master/master-service.h src/lmtp/client.c src/lmtp/main.c src/lmtp/main.h src/log/common.h src/log/log-connection.c src/log/main.c src/login-common/common.h src/login-common/login-proxy.c src/login-common/main.c src/login-common/sasl-server.c src/login-common/ssl-proxy-openssl.c src/master/common.h src/master/service-process.c src/plugins/convert/convert-tool.c src/plugins/expire/expire-tool.c src/pop3-login/client.c src/pop3/main.c src/pop3/pop3-client.c src/pop3/pop3-common.h src/util/doveadm.c
diffstat 34 files changed, 140 insertions(+), 144 deletions(-) [+]
line wrap: on
line diff
--- a/src/anvil/main.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/anvil/main.c	Fri May 22 17:26:27 2009 -0400
@@ -12,8 +12,6 @@
 
 struct connect_limit *connect_limit;
 
-static struct master_service *service;
-
 static void client_connected(const struct master_service_connection *conn)
 {
 	anvil_connection_create(conn->fd);
@@ -23,20 +21,20 @@
 {
 	int c;
 
-	service = master_service_init("anvil", 0, argc, argv);
+	master_service = master_service_init("anvil", 0, argc, argv);
 	while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) {
-		if (!master_service_parse_option(service, c, optarg))
+		if (!master_service_parse_option(master_service, c, optarg))
 			exit(FATAL_DEFAULT);
 	}
 
-	master_service_init_log(service, "anvil: ", 0);
-	master_service_init_finish(service);
+	master_service_init_log(master_service, "anvil: ", 0);
+	master_service_init_finish(master_service);
 	connect_limit = connect_limit_init();
 
-	master_service_run(service, client_connected);
+	master_service_run(master_service, client_connected);
 
 	connect_limit_deinit(&connect_limit);
 	anvil_connections_destroy_all();
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
         return 0;
 }
--- a/src/auth/auth-common.h	Fri May 22 13:07:17 2009 -0400
+++ b/src/auth/auth-common.h	Fri May 22 17:26:27 2009 -0400
@@ -4,7 +4,6 @@
 #include "lib.h"
 #include "auth.h"
 
-extern struct master_service *service;
 extern bool worker, shutdown_request;
 extern time_t process_start_time;
 
--- a/src/auth/auth-master-connection.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/auth/auth-master-connection.c	Fri May 22 17:26:27 2009 -0400
@@ -425,7 +425,7 @@
 		conn->fd = -1;
 	}
 
-        master_service_client_connection_destroyed(service);
+        master_service_client_connection_destroyed(master_service);
 	auth_master_connection_unref(&conn);
 }
 
--- a/src/auth/auth-worker-client.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/auth/auth-worker-client.c	Fri May 22 17:26:27 2009 -0400
@@ -617,7 +617,7 @@
 	net_disconnect(client->fd);
 	client->fd = -1;
 
-        master_service_client_connection_destroyed(service);
+        master_service_client_connection_destroyed(master_service);
 }
 
 void auth_worker_client_unref(struct auth_worker_client **_client)
--- a/src/auth/main.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/auth/main.c	Fri May 22 17:26:27 2009 -0400
@@ -31,7 +31,6 @@
 	AUTH_SOCKET_MASTER
 };
 
-struct master_service *service;
 bool worker = FALSE, shutdown_request = FALSE;
 time_t process_start_time;
 
@@ -54,7 +53,7 @@
 	passdbs_init();
 	userdbs_init();
 	modules = module_dir_load(AUTH_MODULE_DIR, NULL, TRUE,
-				  master_service_get_version_string(service));
+			master_service_get_version_string(master_service));
 	module_dir_init(modules);
 	auth = auth_preinit(set);
 
@@ -85,7 +84,7 @@
 	if (worker) {
 		/* workers have only a single connection from the master
 		   auth process */
-		master_service_set_client_limit(service, 1);
+		master_service_set_client_limit(master_service, 1);
 	} else if (getenv("MASTER_AUTH_FD") != NULL) {
 		(void)auth_master_connection_create(auth, MASTER_AUTH_FD);
 	}
@@ -163,8 +162,8 @@
 	const char *getopt_str, *auth_name = "default";
 	int c;
 
-	service = master_service_init("auth", 0, argc, argv);
-	master_service_init_log(service, "auth: ", 0);
+	master_service = master_service_init("auth", 0, argc, argv);
+	master_service_init_log(master_service, "auth: ", 0);
 
         getopt_str = t_strconcat("w", master_service_getopt_string(), NULL);
 	while ((c = getopt(argc, argv, getopt_str)) > 0) {
@@ -176,19 +175,20 @@
 			worker = TRUE;
 			break;
 		default:
-			if (!master_service_parse_option(service, c, optarg))
+			if (!master_service_parse_option(master_service,
+							 c, optarg))
 				exit(FATAL_DEFAULT);
 			break;
 		}
 	}
 
-	main_preinit(auth_settings_read(service, auth_name));
+	main_preinit(auth_settings_read(master_service, auth_name));
 
-	master_service_init_finish(service);
+	master_service_init_finish(master_service);
 	main_init();
-	master_service_run(service, worker ? worker_connected :
+	master_service_run(master_service, worker ? worker_connected :
 			   client_connected);
 	main_deinit();
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
         return 0;
 }
--- a/src/config/doveconf.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/config/doveconf.c	Fri May 22 17:26:27 2009 -0400
@@ -21,8 +21,6 @@
 	ARRAY_TYPE(const_string) strings;
 };
 
-static struct master_service *service;
-
 static void
 config_request_get_strings(const char *key, const char *value,
 			   bool list, void *context)
@@ -212,8 +210,9 @@
 	int c;
 
 	memset(&filter, 0, sizeof(filter));
-	service = master_service_init("config", MASTER_SERVICE_FLAG_STANDALONE,
-				      argc, argv);
+	master_service = master_service_init("config",
+					     MASTER_SERVICE_FLAG_STANDALONE,
+					     argc, argv);
 	i_set_failure_prefix("doveconf: ");
 	getopt_str = t_strconcat("am:np:e", master_service_getopt_string(), NULL);
 	while ((c = getopt(argc, argv, getopt_str)) > 0) {
@@ -232,11 +231,12 @@
 			filter.service = optarg;
 			break;
 		default:
-			if (!master_service_parse_option(service, c, optarg))
+			if (!master_service_parse_option(master_service,
+							 c, optarg))
 				exit(FATAL_DEFAULT);
 		}
 	}
-	config_path = master_service_get_config_path(service);
+	config_path = master_service_get_config_path(master_service);
 
 	if (argv[optind] != NULL)
 		exec_args = &argv[optind];
@@ -246,7 +246,7 @@
 		printf("# "VERSION": %s\n", config_path);
 		fflush(stdout);
 	}
-	master_service_init_finish(service);
+	master_service_init_finish(master_service);
 
 	config_parse_file(config_path, FALSE);
 
@@ -265,6 +265,6 @@
 		execvp(exec_args[0], exec_args);
 		i_fatal("execvp(%s) failed: %m", exec_args[0]);
 	}
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
         return 0;
 }
--- a/src/config/main.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/config/main.c	Fri May 22 17:26:27 2009 -0400
@@ -11,8 +11,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-static struct master_service *service;
-
 static void client_connected(const struct master_service_connection *conn)
 {
 	config_connection_create(conn->fd);
@@ -22,18 +20,18 @@
 {
 	int c;
 
-	service = master_service_init("config", 0, argc, argv);
+	master_service = master_service_init("config", 0, argc, argv);
 	while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) {
-		if (!master_service_parse_option(service, c, optarg))
+		if (!master_service_parse_option(master_service, c, optarg))
 			exit(FATAL_DEFAULT);
 	}
 
-	master_service_init_log(service, "config: ", 0);
-	master_service_init_finish(service);
-	config_parse_file(master_service_get_config_path(service), TRUE);
+	master_service_init_log(master_service, "config: ", 0);
+	master_service_init_finish(master_service);
+	config_parse_file(master_service_get_config_path(master_service), TRUE);
 
-	master_service_run(service, client_connected);
+	master_service_run(master_service, client_connected);
 	config_connections_destroy_all();
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
         return 0;
 }
--- a/src/imap-login/client.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/imap-login/client.c	Fri May 22 17:26:27 2009 -0400
@@ -575,7 +575,8 @@
 	if (client->common.master_tag != 0) {
 		i_assert(client->common.auth_request == NULL);
 		i_assert(client->common.authenticating);
-		master_auth_request_abort(service, client->common.master_tag);
+		master_auth_request_abort(master_service,
+					  client->common.master_tag);
 	} else if (client->common.auth_request != NULL) {
 		i_assert(client->common.authenticating);
 		sasl_server_auth_client_error(&client->common, NULL);
@@ -653,7 +654,7 @@
 
 	if (!client->common.proxying) {
 		i_assert(client->common.proxy == NULL);
-		master_service_client_connection_destroyed(service);
+		master_service_client_connection_destroyed(master_service);
 	}
 
 	i_free(client->common.virtual_user);
--- a/src/imap/imap-client.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/imap/imap-client.c	Fri May 22 17:26:27 2009 -0400
@@ -72,8 +72,8 @@
 
 	ident = mail_user_get_anvil_userip_ident(client->user);
 	if (ident != NULL) {
-		master_service_anvil_send(service, t_strconcat("CONNECT\t",
-			my_pid, "\t", ident, "/imap\n", NULL));
+		master_service_anvil_send(master_service, t_strconcat(
+			"CONNECT\t", my_pid, "\t", ident, "/imap\n", NULL));
 		client->anvil_sent = TRUE;
 	}
 
@@ -184,8 +184,8 @@
 		mailbox_close(&client->mailbox);
 	}
 	if (client->anvil_sent) {
-		master_service_anvil_send(service, t_strconcat("DISCONNECT\t",
-			my_pid, "\t",
+		master_service_anvil_send(master_service, t_strconcat(
+			"DISCONNECT\t", my_pid, "\t",
 			mail_user_get_anvil_userip_ident(client->user), "/imap"
 			"\n", NULL));
 	}
@@ -219,7 +219,7 @@
 
 	/* quit the program */
 	my_client = NULL;
-	master_service_stop(service);
+	master_service_stop(master_service);
 }
 
 void client_disconnect(struct client *client, const char *reason)
--- a/src/imap/imap-common.h	Fri May 22 13:07:17 2009 -0400
+++ b/src/imap/imap-common.h	Fri May 22 17:26:27 2009 -0400
@@ -23,8 +23,6 @@
 #include "imap-client.h"
 #include "imap-settings.h"
 
-extern struct master_service *service;
-
 extern void (*hook_client_created)(struct client **client);
 
 #endif
--- a/src/imap/main.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/imap/main.c	Fri May 22 17:26:27 2009 -0400
@@ -37,7 +37,6 @@
 
 static struct io *log_io = NULL;
 
-struct master_service *service;
 void (*hook_client_created)(struct client **client) = NULL;
 
 static void log_error_callback(void *context ATTR_UNUSED)
@@ -45,7 +44,7 @@
 	/* the log fd is closed, don't die when trying to log later */
 	i_set_failure_ignore_errors(TRUE);
 
-	master_service_stop(service);
+	master_service_stop(master_service);
 }
 
 static enum client_workarounds
@@ -180,9 +179,9 @@
 			MAIL_STORAGE_SERVICE_FLAG_NO_RESTRICT_ACCESS;
 	}
 
-	service = master_service_init("imap", service_flags, argc, argv);
+	master_service = master_service_init("imap", service_flags, argc, argv);
 	while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) {
-		if (!master_service_parse_option(service, c, optarg))
+		if (!master_service_parse_option(master_service, c, optarg))
 			exit(FATAL_DEFAULT);
 	}
 
@@ -205,9 +204,10 @@
 	commands_init();
 	imap_fetch_handlers_init();
 
-	mail_user = mail_storage_service_init_user(service, &input, set_roots,
+	mail_user = mail_storage_service_init_user(master_service,
+						   &input, set_roots,
 						   storage_service_flags);
-	set = mail_storage_service_get_settings(service);
+	set = mail_storage_service_get_settings(master_service);
 	restrict_access_allow_coredumps(TRUE);
 
         process_title_init(argv, envp);
@@ -220,13 +220,13 @@
 		main_init(set, mail_user, dump_capability);
 	} T_END;
 	if (io_loop_is_running(current_ioloop))
-		master_service_run(service, client_connected);
+		master_service_run(master_service, client_connected);
 
 	main_deinit();
 	mail_storage_service_deinit_user();
 	imap_fetch_handlers_deinit();
 	commands_deinit();
 
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
 	return 0;
 }
--- a/src/lda/main.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/lda/main.c	Fri May 22 17:26:27 2009 -0400
@@ -44,8 +44,6 @@
 	NULL
 };
 
-static struct master_service *service;
-
 static const char *escape_local_part(const char *local_part)
 {
 	const char *p;
@@ -222,8 +220,9 @@
 
 	i_set_failure_exit_callback(failure_exit_callback);
 
-	service = master_service_init("lda", MASTER_SERVICE_FLAG_STANDALONE,
-				      argc, argv);
+	master_service = master_service_init("lda",
+					     MASTER_SERVICE_FLAG_STANDALONE,
+					     argc, argv);
 
 	memset(&ctx, 0, sizeof(ctx));
 	ctx.pool = pool_alloconly_create("mail deliver context", 256);
@@ -277,7 +276,8 @@
 				p_strdup(ctx.pool, address_sanitize(optarg));
 			break;
 		default:
-			if (!master_service_parse_option(service, c, optarg)) {
+			if (!master_service_parse_option(master_service,
+							 c, optarg)) {
 				print_help();
 				exit(EX_USAGE);
 			}
@@ -320,19 +320,21 @@
 	service_input.username = user;
 
 	service_flags |= MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT;
-	ctx.dest_user = mail_storage_service_init_user(service, &service_input,
+	ctx.dest_user = mail_storage_service_init_user(master_service,
+						       &service_input,
 						       set_roots,
 						       service_flags);
 #ifdef SIGXFSZ
         lib_signals_ignore(SIGXFSZ, TRUE);
 #endif
-	ctx.set = mail_storage_service_get_settings(service);
+	ctx.set = mail_storage_service_get_settings(master_service);
         duplicate_init(mail_user_set_get_storage_set(ctx.dest_user->set));
 
 	/* create a separate mail user for the internal namespace */
-	if (master_service_set(service, "mail_full_filesystem_access=yes") < 0)
+	if (master_service_set(master_service,
+			       "mail_full_filesystem_access=yes") < 0)
 		i_unreached();
-	sets = master_service_settings_get_others(service);
+	sets = master_service_settings_get_others(master_service);
 	raw_mail_user = mail_user_alloc(user, sets[0]);
 	mail_user_set_home(raw_mail_user, "/");
 	if (mail_user_init(raw_mail_user, &errstr) < 0)
@@ -429,6 +431,6 @@
 	pool_unref(&ctx.pool);
 
 	mail_storage_service_deinit_user();
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
         return EX_OK;
 }
--- a/src/lib-master/master-service.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/lib-master/master-service.c	Fri May 22 17:26:27 2009 -0400
@@ -26,6 +26,8 @@
 /* getenv(MASTER_DOVECOT_VERSION_ENV) provides master's version number */
 #define MASTER_DOVECOT_VERSION_ENV "DOVECOT_VERSION"
 
+struct master_service *master_service;
+
 static void io_listeners_add(struct master_service *service);
 static void io_listeners_remove(struct master_service *service);
 static void master_status_update(struct master_service *service);
--- a/src/lib-master/master-service.h	Fri May 22 13:07:17 2009 -0400
+++ b/src/lib-master/master-service.h	Fri May 22 17:26:27 2009 -0400
@@ -29,7 +29,7 @@
 typedef void
 master_service_connection_callback_t(const struct master_service_connection *conn);
 
-struct master_service;
+extern struct master_service *master_service;
 
 const char *master_service_getopt_string(void);
 
--- a/src/lmtp/client.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/lmtp/client.c	Fri May 22 17:26:27 2009 -0400
@@ -123,7 +123,7 @@
 	const char *error;
 	void **sets;
 
-	sets = master_service_settings_get_others(service);
+	sets = master_service_settings_get_others(master_service);
 
 	client->raw_mail_user = mail_user_alloc("raw user", sets[0]);
 	mail_user_set_home(client->raw_mail_user, "/");
@@ -196,7 +196,7 @@
 	pool_unref(&client->state_pool);
 	i_free(client);
 
-	master_service_client_connection_destroyed(service);
+	master_service_client_connection_destroyed(master_service);
 }
 
 static const char *client_get_disconnect_reason(struct client *client)
--- a/src/lmtp/main.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/lmtp/main.c	Fri May 22 17:26:27 2009 -0400
@@ -20,7 +20,6 @@
 #define IS_STANDALONE() \
         (getenv("MASTER_SERVICE") == NULL)
 
-struct master_service *service;
 struct mail_storage_service_multi_ctx *multi_service;
 
 static void client_connected(const struct master_service_connection *conn)
@@ -81,23 +80,24 @@
 			MASTER_SERVICE_FLAG_STD_CLIENT;
 	}
 
-	service = master_service_init("lmtp", service_flags, argc, argv);
+	master_service = master_service_init("lmtp", service_flags, argc, argv);
 	while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) {
-		if (!master_service_parse_option(service, c, optarg))
+		if (!master_service_parse_option(master_service, c, optarg))
 			exit(FATAL_DEFAULT);
 	}
 
-	multi_service = mail_storage_service_multi_init(service, set_roots,
+	multi_service = mail_storage_service_multi_init(master_service,
+							set_roots,
 							storage_service_flags);
 	restrict_access_allow_coredumps(TRUE);
 
         process_title_init(argv, envp);
 
 	main_init();
-	master_service_run(service, client_connected);
+	master_service_run(master_service, client_connected);
 
 	main_deinit();
 	mail_storage_service_multi_deinit(&multi_service);
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
 	return 0;
 }
--- a/src/lmtp/main.h	Fri May 22 13:07:17 2009 -0400
+++ b/src/lmtp/main.h	Fri May 22 17:26:27 2009 -0400
@@ -1,7 +1,6 @@
 #ifndef MAIN_H
 #define MAIN_H
 
-extern struct master_service *service;
 extern struct mail_storage_service_multi_ctx *multi_service;
 
 void listener_client_destroyed(void);
--- a/src/log/common.h	Fri May 22 13:07:17 2009 -0400
+++ b/src/log/common.h	Fri May 22 17:26:27 2009 -0400
@@ -3,7 +3,6 @@
 
 #include "lib.h"
 
-extern struct master_service *service;
 extern pid_t master_pid;
 
 #endif
--- a/src/log/log-connection.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/log/log-connection.c	Fri May 22 17:26:27 2009 -0400
@@ -240,7 +240,7 @@
 	i_free(log->prefix);
 	i_free(log);
 
-        master_service_client_connection_destroyed(service);
+        master_service_client_connection_destroyed(master_service);
 }
 
 void log_connections_init(void)
--- a/src/log/main.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/log/main.c	Fri May 22 17:26:27 2009 -0400
@@ -10,7 +10,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-struct master_service *service;
 pid_t master_pid;
 
 static void
@@ -49,25 +48,26 @@
 	const char *error;
 	int c;
 
-	service = master_service_init("log", 0, argc, argv);
+	master_service = master_service_init("log", 0, argc, argv);
 
 	/* use log prefix and log to stderr until we've configured the real
 	   logging */
 	i_set_failure_file("/dev/stderr", "log: ");
 
 	while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) {
-		if (!master_service_parse_option(service, c, optarg))
+		if (!master_service_parse_option(master_service, c, optarg))
 			exit(FATAL_DEFAULT);
 	}
 
-	if (master_service_settings_read_simple(service, NULL, &error) < 0)
+	if (master_service_settings_read_simple(master_service,
+						NULL, &error) < 0)
 		i_fatal("Error reading configuration: %s", error);
 
-	master_service_init_log(service, "log: ", 0);
-	master_service_init_finish(service);
+	master_service_init_log(master_service, "log: ", 0);
+	master_service_init_finish(master_service);
 	main_init();
-	master_service_run(service, client_connected);
+	master_service_run(master_service, client_connected);
 	main_deinit();
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
         return 0;
 }
--- a/src/login-common/common.h	Fri May 22 13:07:17 2009 -0400
+++ b/src/login-common/common.h	Fri May 22 17:26:27 2009 -0400
@@ -18,7 +18,6 @@
 extern bool closing_down;
 extern int anvil_fd;
 
-extern struct master_service *service;
 extern const struct login_settings *global_login_settings;
 
 #endif
--- a/src/login-common/login-proxy.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/login-common/login-proxy.c	Fri May 22 17:26:27 2009 -0400
@@ -244,7 +244,7 @@
 	i_free(proxy->user);
 	i_free(proxy);
 
-	master_service_client_connection_destroyed(service);
+	master_service_client_connection_destroyed(master_service);
 }
 
 bool login_proxy_is_ourself(const struct client *client, const char *host,
--- a/src/login-common/main.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/login-common/main.c	Fri May 22 17:26:27 2009 -0400
@@ -22,7 +22,6 @@
 bool closing_down;
 int anvil_fd = -1;
 
-struct master_service *service;
 const struct login_settings *global_login_settings;
 
 static bool ssl_connections = FALSE;
@@ -43,7 +42,8 @@
 	}
 
 	pool = pool_alloconly_create("login client", 1024);
-	set = login_settings_read(service, pool, &local_ip, &conn->remote_ip);
+	set = login_settings_read(master_service, pool, &local_ip,
+				  &conn->remote_ip);
 
 	if (!ssl_connections && !conn->ssl) {
 		client = client_create(conn->fd, FALSE, pool, set, &local_ip,
@@ -101,7 +101,7 @@
 	   decreased. leave a couple of extra fds for auth sockets and such.
 	   normal connections each use one fd, but SSL connections use two */
 	max_fds = MASTER_LISTEN_FD_FIRST + 16 +
-		master_service_get_socket_count(service) +
+		master_service_get_socket_count(master_service) +
 		global_login_settings->login_max_connections*2;
 	restrict_fd_limit(max_fds);
 	io_loop_set_max_fd_count(current_ioloop, max_fds);
@@ -129,7 +129,7 @@
         auth_client_set_connect_notify(auth_client, auth_connect_notify, NULL);
 
 	clients_init();
-	master_auth_init(service);
+	master_auth_init(master_service);
 }
 
 static void main_deinit(void)
@@ -145,7 +145,7 @@
 		if (close(anvil_fd) < 0)
 			i_error("close(anvil) failed: %m");
 	}
-	master_auth_deinit(service);
+	master_auth_deinit(master_service);
 }
 
 int main(int argc, char *argv[], char *envp[])
@@ -156,11 +156,11 @@
 
 	//FIXME:is_inetd = getenv("DOVECOT_MASTER") == NULL;
 
-	service = master_service_init(login_process_name,
-				      MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN,
-				      argc, argv);
-	master_service_init_log(service, t_strconcat(login_process_name, ": ",
-						     NULL), 0);
+	master_service = master_service_init(login_process_name,
+					MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN,
+					argc, argv);
+	master_service_init_log(master_service, t_strconcat(
+		login_process_name, ": ", NULL), 0);
 
         getopt_str = t_strconcat("DS", master_service_getopt_string(), NULL);
 	while ((c = getopt(argc, argv, getopt_str)) > 0) {
@@ -172,7 +172,8 @@
 			ssl_connections = TRUE;
 			break;
 		default:
-			if (!master_service_parse_option(service, c, optarg))
+			if (!master_service_parse_option(master_service,
+							 c, optarg))
 				exit(FATAL_DEFAULT);
 			break;
 		}
@@ -189,15 +190,15 @@
 	process_title_init(argv, envp);
 	set_pool = pool_alloconly_create("global login settings", 1024);
 	global_login_settings =
-		login_settings_read(service, set_pool, NULL, NULL);
+		login_settings_read(master_service, set_pool, NULL, NULL);
 
 	main_preinit();
-	master_service_init_finish(service);
+	master_service_init_finish(master_service);
 	main_init();
 
-	master_service_run(service, client_connected);
+	master_service_run(master_service, client_connected);
 	main_deinit();
 	pool_unref(&set_pool);
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
         return 0;
 }
--- a/src/login-common/sasl-server.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/login-common/sasl-server.c	Fri May 22 17:26:27 2009 -0400
@@ -9,6 +9,7 @@
 #include "str-sanitize.h"
 #include "auth-client.h"
 #include "ssl-proxy.h"
+#include "master-service.h"
 #include "master-interface.h"
 #include "master-auth.h"
 #include "client-common.h"
@@ -93,7 +94,7 @@
 	req.data_size = buf->used;
 
 	client->master_tag =
-		master_auth_request(service, client->fd, &req, buf->data,
+		master_auth_request(master_service, client->fd, &req, buf->data,
 				    master_auth_callback, client);
 }
 
--- a/src/login-common/ssl-proxy-openssl.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/login-common/ssl-proxy-openssl.c	Fri May 22 17:26:27 2009 -0400
@@ -695,7 +695,7 @@
 
 	ssl_proxy_unref(proxy);
 
-        master_service_client_connection_destroyed(service);
+        master_service_client_connection_destroyed(master_service);
 }
 
 static RSA *ssl_gen_rsa_key(SSL *ssl ATTR_UNUSED,
--- a/src/master/common.h	Fri May 22 13:07:17 2009 -0400
+++ b/src/master/common.h	Fri May 22 17:26:27 2009 -0400
@@ -7,7 +7,6 @@
 
 #define AUTH_SUCCESS_PATH PKG_STATEDIR"/auth-success"
 
-extern struct master_service *master_service;
 extern uid_t master_uid;
 extern gid_t master_gid;
 extern bool auth_success_written;
--- a/src/master/service-process.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/master/service-process.c	Fri May 22 17:26:27 2009 -0400
@@ -15,6 +15,7 @@
 #include "fd-close-on-exec.h"
 #include "restrict-access.h"
 #include "restrict-process-size.h"
+#include "master-service.h"
 #include "master-service-settings.h"
 #include "dup2-array.h"
 #include "service.h"
--- a/src/plugins/convert/convert-tool.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/plugins/convert/convert-tool.c	Fri May 22 17:26:27 2009 -0400
@@ -17,7 +17,6 @@
 
 int main(int argc, char *argv[])
 {
-	struct master_service *service;
 	struct mail_storage_service_input input;
 	struct mail_user *user;
 	struct convert_plugin_settings set;
@@ -26,12 +25,12 @@
 	const char *error;
 	int i, c, ret = 0;
 
-	service = master_service_init("convert-tool",
-				      MASTER_SERVICE_FLAG_STANDALONE,
-				      argc, argv);
+	master_service = master_service_init("convert-tool",
+					     MASTER_SERVICE_FLAG_STANDALONE,
+					     argc, argv);
 
 	while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) {
-		if (!master_service_parse_option(service, c, optarg))
+		if (!master_service_parse_option(master_service, c, optarg))
 			i_fatal(USAGE_STRING);
 	}
 	if (argc - optind < 4)
@@ -54,9 +53,9 @@
 	memset(&input, 0, sizeof(input));
 	input.username = argv[optind];
 
-	master_service_init_log(service,
+	master_service_init_log(master_service,
 		t_strdup_printf("convert-tool(%s): ", input.username), 0);
-	user = mail_storage_service_init_user(service, &input, NULL, 0);
+	user = mail_storage_service_init_user(master_service, &input, NULL, 0);
 
 	memset(&ns_set, 0, sizeof(ns_set));
 	ns_set.location = argv[4];
@@ -79,6 +78,6 @@
 
 	mail_user_unref(&user);
 	mail_storage_service_deinit_user();
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
 	return ret <= 0 ? 1 : 0;
 }
--- a/src/plugins/expire/expire-tool.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/plugins/expire/expire-tool.c	Fri May 22 17:26:27 2009 -0400
@@ -291,14 +291,13 @@
 
 int main(int argc, char *argv[])
 {
-	struct master_service *service;
 	const char *getopt_str;
 	bool test = FALSE;
 	int c;
 
-	service = master_service_init("expire-tool",
-				      MASTER_SERVICE_FLAG_STANDALONE,
-				      argc, argv);
+	master_service = master_service_init("expire-tool",
+					     MASTER_SERVICE_FLAG_STANDALONE,
+					     argc, argv);
 
 	getopt_str = t_strconcat("t", master_service_getopt_string(), NULL);
 	while ((c = getopt(argc, argv, getopt_str)) > 0) {
@@ -307,7 +306,8 @@
 			test = TRUE;
 			break;
 		default:
-			if (!master_service_parse_option(service, c, optarg))
+			if (!master_service_parse_option(master_service,
+							 c, optarg))
 				i_fatal("Unknown parameter: -%c", c);
 			break;
 		}
@@ -315,8 +315,8 @@
 	if (optind != argc)
 		i_fatal("Unknown parameter: %s", argv[optind]);
 
-	expire_run(service, test);
+	expire_run(master_service, test);
 
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
 	return 0;
 }
--- a/src/pop3-login/client.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/pop3-login/client.c	Fri May 22 17:26:27 2009 -0400
@@ -380,7 +380,8 @@
 	if (client->common.master_tag != 0) {
 		i_assert(client->common.auth_request == NULL);
 		i_assert(client->common.authenticating);
-		master_auth_request_abort(service, client->common.master_tag);
+		master_auth_request_abort(master_service,
+					  client->common.master_tag);
 	} else if (client->common.auth_request != NULL) {
 		i_assert(client->common.authenticating);
 		sasl_server_auth_client_error(&client->common, NULL);
@@ -447,7 +448,7 @@
 
 	if (!client->common.proxying) {
 		i_assert(client->common.proxy == NULL);
-		master_service_client_connection_destroyed(service);
+		master_service_client_connection_destroyed(master_service);
 	}
 
 	i_free(client->last_user);
--- a/src/pop3/main.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/pop3/main.c	Fri May 22 17:26:27 2009 -0400
@@ -18,7 +18,6 @@
 #define IS_STANDALONE() \
         (getenv("LOGGED_IN") == NULL)
 
-struct master_service *service;
 void (*hook_client_created)(struct client **client) = NULL;
 
 static struct io *log_io = NULL;
@@ -28,7 +27,7 @@
 	/* the log fd is closed, don't die when trying to log later */
 	i_set_failure_ignore_errors(TRUE);
 
-	master_service_stop(service);
+	master_service_stop(master_service);
 }
 
 static bool main_init(const struct pop3_settings *set, struct mail_user *user)
@@ -105,9 +104,9 @@
 	else
 		service_flags |= MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT;
 
-	service = master_service_init("pop3", service_flags, argc, argv);
+	master_service = master_service_init("pop3", service_flags, argc, argv);
 	while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) {
-		if (!master_service_parse_option(service, c, optarg))
+		if (!master_service_parse_option(master_service, c, optarg))
 			exit(FATAL_DEFAULT);
 	}
 
@@ -126,9 +125,10 @@
 	if ((value = getenv("LOCAL_IP")) != NULL)
 		net_addr2ip(value, &input.local_ip);
 
-	mail_user = mail_storage_service_init_user(service, &input, set_roots,
+	mail_user = mail_storage_service_init_user(master_service,
+						   &input, set_roots,
 						   storage_service_flags);
-	set = mail_storage_service_get_settings(service);
+	set = mail_storage_service_get_settings(master_service);
 	restrict_access_allow_coredumps(TRUE);
 
         process_title_init(argv, envp);
@@ -138,10 +138,10 @@
 	io_loop_set_running(current_ioloop);
 
 	if (main_init(set, mail_user))
-		master_service_run(service, client_connected);
+		master_service_run(master_service, client_connected);
 
 	main_deinit();
 	mail_storage_service_deinit_user();
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
 	return 0;
 }
--- a/src/pop3/pop3-client.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/pop3/pop3-client.c	Fri May 22 17:26:27 2009 -0400
@@ -289,8 +289,8 @@
 
 	ident = mail_user_get_anvil_userip_ident(client->user);
 	if (ident != NULL) {
-		master_service_anvil_send(service, t_strconcat("CONNECT\t",
-			my_pid, "\t", ident, "/pop3\n", NULL));
+		master_service_anvil_send(master_service, t_strconcat(
+			"CONNECT\t", my_pid, "\t", ident, "/pop3\n", NULL));
 		client->anvil_sent = TRUE;
 	}
 
@@ -373,8 +373,8 @@
 	if (client->mailbox != NULL)
 		mailbox_close(&client->mailbox);
 	if (client->anvil_sent) {
-		master_service_anvil_send(service, t_strconcat("DISCONNECT\t",
-			my_pid, "\t",
+		master_service_anvil_send(master_service, t_strconcat(
+			"DISCONNECT\t", my_pid, "\t",
 			mail_user_get_anvil_userip_ident(client->user), "/pop3"
 			"\n", NULL));
 	}
@@ -404,7 +404,7 @@
 
 	/* quit the program */
 	my_client = NULL;
-	master_service_stop(service);
+	master_service_stop(master_service);
 }
 
 void client_disconnect(struct client *client, const char *reason)
--- a/src/pop3/pop3-common.h	Fri May 22 13:07:17 2009 -0400
+++ b/src/pop3/pop3-common.h	Fri May 22 17:26:27 2009 -0400
@@ -17,8 +17,6 @@
 #include "pop3-client.h"
 #include "pop3-settings.h"
 
-extern struct master_service *service;
-
 extern void (*hook_client_created)(struct client **client);
 
 #endif
--- a/src/util/doveadm.c	Fri May 22 13:07:17 2009 -0400
+++ b/src/util/doveadm.c	Fri May 22 17:26:27 2009 -0400
@@ -208,13 +208,13 @@
 int main(int argc, char *argv[])
 {
 	enum mail_storage_service_flags service_flags = 0;
-	struct master_service *service;
 	const char *getopt_str, *username;
 	bool all_users = FALSE;
 	int c;
 
-	service = master_service_init("doveadm", MASTER_SERVICE_FLAG_STANDALONE,
-				      argc, argv);
+	master_service = master_service_init("doveadm",
+					     MASTER_SERVICE_FLAG_STANDALONE,
+					     argc, argv);
 
 	username = getenv("USER");
 	getopt_str = t_strconcat("au:v", master_service_getopt_string(), NULL);
@@ -231,7 +231,8 @@
 			service_flags |= MAIL_STORAGE_SERVICE_FLAG_DEBUG;
 			break;
 		default:
-			if (!master_service_parse_option(service, c, optarg))
+			if (!master_service_parse_option(master_service,
+							 c, optarg))
 				usage();
 		}
 	}
@@ -239,11 +240,11 @@
 		usage();
 
 	if (!all_users) {
-		handle_single_user(service, username, service_flags,
+		handle_single_user(master_service, username, service_flags,
 				   argv + optind);
 	} else {
-		handle_all_users(service, service_flags, argv + optind);
+		handle_all_users(master_service, service_flags, argv + optind);
 	}
-	master_service_deinit(&service);
+	master_service_deinit(&master_service);
 	return 0;
 }