]> git.mikk.net Git - smtpsink/commitdiff
Load modules from central libdir, by default /usr/local/lib/smtpsink/
authorchris mikkelson <chris@mikk.net>
Tue, 30 Mar 2010 17:01:44 +0000 (12:01 -0500)
committerchris mikkelson <chris@mikk.net>
Tue, 30 Mar 2010 17:01:44 +0000 (12:01 -0500)
module.c

index 63c4634b6954749b19db4bb2b35634dd87f7be02..12722a116c24dae142895c991b96ce1d1b654085 100644 (file)
--- a/module.c
+++ b/module.c
@@ -1,7 +1,9 @@
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 #include <dlfcn.h>
 #include <err.h>
+#include <sys/param.h>
 
 #include <sys/queue.h>
 #include <netinet/in.h>
@@ -13,36 +15,39 @@ static struct smtpsink_module **modlist = 0;
 
 /* modulespec is a string formatted as:
 
-       "/path/to/module,options"
+       "modulename,options"
+
+   where modulename corresponds to a dlopen()able module in
+
+       $prefix/lib/smtpsink/ssm_modulename.so
 
    parsing of "options" is module dependent
 */
+
+#define MODDIR "/usr/local/lib/smtpsink"
+
 void
 module_init(char *modulespec) 
 {
-       char modpath[1024];
-       char *file, *t;
+       char modpath[MAXPATHLEN];
+       char *moddir, *t;
        struct smtpsink_module *mod;
        void *dlmod;
 
        t = strchr(modulespec, ',');
-       if (!t) file = modulespec;
-       else {
-               if (t-modulespec - 1 > sizeof(modpath))
-                       errx(1, "module path too long: %s\n", modulespec);
-               strncpy(modpath, modulespec, t - modulespec);
-               modpath[t-modulespec] = 0;
-               file = modpath;
-               t++;
-       }
+       if (t) *t++ = 0;
+
+       moddir = getenv("SMTPSINK_MODDIR");
+       if (!moddir) moddir = MODDIR;
+       snprintf(modpath, sizeof(modpath), "%s/ssm_%s.so", moddir, modulespec); 
 
-       dlmod = dlopen(file, RTLD_NOW);
+       dlmod = dlopen(modpath, RTLD_NOW);
        if (!dlmod) 
-               errx(1, "could not load %s: %s\n", file, dlerror());
+               errx(1, "could not load %s: %s\n", modpath, dlerror());
 
        mod = (void *)dlsym(dlmod, "ss_module");
        if (!mod)
-               errx(1, "module %s invalid: %s\n", file, dlerror());
+               errx(1, "module %s invalid: %s\n", modpath, dlerror());
 
        mod->ssm_module_index = nmod;
        if (mod->ssm_module_init) mod->ssm_module_init(t);