Retire PG_SETMASK() macro.
authorThomas Munro <tmunro@postgresql.org>
Thu, 2 Feb 2023 21:34:56 +0000 (10:34 +1300)
committerThomas Munro <tmunro@postgresql.org>
Thu, 2 Feb 2023 22:29:46 +0000 (11:29 +1300)
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 <nathandbossart@gmail.com>
Discussion: https://postgr.es/m/CA%2BhUKG%2BKfQgrhHP2DLTohX1WwubaCBHmTzGnAEDPZ-Gug-Xskg%40mail.gmail.com

14 files changed:
src/backend/access/transam/xact.c
src/backend/postmaster/autovacuum.c
src/backend/postmaster/bgworker.c
src/backend/postmaster/bgwriter.c
src/backend/postmaster/checkpointer.c
src/backend/postmaster/pgarch.c
src/backend/postmaster/postmaster.c
src/backend/postmaster/startup.c
src/backend/postmaster/syslogger.c
src/backend/postmaster/walwriter.c
src/backend/replication/walreceiver.c
src/backend/tcop/postgres.c
src/backend/utils/init/miscinit.c
src/include/libpq/pqsignal.h

index d85e31390823c0e4de4c45907f90c199352211ed..b87640126075cc54480dcb1fbb582e9dc6486689 100644 (file)
@@ -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
index f5ea381c53e92702805dfa5bb111a6fe487eaf79..ff6149a17937c16314df7e1d5da6bbb478643b73 100644 (file)
@@ -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
index e7a4a7136a13d6092ce3713c277e258f628fc88c..0dd22b23511a1fa13ac4e6bfeb80f21a18f7189f 100644 (file)
@@ -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),
index 69667f0eb4bf235d7099840190280725e1ce8483..9bb47da404d6d6c58675c5d9e030b8541640b02f 100644 (file)
@@ -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.
index de0bbbfa7915c81e420ac80d13f3cb7d6c4bc2ab..aaad5c522811134ee41d40b1f279ebf5ad923b0c 100644 (file)
@@ -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
index 3c714a79c68129b8213a1a01275833a6ebfc406e..e551af29052f2db6fc1e882e47a1cb5507f9e6d6 100644 (file)
@@ -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());
index f92dbc22707eea3296749ea0a53d98f098eefb72..2552327d9043257a417b8f78b1ddd3fcb31cba0b 100644 (file)
@@ -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
index 8786186898dcf17e2df227e9af139c4aa14ecda2..bcd23542f1d14b67e1d0dd071935295ffa7a79e5 100644 (file)
@@ -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.
index a876d02c6f7776412d3b61ff87dc4b55c08aa070..858a2f6b2b9898d5b2000a3e39f258f7d5e32b1c 100644 (file)
@@ -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 */
index 3113e8fbdd51f88a5f18a44062cc734506964075..513e580c513da70bd7e0589580e8c9b84a3d273d 100644 (file)
@@ -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.
index b0cfddd54815ff4bbbb8a632510970137885dee3..f6446da2d6db17108e9242d51a97352aebfa37af 100644 (file)
@@ -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,
index 470b734e9e06b90d128c908652ac2230352ee85f..5d439f27100407255ac601e5b4e55fe0b831380d 100644 (file)
@@ -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.
index 0cdc1e11a33faa336546883d9eec56ba43e6bed2..59532bbd80d5454b7552497bed983eee9e57198f 100644 (file)
@@ -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')
index 1e66f25b7680b5073cecf67399d18595918a33b5..023bcd13bd47c94a9703f4c2b8b2d24d13c8328a 100644 (file)
@@ -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;