aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-17 17:01:59 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-17 17:02:45 +0100
commitbe3414a88cc7dbd8b34f24b4121ccab5fc9aff7c (patch)
tree6fb8f489345398c7b8d00230601b4b7b1d7d7179 /src
parentf4acd9ba6f492526a2364c814c8a4704b7f8f8ce (diff)
downloadrspamd-be3414a88cc7dbd8b34f24b4121ccab5fc9aff7c.tar.gz
rspamd-be3414a88cc7dbd8b34f24b4121ccab5fc9aff7c.zip
[Feature] Execute on_load scripts with ev_base ready
Diffstat (limited to 'src')
-rw-r--r--src/controller.c3
-rw-r--r--src/fuzzy_storage.c3
-rw-r--r--src/hs_helper.c3
-rw-r--r--src/libserver/cfg_utils.c18
-rw-r--r--src/libserver/worker_util.c8
-rw-r--r--src/libserver/worker_util.h2
-rw-r--r--src/log_helper.c3
-rw-r--r--src/lua/lua_common.c32
-rw-r--r--src/lua/lua_common.h9
-rw-r--r--src/lua_worker.c3
-rw-r--r--src/rspamd_proxy.c3
-rw-r--r--src/worker.c2
12 files changed, 62 insertions, 27 deletions
diff --git a/src/controller.c b/src/controller.c
index ba6ee7561..4a1df5aff 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -2977,7 +2977,8 @@ start_controller_worker (struct rspamd_worker *worker)
ctx->ev_base = rspamd_prepare_worker (worker,
"controller",
- rspamd_controller_accept_socket);
+ rspamd_controller_accept_socket,
+ TRUE);
msec_to_tv (ctx->timeout, &ctx->io_tv);
ctx->start_time = time (NULL);
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index feac6e11b..7ee22c38c 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -2252,7 +2252,8 @@ start_fuzzy (struct rspamd_worker *worker)
ctx->ev_base = rspamd_prepare_worker (worker,
"fuzzy",
- NULL);
+ NULL,
+ FALSE);
ctx->peer_fd = -1;
ctx->worker = worker;
double_to_tv (ctx->master_timeout, &ctx->master_io_tv);
diff --git a/src/hs_helper.c b/src/hs_helper.c
index 2d3919362..90abdf0be 100644
--- a/src/hs_helper.c
+++ b/src/hs_helper.c
@@ -278,7 +278,8 @@ start_hs_helper (struct rspamd_worker *worker)
ctx->ev_base = rspamd_prepare_worker (worker,
"hs_helper",
- NULL);
+ NULL,
+ FALSE);
if (!rspamd_rs_compile (ctx, worker, FALSE)) {
/* Tell main not to respawn more workers */
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index a50986c80..f5cf5d232 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -642,8 +642,6 @@ rspamd_config_post_load (struct rspamd_config *cfg,
struct timespec ts;
#endif
struct metric *def_metric;
- struct rspamd_config_post_load_script *sc;
- struct rspamd_config **pcfg;
gboolean ret = TRUE;
#ifdef HAVE_CLOCK_GETTIME
@@ -750,22 +748,6 @@ rspamd_config_post_load (struct rspamd_config *cfg,
rspamd_config_libs (cfg->libs_ctx, cfg);
}
- /* Execute post load scripts */
- LL_FOREACH (cfg->on_load, sc) {
- lua_rawgeti (cfg->lua_state, LUA_REGISTRYINDEX, sc->cbref);
- pcfg = lua_newuserdata (cfg->lua_state, sizeof (*pcfg));
- *pcfg = cfg;
- rspamd_lua_setclass (cfg->lua_state, "rspamd{config}", -1);
-
- if (lua_pcall (cfg->lua_state, 1, 0, 0) != 0) {
- msg_err_config ("error executing post load code: %s",
- lua_tostring (cfg->lua_state, -1));
- lua_pop (cfg->lua_state, 1);
-
- return FALSE;
- }
- }
-
/* Validate cache */
if (opts & RSPAMD_CONFIG_INIT_VALIDATE) {
return rspamd_symbols_cache_validate (cfg->cache, cfg, FALSE) && ret;
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 80fec531c..056177e1c 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -257,7 +257,7 @@ rspamd_worker_init_signals (struct rspamd_worker *worker, struct event_base *bas
struct event_base *
rspamd_prepare_worker (struct rspamd_worker *worker, const char *name,
- void (*accept_handler)(int, short, void *))
+ void (*accept_handler)(int, short, void *), gboolean load_lua)
{
struct event_base *ev_base;
struct event *accept_events;
@@ -301,6 +301,12 @@ rspamd_prepare_worker (struct rspamd_worker *worker, const char *name,
}
}
+ if (load_lua) {
+ struct rspamd_config *cfg = worker->srv->cfg;
+
+ rspamd_lua_run_postloads (cfg->lua_state, cfg, ev_base);
+ }
+
return ev_base;
}
diff --git a/src/libserver/worker_util.h b/src/libserver/worker_util.h
index 9d129f140..63a18a4fe 100644
--- a/src/libserver/worker_util.h
+++ b/src/libserver/worker_util.h
@@ -40,7 +40,7 @@ struct rspamd_worker_signal_handler;
*/
struct event_base *
rspamd_prepare_worker (struct rspamd_worker *worker, const char *name,
- void (*accept_handler)(int, short, void *));
+ void (*accept_handler)(int, short, void *), gboolean load_lua);
/**
* Set special signal handler for a worker
diff --git a/src/log_helper.c b/src/log_helper.c
index 995420a41..96075ea47 100644
--- a/src/log_helper.c
+++ b/src/log_helper.c
@@ -177,7 +177,8 @@ start_log_helper (struct rspamd_worker *worker)
ctx->ev_base = rspamd_prepare_worker (worker,
"log_helper",
- NULL);
+ NULL,
+ TRUE);
ctx->cfg = worker->srv->cfg;
ctx->scripts = worker->cf->scripts;
ctx->L = ctx->cfg->lua_state;
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 0b19f49ae..efe4f45cf 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -16,6 +16,7 @@
#include "lua_common.h"
#include "lua/global_functions.lua.h"
#include "lptree.h"
+#include "utlist.h"
/* Lua module init function */
#define MODULE_INIT_FUNC "module_init"
@@ -1136,3 +1137,34 @@ lua_check_ev_base (lua_State * L, gint pos)
luaL_argcheck (L, ud != NULL, pos, "'event_base' expected");
return ud ? *((struct event_base **)ud) : NULL;
}
+
+gboolean
+rspamd_lua_run_postloads (lua_State *L, struct rspamd_config *cfg,
+ struct event_base *ev_base)
+{
+ struct rspamd_config_post_load_script *sc;
+ struct rspamd_config **pcfg;
+ struct event_base **pev_base;
+
+ /* Execute post load scripts */
+ LL_FOREACH (cfg->on_load, sc) {
+ lua_rawgeti (cfg->lua_state, LUA_REGISTRYINDEX, sc->cbref);
+ pcfg = lua_newuserdata (cfg->lua_state, sizeof (*pcfg));
+ *pcfg = cfg;
+ rspamd_lua_setclass (cfg->lua_state, "rspamd{config}", -1);
+
+ pev_base = lua_newuserdata (cfg->lua_state, sizeof (*pev_base));
+ *pev_base = ev_base;
+ rspamd_lua_setclass (cfg->lua_state, "rspamd{ev_base}", -1);
+
+ if (lua_pcall (cfg->lua_state, 2, 0, 0) != 0) {
+ msg_err_config ("error executing post load code: %s",
+ lua_tostring (cfg->lua_state, -1));
+ lua_pop (cfg->lua_state, 1);
+
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index de6965414..ae0376328 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -364,5 +364,14 @@ void lua_call_finish_script (lua_State *L, struct
rspamd_config_post_load_script *sc,
struct rspamd_task *task);
+/**
+ * Run post-load operations
+ * @param L
+ * @param cfg
+ * @param ev_base
+ */
+gboolean rspamd_lua_run_postloads (lua_State *L, struct rspamd_config *cfg,
+ struct event_base *ev_base);
+
#endif /* WITH_LUA */
#endif /* RSPAMD_LUA_H */
diff --git a/src/lua_worker.c b/src/lua_worker.c
index b74b8d422..63086670a 100644
--- a/src/lua_worker.c
+++ b/src/lua_worker.c
@@ -350,7 +350,8 @@ start_lua_worker (struct rspamd_worker *worker)
ctx->ev_base = rspamd_prepare_worker (worker,
"lua_worker",
- lua_accept_socket);
+ lua_accept_socket,
+ TRUE);
L = worker->srv->cfg->lua_state;
ctx->L = L;
diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c
index 151d1b731..0b5a5607b 100644
--- a/src/rspamd_proxy.c
+++ b/src/rspamd_proxy.c
@@ -1445,7 +1445,8 @@ start_rspamd_proxy (struct rspamd_worker *worker)
struct timeval rot_tv;
ctx->ev_base = rspamd_prepare_worker (worker, "rspamd_proxy",
- proxy_accept_socket);
+ proxy_accept_socket,
+ TRUE);
ctx->resolver = dns_resolver_init (worker->srv->logger,
ctx->ev_base,
diff --git a/src/worker.c b/src/worker.c
index 0e16922f3..03ada9ab3 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -576,7 +576,7 @@ start_worker (struct rspamd_worker *worker)
struct rspamd_worker_ctx *ctx = worker->ctx;
struct rspamd_worker_log_pipe *lp, *ltmp;
- ctx->ev_base = rspamd_prepare_worker (worker, "normal", accept_socket);
+ ctx->ev_base = rspamd_prepare_worker (worker, "normal", accept_socket, TRUE);
msec_to_tv (ctx->timeout, &ctx->io_tv);
rspamd_symbols_cache_start_refresh (worker->srv->cfg->cache, ctx->ev_base);