From: Bruce Momjian Date: Thu, 26 Jun 2008 02:47:19 +0000 (+0000) Subject: Fix 'pg_ctl restart' to preserve command-line arguments. X-Git-Tag: recoveryinfrav9~903 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=fbceb0d471c21783c1b101d85afa76a508d2ad1c;p=users%2Fsimon%2Fpostgres.git Fix 'pg_ctl restart' to preserve command-line arguments. --- diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index eeaba2e226..0f57ab5e04 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -4184,7 +4184,7 @@ CreateOptsFile(int argc, char *argv[], char *fullprogname) fprintf(fp, "%s", fullprogname); for (i = 1; i < argc; i++) - fprintf(fp, " " SYSTEMQUOTE "%s" SYSTEMQUOTE, argv[i]); + fprintf(fp, " \"%s\"", argv[i]); fputs("\n", fp); if (fclose(fp)) diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 424c47b10f..c45ab4de8a 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -573,11 +573,11 @@ read_post_opts(void) { if (post_opts == NULL) { - char **optlines; - post_opts = ""; /* defatult */ if (ctl_command == RESTART_COMMAND) { + char **optlines; + optlines = readfile(postopts_file); if (optlines == NULL) { @@ -593,20 +593,26 @@ read_post_opts(void) else { int len; - char *optline = NULL; + char *optline; char *arg1; optline = optlines[0]; + /* trim off line endings */ len = strcspn(optline, "\r\n"); optline[len] = '\0'; - arg1 = strchr(optline, *SYSTEMQUOTE); - if (arg1 == NULL || arg1 == optline) - post_opts = ""; - else + for (arg1 = optline; *arg1; arg1++) { - *(arg1 - 1) = '\0'; /* this should be a space */ - post_opts = arg1; + /* + * Are we at the first option, as defined by space, + * double-quote, and a dash? + */ + if (*arg1 == ' ' && *(arg1+1) == '"' && *(arg1+2) == '-') + { + *arg1 = '\0'; /* terminate so we get only program name */ + post_opts = arg1 + 1; /* point past whitespace */ + break; + } } if (postgres_path != NULL) postgres_path = optline;