From b6fdd78243d2af67115a9cfbaf9a73a6f475d333 Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Mon, 30 Oct 2023 19:52:33 -0400 Subject: [PATCH] Add logging to INT, TERM, and QUIT handlers --- Changes | 2 ++ lib/PGXN/Manager/Consumer.pm | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 5cdf014..7fe28db 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,8 @@ Revision history for Perl extension PGXN::Manager 0.31.2 - Combined the pgxn_consumer PID number and file location into one output. + - Configured handlers for INT, TERM, and QUIT signals to log flagging + for shutdown in the next loop. 0.31.1 2023-10-07T21:40:53Z - Restored the writing of the pgxn_consumer PID file, accidentally diff --git a/lib/PGXN/Manager/Consumer.pm b/lib/PGXN/Manager/Consumer.pm index ed0abcc..89719a3 100644 --- a/lib/PGXN/Manager/Consumer.pm +++ b/lib/PGXN/Manager/Consumer.pm @@ -81,10 +81,18 @@ sub go { $cfg->{log_fh} = _log_fh delete $cfg->{'log-file'}; $cfg->{pid_file} = delete $cfg->{'pid-file'} if exists $cfg->{'pid-file'}; my $cmd = $class->new( $cfg ); - $SIG{QUIT} = $SIG{INT} = $SIG{TERM} = sub { $cmd->continue(0) }; + $SIG{$_} = $cmd->_signal_handler($_) for qw(TERM INT QUIT); $cmd->run(@ARGV); } +sub _signal_handler { + my ($self, $sig) = @_; + return sub { + $self->log("INFO: $sig signal caught; flagging shutdown for next loop"); + $self->continue(0); + }; +} + sub DEMOLISH { my $self = shift; if (my $path = $self->pid_file) {