From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 5DAE81F9F3 for ; Wed, 22 Sep 2021 02:24:35 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/7] treewide: fix %SIG localization, harder Date: Wed, 22 Sep 2021 02:24:30 +0000 Message-Id: <20210922022435.17835-3-e@80x24.org> In-Reply-To: <20210922022435.17835-1-e@80x24.org> References: <20210922022435.17835-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This fixes the occasional t/lei-sigpipe.t infinite loop under "make check-run". Link: http://nntp.perl.org/group/perl.perl5.porters/258784 Followup-to: b552bb9150775fe4 ("daemon+watch: fix localization of %SIG for non-signalfd users") --- lib/PublicInbox/Admin.pm | 2 +- lib/PublicInbox/ExtSearchIdx.pm | 4 ++-- lib/PublicInbox/IPC.pm | 4 ++-- lib/PublicInbox/TestCommon.pm | 3 ++- lib/PublicInbox/Watch.pm | 4 +++- lib/PublicInbox/Xapcmd.pm | 8 ++++---- t/run.perl | 1 + 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm index 9ff59bca..20964f9c 100644 --- a/lib/PublicInbox/Admin.pm +++ b/lib/PublicInbox/Admin.pm @@ -274,7 +274,7 @@ sub index_inbox { if (my $pr = $opt->{-progress}) { $pr->("indexing $ibx->{inboxdir} ...\n"); } - local %SIG = %SIG; + local @SIG{keys %SIG} = values %SIG; setup_signals(\&index_terminate, $ibx); my $idx = { current_info => $ibx->{inboxdir} }; local $SIG{__WARN__} = sub { diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm index e0ba6c32..6b29789a 100644 --- a/lib/PublicInbox/ExtSearchIdx.pm +++ b/lib/PublicInbox/ExtSearchIdx.pm @@ -1272,7 +1272,7 @@ sub event_step { # PublicInbox::DS::requeue callback sub eidx_watch { # public-inbox-extindex --watch main loop my ($self, $opt) = @_; - local %SIG = %SIG; + local @SIG{keys %SIG} = values %SIG; for my $sig (qw(HUP USR1 TSTP QUIT INT TERM)) { $SIG{$sig} = sub { warn "SIG$sig ignored while scanning\n" }; } @@ -1307,7 +1307,7 @@ sub eidx_watch { # public-inbox-extindex --watch main loop $sig->{QUIT} = $sig->{INT} = $sig->{TERM} = $quit; my $sigfd = PublicInbox::Sigfd->new($sig, $PublicInbox::Syscall::SFD_NONBLOCK); - %SIG = (%SIG, %$sig) if !$sigfd; + @SIG{keys %$sig} = values(%$sig) if !$sigfd; local $self->{-watch_sync} = $sync; # for ->on_inbox_unlock if (!$sigfd) { # wake up every second to accept signals if we don't diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm index 1c699d76..3e29def8 100644 --- a/lib/PublicInbox/IPC.pm +++ b/lib/PublicInbox/IPC.pm @@ -115,7 +115,7 @@ sub ipc_worker_spawn { $fields //= {}; local @$self{keys %$fields} = values(%$fields); my $on_destroy = $self->ipc_atfork_child; - local %SIG = %SIG; + local @SIG{keys %SIG} = values %SIG; PublicInbox::DS::sig_setmask($sigset); ipc_worker_loop($self, $r_req, $w_res); }; @@ -361,7 +361,7 @@ sub _wq_worker_start ($$$$) { $fields //= {}; local @$self{keys %$fields} = values(%$fields); my $on_destroy = $self->ipc_atfork_child; - local %SIG = %SIG; + local @SIG{keys %SIG} = values %SIG; PublicInbox::DS::sig_setmask($oldset); wq_worker_loop($self, $bcast2); }; diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index 9e152394..92a7db36 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -317,7 +317,8 @@ sub run_script ($;$$) { # note: "local *STDIN = *STDIN;" and so forth did not work in # old versions of perl local %ENV = $env ? (%ENV, %$env) : %ENV; - local %SIG = %SIG; + local @SIG{keys %SIG} = map { undef } values %SIG; + local $SIG{FPE} = 'IGNORE'; # Perl default local $0 = join(' ', @$cmd); my $orig_io = _prepare_redirects($fhref); my $cwdfh = $lei_cwdfh; diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm index 387eb6d2..0523ad03 100644 --- a/lib/PublicInbox/Watch.pm +++ b/lib/PublicInbox/Watch.pm @@ -384,7 +384,9 @@ sub watch_atfork_child ($) { delete $self->{poll_pids}; delete $self->{opendirs}; PublicInbox::DS->Reset; - %SIG = (%SIG, %{$self->{sig}}, CHLD => 'DEFAULT'); + my $sig = delete $self->{sig}; + $sig->{CHLD} = 'DEFAULT'; + @SIG{keys %$sig} = values %$sig; PublicInbox::DS::sig_setmask($self->{oldset}); } diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm index 588e7b94..b962fa84 100644 --- a/lib/PublicInbox/Xapcmd.pm +++ b/lib/PublicInbox/Xapcmd.pm @@ -149,7 +149,7 @@ sub process_queue { # run in parallel: my %pids; - local %SIG = %SIG; + local @SIG{keys %SIG} = values %SIG; setup_signals(\&kill_pids, \%pids); while (@$queue) { while (scalar(keys(%pids)) < $max && scalar(@$queue)) { @@ -285,7 +285,7 @@ sub run { PublicInbox::SearchIdx::load_xapian_writable(); } - local %SIG = %SIG; + local @SIG{keys %SIG} = values %SIG; setup_signals(); $ibx->with_umask(\&_run, $ibx, $cb, $opt); } @@ -343,7 +343,7 @@ sub compact ($$) { # cb_spawn callback $pr->("$pfx `".join(' ', @$cmd)."'\n") if $pr; push @$cmd, $src, $dst; my ($rd, $pid); - local %SIG = %SIG; + local @SIG{keys %SIG} = values %SIG; setup_signals(\&kill_compact, \$pid); ($rd, $pid) = popen_rd($cmd, undef, $rdr); while (<$rd>) { @@ -428,7 +428,7 @@ sub cpdb ($$) { # cb_spawn callback } my ($tmp, $ft); - local %SIG = %SIG; + local @SIG{keys %SIG} = values %SIG; if ($opt->{compact}) { my ($dir) = ($new =~ m!(.*?/)[^/]+/*\z!); same_fs_or_die($dir, $new); diff --git a/t/run.perl b/t/run.perl index e5ee0ade..0fe6d08b 100755 --- a/t/run.perl +++ b/t/run.perl @@ -168,6 +168,7 @@ my $start_worker = sub { my $pid = fork // DIE "fork: $!"; if ($pid == 0) { close $wr if $wr; + $SIG{USR1} = undef; # undo parent $SIG{USR1} $worker = $$; while (1) { my $r = sysread($rd, my $buf, UINT_SIZE);