summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Suzuki2013-02-18 04:35:23 +0000
committerKoichi Suzuki2013-02-18 04:35:23 +0000
commite5cc2c9b6f67562bccaacd7a4dc767408017a9ca (patch)
treefb93aa8d5ff25478321153ab056c2a3c06586ca0
parent7bd65566760b24cf773f76d50dd1a848a00ac5fd (diff)
This is a fix for -w option in gtm_ctl start, but Nikhil Sontakke.
-------->8---------------->8---------- PFA, a patch to fix "gtm_ctl -w" behavior in GIT HEAD. I also tested "-w -t nsecs" behavior and it seems to work as well. This patch can be easily be backported to 1.0 if desired. I hope all these obnoxious gtm startup issues are resolved now. Scripting was a bit painful because of these issues. --------8<----------------8<---------- modified: src/bin/gtm_ctl/gtm_ctl.c
-rw-r--r--src/bin/gtm_ctl/gtm_ctl.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/src/bin/gtm_ctl/gtm_ctl.c b/src/bin/gtm_ctl/gtm_ctl.c
index 1aa5622f16..9083856f6a 100644
--- a/src/bin/gtm_ctl/gtm_ctl.c
+++ b/src/bin/gtm_ctl/gtm_ctl.c
@@ -94,6 +94,7 @@ static void *pg_realloc(void *ptr, size_t size);
static char gtmopts_file[MAXPGPATH];
static char pid_file[MAXPGPATH];
+static char conf_file[MAXPGPATH];
static int RunAsDaemon(char *cmd);
/*
@@ -345,7 +346,7 @@ static int RunAsDaemon(char *cmd)
/*
- * Find the pgport and try a connection
+ * Find the gtm port and try a connection
*/
static bool
test_gtm_connection()
@@ -396,6 +397,54 @@ test_gtm_connection()
}
/*
+ * Search config file for a 'port' option.
+ *
+ * This parsing code isn't amazingly bright either, but it should be okay
+ * for valid port settings.
+ */
+ if (!*portstr)
+ {
+ char **optlines;
+
+ optlines = readfile(conf_file);
+ if (optlines != NULL)
+ {
+ for (; *optlines != NULL; optlines++)
+ {
+ p = *optlines;
+
+ while (isspace((unsigned char) *p))
+ p++;
+ if (strncmp(p, "port", 4) != 0)
+ continue;
+ p += 4;
+ while (isspace((unsigned char) *p))
+ p++;
+ if (*p != '=')
+ continue;
+ p++;
+ /* advance past any whitespace/quoting */
+ while (isspace((unsigned char) *p) || *p == '\'' || *p == '"')
+ p++;
+ /* find end of value (not including any ending quote/comment!) */
+ q = p;
+ while (*q &&
+ !(isspace((unsigned char) *q) ||
+ *q == '\'' || *q == '"' || *q == '#'))
+ q++;
+ /* and save the argument value */
+ strlcpy(portstr, p, Min((q - p) + 1, sizeof(portstr)));
+ /* keep looking, maybe there is another */
+ }
+ }
+ }
+
+ /* Still not found? Use compiled-in default */
+#define GTM_DEFAULT_PORT 6666
+ if (!*portstr)
+ snprintf(portstr, sizeof(portstr), "%d", GTM_DEFAULT_PORT);
+
+ /*
* We need to set a connect timeout otherwise on Windows the SCM will
* probably timeout first
* a PGXC node ID has to be set for GTM connection protocol,
@@ -1256,16 +1305,19 @@ main(int argc, char **argv)
{
snprintf(pid_file, MAXPGPATH, "%s/gtm_proxy.pid", gtm_data);
snprintf(gtmopts_file, MAXPGPATH, "%s/gtm_proxy.opts", gtm_data);
+ snprintf(conf_file, MAXPGPATH, "%s/gtm_proxy.conf", gtm_data);
}
else if (strcmp(gtm_app,"gtm") == 0)
{
snprintf(pid_file, MAXPGPATH, "%s/gtm.pid", gtm_data);
snprintf(gtmopts_file, MAXPGPATH, "%s/gtm.opts", gtm_data);
+ snprintf(conf_file, MAXPGPATH, "%s/gtm.conf", gtm_data);
}
else if (strcmp(gtm_app,"gtm_standby") == 0)
{
snprintf(pid_file, MAXPGPATH, "%s/gtm.pid", gtm_data);
snprintf(gtmopts_file, MAXPGPATH, "%s/gtm.opts", gtm_data);
+ snprintf(conf_file, MAXPGPATH, "%s/gtm.conf", gtm_data);
}
if (ctl_command==STATUS_COMMAND)