Author: jelmer Date: 2007-12-17 03:35:59 +0000 (Mon, 17 Dec 2007) New Revision: 26481
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=26481 Log: Make function for loading symbol from DSO more generic, and allow modules to provide an ops table directly rather than an initialization function. Modified: branches/SAMBA_4_0/ branches/SAMBA_4_0/source/lib/ldb/common/ldb.c branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h Changeset: Property changes on: branches/SAMBA_4_0 ___________________________________________________________________ Name: bzr:revision-info ...skipped... Name: bzr:file-ids ...skipped... Name: bzr:revision-id:v3-trunk0 ...skipped... Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb.c =================================================================== --- branches/SAMBA_4_0/source/lib/ldb/common/ldb.c 2007-12-17 03:25:28 UTC (rev 26480) +++ branches/SAMBA_4_0/source/lib/ldb/common/ldb.c 2007-12-17 03:35:59 UTC (rev 26481) @@ -126,7 +126,11 @@ fn = ldb_find_backend(backend); if (fn == NULL) { - if (ldb_try_load_dso(ldb, backend) == 0) { + int (*init_fn) (void); + + init_fn = ldb_dso_load_symbol(ldb, backend, + "init_module"); + if (init_fn != NULL && init_fn() == 0) { fn = ldb_find_backend(backend); } } Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c =================================================================== --- branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c 2007-12-17 03:25:28 UTC (rev 26480) +++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c 2007-12-17 03:35:59 UTC (rev 26481) @@ -203,14 +203,15 @@ return 0; } -int ldb_try_load_dso(struct ldb_context *ldb, const char *name) +void *ldb_dso_load_symbol(struct ldb_context *ldb, const char *name, + const char *symbol) { char *path; void *handle; - int (*init_fn) (void); + void *sym; if (ldb->modules_dir == NULL) - return -1; + return NULL; path = talloc_asprintf(ldb, "%s/%s.%s", ldb->modules_dir, name, SHLIBEXT); @@ -220,19 +221,19 @@ handle = dlopen(path, RTLD_NOW); if (handle == NULL) { ldb_debug(ldb, LDB_DEBUG_WARNING, "unable to load %s from %s: %s\n", name, path, dlerror()); - return -1; + return NULL; } - init_fn = (int (*)(void))dlsym(handle, "init_module"); + sym = (int (*)(void))dlsym(handle, symbol); - if (init_fn == NULL) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "no symbol `init_module' found in %s: %s\n", path, dlerror()); - return -1; + if (sym == NULL) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "no symbol `%s' found in %s: %s\n", symbol, path, dlerror()); + return NULL; } talloc_free(path); - return init_fn(); + return sym; } int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, struct ldb_module *backend, struct ldb_module **out) @@ -248,10 +249,19 @@ ops = ldb_find_module_ops(module_list[i]); if (ops == NULL) { - if (ldb_try_load_dso(ldb, module_list[i]) == 0) { + int (*init_fn) (void); + + init_fn = ldb_dso_load_symbol(ldb, module_list[i], + "init_module"); + if (init_fn != NULL && init_fn() == 0) { ops = ldb_find_module_ops(module_list[i]); } } + + if (ops == NULL) { + ops = ldb_dso_load_symbol(ldb, module_list[i], + "ldb_module_ops"); + } if (ops == NULL) { ldb_debug(ldb, LDB_DEBUG_WARNING, "WARNING: Module [%s] not found\n", Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h =================================================================== --- branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h 2007-12-17 03:25:28 UTC (rev 26480) +++ branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h 2007-12-17 03:35:59 UTC (rev 26481) @@ -159,7 +159,8 @@ int ldb_register_module(const struct ldb_module_ops *); int ldb_register_backend(const char *url_prefix, ldb_connect_fn); -int ldb_try_load_dso(struct ldb_context *ldb, const char *name); +void *ldb_dso_load_symbol(struct ldb_context *ldb, const char *name, + const char *symbol); /* The following definitions come from lib/ldb/common/ldb_debug.c */ void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
