]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SpawnPP.pm
spawn: try to keep signals blocked in spawned child
[public-inbox.git] / lib / PublicInbox / SpawnPP.pm
index fe95d1269c210efb35720fd4d24584ac3eac101c..36223e8132eefa30c380bf1b07fef42bbf40628b 100644 (file)
@@ -3,11 +3,15 @@
 package PublicInbox::SpawnPP;
 use strict;
 use warnings;
-use POSIX qw(dup2);
+use POSIX qw(dup2 :signal_h);
 
 # Pure Perl implementation for folks that do not use Inline::C
 sub public_inbox_fork_exec ($$$$$$) {
        my ($in, $out, $err, $f, $cmd, $env) = @_;
+       my $old = POSIX::SigSet->new();
+       my $set = POSIX::SigSet->new();
+       $set->fillset or die "fillset failed: $!";
+       sigprocmask(SIG_SETMASK, $set, $old) or die "can't block signals: $!";
        my $pid = fork;
        if ($pid == 0) {
                if ($in != 0) {
@@ -29,6 +33,7 @@ sub public_inbox_fork_exec ($$$$$$) {
                        die "exec $cmd->[0] failed: $!\n";
                }
        }
+       sigprocmask(SIG_SETMASK, $old) or die "can't unblock signals: $!";
        $pid;
 }