use strict;
use warnings;
use utf8;
+use feature 'state';
use App::MPD::Feeder::Options;
use App::MPD::Feeder::DB;
$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');
},
)