]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
watch: ensure children can use signal handlers
authorEric Wong <e@80x24.org>
Mon, 4 Sep 2023 10:36:03 +0000 (10:36 +0000)
committerEric Wong <e@80x24.org>
Tue, 5 Sep 2023 03:01:39 +0000 (03:01 +0000)
Blindly using the signal set inherited from the parent process
is wrong, since the parent (or grandparent) could've blocked all
signals.  Ensure children can process signals in the event loop
when sig handlers have to use standard Perl facilities.

lib/PublicInbox/Watch.pm
script/public-inbox-watch

index c3b5b79148431636662af23dfa219c90e9352a10..a2dc125f2e9bc40321a5b34fa7922673e5b1fc73 100644 (file)
@@ -389,7 +389,7 @@ sub watch_atfork_child ($) {
        my $sig = delete $self->{sig};
        $sig->{CHLD} = 'DEFAULT';
        @SIG{keys %$sig} = values %$sig;
-       PublicInbox::DS::sig_setmask($self->{oldset});
+       PublicInbox::DS::sig_setmask(PublicInbox::DS::allowset($sig));
 }
 
 sub watch_atfork_parent ($) { _done_for_now($_[0]) }
@@ -533,8 +533,7 @@ sub watch_nntp_init ($$) {
 }
 
 sub watch { # main entry point
-       my ($self, $sig, $oldset) = @_;
-       $self->{oldset} = $oldset;
+       my ($self, $sig) = @_;
        my $first_sig;
        $self->{sig} //= ($first_sig = $sig);
        my $poll = {}; # intvl_seconds => [ uri1, uri2 ]
@@ -546,7 +545,7 @@ sub watch { # main entry point
        }
        watch_fs_init($self) if $self->{mdre};
        local @PublicInbox::DS::post_loop_do = (sub { !$self->quit_done });
-       PublicInbox::DS::event_loop($first_sig, $oldset); # calls ->event_step
+       PublicInbox::DS::event_loop($first_sig); # calls ->event_step
        _done_for_now($self);
 }
 
index 2fb27343d19b56f378cd218ec8d4a3bf7599f785..75a9a36bf99a2cde6102c616c188bb636b6b4046 100755 (executable)
@@ -17,7 +17,7 @@ my $do_scan = 1;
 GetOptions('scan!' => \$do_scan, # undocumented, testing only
        'help|h' => \(my $show_help)) or do { print STDERR $help; exit 1 };
 if ($show_help) { print $help; exit 0 };
-my $oldset = PublicInbox::DS::block_signals();
+PublicInbox::DS::block_signals();
 STDOUT->autoflush(1);
 STDERR->autoflush(1);
 local $0 = $0; # local since this script may be eval-ed
@@ -55,5 +55,5 @@ if ($watch) {
 
        # --no-scan is only intended for testing atm, undocumented.
        PublicInbox::DS::requeue($scan) if $do_scan;
-       $watch->watch($sig, $oldset) while ($watch);
+       $watch->watch($sig) while ($watch);
 }