Skip to content

Commit f38291e

Browse files
committed
Revert "Hack pg_ctl to report postmaster's exit status."
This reverts commit 6a5084e. We learned what we needed to know from that.
1 parent 1df5875 commit f38291e

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/bin/pg_ctl/pg_ctl.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ static char promote_file[MAXPGPATH];
106106
static char logrotate_file[MAXPGPATH];
107107

108108
static volatile pgpid_t postmasterPID = -1;
109-
static pgpid_t old_postmaster_pid = 0;
110109

111110
#ifdef WIN32
112111
static DWORD pgctl_start_type = SERVICE_AUTO_START;
@@ -486,17 +485,16 @@ start_postmaster(void)
486485

487486
/*
488487
* 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.
493490
*/
494491
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);
497495
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);
500498

501499
(void) execl("/bin/sh", "/bin/sh", "-c", cmd, (char *) NULL);
502500

@@ -583,8 +581,12 @@ wait_for_postmaster(pgpid_t pm_pid, bool do_checkpoint)
583581
pmpid = atol(optlines[LOCK_FILE_LINE_PID - 1]);
584582
pmstart = atol(optlines[LOCK_FILE_LINE_START_TIME - 1]);
585583
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
588590
)
589591
{
590592
/*
@@ -614,7 +616,7 @@ wait_for_postmaster(pgpid_t pm_pid, bool do_checkpoint)
614616
* Check whether the child postmaster process is still alive. This
615617
* lets us exit early if the postmaster fails during startup.
616618
*
617-
* We may be checking the postmaster's parent shell, but
619+
* On Windows, we may be checking the postmaster's parent shell, but
618620
* that's fine for this purpose.
619621
*/
620622
#ifndef WIN32
@@ -816,12 +818,13 @@ do_init(void)
816818
static void
817819
do_start(void)
818820
{
821+
pgpid_t old_pid = 0;
819822
pgpid_t pm_pid;
820823

821824
if (ctl_command != RESTART_COMMAND)
822825
{
823-
old_postmaster_pid = get_pgpid(false);
824-
if (old_postmaster_pid != 0)
826+
old_pid = get_pgpid(false);
827+
if (old_pid != 0)
825828
write_stderr(_("%s: another server might be running; "
826829
"trying to start server anyway\n"),
827830
progname);

0 commit comments

Comments
 (0)