@@ -106,7 +106,6 @@ static char promote_file[MAXPGPATH];
106
106
static char logrotate_file [MAXPGPATH ];
107
107
108
108
static volatile pgpid_t postmasterPID = -1 ;
109
- static pgpid_t old_postmaster_pid = 0 ;
110
109
111
110
#ifdef WIN32
112
111
static DWORD pgctl_start_type = SERVICE_AUTO_START ;
@@ -486,17 +485,16 @@ start_postmaster(void)
486
485
487
486
/*
488
487
* Since there might be quotes to handle here, it is easier simply to pass
489
- * everything to a shell to process them.
490
- *
491
- * Since we aren't telling the shell to directly exec the postmaster,
492
- * the returned PID is a parent process, the same as on Windows.
488
+ * everything to a shell to process them. Use exec so that the postmaster
489
+ * has the same PID as the current child process.
493
490
*/
494
491
if (log_file != NULL )
495
- snprintf (cmd , MAXPGPATH , "exec < \"%s\" >> \"%s\" 2>&1; \"%s\" %s%s; echo postmaster exit status is $?" ,
496
- DEVNULL , log_file , exec_path , pgdata_opt , post_opts );
492
+ snprintf (cmd , MAXPGPATH , "exec \"%s\" %s%s < \"%s\" >> \"%s\" 2>&1" ,
493
+ exec_path , pgdata_opt , post_opts ,
494
+ DEVNULL , log_file );
497
495
else
498
- snprintf (cmd , MAXPGPATH , "exec < \"%s\" 2>&1; \"%s\" %s%s; echo postmaster exit status is $? " ,
499
- DEVNULL , exec_path , pgdata_opt , post_opts );
496
+ snprintf (cmd , MAXPGPATH , "exec \"%s\" %s%s < \"%s\" 2>&1 " ,
497
+ exec_path , pgdata_opt , post_opts , DEVNULL );
500
498
501
499
(void ) execl ("/bin/sh" , "/bin/sh" , "-c" , cmd , (char * ) NULL );
502
500
@@ -583,8 +581,12 @@ wait_for_postmaster(pgpid_t pm_pid, bool do_checkpoint)
583
581
pmpid = atol (optlines [LOCK_FILE_LINE_PID - 1 ]);
584
582
pmstart = atol (optlines [LOCK_FILE_LINE_START_TIME - 1 ]);
585
583
if (pmstart >= start_time - 2 &&
586
- /* If pid is the value we saw before starting, assume it's stale */
587
- pmpid > 0 && pmpid != old_postmaster_pid
584
+ #ifndef WIN32
585
+ pmpid == pm_pid
586
+ #else
587
+ /* Windows can only reject standalone-backend PIDs */
588
+ pmpid > 0
589
+ #endif
588
590
)
589
591
{
590
592
/*
@@ -614,7 +616,7 @@ wait_for_postmaster(pgpid_t pm_pid, bool do_checkpoint)
614
616
* Check whether the child postmaster process is still alive. This
615
617
* lets us exit early if the postmaster fails during startup.
616
618
*
617
- * We may be checking the postmaster's parent shell, but
619
+ * On Windows, we may be checking the postmaster's parent shell, but
618
620
* that's fine for this purpose.
619
621
*/
620
622
#ifndef WIN32
@@ -816,12 +818,13 @@ do_init(void)
816
818
static void
817
819
do_start (void )
818
820
{
821
+ pgpid_t old_pid = 0 ;
819
822
pgpid_t pm_pid ;
820
823
821
824
if (ctl_command != RESTART_COMMAND )
822
825
{
823
- old_postmaster_pid = get_pgpid (false);
824
- if (old_postmaster_pid != 0 )
826
+ old_pid = get_pgpid (false);
827
+ if (old_pid != 0 )
825
828
write_stderr (_ ("%s: another server might be running; "
826
829
"trying to start server anyway\n" ),
827
830
progname );
0 commit comments