1111 * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
1212 * Portions Copyright (c) 1994, Regents of the University of California
1313 *
14- * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.4 2006/07/1916:23:17 tgl Exp $
14+ * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.5 2006/07/1917:02:59 tgl Exp $
1515 *
1616 *-------------------------------------------------------------------------
1717 */
@@ -60,6 +60,7 @@ static char *libdir = LIBDIR;
6060static char * datadir = PGSHAREDIR ;
6161static char * host_platform = HOST_TUPLE ;
6262static char * makeprog = MAKEPROG ;
63+ static char * shellprog = SHELLPROG ;
6364
6465/* currently we can use the same diff switches on all platforms */
6566static const char * basic_diff_opts = "-w" ;
@@ -630,8 +631,20 @@ spawn_process(const char *cmdline)
630631}
631632if (pid == 0 )
632633{
633- /* In child */
634- exit (system (cmdline ) ?1 :0 );
634+ /*
635+ * In child
636+ *
637+ * Instead of using system(), exec the shell directly, and tell it
638+ * to "exec" the command too. This saves two useless processes
639+ * per parallel test case.
640+ */
641+ char * cmdline2 = malloc (strlen (cmdline )+ 6 );
642+
643+ sprintf (cmdline2 ,"exec %s" ,cmdline );
644+ execl (shellprog ,shellprog ,"-c" ,cmdline2 ,NULL );
645+ fprintf (stderr ,_ ("%s: could not exec \"%s\": %s\n" ),
646+ progname ,shellprog ,strerror (errno ));
647+ exit (1 );/* not exit_nicely here... */
635648}
636649/* in parent */
637650return pid ;
@@ -648,7 +661,7 @@ spawn_process(const char *cmdline)
648661
649662if (!CreateProcess (NULL ,cmdline2 ,NULL ,NULL , FALSE,0 ,NULL ,NULL ,& si ,& pi ))
650663{
651- fprintf (stderr ,_ ("failed to start process for \"%s\": %lu\n" ),
664+ fprintf (stderr ,_ ("could not start process for \"%s\": %lu\n" ),
652665cmdline2 ,GetLastError ());
653666exit_nicely (2 );
654667}
@@ -684,7 +697,7 @@ psql_start_test(const char *testname)
684697
685698if (pid == INVALID_PID )
686699{
687- fprintf (stderr ,_ ("failed to start process for test %s\n" ),
700+ fprintf (stderr ,_ ("could not start process for test %s\n" ),
688701testname );
689702exit_nicely (2 );
690703}
@@ -918,7 +931,7 @@ wait_for_tests(PID_TYPE *pids, int num_tests)
918931
919932if (p == -1 )
920933{
921- fprintf (stderr ,_ ("failed to wait(): %s\n" ),strerror (errno ));
934+ fprintf (stderr ,_ ("could not wait(): %s\n" ),strerror (errno ));
922935exit_nicely (2 );
923936}
924937for (i = 0 ;i < num_tests ;i ++ )
@@ -938,7 +951,7 @@ wait_for_tests(PID_TYPE *pids, int num_tests)
938951r = WaitForMultipleObjects (num_tests ,pids , TRUE,INFINITE );
939952if (r != WAIT_OBJECT_0 )
940953{
941- fprintf (stderr ,_ ("failed to wait for commands to finish: %lu\n" ),
954+ fprintf (stderr ,_ ("could not wait for commands to finish: %lu\n" ),
942955GetLastError ());
943956exit_nicely (2 );
944957}
@@ -1228,7 +1241,7 @@ main(int argc, char *argv[])
12281241int c ;
12291242int i ;
12301243int option_index ;
1231- char buf [MAXPGPATH ];
1244+ char buf [MAXPGPATH * 4 ];
12321245
12331246static struct option long_options []= {
12341247{"help" ,no_argument ,NULL ,'h' },
@@ -1431,14 +1444,6 @@ main(int argc, char *argv[])
14311444exit_nicely (2 );
14321445}
14331446
1434- /*
1435- * XXX Note that because we use system() to launch the subprocess,
1436- * the returned postmaster_pid is not really the PID of the
1437- * postmaster itself; on most systems it'll be the PID of a parent
1438- * shell process. This is OK for the limited purposes we currently
1439- * use postmaster_pid for, but beware!
1440- */
1441-
14421447/*
14431448 * Wait till postmaster is able to accept connections (normally only
14441449 * a second or so, but Cygwin is reportedly *much* slower). Don't