changeset 5148:7f2c39d7a2cc HEAD

module_dir_load() doesn't call init() functions anymore. Added a new module_dir_init() which does it. This way imap/pop3 can load the modules before chrooting and initialize them after.
author Timo Sirainen <tss@iki.fi>
date Fri, 16 Feb 2007 15:12:05 +0200
parents 6b0032df7008
children 892b8f1c1916
files src/auth/password-scheme.c src/deliver/deliver.c src/dict/main.c src/imap/main.c src/lib/module-dir.c src/lib/module-dir.h src/pop3/main.c
diffstat 7 files changed, 46 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/password-scheme.c	Fri Feb 16 14:15:28 2007 +0200
+++ b/src/auth/password-scheme.c	Fri Feb 16 15:12:05 2007 +0200
@@ -520,6 +520,7 @@
 #ifdef HAVE_MODULES
 	scheme_modules = module_dir_load(AUTH_MODULE_DIR"/password",
 					 NULL, FALSE);
+	module_dir_init(scheme_modules);
 	for (mod = scheme_modules; mod != NULL; mod = mod->next) {
 		t_push();
 		symbol = t_strconcat(mod->name, "_scheme", NULL);
--- a/src/deliver/deliver.c	Fri Feb 16 14:15:28 2007 +0200
+++ b/src/deliver/deliver.c	Fri Feb 16 15:12:05 2007 +0200
@@ -612,6 +612,7 @@
 			plugin_dir = MODULEDIR"/lda";
 		modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
 					  TRUE);
+		module_dir_init(modules);
 	}
 
 	/* FIXME: how should we handle namespaces? */
--- a/src/dict/main.c	Fri Feb 16 14:15:28 2007 +0200
+++ b/src/dict/main.c	Fri Feb 16 15:12:05 2007 +0200
@@ -79,6 +79,7 @@
 
 	modules = getenv("MODULE_DIR") == NULL ? NULL :
 		module_dir_load(getenv("MODULE_DIR"), NULL, TRUE);
+	module_dir_init(modules);
 
 	path = getenv("DICT_LISTEN_FROM_FD");
 	fd = path == NULL ? -1 : DICT_MASTER_LISTENER_FD;
--- a/src/imap/main.c	Fri Feb 16 14:15:28 2007 +0200
+++ b/src/imap/main.c	Fri Feb 16 15:12:05 2007 +0200
@@ -44,7 +44,7 @@
 enum client_workarounds client_workarounds = 0;
 static struct io *log_io = NULL;
 
-static struct module *modules;
+static struct module *modules = NULL;
 static char log_prefix[128]; /* syslog() needs this to be permanent */
 static pool_t namespace_pool;
 
@@ -135,6 +135,16 @@
 	   chrooting. */
 	random_init();
 
+	/* Load the plugins before chrooting. Their init() is called later. */
+	if (getenv("MAIL_PLUGINS") != NULL) {
+		const char *plugin_dir = getenv("MAIL_PLUGIN_DIR");
+
+		if (plugin_dir == NULL)
+			plugin_dir = MODULEDIR"/imap";
+		modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
+					  TRUE);
+	}
+
 	restrict_access_by_env(!IS_STANDALONE());
 }
 
@@ -190,16 +200,7 @@
 	commands_init();
 	imap_thread_init();
 
-	if (getenv("MAIL_PLUGINS") == NULL)
-		modules = NULL;
-	else {
-		const char *plugin_dir = getenv("MAIL_PLUGIN_DIR");
-
-		if (plugin_dir == NULL)
-			plugin_dir = MODULEDIR"/imap";
-		modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
-					  TRUE);
-	}
+	module_dir_init(modules);
 
 	if (getenv("DUMP_CAPABILITY") != NULL) {
 		printf("%s\n", str_c(capability_string));
--- a/src/lib/module-dir.c	Fri Feb 16 14:15:28 2007 +0200
+++ b/src/lib/module-dir.c	Fri Feb 16 15:12:05 2007 +0200
@@ -86,7 +86,6 @@
 module_load(const char *path, const char *name, bool require_init_funcs)
 {
 	void *handle;
-	void (*init)(void);
 	struct module *module;
 
 	handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW);
@@ -101,14 +100,17 @@
 	module->handle = handle;
 
 	/* get our init func */
-	init = (void (*)(void))
+	module->init = (void (*)(void))
 		get_symbol(module, t_strconcat(name, "_init", NULL),
 			   !require_init_funcs);
-	module->deinit = init == NULL ? NULL : (void (*)(void))
+	module->deinit = module->init == NULL ? NULL : (void (*)(void))
 		get_symbol(module, t_strconcat(name, "_deinit", NULL),
 			   !require_init_funcs);
 
-	if ((init == NULL || module->deinit == NULL) && require_init_funcs) {
+	if ((module->init == NULL || module->deinit == NULL) &&
+	    require_init_funcs) {
+		i_error("Module doesn't have %s function: %s",
+			module->init == NULL ? "init" : "deinit", path);
 		module->deinit = NULL;
 		module_free(module);
 		return NULL;
@@ -116,9 +118,6 @@
 
 	if (getenv("DEBUG") != NULL)
 		i_info("Module loaded: %s", path);
-
-	if (init != NULL)
-		init();
 	return module;
 }
 
@@ -275,6 +274,16 @@
 	return modules;
 }
 
+void module_dir_init(struct module *modules)
+{
+	struct module *module;
+
+	for (module = modules; module != NULL; module = module->next) {
+		if (module->init != NULL)
+			module->init();
+	}
+}
+
 void module_dir_deinit(struct module *modules)
 {
 	struct module *module;
--- a/src/lib/module-dir.h	Fri Feb 16 14:15:28 2007 +0200
+++ b/src/lib/module-dir.h	Fri Feb 16 15:12:05 2007 +0200
@@ -5,6 +5,7 @@
 	char *path, *name;
 
 	void *handle;
+	void (*init)(void);
 	void (*deinit)(void);
 
         struct module *next;
@@ -14,6 +15,8 @@
    module names to load, or NULL to load everything. */
 struct module *module_dir_load(const char *dir, const char *module_names,
 			       bool require_init_funcs);
+/* Call init() in all modules */
+void module_dir_init(struct module *modules);
 /* Call deinit() in all modules and mark them NULL so module_dir_unload()
    won't do it again. */
 void module_dir_deinit(struct module *modules);
--- a/src/pop3/main.c	Fri Feb 16 14:15:28 2007 +0200
+++ b/src/pop3/main.c	Fri Feb 16 15:12:05 2007 +0200
@@ -37,7 +37,7 @@
 
 void (*hook_client_created)(struct client **client) = NULL;
 
-static struct module *modules;
+static struct module *modules = NULL;
 static char log_prefix[128]; /* syslog() needs this to be permanent */
 static struct io *log_io = NULL;
 
@@ -152,6 +152,16 @@
 	   chrooting. */
 	random_init();
 
+	/* Load the plugins before chrooting. Their init() is called later. */
+	if (getenv("MAIL_PLUGINS") != NULL) {
+		const char *plugin_dir = getenv("MAIL_PLUGIN_DIR");
+
+		if (plugin_dir == NULL)
+			plugin_dir = MODULEDIR"/imap";
+		modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
+					  TRUE);
+	}
+
 	restrict_access_by_env(!IS_STANDALONE());
 }
 
@@ -195,16 +205,7 @@
 	mailbox_list_register_all();
 	clients_init();
 
-	if (getenv("MAIL_PLUGINS") == NULL)
-		modules = NULL;
-	else {
-		const char *plugin_dir = getenv("MAIL_PLUGIN_DIR");
-
-		if (plugin_dir == NULL)
-			plugin_dir = MODULEDIR"/imap";
-		modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
-					  TRUE);
-	}
+	module_dir_init(modules);
 
 	mail = getenv("MAIL");
 	if (mail == NULL) {