From 00607a4168ebb1e46a23ea8a9cfb357fd7e26a5d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 25 Sep 2015 13:26:13 +0100 Subject: [PATCH] Add strict mode for configtest. --- src/libutil/logger.c | 10 ++++++++++ src/rspamadm/configtest.c | 15 +++++++++++++++ src/rspamadm/rspamadm.c | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/libutil/logger.c b/src/libutil/logger.c index 82fbf64ab..3367829a6 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -965,3 +965,13 @@ rspamd_log_nodebug (rspamd_logger_t *rspamd_log) { rspamd_log->is_debug = FALSE; } + +const guint64 * +rspamd_log_counters (rspamd_logger_t *logger) +{ + if (logger) { + return logger->log_cnt; + } + + return NULL; +} diff --git a/src/rspamadm/configtest.c b/src/rspamadm/configtest.c index 1e70f1cc0..1de694975 100644 --- a/src/rspamadm/configtest.c +++ b/src/rspamadm/configtest.c @@ -30,6 +30,7 @@ static gboolean quiet = FALSE; static gchar *config = NULL; +static gboolean strict = FALSE; extern struct rspamd_main *rspamd_main; /* Defined in modules.c */ extern module_t *modules[]; @@ -50,6 +51,8 @@ static GOptionEntry entries[] = { "Supress output", NULL}, {"config", 'c', 0, G_OPTION_ARG_STRING, &config, "Config file to test", NULL}, + {"strict", 's', 0, G_OPTION_ARG_NONE, &strict, + "Stop on any error in config", NULL}, {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL} }; @@ -104,6 +107,7 @@ rspamadm_configtest (gint argc, gchar **argv) struct rspamd_config *cfg = rspamd_main->cfg; gboolean ret = FALSE; worker_t **pworker; + const guint64 *log_cnt; context = g_option_context_new ( "keypair - create encryption keys"); @@ -167,6 +171,17 @@ rspamadm_configtest (gint argc, gchar **argv) } } + if (strict && ret) { + log_cnt = rspamd_log_counters (rspamd_main->logger); + + if (log_cnt && log_cnt[0] > 0) { + if (!quiet) { + rspamd_printf ("%L errors found\n", log_cnt[0]); + } + ret = FALSE; + } + } + if (!quiet) { rspamd_printf ("syntax %s\n", ret ? "OK" : "BAD"); } diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index 3698366ae..be35a8be2 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -53,7 +53,7 @@ static GOptionEntry entries[] = { "Enable verbose logging", NULL}, {"list-commands", 'l', 0, G_OPTION_ARG_NONE, &list_commands, "List available commands", NULL}, - {"var", 0, 0, G_OPTION_ARG_CALLBACK, rspamadm_parse_ucl_var, + {"var", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer)rspamadm_parse_ucl_var, "Redefine UCL variable", NULL}, {"help", 'h', 0, G_OPTION_ARG_NONE, &show_help, "Show help", NULL}, -- 2.39.5