From 2ed5393209e6c5b67d62a2496e96be191195147d Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 26 Apr 2017 10:50:43 +0900 Subject: [PATCH] Suppress configuration file warnings if --terse is set --- config.c | 18 ++++++++++-------- config.h | 4 ++-- repmgr-client.c | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/config.c b/config.c index 205aadca..c39c405e 100644 --- a/config.c +++ b/config.c @@ -22,7 +22,7 @@ static void tablespace_list_append(t_configuration_options *options, const char static char *trim(char *s); -static void exit_with_errors(ItemList *config_errors, ItemList *config_warnings); +static void exit_with_errors(ItemList *config_errors, ItemList *config_warnings, bool terse); void @@ -38,7 +38,7 @@ progname(void) } bool -load_config(const char *config_file, bool verbose, t_configuration_options *options, char *argv0) +load_config(const char *config_file, bool verbose, bool terse, t_configuration_options *options, char *argv0) { struct stat stat_config; @@ -156,12 +156,12 @@ load_config(const char *config_file, bool verbose, t_configuration_options *opti } } - return parse_config(options); + return parse_config(options, terse); } bool -parse_config(t_configuration_options *options) +parse_config(t_configuration_options *options, bool terse) { /* Collate configuration file errors here for friendlier reporting */ static ItemList config_errors = { NULL, NULL }; @@ -172,10 +172,10 @@ parse_config(t_configuration_options *options) /* errors found - exit after printing details, and any warnings */ if (config_errors.head != NULL) { - exit_with_errors(&config_errors, &config_warnings); + exit_with_errors(&config_errors, &config_warnings, terse); } - if (config_warnings.head != NULL) + if (terse == false && config_warnings.head != NULL) { ItemListCell *cell; @@ -633,10 +633,11 @@ reload_config(t_configuration_options *orig_options) /* TODO: don't emit warnings if --terse and no errors */ static void -exit_with_errors(ItemList *config_errors, ItemList *config_warnings) +exit_with_errors(ItemList *config_errors, ItemList *config_warnings, bool terse) { ItemListCell *cell; + log_error(_("following errors were found in the configuration file:")); for (cell = config_errors->head; cell; cell = cell->next) @@ -644,7 +645,7 @@ exit_with_errors(ItemList *config_errors, ItemList *config_warnings) fprintf(stderr, " %s\n", cell->string); } - if (config_warnings->head != NULL) + if (terse == false && config_warnings->head != NULL) { puts(""); log_warning(_("the following problems were also found in the configuration file:")); @@ -653,6 +654,7 @@ exit_with_errors(ItemList *config_errors, ItemList *config_warnings) fprintf(stderr, " %s\n", cell->string); } } + exit(ERR_BAD_CONFIG); } diff --git a/config.h b/config.h index 7fc52297..9023c6af 100644 --- a/config.h +++ b/config.h @@ -129,8 +129,8 @@ typedef struct void set_progname(const char *argv0); const char *progname(void); -bool load_config(const char *config_file, bool verbose, t_configuration_options *options, char *argv0); -bool parse_config(t_configuration_options *options); +bool load_config(const char *config_file, bool verbose, bool terse, t_configuration_options *options, char *argv0); +bool parse_config(t_configuration_options *options, bool terse); bool reload_config(t_configuration_options *orig_options); diff --git a/repmgr-client.c b/repmgr-client.c index 3f0f6d97..77ee69a9 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -325,6 +325,7 @@ main(int argc, char **argv) */ config_file_parsed = load_config(runtime_options.config_file, runtime_options.verbose, + runtime_options.terse, &config_file_options, argv[0]);