4
4
*
5
5
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
6
6
*
7
- * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.13 2004/06/10 22:20:53 momjian Exp $
7
+ * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.14 2004/06/11 00:57:25 momjian Exp $
8
8
*
9
9
*-------------------------------------------------------------------------
10
10
*/
@@ -221,6 +221,41 @@ start_postmaster(void)
221
221
* to pass everything to a shell to process them.
222
222
*/
223
223
char cmd [MAXPGPATH ];
224
+ int ret ;
225
+ char * pgexec = postgres_path ;
226
+
227
+ #ifdef WIN32
228
+ /*
229
+ *Win32 has a problem with the interaction between START and system().
230
+ *There is no way to quote the executable name passed to START.
231
+ *Therefore, we put the executable name in a temporary batch file
232
+ *and run it via START.
233
+ */
234
+ char tmp [MAXPGPATH ]= "C:\\PG_CTL_XXXXXX" ,/* good location? */
235
+ bat [MAXPGPATH ];
236
+ int fd = mkstemp (tmp );
237
+
238
+ if (fd == -1 )
239
+ {
240
+ fprintf (stderr ,_ ("%s: cannot create batch file %s to start server: %s\n" ),
241
+ progname ,tmp ,strerror (errno ));
242
+ exit (1 );
243
+ }
244
+ write (fd ,postgres_path ,strlen (postgres_path ));
245
+ write (fd ,"\n" ,1 );
246
+ close (fd );
247
+
248
+ strcpy (bat ,tmp );
249
+ strcat (bat ,".BAT" );
250
+ pgexec = bat ;
251
+ if (rename (tmp ,bat )== -1 )
252
+ {
253
+ fprintf (stderr ,_ ("%s: cannot rename batch file %s to %s: %s\n" ),
254
+ progname ,tmp ,bat ,strerror (errno ));
255
+ unlink (tmp );
256
+ exit (1 );
257
+ }
258
+ #endif
224
259
225
260
if (log_file != NULL )
226
261
/* Win32 needs START /B rather than "&" */
@@ -229,16 +264,28 @@ start_postmaster(void)
229
264
#else
230
265
snprintf (cmd ,MAXPGPATH ,"%sSTART /B \"%s\" %s < \"%s\" >> \"%s\" 2>&1%s" ,
231
266
#endif
232
- SYSTEMQUOTE ,postgres_path ,post_opts ,DEVNULL ,log_file ,
267
+ SYSTEMQUOTE ,pgexec ,post_opts ,DEVNULL ,log_file ,
233
268
SYSTEMQUOTE );
234
269
else
235
270
#ifndef WIN32
236
271
snprintf (cmd ,MAXPGPATH ,"%s\"%s\" %s < \"%s\" 2>&1 &%s" ,
237
272
#else
238
273
snprintf (cmd ,MAXPGPATH ,"%sSTART /B \"%s\" %s < \"%s\" 2>&1%s" ,
239
274
#endif
240
- SYSTEMQUOTE ,postgres_path ,post_opts ,DEVNULL ,SYSTEMQUOTE );
241
- return system (cmd );
275
+ SYSTEMQUOTE ,pgexec ,post_opts ,DEVNULL ,SYSTEMQUOTE );
276
+
277
+ ret = system (cmd );
278
+
279
+ #ifdef WIN32
280
+ /* We are unlinking it while it is running, but that should be OK */
281
+ if (unlink (bat ))
282
+ {
283
+ fprintf (stderr ,_ ("%s: cannot remove batch file %s: %s\n" ),
284
+ progname ,bat ,strerror (errno ));
285
+ exit (1 );
286
+ }
287
+ #endif
288
+ return ret ;
242
289
}
243
290
244
291