Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 10a3d19

Browse files
committed
Handle multiple double-quoted strings using Win32's system() call.
Document limitations.
1 parent 93db6f6 commit 10a3d19

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

src/bin/initdb/initdb.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Portions Copyright (c) 1994, Regents of the University of California
4040
* Portions taken from FreeBSD.
4141
*
42-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.35 2004/06/03 00:07:36 momjian Exp $
42+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.36 2004/06/10 16:35:16 momjian Exp $
4343
*
4444
*-------------------------------------------------------------------------
4545
*/
@@ -812,12 +812,12 @@ test_connections(void)
812812
for (i = 0; i < len; i++)
813813
{
814814
snprintf(cmd, sizeof(cmd),
815-
"\"%s\" -boot -x0 %s "
815+
"%s\"%s\" -boot -x0 %s "
816816
"-c shared_buffers=%d -c max_connections=%d template1 "
817-
"<%s >%s 2>&1",
818-
backend_exec, boot_options,
817+
"< \"%s\" > \"%s\" 2>&1%s",
818+
SYSTEMQUOTE, backend_exec, boot_options,
819819
conns[i] * 5, conns[i],
820-
DEVNULL, DEVNULL);
820+
DEVNULL, DEVNULL, SYSTEMQUOTE);
821821
status = system(cmd);
822822
if (status == 0)
823823
break;
@@ -848,12 +848,12 @@ test_buffers(void)
848848
for (i = 0; i < len; i++)
849849
{
850850
snprintf(cmd, sizeof(cmd),
851-
"\"%s\" -boot -x0 %s "
851+
"%s\"%s\" -boot -x0 %s "
852852
"-c shared_buffers=%d -c max_connections=%d template1 "
853-
"<%s >%s 2>&1",
854-
backend_exec, boot_options,
853+
"< \"%s\" > \"%s\" 2>&1%s",
854+
SYSTEMQUOTE, backend_exec, boot_options,
855855
bufs[i], n_connections,
856-
DEVNULL, DEVNULL);
856+
DEVNULL, DEVNULL, SYSTEMQUOTE);
857857
status = system(cmd);
858858
if (status == 0)
859859
break;

src/bin/pg_ctl/pg_ctl.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.8 2004/06/09 17:36:07 momjian Exp $
7+
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.9 2004/06/10 16:35:17 momjian Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -224,11 +224,12 @@ start_postmaster(void)
224224

225225
/* Does '&' work on Win32? */
226226
if (log_file != NULL)
227-
snprintf(cmd, MAXPGPATH, "'%s' %s < %s >> '%s' 2>&1 &",
228-
postgres_path, post_opts, DEVNULL, log_file);
227+
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s < %s >> \"%s\" 2>&1 &%s",
228+
SYSTEMQUOTE, postgres_path, post_opts, DEVNULL, log_file,
229+
SYSTEMQUOTE);
229230
else
230-
snprintf(cmd, MAXPGPATH, "'%s' %s < %s 2>&1 &",
231-
postgres_path, post_opts, DEVNULL);
231+
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s < \"%s\" 2>&1 &%s",
232+
SYSTEMQUOTE, postgres_path, post_opts, DEVNULL, SYSTEMQUOTE);
232233
return system(cmd);
233234
}
234235

src/bin/pg_dump/pg_dumpall.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.40 2004/06/09 17:37:28 momjian Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.41 2004/06/10 16:35:17 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -690,7 +690,8 @@ runPgDump(const char *dbname)
690690
const char *p;
691691
int ret;
692692

693-
appendPQExpBuffer(cmd, "'%s' %s -Fp '", pg_dump_bin, pgdumpopts->data);
693+
appendPQExpBuffer(cmd, "%s\"%s\" %s -Fp '", SYSTEMQUOTE, pg_dump_bin,
694+
pgdumpopts->data);
694695

695696
/* Shell quoting is not quite like SQL quoting, so can't use fmtId */
696697
for (p = dbname; *p; p++)
@@ -702,6 +703,7 @@ runPgDump(const char *dbname)
702703
}
703704

704705
appendPQExpBufferChar(cmd, '\'');
706+
appendStringLiteral(cmd, SYSTEMQUOTE, false);
705707

706708
if (verbose)
707709
fprintf(stderr, _("%s: running \"%s\"\n"), progname, cmd->data);

src/include/port.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.40 2004/06/03 00:07:38 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.41 2004/06/10 16:35:18 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -72,6 +72,18 @@ extern int find_other_exec(const char *argv0, const char *target,
7272
#define DEVNULL "/dev/null"
7373
#endif
7474

75+
/*
76+
* Win32 needs double quotes at the beginning and end of system()
77+
* strings. If not, it gets confused with multiple quoted strings.
78+
* It also must use double-quotes around the executable name
79+
* and any files use for redirection. Other args can use single-quotes.
80+
*/
81+
#ifdef WIN32
82+
#define SYSTEMQUOTE "\""
83+
#else
84+
#define SYSTEMQUOTE ""
85+
#endif
86+
7587
/* Portable delay handling */
7688
extern void pg_usleep(long microsec);
7789

0 commit comments

Comments
 (0)