Sending mail when killed, not after TERM-signal

git-svn-id: svn+ssh://svn.code.sf.net/p/ddclient/code/trunk@83 3873ddee-7413-0410-b6c4-c2c57c1ab35a
This commit is contained in:
wimpunk 2008-02-05 08:31:06 +00:00
parent 53ccfe931d
commit a97eed732f

View file

@ -602,8 +602,10 @@ if (!opt('daemon') && $programd =~ /d$/) {
} }
my $caught_hup = 0; my $caught_hup = 0;
my $caught_term = 0; my $caught_term = 0;
my $caught_kill = 0;
$SIG{'HUP'} = sub { $caught_hup = 1; }; $SIG{'HUP'} = sub { $caught_hup = 1; };
$SIG{'TERM'} = sub { $caught_term = 1; }; $SIG{'TERM'} = sub { $caught_term = 1; };
$SIG{'KILL'} = sub { $caught_kill = 1; };
if (opt('daemon') && !opt('force')) { if (opt('daemon') && !opt('force')) {
$SIG{'CHLD'} = 'IGNORE'; $SIG{'CHLD'} = 'IGNORE';
my $pid = fork; my $pid = fork;
@ -665,7 +667,7 @@ do {
sendmail(); sendmail();
my $left = $daemon; my $left = $daemon;
while (($left > 0) && !$caught_hup && !$caught_term) { while (($left > 0) && !$caught_hup && !$caught_term && !$caught_kill) {
my $delay = $left > 10 ? 10 : $left; my $delay = $left > 10 ? 10 : $left;
$0 = sprintf("%s - sleeping for %s seconds", $program, $left); $0 = sprintf("%s - sleeping for %s seconds", $program, $left);
@ -681,9 +683,9 @@ do {
} else { } else {
$result = $result eq 'OK' ? 0 : 1; $result = $result eq 'OK' ? 0 : 1;
} }
} while ($daemon && !$result && !$caught_term); } while ($daemon && !$result && !$caught_term && !$caught_kill);
warning("caught SIGTERM; exiting") if $caught_term; warning("caught SIGKILL; exiting") if $caught_kill;
unlink_pid(); unlink_pid();
sendmail(); sendmail();