Moved signal handlers to Lib::Auto.
This commit is contained in:
1 parent
99078cc349
commit
a1e9b7f538
3 files changed
+83
-76
No files matched your search
+77
-1
@@ -4,7 +4,8 @@
|
||||
package Lib::Auto;
|
||||
use strict;
|
||||
use warnings;
|
||||
use API::Log qw(println);
|
||||
use English qw(-no_match_vars);
|
||||
use API::Log qw(println dbug alog);
|
||||
our $VERSION = 3.000000;
|
||||
|
||||
# Update checker.
|
||||
@@ -39,3 +40,78 @@ sub checkver
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
###################
|
||||
# Signal handlers #
|
||||
###################
|
||||
|
||||
# SIGTERM
|
||||
sub signal_term
|
||||
{
|
||||
API::Std::event_run('on_sigterm');
|
||||
foreach (keys %Auto::SOCKET) { API::IRC::quit($_, 'Caught SIGTERM'); }
|
||||
$Auto::DB->disconnect;
|
||||
dbug '!!! Caught SIGTERM; terminating...';
|
||||
alog '!!! Caught SIGTERM; terminating...';
|
||||
if (-e "$Auto::Bin/auto.pid") {
|
||||
unlink "$Auto::Bin/auto.pid";
|
||||
}
|
||||
sleep 1;
|
||||
exit;
|
||||
}
|
||||
|
||||
# SIGINT
|
||||
sub signal_int
|
||||
{
|
||||
API::Std::event_run('on_sigint');
|
||||
foreach (keys %Auto::SOCKET) { API::IRC::quit($_, 'Caught SIGINT'); }
|
||||
$Auto::DB->disconnect;
|
||||
dbug '!!! Caught SIGINT; terminating...';
|
||||
alog '!!! Caught SIGINT; terminating...';
|
||||
if (-e "$Auto::Bin/auto.pid") {
|
||||
unlink "$Auto::Bin/auto.pid";
|
||||
}
|
||||
sleep 1;
|
||||
exit;
|
||||
}
|
||||
|
||||
# SIGHUP
|
||||
sub signal_hup
|
||||
{
|
||||
API::Std::event_run('on_sighup');
|
||||
dbug '!!! Caught SIGHUP but rehash is unavailable; ignoring';
|
||||
alog '!!! Caught SIGHUP but rehash is unavailable; ignoring';
|
||||
return 1;
|
||||
}
|
||||
|
||||
# __WARN__
|
||||
sub signal_perlwarn
|
||||
{
|
||||
my ($warnmsg) = @_;
|
||||
$warnmsg =~ s/(\n|\r)//xsmg;
|
||||
alog 'Perl Warning: '.$warnmsg;
|
||||
if ($Auto::DEBUG) { println 'Perl Warning: '.$warnmsg; }
|
||||
return 1;
|
||||
}
|
||||
|
||||
# __DIE__
|
||||
sub signal_perldie
|
||||
{
|
||||
my ($diemsg) = @_;
|
||||
$diemsg =~ s/(\n|\r)//xsmg;
|
||||
|
||||
return if $EXCEPTIONS_BEING_CAUGHT;
|
||||
alog 'Perl Fatal: '.$diemsg.' -- Terminating program!';
|
||||
foreach (keys %Auto::SOCKET) { API::IRC::quit($_, 'A fatal error occurred!'); }
|
||||
$Auto::DB->disconnect;
|
||||
if (-e "$Auto::Bin/auto.pid") {
|
||||
unlink "$Auto::Bin/auto.pid";
|
||||
}
|
||||
sleep 1;
|
||||
println 'FATAL: '.$diemsg;
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
# vim: set ai sw=4 ts=4:
|
||||
Reference in new issue
Block a user