From cd90ae359bbfacd6d0f15bf701e35ee6c9ed54eb Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 19 Jun 2018 16:17:09 +0100 Subject: [Minor] Allow to initialise stat ctx via Lua API --- src/libstat/stat_config.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/libstat') diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index f5483b3ca..904be726d 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -475,17 +475,23 @@ rspamd_stat_ctx_register_async (rspamd_stat_async_handler handler, elt->ud = d; elt->timeout = timeout; /* Enabled by default */ - elt->enabled = TRUE; - - event_set (&elt->timer_ev, -1, EV_TIMEOUT, rspamd_async_elt_on_timer, elt); - event_base_set (st_ctx->ev_base, &elt->timer_ev); - /* - * First we set timeval to zero as we want cb to be executed as - * fast as possible - */ - elt->tv.tv_sec = 0; - elt->tv.tv_usec = 0; - event_add (&elt->timer_ev, &elt->tv); + + + if (st_ctx->ev_base) { + elt->enabled = TRUE; + event_set (&elt->timer_ev, -1, EV_TIMEOUT, rspamd_async_elt_on_timer, elt); + event_base_set (st_ctx->ev_base, &elt->timer_ev); + /* + * First we set timeval to zero as we want cb to be executed as + * fast as possible + */ + elt->tv.tv_sec = 0; + elt->tv.tv_usec = 0; + event_add (&elt->timer_ev, &elt->tv); + } + else { + elt->enabled = FALSE; + } g_queue_push_tail (st_ctx->async_elts, elt); -- cgit v1.2.3