From: chris mikkelson Date: Tue, 30 Mar 2010 17:01:44 +0000 (-0500) Subject: Load modules from central libdir, by default /usr/local/lib/smtpsink/ X-Git-Url: https://git.mikk.net/?a=commitdiff_plain;h=3b52900d6762a7aea8b810d159554eb2f3bb5a05;p=smtpsink Load modules from central libdir, by default /usr/local/lib/smtpsink/ --- diff --git a/module.c b/module.c index 63c4634..12722a1 100644 --- a/module.c +++ b/module.c @@ -1,7 +1,9 @@ #include #include +#include #include #include +#include #include #include @@ -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);