diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-06-14 19:16:36 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-06-14 19:16:36 +0100 |
commit | a7a0800daba34acc86308d4ba75b8fd8c5fce57c (patch) | |
tree | 542b4f8e8666d36604d0cedf1c8034eadc1c871e /src/lua/lua_common.c | |
parent | 092129b5216cb55de385ee6138a29c537142596c (diff) | |
download | rspamd-a7a0800daba34acc86308d4ba75b8fd8c5fce57c.tar.gz rspamd-a7a0800daba34acc86308d4ba75b8fd8c5fce57c.zip |
[Project] Lua_config: Add post init scripts
Diffstat (limited to 'src/lua/lua_common.c')
-rw-r--r-- | src/lua/lua_common.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index f7793748a..6ee69c072 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -1842,13 +1842,13 @@ void rspamd_lua_run_postloads (lua_State *L, struct rspamd_config *cfg, struct event_base *ev_base, struct rspamd_worker *w) { - struct rspamd_config_post_load_script *sc; + struct rspamd_config_cfg_lua_script *sc; struct rspamd_config **pcfg; struct event_base **pev_base; struct rspamd_worker **pw; /* Execute post load scripts */ - LL_FOREACH (cfg->on_load, sc) { + LL_FOREACH (cfg->on_load_scripts, sc) { struct thread_entry *thread = lua_thread_pool_get_for_config (cfg); thread->error_callback = rspamd_lua_run_postloads_error; L = thread->lua_state; @@ -1871,6 +1871,30 @@ rspamd_lua_run_postloads (lua_State *L, struct rspamd_config *cfg, } +void +rspamd_lua_run_config_post_init (lua_State *L, struct rspamd_config *cfg) +{ + struct rspamd_config_cfg_lua_script *sc; + struct rspamd_config **pcfg; + + LL_FOREACH (cfg->post_init_scripts, sc) { + lua_pushcfunction (L, &rspamd_lua_traceback); + gint err_idx = lua_gettop (L); + + lua_rawgeti (L, LUA_REGISTRYINDEX, sc->cbref); + pcfg = lua_newuserdata (L, sizeof (*pcfg)); + *pcfg = cfg; + rspamd_lua_setclass (L, "rspamd{config}", -1); + + if (lua_pcall (L, 1, 0, err_idx) != 0) { + msg_err_config ("cannot run config post init script: %s", + lua_tostring (L, -1)); + } + + lua_settop (L, err_idx - 1); + } +} + static void rspamd_lua_run_postloads_error (struct thread_entry *thread, int ret, const char *msg) { |