From 77d78f6ab7cf5590930c46d6d71c7345f6422fad Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 11 Jul 2024 14:03:40 +0100 Subject: [PATCH] [Minor] Specify failure reason clearly --- src/libserver/cfg_utils.cxx | 34 +++++++++++++++++++++++++--------- src/rspamd.c | 4 ++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/libserver/cfg_utils.cxx b/src/libserver/cfg_utils.cxx index bcd26d59c..afa4009cc 100644 --- a/src/libserver/cfg_utils.cxx +++ b/src/libserver/cfg_utils.cxx @@ -57,7 +57,7 @@ #ifdef HAVE_SYS_RESOURCE_H #include #endif -#include +#include #include "libserver/composites/composites.h" #include "blas-config.h" @@ -69,6 +69,7 @@ #include "cxx/util.hxx" #include "frozen/unordered_map.h" #include "frozen/string.h" +#include "contrib/expected/expected.hpp" #include "contrib/ankerl/unordered_dense.h" #define DEFAULT_SCORE 10.0 @@ -826,8 +827,7 @@ gboolean rspamd_config_post_load(struct rspamd_config *cfg, enum rspamd_post_load_options opts) { - - auto ret = TRUE; + auto ret = tl::expected{}; rspamd_adjust_clocks_resolution(cfg); rspamd_logger_configure_modules(cfg->debug_modules); @@ -867,14 +867,15 @@ rspamd_config_post_load(struct rspamd_config *cfg, else { if (opts & RSPAMD_CONFIG_INIT_VALIDATE) { msg_err_config("no url_tld option has been specified"); - ret = FALSE; + ret = tl::make_unexpected(std::string{"no url_tld option has been specified"}); } } } else { if (access(cfg->tld_file, R_OK) == -1) { if (opts & RSPAMD_CONFIG_INIT_VALIDATE) { - ret = FALSE; + ret = tl::make_unexpected(fmt::format("cannot access tld file {}: {}", + cfg->tld_file, strerror(errno))); msg_err_config("cannot access tld file %s: %s", cfg->tld_file, strerror(errno)); } @@ -905,13 +906,17 @@ rspamd_config_post_load(struct rspamd_config *cfg, if (!rspamd_config_parse_log_format(cfg)) { msg_err_config("cannot parse log format, task logging will not be available"); if (opts & RSPAMD_CONFIG_INIT_VALIDATE) { - ret = FALSE; + ret = tl::make_unexpected(std::string{"cannot parse log format"}); } } if (opts & RSPAMD_CONFIG_INIT_SYMCACHE) { /* Init config cache */ - ret = rspamd_symcache_init(cfg->cache) && ret; + auto symcache_ret = rspamd_symcache_init(cfg->cache); + + if (!symcache_ret) { + ret = tl::make_unexpected(std::string{"symcache init failed"}); + } /* Init re cache */ rspamd_re_cache_init(cfg->re_cache, cfg); @@ -959,7 +964,11 @@ rspamd_config_post_load(struct rspamd_config *cfg, " Rspamd features will be broken"); } - ret = rspamd_symcache_validate(cfg->cache, cfg, FALSE) && ret; + auto val_ret = rspamd_symcache_validate(cfg->cache, cfg, FALSE); + + if (!val_ret) { + ret = tl::make_unexpected(std::string{"symcache validation failed"}); + } } if (opts & RSPAMD_CONFIG_INIT_POST_LOAD_LUA) { @@ -970,7 +979,14 @@ rspamd_config_post_load(struct rspamd_config *cfg, rspamd_map_preload(cfg); } - return ret; + if (ret) { + return true; + } + else { + msg_err_config("error on post-init stage: %s", ret.error().c_str()); + + return false; + } } struct rspamd_classifier_config * diff --git a/src/rspamd.c b/src/rspamd.c index 117f3b995..b6c361cb2 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -979,12 +979,16 @@ load_rspamd_config(struct rspamd_main *rspamd_main, if (init_modules) { if (!rspamd_init_filters(cfg, reload, false)) { + msg_err_main("init filters failed"); + return FALSE; } } /* Do post-load actions */ if (!rspamd_config_post_load(cfg, opts)) { + msg_err_main("post load failed"); + return FALSE; } } -- 2.39.5