]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Add silent mode for hyperscan validity checks
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 9 Dec 2015 15:46:20 +0000 (15:46 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 9 Dec 2015 15:46:20 +0000 (15:46 +0000)
src/hs_helper.c
src/libserver/re_cache.c
src/libserver/re_cache.h

index ab90b83344d925c97f88d406c07bb74214664677..4d89bedf80ae947cba919470b1e73010962d1f95 100644 (file)
@@ -106,7 +106,7 @@ rspamd_hs_helper_cleanup_dir (struct hs_helper_ctx *ctx)
        if ((rc = glob (pattern, GLOB_DOOFFS, NULL, &globbuf)) == 0) {
                for (i = 0; i < globbuf.gl_pathc; i++) {
                        if (!rspamd_re_cache_is_valid_hyperscan_file (ctx->cfg->re_cache,
-                                               globbuf.gl_pathv[i])) {
+                                               globbuf.gl_pathv[i], TRUE)) {
                                if (unlink (globbuf.gl_pathv[i]) == -1) {
                                        msg_err ("cannot unlink %s: %s", globbuf.gl_pathv[i],
                                                        strerror (errno));
index e1a636c7420d13fbb43ce124b99d965f187b3ebc..4f4a1881c505aab997a630eeb9d4c392d6b46101 100644 (file)
@@ -971,7 +971,7 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
                rspamd_snprintf (path, sizeof (path), "%s%c%s.hs", cache_dir,
                                G_DIR_SEPARATOR, re_class->hash);
 
-               if (rspamd_re_cache_is_valid_hyperscan_file (cache, path)) {
+               if (rspamd_re_cache_is_valid_hyperscan_file (cache, path, TRUE)) {
                        msg_info_re_cache ("skip already valid file for re class '%s'",
                                        re_class->hash);
 
@@ -983,6 +983,7 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
                        read (fd, &n, sizeof (n));
                        total += n;
                        close (fd);
+
                        continue;
                }
 
@@ -1143,7 +1144,7 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
 
 gboolean
 rspamd_re_cache_is_valid_hyperscan_file (struct rspamd_re_cache *cache,
-               const char *path)
+               const char *path, gboolean silent)
 {
        g_assert (cache != NULL);
        g_assert (path != NULL);
@@ -1181,8 +1182,10 @@ rspamd_re_cache_is_valid_hyperscan_file (struct rspamd_re_cache *cache,
                        fd = open (path, O_RDONLY);
 
                        if (fd == -1) {
-                               msg_err_re_cache ("cannot open hyperscan cache file %s: %s",
-                                               path, strerror (errno));
+                               if (!silent) {
+                                       msg_err_re_cache ("cannot open hyperscan cache file %s: %s",
+                                                       path, strerror (errno));
+                               }
                                return FALSE;
                        }
 
@@ -1226,7 +1229,9 @@ rspamd_re_cache_is_valid_hyperscan_file (struct rspamd_re_cache *cache,
                }
        }
 
-       msg_warn_re_cache ("unknown hyperscan cache file %s", path);
+       if (!silent) {
+               msg_warn_re_cache ("unknown hyperscan cache file %s", path);
+       }
 
        return FALSE;
 #endif
@@ -1259,7 +1264,7 @@ rspamd_re_cache_load_hyperscan (struct rspamd_re_cache *cache,
                rspamd_snprintf (path, sizeof (path), "%s%c%s.hs", cache_dir,
                                G_DIR_SEPARATOR, re_class->hash);
 
-               if (rspamd_re_cache_is_valid_hyperscan_file (cache, path)) {
+               if (rspamd_re_cache_is_valid_hyperscan_file (cache, path, FALSE)) {
                        msg_debug_re_cache ("load hyperscan database from '%s'",
                                        re_class->hash);
 
index c812b8ef325c869930a4e663d2d9c4913a80c419..0fffc2d7cb4e38eba56c8bdb21f63e83769103fc 100644 (file)
@@ -136,7 +136,7 @@ gint rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
  * Returns TRUE if the specified file is valid hyperscan cache
  */
 gboolean rspamd_re_cache_is_valid_hyperscan_file (struct rspamd_re_cache *cache,
-               const char *path);
+               const char *path, gboolean silent);
 
 /**
  * Loads all hyperscan regexps precompiled