summaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-10 09:14:58 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-10 09:14:58 +0000
commit02d74cf4194cfeea21d012ba92ceffcf1aae35de (patch)
treea6b02f1c9c535dea319334f12cba1d0d6c03b7d3 /src/libserver
parenta30d6a8b27946bbcd03c8b18ec46a7129363af83 (diff)
downloadrspamd-02d74cf4194cfeea21d012ba92ceffcf1aae35de.tar.gz
rspamd-02d74cf4194cfeea21d012ba92ceffcf1aae35de.zip
Allow tuning for maximum compile time for hyperscan
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/re_cache.c11
-rw-r--r--src/libserver/re_cache.h2
2 files changed, 7 insertions, 6 deletions
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c
index 5b6eb67f6..c2ca68788 100644
--- a/src/libserver/re_cache.c
+++ b/src/libserver/re_cache.c
@@ -882,17 +882,18 @@ rspamd_re_cache_type_from_string (const char *str)
#ifdef WITH_HYPERSCAN
static gboolean
rspamd_re_cache_is_finite (struct rspamd_re_cache *cache,
- rspamd_regexp_t *re, gint flags)
+ rspamd_regexp_t *re, gint flags, gdouble max_time)
{
pid_t cld;
gint status;
struct timespec ts;
hs_compile_error_t *hs_errors;
hs_database_t *test_db;
- const double wait_time = 0.1;
+ gdouble wait_time;
const gint max_tries = 10;
gint tries = 0, rc;
+ wait_time = max_time / max_tries;
/* We need to restore SIGCHLD processing */
signal (SIGCHLD, SIG_DFL);
cld = fork ();
@@ -951,7 +952,7 @@ rspamd_re_cache_is_finite (struct rspamd_re_cache *cache,
gint
rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
- const char *cache_dir,
+ const char *cache_dir, gdouble max_time,
GError **err)
{
g_assert (cache != NULL);
@@ -1039,14 +1040,14 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
&cache->plt,
&test_db,
&hs_errors) != HS_SUCCESS) {
- msg_info_re_cache ("cannot compile %s to hyperscan, try prefilter match",
+ msg_debug_re_cache ("cannot compile %s to hyperscan, try prefilter match",
rspamd_regexp_get_pattern (re));
hs_free_compile_error (hs_errors);
/* The approximation operation might take a significant
* amount of time, so we need to check if it's finite
*/
- if (rspamd_re_cache_is_finite (cache, re, hs_flags[i])) {
+ if (rspamd_re_cache_is_finite (cache, re, hs_flags[i], max_time)) {
hs_flags[i] |= HS_FLAG_PREFILTER;
hs_ids[i] = rspamd_regexp_get_cache_id (re);
hs_pats[i] = rspamd_regexp_get_pattern (re);
diff --git a/src/libserver/re_cache.h b/src/libserver/re_cache.h
index 1f0ab7c9b..429d16e0a 100644
--- a/src/libserver/re_cache.h
+++ b/src/libserver/re_cache.h
@@ -129,7 +129,7 @@ enum rspamd_re_type rspamd_re_cache_type_from_string (const char *str);
* Compile expressions to the hyperscan tree and store in the `cache_dir`
*/
gint rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
- const char *cache_dir,
+ const char *cache_dir, gdouble max_time,
GError **err);