Hi, This is a follow-up for commit c94ae9d8. It's in the spirit of other recent changes to remove noise from ancient pre-standard systems.
The reason we introduced PG_SETMASK() in the first place was to support one particular system that was very slow to adopt the POSIX signals stuff: NeXTSTEP 3.x. >From some time in the dark age before our current repo begins until '97 we used sigprocmask() freely. Then commit a5494a2d added a sigsetmask() fallback for NeXTSTEP (that's a pre-standard function inherited from '80s BSD). In 1999 we added the PG_SETMASK() macro to avoid repeating #ifdef HAVE_SIGPROCMASK to select between them at each call site (commit 47937403676). I have no personal knowledge of those systems; I wonder if it was already effectively quite defunct while we were adding the macro, but I dunno (NS 4.x never shipped?, but its living descendent OSX had already shipped that year). Then we invented a bogus reason to need the macro for a couple more decades: our Windows simulated signal layer accidentally implemented the old BSD interface instead of the standard one, as complained about in commit a65e0864. That's all ancient history now, and I think we might as well drop the macro to make our source a tiny bit less weird for new players, with a slightly richer interface. Trivial patch attached.
From 1233157f7e7e0ea8c36bc4eaaf3ed2c89f3541df Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.mu...@gmail.com> Date: Mon, 9 Jan 2023 12:10:11 +1300 Subject: [PATCH] Retire PG_SETMASK() macro. In the 90s we needed to deal with computers that still had the pre-standard signal masking APIs. That's hasn't been necessary for a very long time on Unix systems (and since c94ae9d8 on Windows system). The wrapper doesn't expose all the functionality, it's not part of the API that extensions are expected to be using (or if they are, the change will be trivial) and it's generally better to use standardised interfaces. So, drop the macro and open-code its expansion. --- src/backend/access/transam/xact.c | 4 ++-- src/backend/postmaster/autovacuum.c | 4 ++-- src/backend/postmaster/bgworker.c | 2 +- src/backend/postmaster/bgwriter.c | 2 +- src/backend/postmaster/checkpointer.c | 2 +- src/backend/postmaster/pgarch.c | 2 +- src/backend/postmaster/postmaster.c | 12 ++++++------ src/backend/postmaster/startup.c | 2 +- src/backend/postmaster/syslogger.c | 2 +- src/backend/postmaster/walwriter.c | 2 +- src/backend/replication/walreceiver.c | 2 +- src/backend/tcop/postgres.c | 4 ++-- src/backend/utils/init/miscinit.c | 4 ++-- src/include/libpq/pqsignal.h | 2 -- 14 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index d85e313908..b876401260 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -2755,7 +2755,7 @@ AbortTransaction(void) * handler. We do this fairly early in the sequence so that the timeout * infrastructure will be functional if needed while aborting. */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* * check the current transaction state @@ -5115,7 +5115,7 @@ AbortSubTransaction(void) * handler. We do this fairly early in the sequence so that the timeout * infrastructure will be functional if needed while aborting. */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* * check the current transaction state diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index f5ea381c53..ff6149a179 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -568,7 +568,7 @@ AutoVacLauncherMain(int argc, char *argv[]) PG_exception_stack = &local_sigjmp_buf; /* must unblock signals before calling rebuild_database_list */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* * Set always-secure search path. Launcher doesn't connect to a database, @@ -1589,7 +1589,7 @@ AutoVacWorkerMain(int argc, char *argv[]) /* We can now handle ereport(ERROR) */ PG_exception_stack = &local_sigjmp_buf; - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* * Set always-secure search path, so malicious users can't redirect user diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c index e7a4a7136a..0dd22b2351 100644 --- a/src/backend/postmaster/bgworker.c +++ b/src/backend/postmaster/bgworker.c @@ -726,7 +726,7 @@ SanityCheckBackgroundWorker(BackgroundWorker *worker, int elevel) static void bgworker_die(SIGNAL_ARGS) { - PG_SETMASK(&BlockSig); + sigprocmask(SIG_SETMASK, &BlockSig, NULL); ereport(FATAL, (errcode(ERRCODE_ADMIN_SHUTDOWN), diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c index 69667f0eb4..9bb47da404 100644 --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -215,7 +215,7 @@ BackgroundWriterMain(void) /* * Unblock signals (they were blocked when the postmaster forked us) */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* * Reset hibernation state after any error. diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index de0bbbfa79..aaad5c5228 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -326,7 +326,7 @@ CheckpointerMain(void) /* * Unblock signals (they were blocked when the postmaster forked us) */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* * Ensure all shared memory values are set correctly for the config. Doing diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c index 8ecdb9ca23..d9d862e5e4 100644 --- a/src/backend/postmaster/pgarch.c +++ b/src/backend/postmaster/pgarch.c @@ -227,7 +227,7 @@ PgArchiverMain(void) pqsignal(SIGCHLD, SIG_DFL); /* Unblock signals (they were blocked when the postmaster forked us) */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* We shouldn't be launched unnecessarily. */ Assert(XLogArchivingActive()); diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 9cedc1b9f0..ec5064a723 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -629,7 +629,7 @@ PostmasterMain(int argc, char *argv[]) * postmaster/bgworker.c and postmaster/checkpointer.c. */ pqinitmask(); - PG_SETMASK(&BlockSig); + sigprocmask(SIG_SETMASK, &BlockSig, NULL); pqsignal(SIGHUP, handle_pm_reload_request_signal); pqsignal(SIGINT, handle_pm_shutdown_request_signal); @@ -665,7 +665,7 @@ PostmasterMain(int argc, char *argv[]) #endif /* Begin accepting signals. */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* * Options setup @@ -4297,7 +4297,7 @@ BackendInitialize(Port *port) pqsignal(SIGTERM, process_startup_packet_die); /* SIGQUIT handler was already set up by InitPostmasterChild */ InitializeTimeouts(); /* establishes SIGALRM handler */ - PG_SETMASK(&StartupBlockSig); + sigprocmask(SIG_SETMASK, &StartupBlockSig, NULL); /* * Get the remote host name and port for logging and status display. @@ -4378,7 +4378,7 @@ BackendInitialize(Port *port) * Disable the timeout, and prevent SIGTERM again. */ disable_timeout(STARTUP_PACKET_TIMEOUT, false); - PG_SETMASK(&BlockSig); + sigprocmask(SIG_SETMASK, &BlockSig, NULL); /* * As a safety check that nothing in startup has yet performed @@ -5637,13 +5637,13 @@ BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, uint32 flags) void BackgroundWorkerBlockSignals(void) { - PG_SETMASK(&BlockSig); + sigprocmask(SIG_SETMASK, &BlockSig, NULL); } void BackgroundWorkerUnblockSignals(void) { - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); } #ifdef EXEC_BACKEND diff --git a/src/backend/postmaster/startup.c b/src/backend/postmaster/startup.c index 8786186898..bcd23542f1 100644 --- a/src/backend/postmaster/startup.c +++ b/src/backend/postmaster/startup.c @@ -259,7 +259,7 @@ StartupProcessMain(void) /* * Unblock signals (they were blocked when the postmaster forked us) */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* * Do what we came for. diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c index a876d02c6f..858a2f6b2b 100644 --- a/src/backend/postmaster/syslogger.c +++ b/src/backend/postmaster/syslogger.c @@ -263,7 +263,7 @@ SysLoggerMain(int argc, char *argv[]) */ pqsignal(SIGCHLD, SIG_DFL); - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); #ifdef WIN32 /* Fire up separate data transfer thread */ diff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.c index 3113e8fbdd..513e580c51 100644 --- a/src/backend/postmaster/walwriter.c +++ b/src/backend/postmaster/walwriter.c @@ -205,7 +205,7 @@ WalWriterMain(void) /* * Unblock signals (they were blocked when the postmaster forked us) */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* * Reset hibernation state after any error. diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 3876c0188d..a6d245ceee 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -294,7 +294,7 @@ WalReceiverMain(void) elog(ERROR, "libpqwalreceiver didn't initialize correctly"); /* Unblock signals (they were blocked when the postmaster forked us) */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* Establish the connection to the primary for XLOG streaming */ wrconn = walrcv_connect(conninfo, false, diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 470b734e9e..5d439f2710 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -2831,7 +2831,7 @@ void quickdie(SIGNAL_ARGS) { sigaddset(&BlockSig, SIGQUIT); /* prevent nested calls */ - PG_SETMASK(&BlockSig); + sigprocmask(SIG_SETMASK, &BlockSig, NULL); /* * Prevent interrupts while exiting; though we just blocked signals that @@ -4129,7 +4129,7 @@ PostgresMain(const char *dbname, const char *username) BaseInit(); /* We need to allow SIGINT, etc during the initial transaction */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* * General initialization. diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 0cdc1e11a3..59532bbd80 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -159,7 +159,7 @@ InitPostmasterChild(void) pqsignal(SIGQUIT, SignalHandlerForCrashExit); sigdelset(&BlockSig, SIGQUIT); - PG_SETMASK(&BlockSig); + sigprocmask(SIG_SETMASK, &BlockSig, NULL); /* Request a signal if the postmaster dies, if possible. */ PostmasterDeathSignalInit(); @@ -196,7 +196,7 @@ InitStandaloneProcess(const char *argv0) * But we don't unblock SIGQUIT or provide a default handler for it. */ pqinitmask(); - PG_SETMASK(&BlockSig); + sigprocmask(SIG_SETMASK, &BlockSig, NULL); /* Compute paths, no postmaster to inherit from */ if (my_exec_path[0] == '\0') diff --git a/src/include/libpq/pqsignal.h b/src/include/libpq/pqsignal.h index 1e66f25b76..023bcd13bd 100644 --- a/src/include/libpq/pqsignal.h +++ b/src/include/libpq/pqsignal.h @@ -15,8 +15,6 @@ #include <signal.h> -#define PG_SETMASK(mask) sigprocmask(SIG_SETMASK, mask, NULL) - #ifdef WIN32 /* Emulate POSIX sigset_t APIs on Windows */ typedef int sigset_t; -- 2.35.1