From 1be62fa6b28f1a4fb8b5dde351b7753a97991a43 Mon Sep 17 00:00:00 2001 From: Greg Smith Date: Thu, 10 Feb 2011 18:26:44 -0500 Subject: [PATCH] Fix use of "options" broken by recent merging --- config.c | 25 ++++++++++++------------- config.h | 5 +++++ dbutils.c | 2 +- repmgr.c | 26 +++++++++++++++----------- repmgrd.c | 6 ++++-- 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/config.c b/config.c index 8e9b4c6f..0640c796 100644 --- a/config.c +++ b/config.c @@ -34,10 +34,10 @@ parse_config(const char* config_file, t_configuration_options* options) } /* Initialize */ - memset(config->cluster_name, 0, sizeof(config->cluster_name)); - config->node = -1; - memset(config->conninfo, 0, sizeof(config->conninfo)); - memset(config->rsync_options, 0, sizeof(config->rsync_options)); + memset(options->cluster_name, 0, sizeof(options->cluster_name)); + options->node = -1; + memset(options->conninfo, 0, sizeof(options->conninfo)); + memset(options->rsync_options, 0, sizeof(options->rsync_options)); /* Read next line */ while ((s = fgets (buff, sizeof buff, fp)) != NULL) @@ -51,14 +51,13 @@ parse_config(const char* config_file, t_configuration_options* options) /* Copy into correct entry in parameters struct */ if (strcmp(name, "cluster") == 0) - strncpy (config->cluster_name, value, MAXLEN); - else if (strcmp(name, "node") == 0) - config->node = atoi(value); - else if (strcmp(name, "conninfo") == 0) - strncpy (config->conninfo, value, MAXLEN); - else if (strcmp(name, "rsync_options") == 0) - strncpy (config->rsync_options, value, QUERY_STR_LEN); strncpy (options->cluster_name, value, MAXLEN); + else if (strcmp(name, "node") == 0) + options->node = atoi(value); + else if (strcmp(name, "conninfo") == 0) + strncpy (options->conninfo, value, MAXLEN); + else if (strcmp(name, "rsync_options") == 0) + strncpy (options->rsync_options, value, QUERY_STR_LEN); else if (strcmp(name, "loglevel") == 0) strncpy (options->loglevel, value, MAXLEN); else if (strcmp(name, "logfacility") == 0) @@ -71,14 +70,14 @@ parse_config(const char* config_file, t_configuration_options* options) fclose (fp); /* Check config settings */ - if (strnlen(config->cluster_name, MAXLEN)==0) + if (strnlen(options->cluster_name, MAXLEN)==0) { fprintf(stderr, "Cluster name is missing. " "Check the configuration file.\n"); exit(ERR_BAD_CONFIG); } - if (config->node == -1) + if (options->node == -1) { fprintf(stderr, "Node information is missing. " "Check the configuration file.\n"); diff --git a/config.h b/config.h index ce0b1363..472d3b82 100644 --- a/config.h +++ b/config.h @@ -17,6 +17,9 @@ * */ +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + #include "repmgr.h" typedef struct { @@ -31,3 +34,5 @@ typedef struct { void parse_config(const char* config_file, t_configuration_options* options); void parse_line(char *buff, char *name, char *value); char *trim(char *s); + +#endif diff --git a/dbutils.c b/dbutils.c index 446062e1..d547eb77 100644 --- a/dbutils.c +++ b/dbutils.c @@ -57,7 +57,7 @@ is_standby(PGconn *conn) fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - exit(ERR_NO_DB_CON); + exit(ERR_DB_QUERY); } if (strcmp(PQgetvalue(res, 0, 0), "f") == 0) diff --git a/repmgr.c b/repmgr.c index 08bca365..328c5a08 100644 --- a/repmgr.c +++ b/repmgr.c @@ -242,8 +242,8 @@ main(int argc, char **argv) /* * Read the configuration file: repmgr.conf */ - parse_config(config_file, &config); - if (config.node == -1) + parse_config(runtime_options.config_file, &options); + if (options.node == -1) { fprintf(stderr, "Node information is missing. " "Check the configuration file.\n"); @@ -1086,9 +1086,13 @@ do_standby_promote(void) /* reconnect to check we got promoted */ conn = establishDBConnection(options.conninfo, true); if (is_standby(conn)) + { log_err("\n%s: STANDBY PROMOTE failed, this is still a standby node.\n", progname); + } else - log_err("\n%s: you should REINDEX any hash indexes you have.\n", progname); + { + log_err("\n%s: STANDBY PROMOTE successful. You should REINDEX any hash indexes you have.\n", progname); + } PQfinish(conn); return; @@ -1299,17 +1303,17 @@ static int copy_remote_files(char *host, char *remote_user, char *remote_path, char *local_path, bool is_directory) { char script[QUERY_STR_LEN]; - char options[QUERY_STR_LEN]; + char rsync_flags[QUERY_STR_LEN]; char host_string[QUERY_STR_LEN]; int r; - if (strnlen(runtime_options.rsync_options, QUERY_STR_LEN) == 0) - snprintf(options, QUERY_STR_LEN, "--archive --checksum --compress --progress --rsh=ssh"); + if (strnlen(options.rsync_options, QUERY_STR_LEN) == 0) + snprintf(rsync_flags, QUERY_STR_LEN, "--archive --checksum --compress --progress --rsh=ssh"); else - strncpy(options, runtime_options.rsync_options, QUERY_STR_LEN); + strncpy(rsync_flags, options.rsync_options, QUERY_STR_LEN); if (runtime_options.force) - strcat(options, " --delete"); + strcat(rsync_flags, " --delete"); if (remote_user == NULL) { @@ -1322,14 +1326,14 @@ copy_remote_files(char *host, char *remote_user, char *remote_path, char *local_ if (is_directory) { - strcat(options, " --exclude=pg_xlog* --exclude=pg_control --exclude=*.pid"); + strcat(rsync_flags, " --exclude=pg_xlog* --exclude=pg_control --exclude=*.pid"); snprintf(script, QUERY_STR_LEN, "rsync %s %s:%s/* %s", - options, host_string, remote_path, local_path); + rsync_flags, host_string, remote_path, local_path); } else { snprintf(script, QUERY_STR_LEN, "rsync %s %s:%s %s/.", - options, host_string, remote_path, local_path); + rsync_flags, host_string, remote_path, local_path); } log_info("rsync command line: '%s'\n", script); diff --git a/repmgrd.c b/repmgrd.c index 19a4a2de..75ba9f77 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -50,8 +50,10 @@ char *config_file = DEFAULT_CONFIG_FILE; bool verbose = false; char repmgr_schema[MAXLEN]; -// should initialize with {0} to be ANSI complaint ? but this raises error with gcc -Wall -repmgr_config config = {}; +/* + * should initialize with {0} to be ANSI complaint ? but this raises + * error with gcc -Wall */ +t_configuration_options config = {}; static void help(const char* progname); static void usage(void);