cvs commit: qpsmtpd qpsmtpd-forkserver

[email protected] (Matt Sergeant)
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
cvsuser     04/03/18 15:02:43

  Modified:    .        qpsmtpd-forkserver
  Log:
  Slightly better signal handling - may help stability issues for some people
  
  Revision  Changes    Path
  1.2       +26 -10    qpsmtpd/qpsmtpd-forkserver
  
  Index: qpsmtpd-forkserver
  ===================================================================
  RCS file: /cvs/public/qpsmtpd/qpsmtpd-forkserver,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- qpsmtpd-forkserver	15 Mar 2004 08:59:02 -0000	1.1
  +++ qpsmtpd-forkserver	18 Mar 2004 23:02:43 -0000	1.2
  @@ -11,7 +11,7 @@
   use Qpsmtpd::Constants;
   use IO::Socket;
   use Socket;
  -use POSIX qw(:sys_wait_h);
  +use POSIX qw(:sys_wait_h :errno_h :signal_h);
   use strict;
   $| = 1;
   
  @@ -19,8 +19,19 @@
   $ENV{PATH} = '/bin:/usr/bin:/var/qmail/bin';
   
   sub REAPER {
  -    1 until (-1 == waitpid(-1, WNOHANG));
  -    $SIG{CHLD} = \&REAPER;                 # unless $] >= 5.002
  +    while (defined(my $child = waitpid(-1, WNOHANG)) ) {
  +        if ($child == -1) {
  +            # No child here? Loop back
  +        }
  +        elsif (WIFEXITED($?)) {
  +            # Process exited
  +            last;
  +        }
  +        else {
  +            # Possibly SIGSTOP on child...
  +            last;
  +        }
  +    }
   }
   
   $SIG{CHLD} = \&REAPER;
  @@ -49,21 +60,28 @@
   
   # $plugin_loader->log(LOGINFO, "Listening on port 25");
   
  -my $client;
   while (1) {
  -    my $hisaddr = accept($client, $server);
  +    my $hisaddr = accept(my $client, $server);
       if (!$hisaddr) {
           # possible something condition...
           next;
       }
       my $pid = fork;
  -    next if $pid;
  +    if ($pid) {
  +        close($client);
  +        next;
  +    }
       die "fork: $!" unless defined $pid;     # failure
       # otherwise child
  -    close($server);                          # no use to child
   
  -    $SIG{CHLD} = 'DEFAULT';
  +    close($server);
  +
  +    $SIG{CHLD} = $SIG{HUP} = $SIG{PIPE} = $SIG{INT} = 
  +        $SIG{TERM} = $SIG{QUIT} = 'DEFAULT';
       
  +    my $localsockaddr = getsockname($client);
  +    my ($lport, $laddr) = sockaddr_in($localsockaddr);
  +    $ENV{TCPLOCALIP} = inet_ntoa($laddr);
       my ($port, $iaddr) = sockaddr_in($hisaddr);
       $ENV{TCPREMOTEIP} = inet_ntoa($iaddr);
       $ENV{TCPREMOTEHOST} = gethostbyaddr($iaddr, AF_INET) || "Unknown";
  @@ -77,8 +95,6 @@
       $qpsmtpd->run();
   
       exit;                                   # child leaves
  -} continue { 
  -    close($client);                          # no use to parent
   }
   
   __END__
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.