diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-21 20:20:32 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-21 20:20:32 +0300 |
commit | 75b9cf03dacf86ac618056eaa69c01b62e7e14a5 (patch) | |
tree | e6e09268e04ed4b58351842e1655a542f41ab2e0 | |
parent | 99eb79fdbaade51a3dcc3cddcc52d8510b2e519d (diff) | |
download | smap-75b9cf03dacf86ac618056eaa69c01b62e7e14a5.tar.gz smap-75b9cf03dacf86ac618056eaa69c01b62e7e14a5.tar.bz2 |
Allow to prepend entries to the load path.
* src/module.c (mod_load_path): Made it array of two elements.
(add_load_path): Second argument gives index to mod_load_path.
(flush_load_path): New static.
(smap_modules_init): First process prepended directories, then
SMAP_MODDIR, and then appended ones.
* src/smapd.c (cfg_load_path): Rename to cfg_append_load_path.
(cfg_prepend_load_path): New function.
(smap_kwtab): New keywords: prepend-load-path, append-load-path.
* src/smapd.h (PATH_PREPEND, PATH_APPEND): New constants.
(add_load_path): Take 2 arguments.
* src/smapd.cfin [LOCAL]: Prepend local dirs to the load path.
* doc/smap.texi: Document prepend-load-path/append-load-path.
-rw-r--r-- | doc/smap.texi | 21 | ||||
-rw-r--r-- | src/module.c | 86 | ||||
-rw-r--r-- | src/smapd.c | 17 | ||||
-rw-r--r-- | src/smapd.cfin | 8 | ||||
-rw-r--r-- | src/smapd.h | 4 |
5 files changed, 83 insertions, 53 deletions
diff --git a/doc/smap.texi b/doc/smap.texi index 353c341..14c3cc0 100644 --- a/doc/smap.texi +++ b/doc/smap.texi @@ -816,9 +816,11 @@ used to refer to that module. @code{module} statement. By default the scan order is as follows: @enumerate 1 +@item Additional search directories specified by +@code{prepend-load-path} (see below); @item Smap module directory: @file{$prefix/lib/smap}; -@item Additional search directories specified by the @code{load-path} -statement (see below); +@item Additional search directories specified by @code{append-load-path} +(see below); @item Directories specified in the environment variable @env{LTDL_LIBRARY_PATH}. @item The system dependent library search path (e.g. on GNU/Linux it is @@ -843,11 +845,18 @@ it tries to append the following suffixes to it: platform, e.g.: @samp{.so}, @samp{.sl}, etc. @end enumerate - Additional search directories may be configured with the -@code{load-path} statement: + Additional search directories may be configured with +@code{prepend-load-path} and @code{append-load-path} statements: -@deffn {Config} load-path path -Adds the directories listed in its argument to the module load path. +@deffn {Config} prepend-load-path path +Prepends the directories listed in its argument to the module load path. +The @var{path} argument must be a colon-separated list of absolute +directory names. +@end deffn + +@deffn {Config} append-load-path path +@deffnx {Config} load-path path +Appends the directories listed in its argument to the module load path. The @var{path} argument must be a colon-separated list of absolute directory names. @end deffn diff --git a/src/module.c b/src/module.c index bab4bde..bcd28db 100644 --- a/src/module.c +++ b/src/module.c @@ -16,21 +16,56 @@ #include "smapd.h" -char *mod_load_path; +char *mod_load_path[2]; void -add_load_path(const char *path) +add_load_path(const char *path, int pathid) { if (path[0] == ':') path++; - if (mod_load_path) { - mod_load_path = erealloc(mod_load_path, - strlen(mod_load_path) + - strlen(path) + 2); - strcat(mod_load_path, ":"); - strcat(mod_load_path, path); + if (mod_load_path[pathid]) { + mod_load_path[pathid] = erealloc(mod_load_path[pathid], + strlen(mod_load_path[pathid]) + + strlen(path) + 2); + strcat(mod_load_path[pathid], ":"); + strcat(mod_load_path[pathid], path); } else - mod_load_path = estrdup(path); + mod_load_path[pathid] = estrdup(path); +} + +static void +flush_load_path(const char *path) +{ + int i; + struct wordsplit ws; + ws.ws_delim = ":"; + ws.ws_error = smap_error; + + if (!path) + return; + if (wordsplit(path, &ws, + WRDSF_NOCMD | WRDSF_NOVAR | + WRDSF_ENOMEMABRT | WRDSF_SQUEEZE_DELIMS | + WRDSF_DELIM | WRDSF_ERROR)) { + smap_error("cannot parse load path: %s", + wordsplit_strerror(&ws)); + return; + } + + for (i = 0; i < ws.ws_wordc; i++) { + if (ws.ws_wordv[i][0]) { + debug(DBG_MODULE, 1, + ("adding %s to the load path", + ws.ws_wordv[i])); + if (lt_dladdsearchdir(ws.ws_wordv[i])) { + smap_error("cannot add `%s' to " + "the load path: %s", + ws.ws_wordv[i], + lt_dlerror()); + } + } + } + wordsplit_free(&ws); } void @@ -38,40 +73,13 @@ smap_modules_init() { lt_dlinit(); + flush_load_path(mod_load_path[PATH_PREPEND]); + debug(DBG_MODULE, 1, ("adding %s to the load path", SMAP_MODDIR)); lt_dladdsearchdir(SMAP_MODDIR); - if (mod_load_path) { - int i; - struct wordsplit ws; - ws.ws_delim = ":"; - ws.ws_error = smap_error; - - if (wordsplit(mod_load_path, &ws, - WRDSF_NOCMD | WRDSF_NOVAR | - WRDSF_ENOMEMABRT | WRDSF_SQUEEZE_DELIMS | - WRDSF_DELIM | WRDSF_ERROR)) { - smap_error("cannot parse load path: %s", - wordsplit_strerror(&ws)); - return; - } - - for (i = 0; i < ws.ws_wordc; i++) { - if (ws.ws_wordv[i][0]) { - debug(DBG_MODULE, 1, - ("adding %s to the load path", - ws.ws_wordv[i])); - if (lt_dladdsearchdir(ws.ws_wordv[i])) { - smap_error("cannot add `%s' to " - "the load path: %s", - ws.ws_wordv[i], - lt_dlerror()); - } - } - } - wordsplit_free(&ws); - } + flush_load_path(mod_load_path[PATH_APPEND]); } diff --git a/src/smapd.c b/src/smapd.c index 541dce8..3365387 100644 --- a/src/smapd.c +++ b/src/smapd.c @@ -657,11 +657,20 @@ cfg_server(struct cfg_kw *kw, int wordc, char **wordv, void *data) } static int -cfg_load_path(struct cfg_kw *kw, int wordc, char **wordv, void *data) +cfg_append_load_path(struct cfg_kw *kw, int wordc, char **wordv, void *data) { if (cfg_chkargc(wordc, 2, 2)) return 1; - add_load_path(wordv[1]); + add_load_path(wordv[1], PATH_APPEND); + return 0; +} + +static int +cfg_prepend_load_path(struct cfg_kw *kw, int wordc, char **wordv, void *data) +{ + if (cfg_chkargc(wordc, 2, 2)) + return 1; + add_load_path(wordv[1], PATH_PREPEND); return 0; } @@ -802,7 +811,9 @@ static struct cfg_kw smap_kwtab[] = { { "server", KWT_FUN, NULL, NULL, NULL, cfg_server }, /* Module Loader */ - { "load-path", KWT_FUN, NULL, NULL, NULL, cfg_load_path }, + { "load-path", KWT_FUN, NULL, NULL, NULL, cfg_append_load_path }, + { "append-load-path", KWT_FUN, NULL, NULL, NULL, cfg_append_load_path }, + { "prepend-load-path", KWT_FUN, NULL, NULL, NULL, cfg_prepend_load_path }, { "module", KWT_FUN, NULL, NULL, NULL, cfg_module }, { "database", KWT_FUN, NULL, NULL, NULL, cfg_database }, { "dispatch", KWT_FUN, NULL, NULL, NULL, cfg_dispatch }, diff --git a/src/smapd.cfin b/src/smapd.cfin index 1326d27..5e6bd1c 100644 --- a/src/smapd.cfin +++ b/src/smapd.cfin @@ -99,11 +99,11 @@ server privileged inet://127.0.0.1:3146 # function. ######################################################################## ifdef(`LOCAL',`dnl -load-path ../modules/echo -load-path ../modules/sed -ifdef(`MAILUTILS',`load-path ../modules/mailutils +prepend-load-path ../modules/echo +prepend-load-path ../modules/sed +ifdef(`MAILUTILS',`prepend-load-path ../modules/mailutils ')dnl -ifdef(`GUILE',`load-path ../modules/guile +ifdef(`GUILE',`prepend-load-path ../modules/guile ')')dnl ## These are the modules shipped with smap. diff --git a/src/smapd.h b/src/smapd.h index 864b01c..5a7b780 100644 --- a/src/smapd.h +++ b/src/smapd.h @@ -203,7 +203,9 @@ struct smap_database_instance { int opened; }; -void add_load_path(const char *path); +#define PATH_PREPEND 0 +#define PATH_APPEND 1 +void add_load_path(const char *path, int); void smap_modules_init(void); int module_declare(const char *file, unsigned line, const char *id, int argc, char **argv, |