]> source.dussan.org Git - rspamd.git/commitdiff
[Rework] Simplify lua path initialization
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 4 Nov 2017 13:17:43 +0000 (13:17 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 4 Nov 2017 13:17:43 +0000 (13:17 +0000)
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/lua/lua_common.c
src/lua/lua_common.h
src/lua/lua_util.c
src/rspamadm/configdump.c
src/rspamadm/confighelp.c
src/rspamadm/configtest.c
src/rspamadm/control.c
src/rspamd.c

index 39f57662ac7619daf37026749b20cb7c07ed548c..d91a4f06e1386072cb2011c09c4de48a94e5c4e2 100644 (file)
@@ -589,8 +589,7 @@ void rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars)
  * @param reconfig
  * @return
  */
-gboolean rspamd_init_filters (struct rspamd_config *cfg, bool reconfig,
-               GHashTable *vars);
+gboolean rspamd_init_filters (struct rspamd_config *cfg, bool reconfig);
 
 /**
  * Add new symbol to the metric
index d32fa19192bcabb5bfec3898a6e732026b0dc7e0..f53b5ca17a0f4f715a05057a3dabf0ab1d32e3c3 100644 (file)
@@ -3624,6 +3624,7 @@ rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
                        MIN (sizeof (cfg->cfg_pool->tag.uid), strlen (cfg->checksum)));
 
        top = rspamd_rcl_config_init (cfg);
+       rspamd_lua_set_path (cfg->lua_state, cfg->rcl_obj, vars);
        rspamd_rcl_set_lua_globals (cfg, cfg->lua_state, vars);
        rspamd_mempool_add_destructor (cfg->cfg_pool, rspamd_rcl_section_free, top);
        err = NULL;
index 079ed71c635b44a96931e3a44a44720bedca82e2..691482773fdf2635aeb84b5310e1b0a696a6cff0 100644 (file)
@@ -1375,7 +1375,7 @@ rspamd_check_worker (struct rspamd_config *cfg, worker_t *wrk)
 }
 
 gboolean
-rspamd_init_filters (struct rspamd_config *cfg, bool reconfig, GHashTable *vars)
+rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
 {
        GList *cur;
        module_t *mod, **pmod;
@@ -1427,7 +1427,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig, GHashTable *vars)
                cur = g_list_next (cur);
        }
 
-       return rspamd_init_lua_filters (cfg, 0, vars);
+       return rspamd_init_lua_filters (cfg, 0);
 }
 
 static void
index dcdfef82302ea611efc57c9bcec851f09b7b6a5f..7b2b073e9f7199bc6b3a69a559b913bf8ea1719c 100644 (file)
@@ -442,8 +442,7 @@ rspamd_free_lua_locked (struct lua_locked_state *st)
 }
 
 gboolean
-rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load,
-               GHashTable *vars)
+rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load)
 {
        struct rspamd_config **pcfg;
        GList *cur;
@@ -452,7 +451,6 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load,
        GString *tb;
        gint err_idx;
 
-       rspamd_lua_set_path (L, cfg->rcl_obj, vars);
        cur = g_list_first (cfg->script_modules);
 
        while (cur) {
index f67401fc281106f698bd087e6d90902740d86d46..9dbd8782bdb875c822403581defea8fa552fcd21 100644 (file)
@@ -163,8 +163,7 @@ lua_State *rspamd_lua_init (void);
  * Load and initialize lua plugins
  */
 gboolean
-rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load,
-               GHashTable *vars);
+rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load);
 
 /**
  * Initialize new locked lua_State structure
index 24273c8c4e619dabcb86253bd1a6701ccbc9ca49..8af61d6d55ff228a143cb4f373f6f52c9ba1bafa 100644 (file)
@@ -658,7 +658,7 @@ lua_util_process_message (lua_State *L)
 
        if (cfg != NULL && message != NULL) {
                base = event_init ();
-               rspamd_init_filters (cfg, FALSE, NULL);
+               rspamd_init_filters (cfg, FALSE);
                task = rspamd_task_new (NULL, cfg, NULL);
                task->ev_base = base;
                task->msg.begin = rspamd_mempool_alloc (task->task_pool, mlen);
index 720d6bf51c24f9c509969e7fb825020eedbc1803..6f320dea141fffb138751d80fecde76385f50436 100644 (file)
@@ -284,9 +284,10 @@ rspamadm_configdump (gint argc, gchar **argv)
        }
        else {
                /* Do post-load actions */
+               rspamd_lua_set_path (cfg->lua_state, cfg->rcl_obj, ucl_vars);
                rspamd_lua_post_load_config (cfg);
 
-               if (!rspamd_init_filters (rspamd_main->cfg, FALSE, ucl_vars)) {
+               if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) {
                        ret = FALSE;
                }
 
index f3da9422d5e4733f78f7cba29fa35cca29dbe4cf..5f8e1cfccc63a179b3081e66a472eb49739552be 100644 (file)
@@ -20,7 +20,6 @@
 #include "cfg_rcl.h"
 #include "rspamd.h"
 #include "lua/lua_common.h"
-#include "confighelp.lua.h"
 
 static gboolean json = FALSE;
 static gboolean compact = FALSE;
@@ -251,7 +250,8 @@ rspamadm_confighelp (gint argc, gchar **argv)
        }
 
        /* Init lua modules */
-       rspamd_init_lua_filters (cfg, TRUE, ucl_vars);
+       rspamd_lua_set_path (cfg->lua_state, cfg->rcl_obj, ucl_vars);
+       rspamd_init_lua_filters (cfg, TRUE);
 
        if (argc > 1) {
                for (i = 1; i < argc; i ++) {
index 3a15b976b21c33e962763b723f9bd4baa685d771..59f466de2ca332a139f02735823945cbb0ebdbce 100644 (file)
@@ -146,7 +146,7 @@ rspamadm_configtest (gint argc, gchar **argv)
                /* Do post-load actions */
                rspamd_lua_post_load_config (cfg);
 
-               if (!rspamd_init_filters (rspamd_main->cfg, FALSE, ucl_vars)) {
+               if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) {
                        ret = FALSE;
                }
 
index 98bcd81f4070459b2e32507506178e85ceb69dbc..62a7e26ae39804b746519c527314efaed3e0820f 100644 (file)
@@ -24,7 +24,6 @@
 #include <event.h>
 #include "libutil/util.h"
 #include "lua/lua_common.h"
-#include "fuzzy_stat.lua.h"
 
 static gchar *control_path = RSPAMD_DBDIR "/rspamd.sock";
 static gboolean json = FALSE;
@@ -135,7 +134,7 @@ rspamd_control_finish_handler (struct rspamd_http_connection *conn,
                                                cbdata->argc,
                                                cbdata->argv,
                                                obj,
-                                               rspamadm_script_fuzzy_stat);
+                                               "fuzzy_stat");
 
                                rspamd_fstring_free (out);
                                ucl_object_unref (obj);
index d301f744987aab78d47dba51414e242b44628cfe..6d20fe50c4768905bbd0c6361441cee624a36b92 100644 (file)
@@ -68,8 +68,7 @@ static gboolean load_rspamd_config (struct rspamd_main *rspamd_main,
                struct rspamd_config *cfg,
                gboolean init_modules,
                enum rspamd_post_load_options opts,
-               gboolean reload,
-               GHashTable *vars);
+               gboolean reload);
 
 /* Control socket */
 static gint control_fd;
@@ -289,7 +288,7 @@ reread_config (struct rspamd_main *rspamd_main)
 
        if (!load_rspamd_config (rspamd_main, tmp_cfg, TRUE,
                        RSPAMD_CONFIG_INIT_VALIDATE|RSPAMD_CONFIG_INIT_SYMCACHE,
-                       TRUE, ucl_vars)) {
+                       TRUE)) {
                rspamd_main->cfg = old_cfg;
                rspamd_log_close_priv (rspamd_main->logger,
                                        rspamd_main->workers_uid,
@@ -871,8 +870,7 @@ static gboolean
 load_rspamd_config (struct rspamd_main *rspamd_main,
                struct rspamd_config *cfg, gboolean init_modules,
                enum rspamd_post_load_options opts,
-               gboolean reload,
-               GHashTable *vars)
+               gboolean reload)
 {
        cfg->compiled_modules = modules;
        cfg->compiled_workers = workers;
@@ -901,7 +899,7 @@ load_rspamd_config (struct rspamd_main *rspamd_main,
        rspamd_lua_post_load_config (cfg);
 
        if (init_modules) {
-               rspamd_init_filters (cfg, reload, vars);
+               rspamd_init_filters (cfg, reload);
        }
 
        /* Do post-load actions */
@@ -1278,7 +1276,7 @@ main (gint argc, gchar **argv, gchar **env)
 
        if (config_test || dump_cache) {
                if (!load_rspamd_config (rspamd_main, rspamd_main->cfg, FALSE, 0,
-                               FALSE, ucl_vars)) {
+                               FALSE)) {
                        exit (EXIT_FAILURE);
                }
 
@@ -1301,7 +1299,7 @@ main (gint argc, gchar **argv, gchar **env)
 
        /* Load config */
        if (!load_rspamd_config (rspamd_main, rspamd_main->cfg, TRUE,
-                       RSPAMD_CONFIG_LOAD_ALL, FALSE, ucl_vars)) {
+                       RSPAMD_CONFIG_LOAD_ALL, FALSE)) {
                exit (EXIT_FAILURE);
        }