Make signal handling slightly more stable

git-svn-id: https://svn.perl.org/qpsmtpd/trunk@246 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Matt Sergeant 2004-06-16 20:27:51 +00:00
parent ac9dd50928
commit 5d40964053

View File

@ -27,6 +27,7 @@ $ENV{PATH} = '/bin:/usr/bin:/var/qmail/bin';
my %childstatus = (); my %childstatus = ();
sub REAPER { sub REAPER {
$SIG{CHLD} = \&REAPER;
while ( defined(my $chld = waitpid(-1, WNOHANG)) ){ while ( defined(my $chld = waitpid(-1, WNOHANG)) ){
last unless $chld > 0; last unless $chld > 0;
warn("$$ cleaning up after $chld\n"); warn("$$ cleaning up after $chld\n");
@ -34,7 +35,15 @@ sub REAPER {
} }
} }
sub HUNTSMAN {
$SIG{CHLD} = 'DEFAULT';
kill 'INT' => keys %childstatus;
exit(0);
}
$SIG{CHLD} = \&REAPER; $SIG{CHLD} = \&REAPER;
$SIG{INT} = \&HUNTSMAN;
$SIG{TERM} = \&HUNTSMAN;
# establish SERVER socket, bind and listen. # establish SERVER socket, bind and listen.
my $server = IO::Socket::INET->new(LocalPort => $PORT, my $server = IO::Socket::INET->new(LocalPort => $PORT,
@ -86,8 +95,7 @@ while (1) {
close($server); close($server);
$SIG{CHLD} = $SIG{HUP} = $SIG{PIPE} = $SIG{INT} = $SIG{$_} = 'DEFAULT' for keys %SIG;
$SIG{TERM} = $SIG{QUIT} = 'DEFAULT';
my $localsockaddr = getsockname($client); my $localsockaddr = getsockname($client);
my ($lport, $laddr) = sockaddr_in($localsockaddr); my ($lport, $laddr) = sockaddr_in($localsockaddr);