diff options
author | Pavan Deolasee | 2014-12-15 10:48:44 +0000 |
---|---|---|
committer | Pavan Deolasee | 2015-04-15 05:46:41 +0000 |
commit | b2c217ee12b4db8020c3ad1b9de6ba98b5633dda (patch) | |
tree | bf64a42dd7e3e6ace2fd0143588bd8d527d0c60d | |
parent | 50fbbefbd08adc7419f803c004d33236db80c595 (diff) |
Do not read prototype config file when dealing with user specified conf file
pgxc_ctl utility was picking up parameters from the default configuration when
such parameters are not defined in the conf file. This creates all sorts of
unintentional side effects. Fix that by skipping default conf while dealing
with a specified conf file.
We had got this wrong in the first attempt. Hopefully, its better now
-rw-r--r-- | contrib/pgxc_ctl/bash_handler.c | 9 | ||||
-rw-r--r-- | contrib/pgxc_ctl/bash_handler.h | 2 | ||||
-rw-r--r-- | contrib/pgxc_ctl/pgxc_ctl.c | 17 |
3 files changed, 22 insertions, 6 deletions
diff --git a/contrib/pgxc_ctl/bash_handler.c b/contrib/pgxc_ctl/bash_handler.c index 1cae6b46b3..c4aa1e27f1 100644 --- a/contrib/pgxc_ctl/bash_handler.c +++ b/contrib/pgxc_ctl/bash_handler.c @@ -24,7 +24,7 @@ extern char *pgxc_ctl_conf_prototype[]; /* * Install bash script. */ -void install_pgxc_ctl_bash(char *path) +void install_pgxc_ctl_bash(char *path, int read_prototype) { char cmd[1024]; FILE *pgxc_ctl_bash = fopen(path, "w"); @@ -35,8 +35,11 @@ void install_pgxc_ctl_bash(char *path) { elog(ERROR, "ERROR: Could not open pgxc_ctl bash script, %s, %s\n", path, strerror(errno)); } - for (i=0; pgxc_ctl_conf_prototype[i]; i++) - fprintf(pgxc_ctl_bash, "%s\n", pgxc_ctl_conf_prototype[i]); + if (read_prototype) + { + for (i=0; pgxc_ctl_conf_prototype[i]; i++) + fprintf(pgxc_ctl_bash, "%s\n", pgxc_ctl_conf_prototype[i]); + } for (i=0; pgxc_ctl_bash_script[i]; i++) fprintf(pgxc_ctl_bash, "%s\n", pgxc_ctl_bash_script[i]); fclose(pgxc_ctl_bash); diff --git a/contrib/pgxc_ctl/bash_handler.h b/contrib/pgxc_ctl/bash_handler.h index c16638b7a3..c0494137bd 100644 --- a/contrib/pgxc_ctl/bash_handler.h +++ b/contrib/pgxc_ctl/bash_handler.h @@ -11,7 +11,7 @@ #ifndef BASH_HANDLER_H #define BASH_HANDLER_H -void install_pgxc_ctl_bash(char *path); +void install_pgxc_ctl_bash(char *path, int read_prototype); void read_config_file(char *path, char *conf); void uninstall_pgxc_ctl_bash(char *path); diff --git a/contrib/pgxc_ctl/pgxc_ctl.c b/contrib/pgxc_ctl/pgxc_ctl.c index d09a2bbd83..81ddd298f2 100644 --- a/contrib/pgxc_ctl/pgxc_ctl.c +++ b/contrib/pgxc_ctl/pgxc_ctl.c @@ -209,6 +209,9 @@ static void build_configuration_path(char *path) elog(ERROR, "ERROR: Default configuration file \"%s\" was not found while no configuration file was specified\n", pgxc_ctl_config_path); pgxc_ctl_config_path[0] = 0; + + /* Read prototype config file if no default config file found */ + install_pgxc_ctl_bash(pgxc_ctl_bash_path, true); return; } } @@ -231,6 +234,16 @@ static void build_configuration_path(char *path) else elog(ERROR, "ERROR: File \"%s\" not found or not a regular file", pgxc_ctl_config_path); + /* Read prototype config file if no config file found */ + install_pgxc_ctl_bash(pgxc_ctl_bash_path, true); + } + else + { + /* + * Since we found a valid config file, don't read the prototype config + * file as it may conflict with the user conf file + */ + install_pgxc_ctl_bash(pgxc_ctl_bash_path, false); } return; } @@ -241,12 +254,12 @@ static void read_configuration(void) FILE *conf; char cmd[MAXPATH+1]; - install_pgxc_ctl_bash(pgxc_ctl_bash_path); if (pgxc_ctl_config_path[0]) snprintf(cmd, MAXPATH, "%s --home %s --configuration %s", pgxc_ctl_bash_path, pgxc_ctl_home, pgxc_ctl_config_path); else snprintf(cmd, MAXPATH, "%s --home %s", pgxc_ctl_bash_path, pgxc_ctl_home); + elog(NOTICE, "Reading configuration using %s\n", cmd); conf = popen(cmd, "r"); if (conf == NULL) @@ -267,7 +280,7 @@ static void prepare_pgxc_ctl_bash(char *path) rc = stat(path, &buf); if (rc) - install_pgxc_ctl_bash(path); + install_pgxc_ctl_bash(path, false); else if (S_ISREG(buf.st_mode)) return; |