Handle SIGTERM, SIGINT and SIGHUP.

This commit is contained in:
Elijah Perrault committed 2011-01-20 14:35:42 -07:00
1 parent bf64eeb5ef
commit 5716570080
1 file changed
+35
+35
View File
@@ -64,6 +64,11 @@ if ($BFVER[0] ne VER.".".SVER.".".REV.RSTAGE."\n") {
}
undef @BFVER;
# Set signal handlers.
$SIG{TERM} = \&signal_TERM;
$SIG{INT} = \&signal_INT;
$SIG{HUP} = \&signal_HUP;
# Print startup message.
println "* ".NAME." (version ".VER.".".SVER.".".REV.RSTAGE.") is starting up...";
@@ -234,3 +239,33 @@ sub mod_load {
return 0;
}
}
## Signal handlers
# SIGTERM
sub signal_TERM
{
API::IRC::quit($_, "Caught SIGTERM") foreach (keys %SOCKET);
dbug "!!! Caught SIGTERM; terminating...";
alog "!!! Caught SIGTERM; terminating...";
sleep 1;
exit;
}
# SIGINT
sub signal_INT
{
API::IRC::quit($_, "Caught SIGINT") foreach (keys %SOCKET);
dbug "!!! Caught SIGINT; terminating...";
alog "!!! Caught SIGINT; terminating...";
sleep 1;
exit;
}
# SIGHUP
sub signal_HUP
{
dbug "!!! Caught SIGHUP but rehash is unavailable; ignoring";
alog "!!! Caught SIGHUP but rehash is unavailable; ignoring";
}