successful completion of recovery instead.
static volatile sig_atomic_t shutdown_requested = false;
/*
* Flag set when executing a restore command, to tell SIGTERM signal handler
- * that it's safe to just proc_exit(0).
+ * that it's safe to just proc_exit.
*/
static volatile sig_atomic_t in_restore_command = false;
*/
in_restore_command = true;
if (shutdown_requested)
- proc_exit(0);
+ proc_exit(1);
/*
* Copy xlog from archival storage to XLOGDIR
* On SIGTERM, assume we have received a fast shutdown request, and exit
* cleanly. It's pure chance whether we receive the SIGTERM first, or the
* child process. If we receive it first, the signal handler will call
- * proc_exit(0), otherwise we do it here. If we or the child process
+ * proc_exit(1), otherwise we do it here. If we or the child process
* received SIGTERM for any other reason than a fast shutdown request,
* postmaster will perform an immediate shutdown when it sees us exiting
* unexpectedly.
* too.
*/
if (WTERMSIG(rc) == SIGTERM)
- proc_exit(0);
+ proc_exit(1);
signaled = WIFSIGNALED(rc) || WEXITSTATUS(rc) > 125;
* recovery.
*/
if (shutdown_requested)
- proc_exit(0);
+ proc_exit(1);
/*
* Have we reached our safe starting point? If so, we can
StartupProcShutdownHandler(SIGNAL_ARGS)
{
if (in_restore_command)
- proc_exit(0);
+ proc_exit(1);
else
shutdown_requested = true;
}
BuildFlatFiles(false);
- /* Let postmaster know that startup is finished */
- SetPostmasterSignal(PMSIGNAL_RECOVERY_COMPLETED);
-
- /* exit normally */
+ /*
+ * Exit normally. Exit code 0 tells postmaster that we completed
+ * recovery successfully.
+ */
proc_exit(0);
}
*/
if (pid == StartupPID)
{
- bool recoveryCompleted;
-
StartupPID = 0;
- /*
- * Check if the startup process completed recovery before exiting
- */
- if (CheckPostmasterSignal(PMSIGNAL_RECOVERY_COMPLETED))
- recoveryCompleted = true;
- else
- recoveryCompleted = false;
-
/*
* Unexpected exit of startup process (including FATAL exit)
* during PM_STARTUP is treated as catastrophic. There is no
* other processes running yet, so we can just exit.
*/
- if (pmState == PM_STARTUP && !recoveryCompleted)
+ if (pmState == PM_STARTUP && !EXIT_STATUS_0(exitstatus))
{
LogChildExit(LOG, _("startup process"),
pid, exitstatus);
(errmsg("aborting startup due to startup process failure")));
ExitPostmaster(1);
}
- /*
- * Any unexpected exit (including FATAL exit) of the startup
- * process is treated as a crash, except that we don't want
- * to reinitialize.
- */
- if (!EXIT_STATUS_0(exitstatus))
- {
- RecoveryError = true;
- HandleChildCrash(pid, exitstatus,
- _("startup process"));
- continue;
- }
/*
* Startup process exited in response to a shutdown request (or
- * it finished normally regardless of the shutdown request).
+ * it completed normally regardless of the shutdown request).
*/
- if (Shutdown > NoShutdown)
+ if (Shutdown > NoShutdown &&
+ (EXIT_STATUS_0(exitstatus) || EXIT_STATUS_1(exitstatus)))
{
pmState = PM_WAIT_BACKENDS;
/* PostmasterStateMachine logic does the rest */
continue;
}
/*
- * Startup process exited normally, but didn't finish recovery.
- * This can happen if someone else than postmaster kills the
- * startup process with SIGTERM. Treat it like a crash.
+ * Any unexpected exit (including FATAL exit) of the startup
+ * process is treated as a crash, except that we don't want
+ * to reinitialize.
*/
- if (!recoveryCompleted)
+ if (!EXIT_STATUS_0(exitstatus))
{
RecoveryError = true;
HandleChildCrash(pid, exitstatus,
kill(PostmasterPid, SIGUSR1);
}
-/*
- * SetPostmasterSignal - like SendPostmasterSignal, but don't wake up
- * postmaster
- *
- * This is for signals that the postmaster polls with CheckPostmasterSignal()
- * but isn't interested in processing immediately.
- */
-void
-SetPostmasterSignal(PMSignalReason reason)
-{
- /* If called in a standalone backend, do nothing */
- if (!IsUnderPostmaster)
- return;
- /* Atomically set the proper flag */
- PMSignalFlags[reason] = true;
-}
-
/*
* CheckPostmasterSignal - check to see if a particular reason has been
* signaled, and clear the signal flag. Should be called by postmaster
{
PMSIGNAL_RECOVERY_STARTED, /* recovery has started */
PMSIGNAL_RECOVERY_CONSISTENT, /* recovery has reached consistent state */
- PMSIGNAL_RECOVERY_COMPLETED, /* recovery has completed */
PMSIGNAL_PASSWORD_CHANGE, /* pg_auth file has changed */
PMSIGNAL_WAKEN_ARCHIVER, /* send a NOTIFY signal to xlog archiver */
PMSIGNAL_ROTATE_LOGFILE, /* send SIGUSR1 to syslogger to rotate logfile */
*/
extern void PMSignalInit(void);
extern void SendPostmasterSignal(PMSignalReason reason);
-extern void SetPostmasterSignal(PMSignalReason reason);
extern bool CheckPostmasterSignal(PMSignalReason reason);
extern bool PostmasterIsAlive(bool amDirectChild);