Code

plugin, daemon: Use '::' in plugin names to indicate subdirectories.
authorSebastian Harl <sh@tokkee.org>
Sun, 10 Mar 2013 21:38:05 +0000 (22:38 +0100)
committerSebastian Harl <sh@tokkee.org>
Sun, 10 Mar 2013 21:38:05 +0000 (22:38 +0100)
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
src/daemon/config.c

index 306f5e902565d3a0b025ea8d08851672a4b53fbe..c8e8e9e0db06a7799275608b4724eb8929d5b89f 100644 (file)
@@ -264,6 +264,10 @@ sdb_plugin_add_callback(sdb_llist_t **list, const char *type,
 int
 sdb_plugin_load(const char *name)
 {
 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;
        char filename[1024];
 
        lt_dlhandle lh;
@@ -273,14 +277,27 @@ sdb_plugin_load(const char *name)
 
        int status;
 
 
        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",
        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];
        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;
        }
 
                return -1;
        }
 
index 2975e06fa7d218393907bbcd770809d6689353ff..95e45e311aa9409da52236ecf7d0808d5290e1bb 100644 (file)
@@ -108,7 +108,7 @@ daemon_load_backend(oconfig_item_t *ci)
                return -1;
        }
 
                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;
 
        for (i = 0; i < ci->children_num; ++i) {
                oconfig_item_t *child = ci->children + i;