From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B6A231F569 for ; Mon, 4 Sep 2023 10:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1693823768; bh=jkGvqI2okK4w+oQvsBRf2pwYvqp8gwdWuF9MkFwMJp0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MGP35H4G9TPY2EHA89v3bIOBJoYbLJ8klK3qickNLNcK1xh7TNUO6XRgDVXQgG/Ot 31IbvRZwJGUpYOR3TPulLSUCwLBCOmhLoM2ve/XOfdvaReRb9iLewo2TYyfgS3u6Ch re0hD+XUwCl4kr7ee4jogqw6lWUdfcZNiifuglXs= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 06/10] watch: ensure children can use signal handlers Date: Mon, 4 Sep 2023 10:36:03 +0000 Message-ID: <20230904103607.1940839-7-e@80x24.org> In-Reply-To: <20230904103607.1940839-1-e@80x24.org> References: <20230904103607.1940839-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 7 +++---- script/public-inbox-watch | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm index c3b5b791..a2dc125f 100644 --- a/lib/PublicInbox/Watch.pm +++ b/lib/PublicInbox/Watch.pm @@ -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); } diff --git a/script/public-inbox-watch b/script/public-inbox-watch index 2fb27343..75a9a36b 100755 --- a/script/public-inbox-watch +++ b/script/public-inbox-watch @@ -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); }