summaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-16 16:34:54 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-16 16:34:54 +0000
commit858dd01f283427ba7554de1ccebbbf5eec18aaf3 (patch)
treef05776371d2e924667def91ef524d3eedb9b7de2 /src/lua
parentc06429374af27b25c03482abd2695714b6d61d74 (diff)
downloadrspamd-858dd01f283427ba7554de1ccebbbf5eec18aaf3.tar.gz
rspamd-858dd01f283427ba7554de1ccebbbf5eec18aaf3.zip
Set lua path according to rspamd settings.
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_common.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 73471719b..78a80f1ea 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -281,6 +281,40 @@ lua_add_actions_global (lua_State *L)
lua_setglobal (L, "rspamd_actions");
}
+static void
+rspamd_lua_set_path (lua_State *L, struct rspamd_config *cfg)
+{
+ const gchar *old_path, *additional_path = NULL;
+ const ucl_object_t *opts;
+ gchar path_buf[PATH_MAX];
+
+ lua_getglobal (L, "package");
+ lua_getfield (L, -1, "path");
+ old_path = luaL_checkstring (L, -1);
+
+ opts = ucl_object_find_key (cfg->rcl_obj, "options");
+ if (opts != NULL) {
+ opts = ucl_object_find_key (opts, "lua_path");
+ if (opts != NULL && ucl_object_type (opts) == UCL_STRING) {
+ additional_path = ucl_object_tostring (opts);
+ }
+ }
+
+ if (additional_path) {
+ rspamd_snprintf (path_buf, sizeof (path_buf), "%s;%s/?.lua;%s/?.lua;%s",
+ old_path, RSPAMD_PLUGINSDIR, RSPAMD_CONFDIR, additional_path);
+ }
+ else {
+ rspamd_snprintf (path_buf, sizeof (path_buf), "%s;%s/?.lua;%s/?.lua",
+ old_path, RSPAMD_PLUGINSDIR, RSPAMD_CONFDIR);
+ }
+
+ lua_pop (L, 1);
+ lua_pushstring (L, path_buf);
+ lua_setfield (L, -2, "path");
+ lua_pop (L, 1);
+}
+
lua_State *
rspamd_lua_init (struct rspamd_config *cfg)
{
@@ -317,6 +351,8 @@ rspamd_lua_init (struct rspamd_config *cfg)
rspamd_lua_add_preload (L, "ucl", luaopen_ucl);
+ rspamd_lua_set_path (L, cfg);
+
return L;
}
@@ -360,6 +396,7 @@ rspamd_init_lua_filters (struct rspamd_config *cfg)
lua_State *L = cfg->lua_state;
cur = g_list_first (cfg->script_modules);
+
while (cur) {
module = cur->data;
if (module->path) {