diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-12-26 16:46:55 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:47:45 -0500 |
commit | 448483199fb436309735f5203b3282fca2c517ec (patch) | |
tree | fcd663e46d0eac19b98037008a435bdd57ca7f8e /source4/lib/module.c | |
parent | ee10fb1a12391a76fe81e6e7a92d282ef885bc30 (diff) | |
download | samba-448483199fb436309735f5203b3282fca2c517ec.tar.gz samba-448483199fb436309735f5203b3282fca2c517ec.tar.xz samba-448483199fb436309735f5203b3282fca2c517ec.zip |
r12494: Support loading modules from .so files for most subsystems.
We now use a different system for initializing the modules for a subsystem.
Most subsystems now have an init function that looks something like this:
init_module_fn static_init[] = STATIC_AUTH_MODULES;
init_module_fn *shared_init = load_samba_modules(NULL, "auth");
run_init_functions(static_init);
run_init_functions(shared_init);
talloc_free(shared_init);
I hope to eliminate the other init functions later on (the
init_programname_subsystems; defines).
(This used to be commit b6d2ad4ce0a91c4be790dd258820c492ff1787ea)
Diffstat (limited to 'source4/lib/module.c')
-rw-r--r-- | source4/lib/module.c | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/source4/lib/module.c b/source4/lib/module.c index abb98cbf7b2..672d8df7cef 100644 --- a/source4/lib/module.c +++ b/source4/lib/module.c @@ -21,65 +21,77 @@ #include "includes.h" #include "system/dir.h" -static BOOL load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name) +static void *load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name) { char *path; void *handle; - BOOL (*init_module_fn) (void); - BOOL ret; + void *init_fn; path = talloc_asprintf(mem_ctx, "%s/%s", dir, name); handle = dlopen(path, RTLD_NOW); if (handle == NULL) { DEBUG(0, ("Unable to open %s: %s\n", path, dlerror())); - return False; + talloc_free(path); + return NULL; } - init_module_fn = dlsym(handle, "init_module"); + init_fn = dlsym(handle, "init_module"); - if (init_module_fn == NULL) { + if (init_fn == NULL) { DEBUG(0, ("Unable to find init_module() in %s: %s\n", path, dlerror())); - return False; - } - - ret = init_module_fn(); - if (!ret) { DEBUG(1, ("Loading module '%s' failed\n", path)); + dlclose(handle); + talloc_free(path); + return NULL; } - dlclose(handle); - talloc_free(path); - return ret; + return init_fn; } -BOOL load_modules(const char *path) +init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) { DIR *dir; struct dirent *entry; - BOOL ret = True; - TALLOC_CTX *mem_ctx; - - mem_ctx = talloc_init(NULL); + int success = 0; + init_module_fn *ret = talloc_array(mem_ctx, init_module_fn, 2); + ret[0] = NULL; + dir = opendir(path); if (dir == NULL) { - talloc_free(mem_ctx); - return False; + talloc_free(ret); + return NULL; } while((entry = readdir(dir))) { if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) continue; - ret &= load_module(mem_ctx, path, entry->d_name); + ret[success] = load_module(mem_ctx, path, entry->d_name); + if (ret[success]) { + ret = talloc_realloc(mem_ctx, ret, init_module_fn, success+2); + success++; + ret[success] = NULL; + } } closedir(dir); - talloc_free(mem_ctx); + return ret; +} + +BOOL run_init_functions(NTSTATUS (**fns) (void)) +{ + int i; + BOOL ret; + + if (fns == NULL) + return True; + + for (i = 0; fns[i]; i++) { ret &= NT_STATUS_IS_OK(fns[i]()); } return ret; } |