Fix use of "options" broken by recent merging

This commit is contained in:
Greg Smith
2011-02-10 18:26:44 -05:00
parent b62ad056f1
commit 1be62fa6b2
5 changed files with 37 additions and 27 deletions

View File

@@ -34,10 +34,10 @@ parse_config(const char* config_file, t_configuration_options* options)
} }
/* Initialize */ /* Initialize */
memset(config->cluster_name, 0, sizeof(config->cluster_name)); memset(options->cluster_name, 0, sizeof(options->cluster_name));
config->node = -1; options->node = -1;
memset(config->conninfo, 0, sizeof(config->conninfo)); memset(options->conninfo, 0, sizeof(options->conninfo));
memset(config->rsync_options, 0, sizeof(config->rsync_options)); memset(options->rsync_options, 0, sizeof(options->rsync_options));
/* Read next line */ /* Read next line */
while ((s = fgets (buff, sizeof buff, fp)) != NULL) 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 */ /* Copy into correct entry in parameters struct */
if (strcmp(name, "cluster") == 0) 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); 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) else if (strcmp(name, "loglevel") == 0)
strncpy (options->loglevel, value, MAXLEN); strncpy (options->loglevel, value, MAXLEN);
else if (strcmp(name, "logfacility") == 0) else if (strcmp(name, "logfacility") == 0)
@@ -71,14 +70,14 @@ parse_config(const char* config_file, t_configuration_options* options)
fclose (fp); fclose (fp);
/* Check config settings */ /* Check config settings */
if (strnlen(config->cluster_name, MAXLEN)==0) if (strnlen(options->cluster_name, MAXLEN)==0)
{ {
fprintf(stderr, "Cluster name is missing. " fprintf(stderr, "Cluster name is missing. "
"Check the configuration file.\n"); "Check the configuration file.\n");
exit(ERR_BAD_CONFIG); exit(ERR_BAD_CONFIG);
} }
if (config->node == -1) if (options->node == -1)
{ {
fprintf(stderr, "Node information is missing. " fprintf(stderr, "Node information is missing. "
"Check the configuration file.\n"); "Check the configuration file.\n");

View File

@@ -17,6 +17,9 @@
* *
*/ */
#ifndef _CONFIG_H_
#define _CONFIG_H_
#include "repmgr.h" #include "repmgr.h"
typedef struct { typedef struct {
@@ -31,3 +34,5 @@ typedef struct {
void parse_config(const char* config_file, t_configuration_options* options); void parse_config(const char* config_file, t_configuration_options* options);
void parse_line(char *buff, char *name, char *value); void parse_line(char *buff, char *name, char *value);
char *trim(char *s); char *trim(char *s);
#endif

View File

@@ -57,7 +57,7 @@ is_standby(PGconn *conn)
fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn)); fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn));
PQclear(res); PQclear(res);
PQfinish(conn); PQfinish(conn);
exit(ERR_NO_DB_CON); exit(ERR_DB_QUERY);
} }
if (strcmp(PQgetvalue(res, 0, 0), "f") == 0) if (strcmp(PQgetvalue(res, 0, 0), "f") == 0)

View File

@@ -242,8 +242,8 @@ main(int argc, char **argv)
/* /*
* Read the configuration file: repmgr.conf * Read the configuration file: repmgr.conf
*/ */
parse_config(config_file, &config); parse_config(runtime_options.config_file, &options);
if (config.node == -1) if (options.node == -1)
{ {
fprintf(stderr, "Node information is missing. " fprintf(stderr, "Node information is missing. "
"Check the configuration file.\n"); "Check the configuration file.\n");
@@ -1086,9 +1086,13 @@ do_standby_promote(void)
/* reconnect to check we got promoted */ /* reconnect to check we got promoted */
conn = establishDBConnection(options.conninfo, true); conn = establishDBConnection(options.conninfo, true);
if (is_standby(conn)) if (is_standby(conn))
{
log_err("\n%s: STANDBY PROMOTE failed, this is still a standby node.\n", progname); log_err("\n%s: STANDBY PROMOTE failed, this is still a standby node.\n", progname);
}
else 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); PQfinish(conn);
return; return;
@@ -1299,17 +1303,17 @@ static int
copy_remote_files(char *host, char *remote_user, char *remote_path, char *local_path, bool is_directory) copy_remote_files(char *host, char *remote_user, char *remote_path, char *local_path, bool is_directory)
{ {
char script[QUERY_STR_LEN]; char script[QUERY_STR_LEN];
char options[QUERY_STR_LEN]; char rsync_flags[QUERY_STR_LEN];
char host_string[QUERY_STR_LEN]; char host_string[QUERY_STR_LEN];
int r; int r;
if (strnlen(runtime_options.rsync_options, QUERY_STR_LEN) == 0) if (strnlen(options.rsync_options, QUERY_STR_LEN) == 0)
snprintf(options, QUERY_STR_LEN, "--archive --checksum --compress --progress --rsh=ssh"); snprintf(rsync_flags, QUERY_STR_LEN, "--archive --checksum --compress --progress --rsh=ssh");
else else
strncpy(options, runtime_options.rsync_options, QUERY_STR_LEN); strncpy(rsync_flags, options.rsync_options, QUERY_STR_LEN);
if (runtime_options.force) if (runtime_options.force)
strcat(options, " --delete"); strcat(rsync_flags, " --delete");
if (remote_user == NULL) if (remote_user == NULL)
{ {
@@ -1322,14 +1326,14 @@ copy_remote_files(char *host, char *remote_user, char *remote_path, char *local_
if (is_directory) 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", 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 else
{ {
snprintf(script, QUERY_STR_LEN, "rsync %s %s:%s %s/.", 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); log_info("rsync command line: '%s'\n", script);

View File

@@ -50,8 +50,10 @@ char *config_file = DEFAULT_CONFIG_FILE;
bool verbose = false; bool verbose = false;
char repmgr_schema[MAXLEN]; 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 help(const char* progname);
static void usage(void); static void usage(void);