From 71fee3e1ba309196cfc07c1df29c366385896223 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 10 Mar 2013 22:38:05 +0100 Subject: [PATCH] plugin, daemon: Use '::' in plugin names to indicate subdirectories. That is, behave similar to Perl when encountering a '::' in a plugin's name and translate that to a slash. "foo::bar" will thus become PKGLIBDIR/foo/bar.so. This will be used to name plugins accessing the same backend using different methods and to have an, imho, nicer name for those. The daemon will now use that to prepend "backend::" to the name of backends. This is no different to the behavior before but only uses different names that will be displayed in log messages. --- src/core/plugin.c | 23 ++++++++++++++++++++--- src/daemon/config.c | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/core/plugin.c b/src/core/plugin.c index 306f5e9..c8e8e9e 100644 --- a/src/core/plugin.c +++ b/src/core/plugin.c @@ -264,6 +264,10 @@ sdb_plugin_add_callback(sdb_llist_t **list, const char *type, int sdb_plugin_load(const char *name) { + char real_name[strlen(name) > 0 ? strlen(name) : 1]; + const char *name_ptr; + char *tmp; + char filename[1024]; lt_dlhandle lh; @@ -273,14 +277,27 @@ sdb_plugin_load(const char *name) int status; + if ((! name) || (! *name)) + return -1; + + real_name[0] = '\0'; + name_ptr = name; + + while ((tmp = strstr(name_ptr, "::"))) { + strncat(real_name, name_ptr, (size_t)(tmp - name_ptr)); + strcat(real_name, "/"); + name_ptr = tmp + strlen("::"); + } + strcat(real_name, name_ptr); + snprintf(filename, sizeof(filename), "%s/%s.so", - PKGLIBDIR, name); + PKGLIBDIR, real_name); filename[sizeof(filename) - 1] = '\0'; if (access(filename, R_OK)) { char errbuf[1024]; - sdb_log(SDB_LOG_ERR, "plugin: Failed to load plugin '%s': %s\n", - name, sdb_strerror(errno, errbuf, sizeof(errbuf))); + sdb_log(SDB_LOG_ERR, "plugin: Failed to load plugin '%s' (%s): %s\n", + name, filename, sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } diff --git a/src/daemon/config.c b/src/daemon/config.c index 2975e06..95e45e3 100644 --- a/src/daemon/config.c +++ b/src/daemon/config.c @@ -108,7 +108,7 @@ daemon_load_backend(oconfig_item_t *ci) return -1; } - snprintf(plugin_name, sizeof(plugin_name), "backend/%s", name); + snprintf(plugin_name, sizeof(plugin_name), "backend::%s", name); for (i = 0; i < ci->children_num; ++i) { oconfig_item_t *child = ci->children + i; -- 2.30.2