]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Implement hyperscan loading by receiving signal
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 8 Dec 2015 18:35:05 +0000 (18:35 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 8 Dec 2015 18:35:05 +0000 (18:35 +0000)
src/libserver/re_cache.c
src/worker.c

index 3e67fd9ed4a1365e3d4997bb4c6fb2c722879891..2e348fe644e0fab158f12688e36523e7def925c8 100644 (file)
@@ -1121,7 +1121,7 @@ rspamd_re_cache_load_hyperscan (struct rspamd_re_cache *cache,
                                G_DIR_SEPARATOR, re_class->hash);
 
                if (rspamd_re_cache_is_valid_hyperscan_file (cache, path)) {
-                       msg_info_re_cache ("skip already valid file for re class '%s'",
+                       msg_debug_re_cache ("load hyperscan database from '%s'",
                                        re_class->hash);
 
                        fd = open (path, O_RDONLY);
@@ -1181,7 +1181,7 @@ rspamd_re_cache_load_hyperscan (struct rspamd_re_cache *cache,
                         * specify that they should be matched using hyperscan
                         */
                        for (i = 0; i < n; i ++) {
-                               g_assert ((gint)cache->re->len < hs_ids[i] && hs_ids[i] >= 0);
+                               g_assert ((gint)cache->re->len > hs_ids[i] && hs_ids[i] >= 0);
                                elt = g_ptr_array_index (cache->re, hs_ids[i]);
                                elt->match_type = RSPAMD_RE_CACHE_HYPERSCAN;
                        }
index e6362484823764715f694efc2214bf7cf2d52aa8..2598be415a5ff280d1d2ffcc5ccd49b3c51bf026 100644 (file)
@@ -26,6 +26,7 @@
  * Rspamd worker implementation
  */
 
+#include <libserver/rspamd_control.h>
 #include "config.h"
 #include "libutil/util.h"
 #include "libutil/map.h"
@@ -39,6 +40,7 @@
 #include "keypairs_cache.h"
 #include "libstat/stat_api.h"
 #include "libserver/worker_util.h"
+#include "libserver/rspamd_control.h"
 
 #include "lua/lua_common.h"
 
@@ -280,6 +282,31 @@ accept_socket (gint fd, short what, void *arg)
                ctx->ev_base);
 }
 
+#ifdef WITH_HYPERSCAN
+static gboolean
+rspamd_worker_hyperscan_ready (struct rspamd_main *rspamd_main,
+               struct rspamd_worker *worker, gint fd,
+               struct rspamd_control_command *cmd,
+               gpointer ud)
+{
+       struct rspamd_control_reply rep;
+
+       msg_info ("loading hyperscan expressions after receiving compilation notice");
+       memset (&rep, 0, sizeof (rep));
+       rep.type = RSPAMD_CONTROL_HYPERSCAN_LOADED;
+
+       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
+
 gpointer
 init_worker (struct rspamd_config *cfg)
 {
@@ -359,6 +386,11 @@ start_worker (struct rspamd_worker *worker)
        ctx->keys_cache = rspamd_keypair_cache_new (256);
        rspamd_stat_init (worker->srv->cfg);
 
+#ifdef WITH_HYPERSCAN
+       rspamd_control_worker_add_cmd_handler (worker, RSPAMD_CONTROL_HYPERSCAN_LOADED,
+                       rspamd_worker_hyperscan_ready, ctx);
+#endif
+
        event_base_loop (ctx->ev_base, 0);
        rspamd_worker_block_signals ();