user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/7] treewide: fix %SIG localization, harder
Date: Wed, 22 Sep 2021 02:24:30 +0000	[thread overview]
Message-ID: <20210922022435.17835-3-e@80x24.org> (raw)
In-Reply-To: <20210922022435.17835-1-e@80x24.org>

This fixes the occasional t/lei-sigpipe.t infinite loop
under "make check-run".

Link: http://nntp.perl.org/group/perl.perl5.porters/258784
  <CAHhgV8hPbcmkzWizp6Vijw921M5BOXixj4+zTh3nRS9vRBYk8w@mail.gmail.com>
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);

  parent reply	other threads:[~2021-09-22  2:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22  2:24 [PATCH 0/7] lei bugfixes and other fixes Eric Wong
2021-09-22  2:24 ` [PATCH 1/7] ipc: do not add "0" to $0 of solo workers Eric Wong
2021-09-22  2:24 ` Eric Wong [this message]
2021-09-22  2:24 ` [PATCH 3/7] script/lei: describe purpose of sleep loop Eric Wong
2021-09-22  2:24 ` [PATCH 4/7] lei: dclose: do not close unnecessarily Eric Wong
2021-09-22  2:24 ` [PATCH 5/7] inbox: do not waste hash slot on httpbackend_limiter Eric Wong
2021-09-22  2:24 ` [PATCH 6/7] lei up: avoid excessively parallel --all Eric Wong
2021-09-22  2:24 ` [PATCH 7/7] lei: drop redundant WQ EOF callbacks Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210922022435.17835-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    --subject='Re: [PATCH 2/7] treewide: fix %SIG localization, harder' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).