diff options
author | Daniel Gustafsson <dgustafsson@postgresql.org> | 2022-09-14 16:32:24 +0200 |
---|---|---|
committer | Daniel Gustafsson <dgustafsson@postgresql.org> | 2022-09-14 16:32:24 +0200 |
commit | 8b60db774356117fab2eb53fb37160fa3e173cdb (patch) | |
tree | 82dbf0fb5344b10ac0adbf105be3f3e1c5fb7b13 /src | |
parent | 0e733278e346f19df93843bce9a81c8183df6e1d (diff) | |
download | postgresql-8b60db774356117fab2eb53fb37160fa3e173cdb.tar.gz postgresql-8b60db774356117fab2eb53fb37160fa3e173cdb.zip |
Handle SIGTERM in pg_receivewal and pg_recvlogical
In pg_receivewal, compressed output is only flushed on clean exits. The
reason to support SIGTERM as well as SIGINT (which is currently handled)
is that pg_receivewal might well be running as a daemon, and systemd's
default KillSignal is SIGTERM.
Since pg_recvlogical is also supposed to run as a daemon, teach it about
SIGTERM as well and update the documentation to match. While in there,
change pg_receivewal's time_to_stop to be sig_atomic_t like it is in
pg_recvlogical.
Author: Christoph Berg <myon@debian.org>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/Yvo/5No5S0c4EFMj@msg.df7cb.de
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pg_basebackup/pg_receivewal.c | 11 | ||||
-rw-r--r-- | src/bin/pg_basebackup/pg_recvlogical.c | 9 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c index a6e3387a6d4..37c14d1a029 100644 --- a/src/bin/pg_basebackup/pg_receivewal.c +++ b/src/bin/pg_basebackup/pg_receivewal.c @@ -45,7 +45,7 @@ static int verbose = 0; static int compresslevel = 0; static int noloop = 0; static int standby_message_timeout = 10 * 1000; /* 10 sec = default */ -static volatile bool time_to_stop = false; +static volatile sig_atomic_t time_to_stop = false; static bool do_create_slot = false; static bool slot_exists_ok = false; static bool do_drop_slot = false; @@ -673,13 +673,13 @@ StreamLog(void) } /* - * When sigint is called, just tell the system to exit at the next possible - * moment. + * When SIGINT/SIGTERM are caught, just tell the system to exit at the next + * possible moment. */ #ifndef WIN32 static void -sigint_handler(int signum) +sigexit_handler(int signum) { time_to_stop = true; } @@ -905,7 +905,8 @@ main(int argc, char **argv) * if one is needed, in GetConnection.) */ #ifndef WIN32 - pqsignal(SIGINT, sigint_handler); + pqsignal(SIGINT, sigexit_handler); + pqsignal(SIGTERM, sigexit_handler); #endif /* diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c index 2a4c8b130a0..a86739ec126 100644 --- a/src/bin/pg_basebackup/pg_recvlogical.c +++ b/src/bin/pg_basebackup/pg_recvlogical.c @@ -650,11 +650,11 @@ error: #ifndef WIN32 /* - * When sigint is called, just tell the system to exit at the next possible - * moment. + * When SIGINT/SIGTERM are caught, just tell the system to exit at the next + * possible moment. */ static void -sigint_handler(int signum) +sigexit_handler(int signum) { time_to_abort = true; } @@ -922,7 +922,8 @@ main(int argc, char **argv) * if one is needed, in GetConnection.) */ #ifndef WIN32 - pqsignal(SIGINT, sigint_handler); + pqsignal(SIGINT, sigexit_handler); + pqsignal(SIGTERM, sigexit_handler); pqsignal(SIGHUP, sighup_handler); #endif |