diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-12-30 17:23:31 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-12-30 17:23:31 +0000 |
commit | d3bb11ac4358dc6b96044bcb681112520cf9c272 (patch) | |
tree | db32b4a819b3b085a837c7a091567b369cb1e475 /src/lua | |
parent | 3003f8f75fc3fa01012a9ebd20b0bdd332c938d7 (diff) | |
download | rspamd-d3bb11ac4358dc6b96044bcb681112520cf9c272.tar.gz rspamd-d3bb11ac4358dc6b96044bcb681112520cf9c272.zip |
[Fix] Allow to set priorities between post init scripts
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_common.c | 4 | ||||
-rw-r--r-- | src/lua/lua_config.c | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 87474793c..482245ac9 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -2159,8 +2159,8 @@ rspamd_lua_run_config_post_init (lua_State *L, struct rspamd_config *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)); + msg_err_config ("cannot run config post init script: %s; priority = %d", + lua_tostring (L, -1), sc->priority); } lua_settop (L, err_idx - 1); diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 836654500..89f93730d 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -3155,21 +3155,36 @@ lua_config_add_on_load (lua_State *L) return 0; } +static inline int +rspamd_post_init_sc_sort (const struct rspamd_config_cfg_lua_script *pra, + const struct rspamd_config_cfg_lua_script *prb) +{ + /* Inverse sort */ + return prb->priority - pra->priority; +} + static gint lua_config_add_post_init (lua_State *L) { LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config (L, 1); struct rspamd_config_cfg_lua_script *sc; + guint priority = 0; if (cfg == NULL || lua_type (L, 2) != LUA_TFUNCTION) { return luaL_error (L, "invalid arguments"); } + if (lua_type (L, 3) == LUA_TNUMBER) { + priority = lua_tointeger (L , 3); + } + sc = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*sc)); lua_pushvalue (L, 2); sc->cbref = luaL_ref (L, LUA_REGISTRYINDEX); + sc->priority = priority; DL_APPEND (cfg->post_init_scripts, sc); + DL_SORT (cfg->post_init_scripts, rspamd_post_init_sc_sort); return 0; } |