diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-27 09:42:59 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-27 09:42:59 +0000 |
commit | ad664dd4c66be1f803dcdf208bb228478422f102 (patch) | |
tree | 7829b9e442219c4cf5ecb9589848b78e74fdc4af /src/libserver | |
parent | 880300de81564ce2fa4664953fb2a42be9d0bcd0 (diff) | |
download | rspamd-ad664dd4c66be1f803dcdf208bb228478422f102.tar.gz rspamd-ad664dd4c66be1f803dcdf208bb228478422f102.zip |
[Feature] Allow to explicitly set events backend
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/cfg_file.h | 4 | ||||
-rw-r--r-- | src/libserver/cfg_rcl.c | 6 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 76 | ||||
-rw-r--r-- | src/libserver/worker_util.c | 3 |
4 files changed, 88 insertions, 1 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 3ee832d5a..0aa8df36c 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -439,6 +439,7 @@ struct rspamd_config { gchar *history_file; /**< file to save rolling history */ gchar *tld_file; /**< file to load effective tld list from */ gchar *hs_cache_dir; /**< directory to save hyperscan databases */ + gchar *events_backend; /**< string representation of the events backend used */ gdouble dns_timeout; /**< timeout in milliseconds for waiting for dns reply */ guint32 dns_retransmits; /**< maximum retransmits count */ @@ -808,6 +809,9 @@ struct rspamd_action *rspamd_config_get_action (struct rspamd_config *cfg, struct rspamd_action *rspamd_config_get_action_by_type (struct rspamd_config *cfg, enum rspamd_action_type type); +int rspamd_config_ev_backend_get (struct rspamd_config *cfg); +const gchar * rspamd_config_ev_backend_to_string (int ev_backend, gboolean *effective); + #define msg_err_config(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \ cfg->cfg_pool->tag.tagname, cfg->checksum, \ G_STRFUNC, \ diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 7936c8725..bc2d50bb2 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -2207,6 +2207,12 @@ rspamd_rcl_config_init (struct rspamd_config *cfg, GHashTable *skip_sections) G_STRUCT_OFFSET (struct rspamd_config, max_blas_threads), RSPAMD_CL_FLAG_INT_32, "Maximum number of Blas threads for learning neural networks (default: 1)"); + rspamd_rcl_add_default_handler (sub, + "events_backend", + rspamd_rcl_parse_struct_string, + G_STRUCT_OFFSET (struct rspamd_config, events_backend), + 0, + "Events backend to use: kqueue, epoll, select, poll or auto (default: auto)"); /* Neighbours configuration */ rspamd_rcl_add_section_doc (&sub->subsections, "neighbours", "name", diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 98a50bea3..59840847b 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -2511,3 +2511,79 @@ rspamd_config_register_settings_id (struct rspamd_config *cfg, DL_APPEND (cfg->setting_ids, elt); } } + +int +rspamd_config_ev_backend_get (struct rspamd_config *cfg) +{ + if (cfg == NULL || cfg->events_backend == NULL) { + return ev_supported_backends (); + } + + if (strcmp (cfg->events_backend, "auto") == 0) { + return ev_supported_backends (); + } + else if (strcmp (cfg->events_backend, "epoll") == 0) { + if (ev_supported_backends () & EVBACKEND_EPOLL) { + return EVBACKEND_EPOLL; + } + else { + msg_warn_config ("unsupported events_backend: %s; defaulting to auto", + cfg->events_backend); + return ev_supported_backends (); + } + } + else if (strcmp (cfg->events_backend, "kqueue") == 0) { + if (ev_supported_backends () & EVBACKEND_KQUEUE) { + return EVBACKEND_KQUEUE; + } + else { + msg_warn_config ("unsupported events_backend: %s; defaulting to auto", + cfg->events_backend); + return ev_supported_backends (); + } + } + else if (strcmp (cfg->events_backend, "poll") == 0) { + return EVBACKEND_POLL; + } + else if (strcmp (cfg->events_backend, "select") == 0) { + return EVBACKEND_SELECT; + } + else { + msg_warn_config ("unknown events_backend: %s; defaulting to auto", + cfg->events_backend); + } + + return EVBACKEND_ALL; +} + +const gchar * +rspamd_config_ev_backend_to_string (int ev_backend, gboolean *effective) +{ +#define SET_EFFECTIVE(b) do { if ((effective) != NULL) *(effective) = b; } while(0) + + if ((ev_backend & EVBACKEND_ALL) == EVBACKEND_ALL) { + SET_EFFECTIVE (TRUE); + return "auto"; + } + + if (ev_backend & EVBACKEND_EPOLL) { + SET_EFFECTIVE (TRUE); + return "epoll"; + } + if (ev_backend & EVBACKEND_KQUEUE) { + SET_EFFECTIVE (TRUE); + return "kqueue"; + } + if (ev_backend & EVBACKEND_POLL) { + SET_EFFECTIVE (FALSE); + return "poll"; + } + if (ev_backend & EVBACKEND_SELECT) { + SET_EFFECTIVE (FALSE); + return "select"; + } + + SET_EFFECTIVE (FALSE); + return "unknown"; +#undef SET_EFFECTIVE +}
\ No newline at end of file diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index 630d1fbbd..c45060aa6 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -361,7 +361,8 @@ rspamd_prepare_worker (struct rspamd_worker *worker, const char *name, worker->signal_events = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, rspamd_sigh_free); - event_loop = ev_loop_new (EVBACKEND_ALL|EVFLAG_SIGNALFD); + event_loop = ev_loop_new (rspamd_config_ev_backend_get (worker->srv->cfg) | + EVFLAG_SIGNALFD); worker->srv->event_loop = event_loop; |