diff options
author | Andres Freund <andres@anarazel.de> | 2017-06-05 18:53:41 -0700 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2017-06-05 19:18:16 -0700 |
commit | 6e1dd2773eb60a6ab87b27b8d9391b756e904ac3 (patch) | |
tree | e05bc12289d129431ae8eb1f209784acf7496e55 /src/backend/tcop/postgres.c | |
parent | c6c333436491a292d56044ed6e167e2bdee015a2 (diff) | |
download | postgresql-6e1dd2773eb60a6ab87b27b8d9391b756e904ac3.tar.gz postgresql-6e1dd2773eb60a6ab87b27b8d9391b756e904ac3.zip |
Unify SIGHUP handling between normal and walsender backends.
Because walsender and normal backends share the same main loop it's
problematic to have two different flag variables, set in signal
handlers, indicating a pending configuration reload. Only certain
walsender commands reach code paths checking for the
variable (START_[LOGICAL_]REPLICATION, CREATE_REPLICATION_SLOT
... LOGICAL, notably not base backups).
This is a bug present since the introduction of walsender, but has
gotten worse in releases since then which allow walsender to do more.
A later patch, not slated for v10, will similarly unify SIGHUP
handling in other types of processes as well.
Author: Petr Jelinek, Andres Freund
Reviewed-By: Michael Paquier
Discussion: https://postgr.es/m/20170423235941.qosiuoyqprq4nu7v@alap3.anarazel.de
Backpatch: 9.2-, bug is present since 9.0
Diffstat (limited to 'src/backend/tcop/postgres.c')
-rw-r--r-- | src/backend/tcop/postgres.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 13577691505..1c60b431631 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -123,13 +123,6 @@ char *register_stack_base_ptr = NULL; #endif /* - * Flag to mark SIGHUP. Whenever the main loop comes around it - * will reread the configuration file. (Better than doing the - * reading in the signal handler, ey?) - */ -static volatile sig_atomic_t got_SIGHUP = false; - -/* * Flag to keep track of whether we have started a transaction. * For extended query protocol this has to be remembered across messages. */ @@ -187,7 +180,6 @@ static bool IsTransactionExitStmt(Node *parsetree); static bool IsTransactionExitStmtList(List *pstmts); static bool IsTransactionStmtList(List *pstmts); static void drop_unnamed_stmt(void); -static void SigHupHandler(SIGNAL_ARGS); static void log_disconnections(int code, Datum arg); @@ -2684,13 +2676,19 @@ FloatExceptionHandler(SIGNAL_ARGS) "invalid operation, such as division by zero."))); } -/* SIGHUP: set flag to re-read config file at next convenient time */ -static void -SigHupHandler(SIGNAL_ARGS) +/* + * SIGHUP: set flag to re-read config file at next convenient time. + * + * Sets the ConfigReloadPending flag, which should be checked at convenient + * places inside main loops. (Better than doing the reading in the signal + * handler, ey?) + */ +void +PostgresSigHupHandler(SIGNAL_ARGS) { int save_errno = errno; - got_SIGHUP = true; + ConfigReloadPending = true; SetLatch(MyLatch); errno = save_errno; @@ -3632,8 +3630,8 @@ PostgresMain(int argc, char *argv[], WalSndSignals(); else { - pqsignal(SIGHUP, SigHupHandler); /* set flag to read config - * file */ + pqsignal(SIGHUP, PostgresSigHupHandler); /* set flag to read config + * file */ pqsignal(SIGINT, StatementCancelHandler); /* cancel current query */ pqsignal(SIGTERM, die); /* cancel current query and exit */ @@ -4046,9 +4044,9 @@ PostgresMain(int argc, char *argv[], * (6) check for any other interesting events that happened while we * slept. */ - if (got_SIGHUP) + if (ConfigReloadPending) { - got_SIGHUP = false; + ConfigReloadPending = false; ProcessConfigFile(PGC_SIGHUP); } |