Mercurial > dovecot > original-hg > dovecot-1.2
changeset 4945:cc9832968e8e HEAD
Give an error if there are duplicate files for a single module. Also if the
module directory can't be opened, die immediately.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 21 Dec 2006 13:29:25 +0200 |
parents | 51e2a2adc141 |
children | 460d589403d0 |
files | src/lib/module-dir.c |
diffstat | 1 files changed, 25 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/module-dir.c Thu Dec 21 13:25:21 2006 +0200 +++ b/src/lib/module-dir.c Thu Dec 21 13:29:25 2006 +0200 @@ -155,6 +155,25 @@ return FALSE; } +static void check_duplicates(ARRAY_TYPE(const_string) *names, + const char *name, const char *dir) +{ + const char *const *names_p, *base_name, *tmp; + unsigned int i, count; + + t_push(); + base_name = module_file_get_name(name); + names_p = array_get(names, &count); + for (i = 0; i < count; i++) { + tmp = module_file_get_name(names_p[i]); + + if (strcmp(tmp, base_name) == 0) + i_fatal("Multiple files for module %s: %s/%s, %s/%s", + base_name, dir, name, dir, names_p[i]); + } + t_pop(); +} + struct module *module_dir_load(const char *dir, const char *module_names, bool require_init_funcs) { @@ -164,18 +183,15 @@ const char **module_names_arr; struct module *modules, *module; unsigned int i, count; - ARRAY_DEFINE(names, const char *); + ARRAY_TYPE(const_string) names; pool_t pool; if (getenv("DEBUG") != NULL) i_info("Loading modules from directory: %s", dir); dirp = opendir(dir); - if (dirp == NULL) { - if (errno != ENOENT) - i_error("opendir(%s) failed: %m", dir); - return NULL; - } + if (dirp == NULL) + i_fatal("opendir(%s) failed: %m", dir); pool = pool_alloconly_create("module loader", 1024); p_array_init(&names, pool, 32); @@ -191,6 +207,8 @@ if (p == NULL || strlen(p) != 3) continue; + check_duplicates(&names, name, dir); + name = p_strdup(pool, d->d_name); array_append(&names, &name, 1); } @@ -204,7 +222,7 @@ else { module_names_arr = t_strsplit_spaces(module_names, ", "); /* allow giving the module names also in non-base form. - conver them in here. */ + convert them in here. */ for (i = 0; module_names_arr[i] != NULL; i++) { module_names_arr[i] = module_file_get_name(module_names_arr[i]);