diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index bb1d44ccb7..babee386c4 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -104,13 +104,6 @@ static int recvFile = -1; static TimeLineID recvFileTLI = 0; static XLogSegNo recvSegNo = 0; -/* - * Flags set by interrupt handlers of walreceiver for later service in the - * main loop. - */ -static volatile sig_atomic_t got_SIGHUP = false; -static volatile sig_atomic_t got_SIGTERM = false; - /* * LogstreamResult indicates the byte positions that we have already * written/fsynced. @@ -135,11 +128,6 @@ static void XLogWalRcvSendReply(bool force, bool requestReply); static void XLogWalRcvSendHSFeedback(bool immed); static void ProcessWalSndrMessage(XLogRecPtr walEnd, TimestampTz sendTime); -/* Signal handlers */ -static void WalRcvSigHupHandler(SIGNAL_ARGS); -static void WalRcvShutdownHandler(SIGNAL_ARGS); - - /* * Process any interrupts the walreceiver process may have received. * This should be called any time the process's latch has become set. @@ -164,7 +152,7 @@ ProcessWalRcvInterrupts(void) */ CHECK_FOR_INTERRUPTS(); - if (got_SIGTERM) + if (ShutdownRequestPending) { ereport(FATAL, (errcode(ERRCODE_ADMIN_SHUTDOWN), @@ -267,9 +255,10 @@ WalReceiverMain(void) on_shmem_exit(WalRcvDie, 0); /* Properly accept or ignore signals the postmaster might send us */ - pqsignal(SIGHUP, WalRcvSigHupHandler); /* set flag to read config file */ + pqsignal(SIGHUP, SignalHandlerForConfigReload); /* set flag to read config + * file */ pqsignal(SIGINT, SIG_IGN); - pqsignal(SIGTERM, WalRcvShutdownHandler); /* request shutdown */ + pqsignal(SIGTERM, SignalHandlerForShutdownRequest); /* request shutdown */ /* SIGQUIT handler was already set up by InitPostmasterChild */ pqsignal(SIGALRM, SIG_IGN); pqsignal(SIGPIPE, SIG_IGN); @@ -441,9 +430,9 @@ WalReceiverMain(void) /* Process any requests or signals received recently */ ProcessWalRcvInterrupts(); - if (got_SIGHUP) + if (ConfigReloadPending) { - got_SIGHUP = false; + ConfigReloadPending = false; ProcessConfigFile(PGC_SIGHUP); XLogWalRcvSendHSFeedback(true); } @@ -510,7 +499,7 @@ WalReceiverMain(void) * avoiding some system calls. */ Assert(wait_fd != PGINVALID_SOCKET); - rc = WaitLatchOrSocket(walrcv->latch, + rc = WaitLatchOrSocket(MyLatch, WL_EXIT_ON_PM_DEATH | WL_SOCKET_READABLE | WL_TIMEOUT | WL_LATCH_SET, wait_fd, @@ -518,7 +507,7 @@ WalReceiverMain(void) WAIT_EVENT_WAL_RECEIVER_MAIN); if (rc & WL_LATCH_SET) { - ResetLatch(walrcv->latch); + ResetLatch(MyLatch); ProcessWalRcvInterrupts(); if (walrcv->force_reply) @@ -669,7 +658,7 @@ WalRcvWaitForStartPosition(XLogRecPtr *startpoint, TimeLineID *startpointTLI) WakeupRecovery(); for (;;) { - ResetLatch(walrcv->latch); + ResetLatch(MyLatch); ProcessWalRcvInterrupts(); @@ -701,7 +690,7 @@ WalRcvWaitForStartPosition(XLogRecPtr *startpoint, TimeLineID *startpointTLI) } SpinLockRelease(&walrcv->mutex); - (void) WaitLatch(walrcv->latch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0, + (void) WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0, WAIT_EVENT_WAL_RECEIVER_WAIT_START); } @@ -806,28 +795,6 @@ WalRcvDie(int code, Datum arg) WakeupRecovery(); } -/* SIGHUP: set flag to re-read config file at next convenient time */ -static void -WalRcvSigHupHandler(SIGNAL_ARGS) -{ - got_SIGHUP = true; -} - - -/* SIGTERM: set flag for ProcessWalRcvInterrupts */ -static void -WalRcvShutdownHandler(SIGNAL_ARGS) -{ - int save_errno = errno; - - got_SIGTERM = true; - - if (WalRcv->latch) - SetLatch(WalRcv->latch); - - errno = save_errno; -} - /* * Accept the message from XLOG stream, and process it. */