Browse Source

Implement hyperscan loading by receiving signal

tags/1.1.0
Vsevolod Stakhov 8 years ago
parent
commit
801cf9058e
2 changed files with 34 additions and 2 deletions
  1. 2
    2
      src/libserver/re_cache.c
  2. 32
    0
      src/worker.c

+ 2
- 2
src/libserver/re_cache.c View 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;
}

+ 32
- 0
src/worker.c View 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 ();


Loading…
Cancel
Save