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/19 16:23:17 tgl Exp $
14+ * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.5 2006/07/19 17: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 }
631632 if (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 */
637650 return pid ;
@@ -648,7 +661,7 @@ spawn_process(const char *cmdline)
648661
649662 if (!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" ),
652665 cmdline2 , GetLastError ());
653666 exit_nicely (2 );
654667 }
@@ -684,7 +697,7 @@ psql_start_test(const char *testname)
684697
685698 if (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" ),
688701 testname );
689702 exit_nicely (2 );
690703 }
@@ -918,7 +931,7 @@ wait_for_tests(PID_TYPE *pids, int num_tests)
918931
919932 if (p == -1 )
920933 {
921- fprintf (stderr , _ ("failed to wait(): %s\n" ), strerror (errno ));
934+ fprintf (stderr , _ ("could not wait(): %s\n" ), strerror (errno ));
922935 exit_nicely (2 );
923936 }
924937 for (i = 0 ; i < num_tests ; i ++ )
@@ -938,7 +951,7 @@ wait_for_tests(PID_TYPE *pids, int num_tests)
938951 r = WaitForMultipleObjects (num_tests , pids , TRUE, INFINITE );
939952 if (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" ),
942955 GetLastError ());
943956 exit_nicely (2 );
944957 }
@@ -1228,7 +1241,7 @@ main(int argc, char *argv[])
12281241 int c ;
12291242 int i ;
12301243 int option_index ;
1231- char buf [MAXPGPATH ];
1244+ char buf [MAXPGPATH * 4 ];
12321245
12331246 static struct option long_options [] = {
12341247 {"help" , no_argument , NULL , 'h' },
@@ -1431,14 +1444,6 @@ main(int argc, char *argv[])
14311444 exit_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
0 commit comments