diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2006-04-08 13:44:40 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:00:51 -0500 |
commit | 8a069bcc53bbd0334d58f199e9d81f0f62ab7225 (patch) | |
tree | 021ca4a75c835ea16e86f413c5d8c76c5b541a89 /source4/lib/util/module.c | |
parent | a4d7c38c38aef5f3c8830bcdc501fa9c04183454 (diff) | |
download | samba-8a069bcc53bbd0334d58f199e9d81f0f62ab7225.tar.gz samba-8a069bcc53bbd0334d58f199e9d81f0f62ab7225.tar.bz2 samba-8a069bcc53bbd0334d58f199e9d81f0f62ab7225.zip |
r14992: Allow load_module() to be used externally
(This used to be commit a9d5d7ab5807d8a50ce8f9e3aeedfd5b6530f3a3)
Diffstat (limited to 'source4/lib/util/module.c')
-rw-r--r-- | source4/lib/util/module.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/source4/lib/util/module.c b/source4/lib/util/module.c index dc8b353547..68962d9780 100644 --- a/source4/lib/util/module.c +++ b/source4/lib/util/module.c @@ -26,18 +26,17 @@ #include "includes.h" #include "system/dir.h" -static void *load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name) +/** + * Obtain the init function from a shared library file + */ +_PUBLIC_ init_module_fn load_module(TALLOC_CTX *mem_ctx, const char *path) { - char *path; void *handle; 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())); - talloc_free(path); return NULL; } @@ -47,13 +46,10 @@ static void *load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name) DEBUG(0, ("Unable to find init_module() in %s: %s\n", path, dlerror())); DEBUG(1, ("Loading module '%s' failed\n", path)); dlclose(handle); - talloc_free(path); return NULL; } - talloc_free(path); - - return init_fn; + return (init_module_fn)init_fn; } /** @@ -64,6 +60,7 @@ _PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) { DIR *dir; struct dirent *entry; + char *filename; int success = 0; init_module_fn *ret = talloc_array(mem_ctx, init_module_fn, 2); @@ -79,12 +76,16 @@ _PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path) if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) continue; - ret[success] = load_module(mem_ctx, path, entry->d_name); + filename = talloc_asprintf(mem_ctx, "%s/%s", path, entry->d_name); + + ret[success] = load_module(mem_ctx, filename); if (ret[success]) { ret = talloc_realloc(mem_ctx, ret, init_module_fn, success+2); success++; ret[success] = NULL; } + + talloc_free(filename); } closedir(dir); |