commit a2d93ce: [Minor] Reduce log noise
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Mar 23 16:21:09 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-03-23 16:13:45 +0000
URL: https://github.com/rspamd/rspamd/commit/a2d93ce10154bef4c7def0905ae3c369d7df93a6 (HEAD -> master)
[Minor] Reduce log noise
---
src/libserver/cfg_utils.c | 3 ++-
src/libserver/re_cache.c | 40 ++++++++++++++++++++++++++++++++--------
src/libserver/re_cache.h | 6 ++++--
src/libserver/rspamd_control.c | 3 ++-
src/libserver/worker_util.c | 2 +-
5 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 23ad382b0..7a5da9807 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -891,7 +891,8 @@ rspamd_config_post_load (struct rspamd_config *cfg,
/* Try load Hypersan */
rspamd_re_cache_load_hyperscan (cfg->re_cache,
- cfg->hs_cache_dir ? cfg->hs_cache_dir : RSPAMD_DBDIR "/");
+ cfg->hs_cache_dir ? cfg->hs_cache_dir : RSPAMD_DBDIR "/",
+ true);
}
if (opts & RSPAMD_CONFIG_INIT_LIBS) {
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c
index 29edbe0f7..6dc13220b 100644
--- a/src/libserver/re_cache.c
+++ b/src/libserver/re_cache.c
@@ -2366,7 +2366,7 @@ rspamd_re_cache_is_valid_hyperscan_file (struct rspamd_re_cache *cache,
enum rspamd_hyperscan_status
rspamd_re_cache_load_hyperscan (struct rspamd_re_cache *cache,
- const char *cache_dir)
+ const char *cache_dir, bool try_load)
{
g_assert (cache != NULL);
g_assert (cache_dir != NULL);
@@ -2391,7 +2391,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, FALSE, FALSE)) {
+ if (rspamd_re_cache_is_valid_hyperscan_file (cache, path, try_load, FALSE)) {
msg_debug_re_cache ("load hyperscan database from '%s'",
re_class->hash);
@@ -2404,7 +2404,13 @@ rspamd_re_cache_load_hyperscan (struct rspamd_re_cache *cache,
map = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (map == MAP_FAILED) {
- msg_err_re_cache ("cannot mmap %s: %s", path, strerror (errno));
+ if (!try_load) {
+ msg_err_re_cache ("cannot mmap %s: %s", path, strerror (errno));
+ }
+ else {
+ msg_debug_re_cache ("cannot mmap %s: %s", path, strerror (errno));
+ }
+
close (fd);
all_valid = FALSE;
continue;
@@ -2420,8 +2426,15 @@ rspamd_re_cache_load_hyperscan (struct rspamd_re_cache *cache,
RSPAMD_HS_MAGIC_LEN + /* header */
sizeof (cache->plt) > (gsize)st.st_size) {
/* Some wrong amount of regexps */
- msg_err_re_cache ("bad number of expressions in %s: %d",
- path, n);
+ if (!try_load) {
+ msg_err_re_cache ("bad number of expressions in %s: %d",
+ path, n);
+ }
+ else {
+ msg_debug_re_cache ("bad number of expressions in %s: %d",
+ path, n);
+ }
+
munmap (map, st.st_size);
all_valid = FALSE;
continue;
@@ -2457,7 +2470,12 @@ rspamd_re_cache_load_hyperscan (struct rspamd_re_cache *cache,
if ((ret = hs_deserialize_database (p, end - p, &re_class->hs_db))
!= HS_SUCCESS) {
- msg_err_re_cache ("bad hs database in %s: %d", path, ret);
+ if (!try_load) {
+ msg_err_re_cache ("bad hs database in %s: %d", path, ret);
+ }
+ else {
+ msg_debug_re_cache ("bad hs database in %s: %d", path, ret);
+ }
munmap (map, st.st_size);
g_free (hs_ids);
g_free (hs_flags);
@@ -2501,8 +2519,14 @@ rspamd_re_cache_load_hyperscan (struct rspamd_re_cache *cache,
}
}
else {
- msg_err_re_cache ("invalid hyperscan hash file '%s'",
- path);
+ if (!try_load) {
+ msg_err_re_cache ("invalid hyperscan hash file '%s'",
+ path);
+ }
+ else {
+ msg_debug_re_cache ("invalid hyperscan hash file '%s'",
+ path);
+ }
all_valid = FALSE;
continue;
}
diff --git a/src/libserver/re_cache.h b/src/libserver/re_cache.h
index 79bcaca16..26ffa1603 100644
--- a/src/libserver/re_cache.h
+++ b/src/libserver/re_cache.h
@@ -185,14 +185,16 @@ 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, gboolean silent, gboolean try_load);
+ const char *path,
+ gboolean silent,
+ gboolean try_load);
/**
* Loads all hyperscan regexps precompiled
*/
enum rspamd_hyperscan_status rspamd_re_cache_load_hyperscan (
struct rspamd_re_cache *cache,
- const char *cache_dir);
+ const char *cache_dir, bool try_load);
/**
* Registers lua selector in the cache
diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index 1bb4ac4d6..4b2cfc733 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -909,7 +909,8 @@ rspamd_srv_handler (EV_P_ ev_io *w, int revents)
cmd.cmd.hs_loaded.forced) {
rspamd_re_cache_load_hyperscan (
srv->cfg->re_cache,
- cmd.cmd.hs_loaded.cache_dir);
+ cmd.cmd.hs_loaded.cache_dir,
+ false);
}
/* Broadcast command to all workers */
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 5796b8d7f..d97190f2b 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -1597,7 +1597,7 @@ rspamd_worker_hyperscan_ready (struct rspamd_main *rspamd_main,
(rspamd_re_cache_is_hs_loaded (cache) != RSPAMD_HYPERSCAN_LOADED_FULL) ?
"new db" : "forced update");
rep.reply.hs_loaded.status = rspamd_re_cache_load_hyperscan (
- worker->srv->cfg->re_cache, cmd->cmd.hs_loaded.cache_dir);
+ worker->srv->cfg->re_cache, cmd->cmd.hs_loaded.cache_dir, false);
}
if (write (fd, &rep, sizeof (rep)) != sizeof (rep)) {
More information about the Commits
mailing list