commit 562fac4: [Minor] Load hyperscan cache in controller as well
Vsevolod Stakhov
vsevolod at highsecure.ru
Sat Jun 22 12:14:51 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-06-21 13:46:01 +0100
URL: https://github.com/rspamd/rspamd/commit/562fac4c3c2045cc3a65f0bb37db0a7b2d47c6cb
[Minor] Load hyperscan cache in controller as well
---
src/controller.c | 7 +++++++
src/libserver/rspamd_control.c | 1 +
src/libserver/worker_util.c | 34 +++++++++++++++++++++++++++++++++-
src/libserver/worker_util.h | 9 +++++++++
src/rspamd_proxy.c | 1 +
src/worker.c | 32 --------------------------------
6 files changed, 51 insertions(+), 33 deletions(-)
diff --git a/src/controller.c b/src/controller.c
index f24269999..46c02d47c 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -3910,6 +3910,13 @@ start_controller_worker (struct rspamd_worker *worker)
rspamd_lua_run_postloads (ctx->cfg->lua_state, ctx->cfg, ctx->event_loop, worker);
+#ifdef WITH_HYPERSCAN
+ rspamd_control_worker_add_cmd_handler (worker,
+ RSPAMD_CONTROL_HYPERSCAN_LOADED,
+ rspamd_worker_hyperscan_ready,
+ NULL);
+#endif
+
/* Start event loop */
ev_loop (ctx->event_loop, 0);
rspamd_worker_block_signals ();
diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index 1d161f6bc..257c743ac 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -794,6 +794,7 @@ rspamd_control_handle_on_fork (struct rspamd_srv_command *cmd,
}
}
+
static void
rspamd_srv_handler (EV_P_ ev_io *w, int revents)
{
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 4072b9598..5c5d41b90 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -1294,4 +1294,36 @@ rspamd_check_termination_clause (struct rspamd_main *rspamd_main,
}
return need_refork;
-}
\ No newline at end of file
+}
+
+#ifdef WITH_HYPERSCAN
+gboolean
+rspamd_worker_hyperscan_ready (struct rspamd_main *rspamd_main,
+ struct rspamd_worker *worker, gint fd,
+ gint attached_fd,
+ struct rspamd_control_command *cmd,
+ gpointer ud)
+{
+ struct rspamd_control_reply rep;
+ struct rspamd_re_cache *cache = worker->srv->cfg->re_cache;
+
+ memset (&rep, 0, sizeof (rep));
+ rep.type = RSPAMD_CONTROL_HYPERSCAN_LOADED;
+
+ if (!rspamd_re_cache_is_hs_loaded (cache) || cmd->cmd.hs_loaded.forced) {
+ msg_info ("loading hyperscan expressions after receiving compilation "
+ "notice: %s",
+ (!rspamd_re_cache_is_hs_loaded (cache)) ?
+ "new db" : "forced update");
+ rep.reply.hs_loaded.status = rspamd_re_cache_load_hyperscan (
+ worker->srv->cfg->re_cache, cmd->cmd.hs_loaded.cache_dir);
+ }
+
+ if (write (fd, &rep, sizeof (rep)) != sizeof (rep)) {
+ msg_err ("cannot write reply to the control socket: %s",
+ strerror (errno));
+ }
+
+ return TRUE;
+}
+#endif
\ No newline at end of file
diff --git a/src/libserver/worker_util.h b/src/libserver/worker_util.h
index cafe1608f..49bbda62b 100644
--- a/src/libserver/worker_util.h
+++ b/src/libserver/worker_util.h
@@ -223,6 +223,15 @@ void rspamd_worker_throttle_accept_events (gint sock, void *data);
gboolean rspamd_check_termination_clause (struct rspamd_main *rspamd_main,
struct rspamd_worker *wrk, int status);
+#ifdef WITH_HYPERSCAN
+struct rspamd_control_command;
+gboolean rspamd_worker_hyperscan_ready (struct rspamd_main *rspamd_main,
+ struct rspamd_worker *worker, gint fd,
+ gint attached_fd,
+ struct rspamd_control_command *cmd,
+ gpointer ud);
+#endif
+
#define msg_err_main(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
rspamd_main->server_pool->tag.tagname, rspamd_main->server_pool->tag.uid, \
G_STRFUNC, \
diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c
index b14bd086a..9122df514 100644
--- a/src/rspamd_proxy.c
+++ b/src/rspamd_proxy.c
@@ -2158,6 +2158,7 @@ start_rspamd_proxy (struct rspamd_worker *worker)
/* Additional initialisation needed */
rspamd_worker_init_scanner (worker, ctx->event_loop, ctx->resolver,
&ctx->lang_det);
+
}
if (worker->srv->cfg->enable_sessions_cache) {
diff --git a/src/worker.c b/src/worker.c
index ad0782b17..446de0799 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -407,38 +407,6 @@ accept_socket (EV_P_ ev_io *w, int revents)
ctx->timeout);
}
-#ifdef WITH_HYPERSCAN
-static gboolean
-rspamd_worker_hyperscan_ready (struct rspamd_main *rspamd_main,
- struct rspamd_worker *worker, gint fd,
- gint attached_fd,
- struct rspamd_control_command *cmd,
- gpointer ud)
-{
- struct rspamd_control_reply rep;
- struct rspamd_re_cache *cache = worker->srv->cfg->re_cache;
-
- memset (&rep, 0, sizeof (rep));
- rep.type = RSPAMD_CONTROL_HYPERSCAN_LOADED;
-
- if (!rspamd_re_cache_is_hs_loaded (cache) || cmd->cmd.hs_loaded.forced) {
- msg_info ("loading hyperscan expressions after receiving compilation "
- "notice: %s",
- (!rspamd_re_cache_is_hs_loaded (cache)) ?
- "new db" : "forced update");
- rep.reply.hs_loaded.status = rspamd_re_cache_load_hyperscan (
- worker->srv->cfg->re_cache, cmd->cmd.hs_loaded.cache_dir);
- }
-
- if (write (fd, &rep, sizeof (rep)) != sizeof (rep)) {
- msg_err ("cannot write reply to the control socket: %s",
- strerror (errno));
- }
-
- return TRUE;
-}
-#endif
-
static gboolean
rspamd_worker_log_pipe_handler (struct rspamd_main *rspamd_main,
struct rspamd_worker *worker, gint fd,
More information about the Commits
mailing list