summaryrefslogtreecommitdiff
path: root/src/backend/postmaster
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/postmaster')
-rw-r--r--src/backend/postmaster/autovacuum.c9
-rw-r--r--src/backend/postmaster/postmaster.c36
-rw-r--r--src/backend/postmaster/startup.c22
3 files changed, 45 insertions, 22 deletions
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index dade5cc3c05..7c946804a5f 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -97,6 +97,7 @@
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
+#include "utils/timeout.h"
#include "utils/timestamp.h"
#include "utils/tqual.h"
@@ -432,7 +433,7 @@ AutoVacLauncherMain(int argc, char *argv[])
pqsignal(SIGTERM, avl_sigterm_handler);
pqsignal(SIGQUIT, quickdie);
- pqsignal(SIGALRM, handle_sig_alarm);
+ InitializeTimeouts(); /* establishes SIGALRM handler */
pqsignal(SIGPIPE, SIG_IGN);
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
@@ -482,9 +483,9 @@ AutoVacLauncherMain(int argc, char *argv[])
/* Prevents interrupts while cleaning up */
HOLD_INTERRUPTS();
- /* Forget any pending QueryCancel request */
+ /* Forget any pending QueryCancel or timeout request */
QueryCancelPending = false;
- disable_sig_alarm(true);
+ disable_all_timeouts(false);
QueryCancelPending = false; /* again in case timeout occurred */
/* Report the error to the server log */
@@ -1492,7 +1493,7 @@ AutoVacWorkerMain(int argc, char *argv[])
pqsignal(SIGINT, StatementCancelHandler);
pqsignal(SIGTERM, die);
pqsignal(SIGQUIT, quickdie);
- pqsignal(SIGALRM, handle_sig_alarm);
+ InitializeTimeouts(); /* establishes SIGALRM handler */
pqsignal(SIGPIPE, SIG_IGN);
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 45f6ac624eb..0be3230c2a5 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -112,12 +112,12 @@
#include "storage/ipc.h"
#include "storage/pg_shmem.h"
#include "storage/pmsignal.h"
-#include "storage/proc.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/datetime.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
+#include "utils/timeout.h"
#ifdef EXEC_BACKEND
#include "storage/spin.h"
@@ -337,6 +337,7 @@ static void reaper(SIGNAL_ARGS);
static void sigusr1_handler(SIGNAL_ARGS);
static void startup_die(SIGNAL_ARGS);
static void dummy_handler(SIGNAL_ARGS);
+static void StartupPacketTimeoutHandler(void);
static void CleanupBackend(int pid, int exitstatus);
static void HandleChildCrash(int pid, int exitstatus, const char *procname);
static void LogChildExit(int lev, const char *procname,
@@ -3415,7 +3416,7 @@ BackendInitialize(Port *port)
*/
pqsignal(SIGTERM, startup_die);
pqsignal(SIGQUIT, startup_die);
- pqsignal(SIGALRM, startup_die);
+ InitializeTimeouts(); /* establishes SIGALRM handler */
PG_SETMASK(&StartupBlockSig);
/*
@@ -3469,9 +3470,18 @@ BackendInitialize(Port *port)
* time delay, so that a broken client can't hog a connection
* indefinitely. PreAuthDelay and any DNS interactions above don't count
* against the time limit.
+ *
+ * Note: AuthenticationTimeout is applied here while waiting for the
+ * startup packet, and then again in InitPostgres for the duration of any
+ * authentication operations. So a hostile client could tie up the
+ * process for nearly twice AuthenticationTimeout before we kick him off.
+ *
+ * Note: because PostgresMain will call InitializeTimeouts again, the
+ * registration of STARTUP_PACKET_TIMEOUT will be lost. This is okay
+ * since we never use it again after this function.
*/
- if (!enable_sig_alarm(AuthenticationTimeout * 1000, false))
- elog(FATAL, "could not set timer for startup packet timeout");
+ RegisterTimeout(STARTUP_PACKET_TIMEOUT, StartupPacketTimeoutHandler);
+ enable_timeout_after(STARTUP_PACKET_TIMEOUT, AuthenticationTimeout * 1000);
/*
* Receive the startup packet (which might turn out to be a cancel request
@@ -3508,8 +3518,7 @@ BackendInitialize(Port *port)
/*
* Disable the timeout, and prevent SIGTERM/SIGQUIT again.
*/
- if (!disable_sig_alarm(false))
- elog(FATAL, "could not disable timer for startup packet timeout");
+ disable_timeout(STARTUP_PACKET_TIMEOUT, false);
PG_SETMASK(&BlockSig);
}
@@ -4311,8 +4320,8 @@ sigusr1_handler(SIGNAL_ARGS)
}
/*
- * Timeout or shutdown signal from postmaster while processing startup packet.
- * Cleanup and exit(1).
+ * SIGTERM or SIGQUIT while processing startup packet.
+ * Clean up and exit(1).
*
* XXX: possible future improvement: try to send a message indicating
* why we are disconnecting. Problem is to be sure we don't block while
@@ -4340,6 +4349,17 @@ dummy_handler(SIGNAL_ARGS)
}
/*
+ * Timeout while processing startup packet.
+ * As for startup_die(), we clean up and exit(1).
+ */
+static void
+StartupPacketTimeoutHandler(void)
+{
+ proc_exit(1);
+}
+
+
+/*
* RandomSalt
*/
static void
diff --git a/src/backend/postmaster/startup.c b/src/backend/postmaster/startup.c
index ed75d0958e0..ab4d1645f24 100644
--- a/src/backend/postmaster/startup.c
+++ b/src/backend/postmaster/startup.c
@@ -27,8 +27,9 @@
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/pmsignal.h"
-#include "storage/proc.h"
+#include "storage/standby.h"
#include "utils/guc.h"
+#include "utils/timeout.h"
/*
@@ -185,20 +186,12 @@ StartupProcessMain(void)
/*
* Properly accept or ignore signals the postmaster might send us.
- *
- * Note: ideally we'd not enable handle_standby_sig_alarm unless actually
- * doing hot standby, but we don't know that yet. Rely on it to not do
- * anything if it shouldn't.
*/
pqsignal(SIGHUP, StartupProcSigHupHandler); /* reload config file */
pqsignal(SIGINT, SIG_IGN); /* ignore query cancel */
pqsignal(SIGTERM, StartupProcShutdownHandler); /* request shutdown */
pqsignal(SIGQUIT, startupproc_quickdie); /* hard crash time */
- if (EnableHotStandby)
- pqsignal(SIGALRM, handle_standby_sig_alarm); /* ignored unless
- * InHotStandby */
- else
- pqsignal(SIGALRM, SIG_IGN);
+ InitializeTimeouts(); /* establishes SIGALRM handler */
pqsignal(SIGPIPE, SIG_IGN);
pqsignal(SIGUSR1, StartupProcSigUsr1Handler);
pqsignal(SIGUSR2, StartupProcTriggerHandler);
@@ -213,10 +206,19 @@ StartupProcessMain(void)
pqsignal(SIGWINCH, SIG_DFL);
/*
+ * Register timeouts needed for standby mode
+ */
+ RegisterTimeout(STANDBY_DEADLOCK_TIMEOUT, StandbyDeadLockHandler);
+ RegisterTimeout(STANDBY_TIMEOUT, StandbyTimeoutHandler);
+
+ /*
* Unblock signals (they were blocked when the postmaster forked us)
*/
PG_SETMASK(&UnBlockSig);
+ /*
+ * Do what we came for.
+ */
StartupXLOG();
/*