From: Damyan Ivanov Date: Fri, 12 Nov 2021 09:03:56 +0000 (+0000) Subject: a second HIP/INT signal causes a hard exit() X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=cf42fecf66262360d46ca2d195cffa05464533ac;p=mpd-feeder.git a second HIP/INT signal causes a hard exit() --- diff --git a/lib/App/MPD/Feeder.pm b/lib/App/MPD/Feeder.pm index 1b5ed30..9cb1a25 100644 --- a/lib/App/MPD/Feeder.pm +++ b/lib/App/MPD/Feeder.pm @@ -3,6 +3,7 @@ package App::MPD::Feeder; use strict; use warnings; use utf8; +use feature 'state'; use App::MPD::Feeder::Options; use App::MPD::Feeder::DB; @@ -60,31 +61,33 @@ use constant DEFAULT_CONFIG_FILE => '/etc/mpd-feeder/mpd-feeder.conf'; $mpd = Net::Async::MPD->new(%conn); - $mpd->loop->add( - IO::Async::Signal->new( - name => 'TERM', - on_receipt => sub { - $log->debug("SIGTERM received. Stopping loop"); - $mpd->loop->stop('quit'); - }, - ) - ); + my $int_signal_handler = sub { + state $signal_count = 0; + $signal_count++; + $log->debug("Signal received. Stopping loop"); + $mpd->loop->stop('quit'); - $mpd->loop->add( - IO::Async::Signal->new( - name => 'INT', - on_receipt => sub { - $log->debug("SIGINT received. Stopping loop"); - $mpd->loop->stop('quit'); - }, - ) - ); + if ( $signal_count > 1 ) { + $log->warn("Another signal received (#$signal_count)"); + $log->warn("Exiting abruptly"); + exit 2; + } + }; + + for (qw(TERM INT)) { + $mpd->loop->add( + IO::Async::Signal->new( + name => $_, + on_receipt => $int_signal_handler, + ) + ); + } $mpd->loop->add( IO::Async::Signal->new( name => 'HUP', on_receipt => sub { - $log->debug("SIGHUP received. Stopping loop"); + $log->debug("SIGHUP received. Scheduling reload"); $mpd->loop->stop('reload'); }, )