11
11
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
12
12
* Portions Copyright (c) 1994, Regents of the University of California
13
13
*
14
- * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.53 2008/11/26 13:26:52 tgl Exp $
14
+ * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.54 2008/11/28 12:45:34 petere Exp $
15
15
*
16
16
*-------------------------------------------------------------------------
17
17
*/
@@ -83,10 +83,10 @@ static _stringlist *extra_tests = NULL;
83
83
static char * temp_install = NULL ;
84
84
static char * temp_config = NULL ;
85
85
static char * top_builddir = NULL ;
86
- static int temp_port = 65432 ;
87
86
static bool nolocale = false;
88
87
static char * hostname = NULL ;
89
88
static int port = -1 ;
89
+ static bool port_specified_by_user = false;
90
90
static char * dlpath = PKGLIBDIR ;
91
91
static char * user = NULL ;
92
92
static _stringlist * extraroles = NULL ;
@@ -1844,7 +1844,7 @@ help(void)
1844
1844
printf (_ ("Options for \"temp-install\" mode:\n" ));
1845
1845
printf (_ (" --no-locale use C locale\n" ));
1846
1846
printf (_ (" --top-builddir=DIR (relative) path to top level build directory\n" ));
1847
- printf (_ (" --temp- port=PORT port number to start temp postmaster on\n" ));
1847
+ printf (_ (" --port=PORT start postmaster on PORT \n" ));
1848
1848
printf (_ (" --temp-config=PATH append contents of PATH to temporary config\n" ));
1849
1849
printf (_ ("\n" ));
1850
1850
printf (_ ("Options for using an existing installation:\n" ));
@@ -1867,6 +1867,7 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
1867
1867
int i ;
1868
1868
int option_index ;
1869
1869
char buf [MAXPGPATH * 4 ];
1870
+ char buf2 [MAXPGPATH * 4 ];
1870
1871
1871
1872
static struct option long_options [] = {
1872
1873
{"help" , no_argument , NULL , 'h' },
@@ -1882,7 +1883,6 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
1882
1883
{"temp-install" , required_argument , NULL , 9 },
1883
1884
{"no-locale" , no_argument , NULL , 10 },
1884
1885
{"top-builddir" , required_argument , NULL , 11 },
1885
- {"temp-port" , required_argument , NULL , 12 },
1886
1886
{"host" , required_argument , NULL , 13 },
1887
1887
{"port" , required_argument , NULL , 14 },
1888
1888
{"user" , required_argument , NULL , 15 },
@@ -1956,20 +1956,12 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
1956
1956
case 11 :
1957
1957
top_builddir = strdup (optarg );
1958
1958
break ;
1959
- case 12 :
1960
- {
1961
- int p = atoi (optarg );
1962
-
1963
- /* Since Makefile isn't very bright, check port range */
1964
- if (p >= 1024 && p <= 65535 )
1965
- temp_port = p ;
1966
- }
1967
- break ;
1968
1959
case 13 :
1969
1960
hostname = strdup (optarg );
1970
1961
break ;
1971
1962
case 14 :
1972
1963
port = atoi (optarg );
1964
+ port_specified_by_user = true;
1973
1965
break ;
1974
1966
case 15 :
1975
1967
user = strdup (optarg );
@@ -2005,8 +1997,13 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
2005
1997
optind ++ ;
2006
1998
}
2007
1999
2008
- if (temp_install )
2009
- port = temp_port ;
2000
+ if (temp_install && !port_specified_by_user )
2001
+ /*
2002
+ * To reduce chances of interference with parallel
2003
+ * installations, use a port number starting in the private
2004
+ * range (49152-65535) calculated from the version number.
2005
+ */
2006
+ port = 0xC000 | (PG_VERSION_NUM & 0x3FFF );
2010
2007
2011
2008
inputdir = make_absolute_path (inputdir );
2012
2009
outputdir = make_absolute_path (outputdir );
@@ -2106,6 +2103,37 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
2106
2103
fclose (pg_conf );
2107
2104
}
2108
2105
2106
+ /*
2107
+ * Check if there is a postmaster running already.
2108
+ */
2109
+ snprintf (buf2 , sizeof (buf2 ),
2110
+ SYSTEMQUOTE "\"%s/psql\" -X postgres <%s 2>%s" SYSTEMQUOTE ,
2111
+ bindir , DEVNULL , DEVNULL );
2112
+
2113
+ for (i = 0 ; i < 16 ; i ++ )
2114
+ {
2115
+ if (system (buf2 ) == 0 )
2116
+ {
2117
+ char s [16 ];
2118
+
2119
+ if (port_specified_by_user || i == 15 )
2120
+ {
2121
+ fprintf (stderr , _ ("port %d apparently in use\n" ), port );
2122
+ if (!port_specified_by_user )
2123
+ fprintf (stderr , _ ("%s: could not determine an available port\n" ), progname );
2124
+ fprintf (stderr , _ ("Specify an unused port using the --port option or shut down any conflicting PostgreSQL servers.\n" ));
2125
+ exit_nicely (2 );
2126
+ }
2127
+
2128
+ fprintf (stderr , _ ("port %d apparently in use, trying %d\n" ), port , port + 1 );
2129
+ port ++ ;
2130
+ sprintf (s , "%d" , port );
2131
+ doputenv ("PGPORT" , s );
2132
+ }
2133
+ else
2134
+ break ;
2135
+ }
2136
+
2109
2137
/*
2110
2138
* Start the temp postmaster
2111
2139
*/
@@ -2129,13 +2157,10 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
2129
2157
* second or so, but Cygwin is reportedly *much* slower). Don't wait
2130
2158
* forever, however.
2131
2159
*/
2132
- snprintf (buf , sizeof (buf ),
2133
- SYSTEMQUOTE "\"%s/psql\" -X postgres <%s 2>%s" SYSTEMQUOTE ,
2134
- bindir , DEVNULL , DEVNULL );
2135
2160
for (i = 0 ; i < 60 ; i ++ )
2136
2161
{
2137
2162
/* Done if psql succeeds */
2138
- if (system (buf ) == 0 )
2163
+ if (system (buf2 ) == 0 )
2139
2164
break ;
2140
2165
2141
2166
/*
@@ -2180,7 +2205,7 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
2180
2205
postmaster_running = true;
2181
2206
2182
2207
printf (_ ("running on port %d with pid %lu\n" ),
2183
- temp_port , (unsigned long ) postmaster_pid );
2208
+ port , (unsigned long ) postmaster_pid );
2184
2209
}
2185
2210
else
2186
2211
{
0 commit comments