changeset 3753:d531130a0e4d HEAD

Load plugins in sorted order. Prefixed plugins with nn_ set their order.
author Timo Sirainen <tss@iki.fi>
date Wed, 14 Dec 2005 23:50:56 +0200
parents aea926f980b8
children ca188c8f1457
files src/lib/module-dir.c src/plugins/imap-quota/Makefile.am src/plugins/quota/Makefile.am src/plugins/trash/Makefile.am
diffstat 4 files changed, 62 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/module-dir.c	Wed Dec 14 23:34:28 2005 +0200
+++ b/src/lib/module-dir.c	Wed Dec 14 23:50:56 2005 +0200
@@ -1,6 +1,7 @@
 /* Copyright (C) 2003 Timo Sirainen */
 
 #include "lib.h"
+#include "array.h"
 #include "module-dir.h"
 
 #ifdef HAVE_MODULES
@@ -95,12 +96,27 @@
 	return module;
 }
 
+static int module_name_cmp(const void *p1, const void *p2)
+{
+	const char *n1 = p1, *n2 = p2;
+
+	if (strncmp(n1, "lib", 3) == 0)
+		n1 += 3;
+	if (strncmp(n2, "lib", 3) == 0)
+		n1 += 3;
+
+	return strcmp(n1, n2);
+}
+
 struct module *module_dir_load(const char *dir, int require_init_funcs)
 {
 	DIR *dirp;
 	struct dirent *d;
-	const char *name, *path, *p;
+	const char *name, *path, *p, *stripped_name, **names_p;
 	struct module *modules, *module;
+	unsigned int i, count;
+	array_t ARRAY_DEFINE(names, const char *);
+	pool_t pool;
 
 	if (getenv("DEBUG") != NULL)
 		i_info("Loading modules from directory: %s", dir);
@@ -112,6 +128,9 @@
 		return NULL;
 	}
 
+	pool = pool_alloconly_create("module loader", 1024);
+	ARRAY_CREATE(&names, pool, const char *, 32);
+
 	modules = NULL;
 	while ((d = readdir(dirp)) != NULL) {
 		name = d->d_name;
@@ -123,13 +142,36 @@
 		if (p == NULL || strlen(p) != 3)
 			continue;
 
-		if (strncmp(name, "lib", 3) == 0)
-			name += 3;
+		name = p_strdup(pool, d->d_name);
+		array_append(&names, &name, 1);
+	}
+
+	names_p = array_get_modifyable(&names, NULL);
+	count = array_count(&names);
+	qsort(names_p, count, sizeof(const char *), module_name_cmp);
+
+	for (i = 0; i < count; i++) {
+		const char *name = names_p[i];
+
+		/* [lib][nn_]name(.so) */
+                stripped_name = name;
+		if (strncmp(stripped_name, "lib", 3) == 0)
+			stripped_name += 3;
+
+		for (p = stripped_name; *p != '\0'; p++) {
+			if (*p < '0' || *p > '9')
+				break;
+		}
+		if (*p == '_')
+			stripped_name = p + 1;
+
+		p = strstr(stripped_name, ".so");
+		i_assert(p != NULL);
 
 		t_push();
-		name = t_strdup_until(name, p);
-		path = t_strconcat(dir, "/", d->d_name, NULL);
-		module = module_load(path, name, require_init_funcs);
+		stripped_name = t_strdup_until(stripped_name, p);
+		path = t_strconcat(dir, "/", name, NULL);
+		module = module_load(path, stripped_name, require_init_funcs);
 		t_pop();
 
 		if (module != NULL) {
@@ -137,6 +179,7 @@
 			modules = module;
 		}
 	}
+	pool_unref(pool);
 
 	if (closedir(dirp) < 0)
 		i_error("closedir(%s) failed: %m", dir);
--- a/src/plugins/imap-quota/Makefile.am	Wed Dec 14 23:34:28 2005 +0200
+++ b/src/plugins/imap-quota/Makefile.am	Wed Dec 14 23:50:56 2005 +0200
@@ -8,12 +8,12 @@
 
 imap_moduledir = $(moduledir)/imap
 
-libimap_quota_plugin_la_LDFLAGS = -module -avoid-version
+lib02_imap_quota_plugin_la_LDFLAGS = -module -avoid-version
 
 imap_module_LTLIBRARIES = \
-	libimap_quota_plugin.la
+	lib02_imap_quota_plugin.la
 
-libimap_quota_plugin_la_SOURCES = \
+lib02_imap_quota_plugin_la_SOURCES = \
 	imap-quota-plugin.c
 
 noinst_HEADERS = \
--- a/src/plugins/quota/Makefile.am	Wed Dec 14 23:34:28 2005 +0200
+++ b/src/plugins/quota/Makefile.am	Wed Dec 14 23:50:56 2005 +0200
@@ -4,12 +4,12 @@
 	-I$(top_srcdir)/src/lib-mail \
 	-I$(top_srcdir)/src/lib-storage
 
-libquota_plugin_la_LDFLAGS = -module -avoid-version
+lib01_quota_plugin_la_LDFLAGS = -module -avoid-version
 
 module_LTLIBRARIES = \
-	libquota_plugin.la
+	lib01_quota_plugin.la
 
-libquota_plugin_la_SOURCES = \
+lib01_quota_plugin_la_SOURCES = \
 	quota.c \
 	quota-fs.c \
 	quota-dict.c \
@@ -26,6 +26,6 @@
 install-exec-local:
 	$(mkdir_p) $(DESTDIR)$(moduledir)/imap $(DESTDIR)$(moduledir)/lda
 	for d in imap lda; do \
-	  rm -f $(DESTDIR)$(moduledir)/$$d/libquota_plugin.so; \
-	  $(LN_S) ../libquota_plugin.so $(DESTDIR)$(moduledir)/$$d; \
+	  rm -f $(DESTDIR)$(moduledir)/$$d/lib01_quota_plugin.so; \
+	  $(LN_S) ../lib01_quota_plugin.so $(DESTDIR)$(moduledir)/$$d; \
 	done
--- a/src/plugins/trash/Makefile.am	Wed Dec 14 23:34:28 2005 +0200
+++ b/src/plugins/trash/Makefile.am	Wed Dec 14 23:50:56 2005 +0200
@@ -4,12 +4,12 @@
 	-I$(top_srcdir)/src/lib-storage \
 	-I$(top_srcdir)/src/plugins/quota
 
-libtrash_plugin_la_LDFLAGS = -module -avoid-version
+lib02_trash_plugin_la_LDFLAGS = -module -avoid-version
 
 module_LTLIBRARIES = \
-	libtrash_plugin.la
+	lib02_trash_plugin.la
 
-libtrash_plugin_la_SOURCES = \
+lib02_trash_plugin_la_SOURCES = \
 	trash-plugin.c
 
 noinst_HEADERS = \
@@ -18,7 +18,7 @@
 install-exec-local:
 	$(mkdir_p) $(DESTDIR)$(moduledir)/imap $(DESTDIR)$(moduledir)/lda
 	for d in imap lda; do \
-	  rm -f $(DESTDIR)$(moduledir)/$$d/libtrash_plugin.so; \
-	  $(LN_S) ../libtrash_plugin.so $(DESTDIR)$(moduledir)/$$d; \
+	  rm -f $(DESTDIR)$(moduledir)/$$d/lib02_trash_plugin.so; \
+	  $(LN_S) ../lib02_trash_plugin.so $(DESTDIR)$(moduledir)/$$d; \
 	done