From 5d409640536131ebcd634196d3b4a43bec30bf75 Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Wed, 16 Jun 2004 20:27:51 +0000 Subject: [PATCH] Make signal handling slightly more stable git-svn-id: https://svn.perl.org/qpsmtpd/trunk@246 958fd67b-6ff1-0310-b445-bb7760255be9 --- qpsmtpd-forkserver | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qpsmtpd-forkserver b/qpsmtpd-forkserver index a81fc17..72d47c4 100755 --- a/qpsmtpd-forkserver +++ b/qpsmtpd-forkserver @@ -27,6 +27,7 @@ $ENV{PATH} = '/bin:/usr/bin:/var/qmail/bin'; my %childstatus = (); sub REAPER { + $SIG{CHLD} = \&REAPER; while ( defined(my $chld = waitpid(-1, WNOHANG)) ){ last unless $chld > 0; 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{INT} = \&HUNTSMAN; +$SIG{TERM} = \&HUNTSMAN; # establish SERVER socket, bind and listen. my $server = IO::Socket::INET->new(LocalPort => $PORT, @@ -86,8 +95,7 @@ while (1) { close($server); - $SIG{CHLD} = $SIG{HUP} = $SIG{PIPE} = $SIG{INT} = - $SIG{TERM} = $SIG{QUIT} = 'DEFAULT'; + $SIG{$_} = 'DEFAULT' for keys %SIG; my $localsockaddr = getsockname($client); my ($lport, $laddr) = sockaddr_in($localsockaddr);