aboutsummaryrefslogtreecommitdiffstats
path: root/src/hs_helper.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-08 18:28:30 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-08 18:28:30 +0000
commit8178bc554d0abe8a6cf95755a266859c84cfd786 (patch)
treec57d283e7e32de0e27c694a2e9ce32b8c7c2a4d5 /src/hs_helper.c
parenteccc8fb354cc26ae171d43d6a25c5ffcdb861263 (diff)
downloadrspamd-8178bc554d0abe8a6cf95755a266859c84cfd786.tar.gz
rspamd-8178bc554d0abe8a6cf95755a266859c84cfd786.zip
Send notifications by hs_helper process
Diffstat (limited to 'src/hs_helper.c')
-rw-r--r--src/hs_helper.c66
1 files changed, 55 insertions, 11 deletions
diff --git a/src/hs_helper.c b/src/hs_helper.c
index 9b0f5b7c8..ab90b8334 100644
--- a/src/hs_helper.c
+++ b/src/hs_helper.c
@@ -32,6 +32,8 @@
#ifdef HAVE_GLOB_H
#include <glob.h>
+#include <libserver/rspamd_control.h>
+
#endif
static gpointer init_hs_helper (struct rspamd_config *cfg);
@@ -52,7 +54,7 @@ worker_t hs_helper_worker = {
* Worker's context
*/
struct hs_helper_ctx {
- const gchar *hs_dir;
+ gchar *hs_dir;
struct rspamd_config *cfg;
struct event_base *ev_base;
};
@@ -124,18 +126,13 @@ rspamd_hs_helper_cleanup_dir (struct hs_helper_ctx *ctx)
return ret;
}
-static void
-start_hs_helper (struct rspamd_worker *worker)
+static gboolean
+rspamd_rs_compile (struct hs_helper_ctx *ctx, struct rspamd_worker *worker)
{
- struct hs_helper_ctx *ctx = worker->ctx;
GError *err = NULL;
- struct rspamd_srv_command srv_cmd;
+ static struct rspamd_srv_command srv_cmd;
gint ncompiled;
- ctx->ev_base = rspamd_prepare_worker (worker,
- "hs_helper",
- NULL);
-
if (!rspamd_hs_helper_cleanup_dir (ctx)) {
msg_warn ("cannot cleanup cache dir '%s'", ctx->hs_dir);
}
@@ -146,13 +143,60 @@ start_hs_helper (struct rspamd_worker *worker)
msg_err ("failed to compile re cache: %e", err);
g_error_free (err);
- /* Tell main not to respawn process */
- exit (EXIT_SUCCESS);
+ return FALSE;
}
msg_info ("compiled %d regular expressions to the hyperscan tree",
ncompiled);
+ srv_cmd.type = RSPAMD_SRV_HYPERSCAN_LOADED;
+ srv_cmd.cmd.hs_loaded.cache_dir = ctx->hs_dir;
+
+ rspamd_srv_send_command (worker, ctx->ev_base, &srv_cmd, NULL, NULL);
+
+ return TRUE;
+}
+
+static gboolean
+rspamd_hs_helper_reload (struct rspamd_main *rspamd_main,
+ struct rspamd_worker *worker, gint fd,
+ struct rspamd_control_command *cmd,
+ gpointer ud)
+{
+ struct rspamd_control_reply rep;
+ struct hs_helper_ctx *ctx = ud;
+
+ msg_info ("recompiling hyperscan expressions after receiving reload command");
+ memset (&rep, 0, sizeof (rep));
+ rep.type = RSPAMD_CONTROL_RECOMPILE;
+
+ rep.reply.recompile.status = rspamd_rs_compile (ctx, worker);
+
+ if (write (fd, &rep, sizeof (rep)) != sizeof (rep)) {
+ msg_err ("cannot write reply to the control socket: %s",
+ strerror (errno));
+ }
+
+ return TRUE;
+}
+
+static void
+start_hs_helper (struct rspamd_worker *worker)
+{
+ struct hs_helper_ctx *ctx = worker->ctx;
+
+ ctx->ev_base = rspamd_prepare_worker (worker,
+ "hs_helper",
+ NULL);
+
+ if (!rspamd_rs_compile (ctx, worker)) {
+ /* Tell main not to respawn more workers */
+ exit (EXIT_SUCCESS);
+ }
+
+ rspamd_control_worker_add_cmd_handler (worker, RSPAMD_CONTROL_RECOMPILE,
+ rspamd_hs_helper_reload, ctx);
+
event_base_loop (ctx->ev_base, 0);
rspamd_worker_block_signals ();