do not explicitly wait on the pid in question; just reap the zombies on SIGCHLD
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Wed, 27 Oct 2010 05:03:46 +0000 (01:03 -0400)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Wed, 27 Oct 2010 05:03:46 +0000 (01:03 -0400)
Crypt/Monkeysphere/MSVA.pm

index ee712361d7a0655a135a019044781f44f8fb482e..72061ab278b82a5f8fd2e15f9d8b372309719f75 100755 (executable)
     my $server = shift;
 
     $self->spawn_master_subproc($server);
-    if (exists $self->{child_pid} &&
-        $self->{child_pid} != 0) {
-      my $val;
-      while (defined($val = POSIX::waitpid(-1, POSIX::WNOHANG)) && $val > 0) {
-        msvalog('debug', "waitpid on %d: got %d\n", $self->{child_pid}, $val);
-        if ($val == $self->{child_pid}) {
-          $self->master_subprocess_died($server, $?);
-        }
-      }
-    }
   }
 
   sub master_subprocess_died {
     } elsif ($#ARGV >= 0) {
       $self->{child_pid} = 0; # indicate that we are planning to fork.
       # avoid ignoring SIGCHLD right before we fork.
-      $SIG{CHLD} = 'DEFAULT';
+      $SIG{CHLD} = sub {
+        my $val;
+        while (defined($val = POSIX::waitpid(-1, POSIX::WNOHANG)) && $val > 0) {
+          $self->child_dies($val, $server);
+        }
+      };
       my $fork = fork();
       if (! defined $fork) {
         msvalog('error', "could not fork\n");