about summary refs log tree commit homepage
path: root/lib/PublicInbox/SpawnPP.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-06-18 10:53:32 +0000
committerEric Wong <e@80x24.org>2016-06-18 21:48:25 +0000
commite748f75979046724ead380bd00eadc677bdc07e9 (patch)
treefbcd16686324cc689a1cd1b0de642bc9a9881601 /lib/PublicInbox/SpawnPP.pm
parent1701875544e31d77f65cf467a35c8dd2bcebf8fa (diff)
downloadpublic-inbox-e748f75979046724ead380bd00eadc677bdc07e9.tar.gz
While we only want to stop our daemons and gracefully destroy
subprocesses, it is common for 'Ctrl-C' from a terminal to kill
the entire pgroup.

Killing an entire pgroup nukes subprocesses like git-upload-pack
breaks graceful shutdown on long clones.  Make a best effort to
ensure git-upload-pack processes are not broken when somebody
signals an entire process group.

Followup-to: commit 37bf2db81bbbe114d7fc5a00e30d3d5a6fa74de5
("doc: systemd examples should only kill one process")
Diffstat (limited to 'lib/PublicInbox/SpawnPP.pm')
-rw-r--r--lib/PublicInbox/SpawnPP.pm7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/PublicInbox/SpawnPP.pm b/lib/PublicInbox/SpawnPP.pm
index fe95d126..36223e81 100644
--- a/lib/PublicInbox/SpawnPP.pm
+++ b/lib/PublicInbox/SpawnPP.pm
@@ -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;
 }