From 846c63f269f2bd333a24730b3cb92dbb37960328 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 4 Apr 2018 13:03:21 +0100 Subject: [PATCH] [Feature] Allow to set lua_cpath from options --- src/lua/lua_common.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index a1d3f27bc..183fa0503 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -225,7 +225,7 @@ void rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars) { const gchar *old_path, *additional_path = NULL; - const ucl_object_t *opts; + const ucl_object_t *opts = NULL; const gchar *pluginsdir = RSPAMD_PLUGINSDIR, *rulesdir = RSPAMD_RULESDIR, *lualibdir = RSPAMD_LUALIBDIR, @@ -341,13 +341,33 @@ rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars lua_getfield (L, -1, "cpath"); old_path = luaL_checkstring (L, -1); + additional_path = NULL; - rspamd_snprintf (path_buf, sizeof (path_buf), - "%s/?%s;" - "%s", - libdir, - OS_SO_SUFFIX, - old_path); + if (opts != NULL) { + opts = ucl_object_lookup (opts, "lua_cpath"); + 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;" + "%s;" + "%s", + libdir, + OS_SO_SUFFIX, + additional_path, + old_path); + } + else { + rspamd_snprintf (path_buf, sizeof (path_buf), + "%s/?%s;" + "%s", + libdir, + OS_SO_SUFFIX, + old_path); + } lua_pop (L, 1); lua_pushstring (L, path_buf); lua_setfield (L, -2, "cpath"); -- 2.39.5