diff options
author | Robert Haas <rhaas@postgresql.org> | 2019-12-17 13:14:28 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2019-12-17 13:14:28 -0500 |
commit | 7dbfea3c455e83a77213a92b9dfdc1c0577441ea (patch) | |
tree | 89ed47744448377a89e05a3ac2316a67c8b02fba /src/backend/postmaster/pgstat.c | |
parent | 1e53fe0e70f610c34f4c9e770d108cd94151342c (diff) | |
download | postgresql-7dbfea3c455e83a77213a92b9dfdc1c0577441ea.tar.gz postgresql-7dbfea3c455e83a77213a92b9dfdc1c0577441ea.zip |
Partially deduplicate interrupt handling for background processes.
Where possible, share signal handler code and main loop interrupt
checking. This saves quite a bit of code and should simplify
maintenance, too.
This commit intends not to change the way anything works, even
though that might allow more code to be unified. It does unify
a bunch of individual variables into a ShutdownRequestPending
flag that has is now used by a bunch of different process types,
though.
Patch by me, reviewed by Andres Freund and Daniel Gustafsson.
Discussion: http://postgr.es/m/CA+TgmoZwDk=BguVDVa+qdA6SBKef=PKbaKDQALTC_9qoz1mJqg@mail.gmail.com
Diffstat (limited to 'src/backend/postmaster/pgstat.c')
-rw-r--r-- | src/backend/postmaster/pgstat.c | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index 96a9e09cedc..e9315122033 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -49,6 +49,7 @@ #include "pgstat.h" #include "postmaster/autovacuum.h" #include "postmaster/fork_process.h" +#include "postmaster/interrupt.h" #include "postmaster/postmaster.h" #include "replication/walsender.h" #include "storage/backendid.h" @@ -262,9 +263,6 @@ static PgStat_GlobalStats globalStats; */ static List *pending_write_requests = NIL; -/* Signal handler flags */ -static volatile bool need_exit = false; - /* * Total time charged to functions so far in the current backend. * We use this to help separate "self" and "other" time charges. @@ -282,7 +280,6 @@ static pid_t pgstat_forkexec(void); #endif NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn(); -static void pgstat_exit(SIGNAL_ARGS); static void pgstat_beshutdown_hook(int code, Datum arg); static PgStat_StatDBEntry *pgstat_get_db_entry(Oid databaseid, bool create); @@ -4432,10 +4429,10 @@ PgstatCollectorMain(int argc, char *argv[]) * except SIGHUP and SIGQUIT. Note we don't need a SIGUSR1 handler to * support latch operations, because we only use a local latch. */ - pqsignal(SIGHUP, PostgresSigHupHandler); + pqsignal(SIGHUP, SignalHandlerForConfigReload); pqsignal(SIGINT, SIG_IGN); pqsignal(SIGTERM, SIG_IGN); - pqsignal(SIGQUIT, pgstat_exit); + pqsignal(SIGQUIT, SignalHandlerForShutdownRequest); pqsignal(SIGALRM, SIG_IGN); pqsignal(SIGPIPE, SIG_IGN); pqsignal(SIGUSR1, SIG_IGN); @@ -4477,14 +4474,14 @@ PgstatCollectorMain(int argc, char *argv[]) /* * Quit if we get SIGQUIT from the postmaster. */ - if (need_exit) + if (ShutdownRequestPending) break; /* * Inner loop iterates as long as we keep getting messages, or until - * need_exit becomes set. + * ShutdownRequestPending becomes set. */ - while (!need_exit) + while (!ShutdownRequestPending) { /* * Reload configuration if we got SIGHUP from the postmaster. @@ -4676,19 +4673,6 @@ PgstatCollectorMain(int argc, char *argv[]) exit(0); } - -/* SIGQUIT signal handler for collector process */ -static void -pgstat_exit(SIGNAL_ARGS) -{ - int save_errno = errno; - - need_exit = true; - SetLatch(MyLatch); - - errno = save_errno; -} - /* * Subroutine to clear stats in a database entry * |