dovecot-2.0: module_dir_load(): Support <name>_dependencies arra...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Oct 9 04:22:19 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/bdd87f9ccccf
changeset: 10009:bdd87f9ccccf
user: Timo Sirainen <tss at iki.fi>
date: Thu Oct 08 21:19:29 2009 -0400
description:
module_dir_load(): Support <name>_dependencies array listing required modules.
diffstat:
1 file changed, 40 insertions(+), 2 deletions(-)
src/lib/module-dir.c | 42 ++++++++++++++++++++++++++++++++++++++++--
diffs (68 lines):
diff -r a15182f41f30 -r bdd87f9ccccf src/lib/module-dir.c
--- a/src/lib/module-dir.c Thu Oct 08 20:49:31 2009 -0400
+++ b/src/lib/module-dir.c Thu Oct 08 21:19:29 2009 -0400
@@ -82,9 +82,40 @@ static void module_free(struct module *m
i_free(module);
}
+static bool
+module_check_missing_dependencies(struct module *module,
+ struct module *all_modules)
+{
+ const char **deps;
+ struct module *m;
+ unsigned int len;
+
+ deps = dlsym(module->handle,
+ t_strconcat(module->name, "_dependencies", NULL));
+ if (deps == NULL)
+ return TRUE;
+
+ for (; *deps != NULL; deps++) {
+ len = strlen(*deps);
+ for (m = all_modules; m != NULL; m = m->next) {
+ if (strncmp(m->name, *deps, len) == 0 &&
+ (m->name[len] == '\0' ||
+ strcmp(m->name+len, "_plugin") == 0))
+ break;
+ }
+ if (m == NULL) {
+ i_error("Can't load plugin %s: "
+ "Plugin %s must be loaded also",
+ module->name, *deps);
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
static struct module *
module_load(const char *path, const char *name, bool require_init_funcs,
- const char *version)
+ const char *version, struct module *all_modules)
{
void *handle;
struct module *module;
@@ -123,6 +154,12 @@ module_load(const char *path, const char
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;
+ }
+
+ if (!module_check_missing_dependencies(module, all_modules)) {
module->deinit = NULL;
module_free(module);
return NULL;
@@ -258,7 +295,8 @@ module_dir_load_real(const char *dir, co
else {
path = t_strconcat(dir, "/", name, NULL);
module = module_load(path, stripped_name,
- require_init_funcs, version);
+ require_init_funcs, version,
+ modules);
if (module == NULL && module_names_arr != NULL)
i_fatal("Couldn't load required plugins");
}
More information about the dovecot-cvs
mailing list