From 10a3d19ad464296babb8680521dd8b1d5e086e15 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Thu, 10 Jun 2004 16:35:18 +0000 Subject: [PATCH] Handle multiple double-quoted strings using Win32's system() call. Document limitations. --- src/bin/initdb/initdb.c | 18 +++++++++--------- src/bin/pg_ctl/pg_ctl.c | 11 ++++++----- src/bin/pg_dump/pg_dumpall.c | 6 ++++-- src/include/port.h | 14 +++++++++++++- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 951d103f57..726e4658fd 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -39,7 +39,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * Portions taken from FreeBSD. * - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.35 2004/06/03 00:07:36 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.36 2004/06/10 16:35:16 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -812,12 +812,12 @@ test_connections(void) for (i = 0; i < len; i++) { snprintf(cmd, sizeof(cmd), - "\"%s\" -boot -x0 %s " + "%s\"%s\" -boot -x0 %s " "-c shared_buffers=%d -c max_connections=%d template1 " - "<%s >%s 2>&1", - backend_exec, boot_options, + "< \"%s\" > \"%s\" 2>&1%s", + SYSTEMQUOTE, backend_exec, boot_options, conns[i] * 5, conns[i], - DEVNULL, DEVNULL); + DEVNULL, DEVNULL, SYSTEMQUOTE); status = system(cmd); if (status == 0) break; @@ -848,12 +848,12 @@ test_buffers(void) for (i = 0; i < len; i++) { snprintf(cmd, sizeof(cmd), - "\"%s\" -boot -x0 %s " + "%s\"%s\" -boot -x0 %s " "-c shared_buffers=%d -c max_connections=%d template1 " - "<%s >%s 2>&1", - backend_exec, boot_options, + "< \"%s\" > \"%s\" 2>&1%s", + SYSTEMQUOTE, backend_exec, boot_options, bufs[i], n_connections, - DEVNULL, DEVNULL); + DEVNULL, DEVNULL, SYSTEMQUOTE); status = system(cmd); if (status == 0) break; diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 421b13655b..49fd26803c 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -4,7 +4,7 @@ * * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.8 2004/06/09 17:36:07 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.9 2004/06/10 16:35:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -224,11 +224,12 @@ start_postmaster(void) /* Does '&' work on Win32? */ if (log_file != NULL) - snprintf(cmd, MAXPGPATH, "'%s' %s < %s >> '%s' 2>&1 &", - postgres_path, post_opts, DEVNULL, log_file); + snprintf(cmd, MAXPGPATH, "%s\"%s\" %s < %s >> \"%s\" 2>&1 &%s", + SYSTEMQUOTE, postgres_path, post_opts, DEVNULL, log_file, + SYSTEMQUOTE); else - snprintf(cmd, MAXPGPATH, "'%s' %s < %s 2>&1 &", - postgres_path, post_opts, DEVNULL); + snprintf(cmd, MAXPGPATH, "%s\"%s\" %s < \"%s\" 2>&1 &%s", + SYSTEMQUOTE, postgres_path, post_opts, DEVNULL, SYSTEMQUOTE); return system(cmd); } diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 2a0a8dae61..11678df330 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.40 2004/06/09 17:37:28 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.41 2004/06/10 16:35:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -690,7 +690,8 @@ runPgDump(const char *dbname) const char *p; int ret; - appendPQExpBuffer(cmd, "'%s' %s -Fp '", pg_dump_bin, pgdumpopts->data); + appendPQExpBuffer(cmd, "%s\"%s\" %s -Fp '", SYSTEMQUOTE, pg_dump_bin, + pgdumpopts->data); /* Shell quoting is not quite like SQL quoting, so can't use fmtId */ for (p = dbname; *p; p++) @@ -702,6 +703,7 @@ runPgDump(const char *dbname) } appendPQExpBufferChar(cmd, '\''); + appendStringLiteral(cmd, SYSTEMQUOTE, false); if (verbose) fprintf(stderr, _("%s: running \"%s\"\n"), progname, cmd->data); diff --git a/src/include/port.h b/src/include/port.h index 7ee0a138cd..8d089a8e23 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/port.h,v 1.40 2004/06/03 00:07:38 momjian Exp $ + * $PostgreSQL: pgsql/src/include/port.h,v 1.41 2004/06/10 16:35:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -72,6 +72,18 @@ extern int find_other_exec(const char *argv0, const char *target, #define DEVNULL "/dev/null" #endif +/* + * Win32 needs double quotes at the beginning and end of system() + * strings. If not, it gets confused with multiple quoted strings. + * It also must use double-quotes around the executable name + * and any files use for redirection. Other args can use single-quotes. + */ +#ifdef WIN32 +#define SYSTEMQUOTE "\"" +#else +#define SYSTEMQUOTE "" +#endif + /* Portable delay handling */ extern void pg_usleep(long microsec);