Author: jelmer
Date: 2006-04-08 13:44:40 +0000 (Sat, 08 Apr 2006)
New Revision: 14992

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=14992

Log:
Allow load_module() to be used externally

Modified:
   branches/SAMBA_4_0/source/lib/util/module.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/util/module.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util/module.c 2006-04-08 13:43:57 UTC (rev 
14991)
+++ branches/SAMBA_4_0/source/lib/util/module.c 2006-04-08 13:44:40 UTC (rev 
14992)
@@ -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 @@
                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 @@
 {
        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 @@
                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);

Reply via email to