about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-08-31 04:41:35 +0000
committerEric Wong <e@80x24.org>2020-09-01 00:19:17 +0000
commit03c9119ec613fa43dcf0a50b5f35754f13228bc8 (patch)
tree8d9ced1e58f7e3e05743286204e397d224dfca5c
parent94ae705673cb03045a109041eec9a6704b8a735b (diff)
downloadpublic-inbox-03c9119ec613fa43dcf0a50b5f35754f13228bc8.tar.gz
In case there's non-Linux or BSD users w/o IO::KQueue, we
shouldn't let signal handlers fire in the child processes.

The child processes always assumed signals were blocked by
the parent, so no changes were necessary, there.
-rw-r--r--lib/PublicInbox/Watch.pm21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm
index 0bb92d0a..2698c44a 100644
--- a/lib/PublicInbox/Watch.pm
+++ b/lib/PublicInbox/Watch.pm
@@ -589,6 +589,7 @@ sub watch_atfork_child ($) {
 sub watch_atfork_parent ($) {
         my ($self) = @_;
         _done_for_now($self);
+        PublicInbox::Sigfd::block_signals();
 }
 
 sub imap_idle_requeue ($) { # DS::add_timer callback
@@ -628,10 +629,14 @@ sub event_step {
         return if $self->{quit};
         my $idle_todo = $self->{idle_todo};
         if ($idle_todo && @$idle_todo) {
-                watch_atfork_parent($self);
-                while (my $url_intvl = shift(@$idle_todo)) {
-                        imap_idle_fork($self, $url_intvl);
-                }
+                my $oldset = watch_atfork_parent($self);
+                eval {
+                        while (my $url_intvl = shift(@$idle_todo)) {
+                                imap_idle_fork($self, $url_intvl);
+                        }
+                };
+                PublicInbox::Sigfd::sig_setmask($oldset);
+                die $@ if $@;
         }
         goto(&fs_scan_step) if $self->{mdre};
 }
@@ -684,9 +689,9 @@ sub watch_nntp_fetch_all ($$) {
 sub poll_fetch_fork ($) { # DS::add_timer callback
         my ($self, $intvl, $urls) = @{$_[0]};
         return if $self->{quit};
-        watch_atfork_parent($self);
-        defined(my $pid = fork) or die "fork: $!";
-        if ($pid == 0) {
+        my $oldset = watch_atfork_parent($self);
+        my $pid = fork;
+        if (defined($pid) && $pid == 0) {
                 watch_atfork_child($self);
                 if ($urls->[0] =~ m!\Aimaps?://!i) {
                         watch_imap_fetch_all($self, $urls);
@@ -695,6 +700,8 @@ sub poll_fetch_fork ($) { # DS::add_timer callback
                 }
                 _exit(0);
         }
+        PublicInbox::Sigfd::sig_setmask($oldset);
+        die "fork: $!"  unless defined $pid;
         $self->{poll_pids}->{$pid} = [ $intvl, $urls ];
         PublicInbox::DS::dwaitpid($pid, \&poll_fetch_reap, $self);
 }