From cdf6518ef08ee602b94db4e5ba5887a1d7053c24 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Fri, 3 Feb 2023 10:34:56 +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 hasn't been relevant for a very long time on Unix systems, and c94ae9d8 got rid of a remaining dependency in our Windows porting code. PG_SETMASK didn't expose save/restore functionality, so we'd already started using sigprocmask() directly in places, creating the visual distraction of having two ways to spell it. It's not part of the API that extensions are expected to be using (but if they are, the change will be trivial). It seems like a good time to drop the old macro and just call the standard POSIX function. Reviewed-by: Nathan Bossart Discussion: https://postgr.es/m/CA%2BhUKG%2BKfQgrhHP2DLTohX1WwubaCBHmTzGnAEDPZ-Gug-Xskg%40mail.gmail.com --- 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 3c714a79c6..e551af2905 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 f92dbc2270..2552327d90 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -639,7 +639,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); @@ -675,7 +675,7 @@ PostmasterMain(int argc, char *argv[]) #endif /* Begin accepting signals. */ - PG_SETMASK(&UnBlockSig); + sigprocmask(SIG_SETMASK, &UnBlockSig, NULL); /* * Options setup @@ -4321,7 +4321,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. @@ -4402,7 +4402,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 @@ -5661,13 +5661,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 b0cfddd548..f6446da2d6 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -293,7 +293,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 -#define PG_SETMASK(mask) sigprocmask(SIG_SETMASK, mask, NULL) - #ifdef WIN32 /* Emulate POSIX sigset_t APIs on Windows */ typedef int sigset_t; -- 2.39.5