aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_config.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-12-30 17:23:31 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-12-30 17:23:31 +0000
commitd3bb11ac4358dc6b96044bcb681112520cf9c272 (patch)
treedb32b4a819b3b085a837c7a091567b369cb1e475 /src/lua/lua_config.c
parent3003f8f75fc3fa01012a9ebd20b0bdd332c938d7 (diff)
downloadrspamd-d3bb11ac4358dc6b96044bcb681112520cf9c272.tar.gz
rspamd-d3bb11ac4358dc6b96044bcb681112520cf9c272.zip
[Fix] Allow to set priorities between post init scripts
Diffstat (limited to 'src/lua/lua_config.c')
-rw-r--r--src/lua/lua_config.c15
1 files changed, 15 insertions, 0 deletions
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;
}