Browse Source

Add periodic checks for hyperscan files

tags/1.1.0
Vsevolod Stakhov 8 years ago
parent
commit
aac1c37798
1 changed files with 41 additions and 1 deletions
  1. 41
    1
      src/hs_helper.c

+ 41
- 1
src/hs_helper.c View File

}; };


const static gdouble default_max_time = 1.0; const static gdouble default_max_time = 1.0;
const static gdouble default_recompile_time = 60.0;


/* /*
* Worker's context * Worker's context
*/ */
struct hs_helper_ctx { struct hs_helper_ctx {
gchar *hs_dir; gchar *hs_dir;
gboolean loaded;
gdouble max_time; gdouble max_time;
gdouble recompile_time;
struct rspamd_config *cfg; struct rspamd_config *cfg;
struct event recompile_timer;
struct event_base *ev_base; struct event_base *ev_base;
}; };


ctx->cfg = cfg; ctx->cfg = cfg;
ctx->hs_dir = RSPAMD_DBDIR "/"; ctx->hs_dir = RSPAMD_DBDIR "/";
ctx->max_time = default_max_time; ctx->max_time = default_max_time;
ctx->recompile_time = default_recompile_time;


rspamd_rcl_register_worker_option (cfg, rspamd_rcl_register_worker_option (cfg,
type, type,
G_STRUCT_OFFSET (struct hs_helper_ctx, max_time), G_STRUCT_OFFSET (struct hs_helper_ctx, max_time),
RSPAMD_CL_FLAG_TIME_FLOAT, RSPAMD_CL_FLAG_TIME_FLOAT,
"Maximum time to wait for compilation of a single expression"); "Maximum time to wait for compilation of a single expression");
rspamd_rcl_register_worker_option (cfg,
type,
"recompile",
rspamd_rcl_parse_struct_time,
ctx,
G_STRUCT_OFFSET (struct hs_helper_ctx, recompile_time),
RSPAMD_CL_FLAG_TIME_FLOAT,
"Time between recompilation checks");
rspamd_rcl_register_worker_option (cfg, rspamd_rcl_register_worker_option (cfg,
type, type,
"timeout", "timeout",
* Do not send notification unless all other workers are started * Do not send notification unless all other workers are started
* XXX: now we just sleep for 5 seconds to ensure that * XXX: now we just sleep for 5 seconds to ensure that
*/ */
sleep (5);
if (!ctx->loaded) {
sleep (5);
ctx->loaded = TRUE;
}


srv_cmd.type = RSPAMD_SRV_HYPERSCAN_LOADED; srv_cmd.type = RSPAMD_SRV_HYPERSCAN_LOADED;
srv_cmd.cmd.hs_loaded.cache_dir = ctx->hs_dir; srv_cmd.cmd.hs_loaded.cache_dir = ctx->hs_dir;
return TRUE; return TRUE;
} }


static void
rspamd_hs_helper_timer (gint fd, short what, gpointer ud)
{
struct rspamd_worker *worker = ud;
struct hs_helper_ctx *ctx;
struct timeval tv;
double tim;

ctx = worker->ctx;
tim = rspamd_time_jitter (ctx->recompile_time, 0);
double_to_tv (tim, &tv);
event_del (&ctx->recompile_timer);
rspamd_rs_compile (ctx, worker, FALSE);
event_add (&ctx->recompile_timer, &tv);
}

static void static void
start_hs_helper (struct rspamd_worker *worker) start_hs_helper (struct rspamd_worker *worker)
{ {
struct hs_helper_ctx *ctx = worker->ctx; struct hs_helper_ctx *ctx = worker->ctx;
struct timeval tv;
double tim;


ctx->ev_base = rspamd_prepare_worker (worker, ctx->ev_base = rspamd_prepare_worker (worker,
"hs_helper", "hs_helper",
rspamd_control_worker_add_cmd_handler (worker, RSPAMD_CONTROL_RECOMPILE, rspamd_control_worker_add_cmd_handler (worker, RSPAMD_CONTROL_RECOMPILE,
rspamd_hs_helper_reload, ctx); rspamd_hs_helper_reload, ctx);


event_set (&ctx->recompile_timer, -1, EV_TIMEOUT, rspamd_hs_helper_timer,
worker);
event_base_set (ctx->ev_base, &ctx->recompile_timer);
tim = rspamd_time_jitter (ctx->recompile_time, 0);
double_to_tv (tim, &tv);
event_add (&ctx->recompile_timer, &tv);
event_base_loop (ctx->ev_base, 0); event_base_loop (ctx->ev_base, 0);
rspamd_worker_block_signals (); rspamd_worker_block_signals ();



Loading…
Cancel
Save