From 32d934c91fc7d08f9d4ba0426366aeb202d7a468 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 27 Apr 2014 12:44:53 +0200 Subject: [PATCH] core: Make the plugin directory configurable. --- src/core/plugin.c | 14 +++++++++----- src/include/core/plugin.h | 6 ++++-- src/tools/sysdbd/configfile.c | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/core/plugin.c b/src/core/plugin.c index eb9797f..8cd490a 100644 --- a/src/core/plugin.c +++ b/src/core/plugin.c @@ -442,7 +442,8 @@ module_init(const char *name, lt_dlhandle lh, sdb_plugin_info_t *info) } /* module_init */ static int -module_load(const char *name, const sdb_plugin_ctx_t *plugin_ctx) +module_load(const char *basedir, const char *name, + const sdb_plugin_ctx_t *plugin_ctx) { char base_name[name ? strlen(name) + 1 : 1]; const char *name_ptr; @@ -467,8 +468,10 @@ module_load(const char *name, const sdb_plugin_ctx_t *plugin_ctx) } strcat(base_name, name_ptr); - snprintf(filename, sizeof(filename), "%s/%s.so", - PKGLIBDIR, base_name); + if (! basedir) + basedir = PKGLIBDIR; + + snprintf(filename, sizeof(filename), "%s/%s.so", basedir, base_name); filename[sizeof(filename) - 1] = '\0'; if (access(filename, R_OK)) { @@ -575,7 +578,8 @@ plugin_add_callback(sdb_llist_t **list, const char *type, */ int -sdb_plugin_load(const char *name, const sdb_plugin_ctx_t *plugin_ctx) +sdb_plugin_load(const char *basedir, const char *name, + const sdb_plugin_ctx_t *plugin_ctx) { ctx_t *ctx; @@ -612,7 +616,7 @@ sdb_plugin_load(const char *name, const sdb_plugin_ctx_t *plugin_ctx) return 0; } - return module_load(name, plugin_ctx); + return module_load(basedir, name, plugin_ctx); } /* sdb_plugin_load */ int diff --git a/src/include/core/plugin.h b/src/include/core/plugin.h index e5e222f..69c18b4 100644 --- a/src/include/core/plugin.h +++ b/src/include/core/plugin.h @@ -64,10 +64,12 @@ typedef struct { * sdb_plugin_load: * Load (any type of) plugin by loading the shared object file and calling the * sdb_module_init function. If specified, 'plugin_ctx' fine-tunes the - * behavior of the plugin. + * behavior of the plugin. If specified, the plugin will be looked up in + * 'basedir', else it defaults to the package libdir. */ int -sdb_plugin_load(const char *name, const sdb_plugin_ctx_t *plugin_ctx); +sdb_plugin_load(const char *basedir, const char *name, + const sdb_plugin_ctx_t *plugin_ctx); /* * sdb_plugin_set_info: diff --git a/src/tools/sysdbd/configfile.c b/src/tools/sysdbd/configfile.c index 25c9404..8dc4394 100644 --- a/src/tools/sysdbd/configfile.c +++ b/src/tools/sysdbd/configfile.c @@ -176,7 +176,7 @@ daemon_load_plugin(oconfig_item_t *ci) } /* returns a negative value on error */ - return sdb_plugin_load(name, NULL); + return sdb_plugin_load(NULL, name, NULL); } /* daemon_load_plugin */ static int @@ -215,7 +215,7 @@ daemon_load_backend(oconfig_item_t *ci) } } - return sdb_plugin_load(plugin_name, &ctx); + return sdb_plugin_load(NULL, plugin_name, &ctx); } /* daemon_load_backend */ static int -- 2.30.2