aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/init/miscinit.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-09-16 16:04:36 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-09-16 16:04:36 -0400
commit44fc6e259b799f9924de206eeddc1b1fcbcd172f (patch)
tree7a3dcb4d2e006b4e1b6ee0597d1420ee0557ab28 /src/backend/utils/init/miscinit.c
parent2000b6c10aa6777929f1a8b613f30426bb90f849 (diff)
downloadpostgresql-44fc6e259b799f9924de206eeddc1b1fcbcd172f.tar.gz
postgresql-44fc6e259b799f9924de206eeddc1b1fcbcd172f.zip
Centralize setup of SIGQUIT handling for postmaster child processes.
We decided that the policy established in commit 7634bd4f6 for the bgwriter, checkpointer, walwriter, and walreceiver processes, namely that they should accept SIGQUIT at all times, really ought to apply uniformly to all postmaster children. Therefore, get rid of the duplicative and inconsistent per-process code for establishing that signal handler and removing SIGQUIT from BlockSig. Instead, make InitPostmasterChild do it. The handler set up by InitPostmasterChild is SignalHandlerForCrashExit, which just summarily does _exit(2). In interactive backends, we almost immediately replace that with quickdie, since we would prefer to try to tell the client that we're dying. However, this patch is changing the behavior of autovacuum (both launcher and workers), as well as walsenders. Those processes formerly also used quickdie, but AFAICS that was just mindless copy-and-paste: they don't have any interactive client that's likely to benefit from being told this. The stats collector continues to be an outlier, in that it thinks SIGQUIT means normal exit. That should probably be changed for consistency, but there's another patch set where that's being dealt with, so I didn't do so here. Discussion: https://postgr.es/m/644875.1599933441@sss.pgh.pa.us
Diffstat (limited to 'src/backend/utils/init/miscinit.c')
-rw-r--r--src/backend/utils/init/miscinit.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index cf8f9579c34..ed2ab4b5b29 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -32,10 +32,12 @@
#include "catalog/pg_authid.h"
#include "common/file_perm.h"
#include "libpq/libpq.h"
+#include "libpq/pqsignal.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "postmaster/autovacuum.h"
+#include "postmaster/interrupt.h"
#include "postmaster/postmaster.h"
#include "storage/fd.h"
#include "storage/ipc.h"
@@ -133,6 +135,23 @@ InitPostmasterChild(void)
elog(FATAL, "setsid() failed: %m");
#endif
+ /* In EXEC_BACKEND case we will not have inherited BlockSig etc values */
+#ifdef EXEC_BACKEND
+ pqinitmask();
+#endif
+
+ /*
+ * Every postmaster child process is expected to respond promptly to
+ * SIGQUIT at all times. Therefore we centrally remove SIGQUIT from
+ * BlockSig and install a suitable signal handler. (Client-facing
+ * processes may choose to replace this default choice of handler with
+ * quickdie().) All other blockable signals remain blocked for now.
+ */
+ pqsignal(SIGQUIT, SignalHandlerForCrashExit);
+
+ sigdelset(&BlockSig, SIGQUIT);
+ PG_SETMASK(&BlockSig);
+
/* Request a signal if the postmaster dies, if possible. */
PostmasterDeathSignalInit();
}
@@ -155,6 +174,13 @@ InitStandaloneProcess(const char *argv0)
InitLatch(MyLatch);
InitializeLatchWaitSet();
+ /*
+ * For consistency with InitPostmasterChild, initialize signal mask here.
+ * But we don't unblock SIGQUIT or provide a default handler for it.
+ */
+ pqinitmask();
+ PG_SETMASK(&BlockSig);
+
/* Compute paths, no postmaster to inherit from */
if (my_exec_path[0] == '\0')
{