* [PATCH 2/7] treewide: fix %SIG localization, harder
@ 2021-09-22 2:24 4% ` Eric Wong
0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2021-09-22 2:24 UTC (permalink / raw)
To: meta
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);
^ permalink raw reply related [relevance 4%]
* [PATCH 03/14] daemon+watch: fix localization of %SIG for non-signalfd users
2021-01-14 7:06 5% [PATCH 00/14] lei: another pile of changes Eric Wong
@ 2021-01-14 7:06 7% ` Eric Wong
0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2021-01-14 7:06 UTC (permalink / raw)
To: meta
It turns out "local" did not take effect in the way we used it:
http://nntp.perl.org/group/perl.perl5.porters/258784
<CAHhgV8hPbcmkzWizp6Vijw921M5BOXixj4+zTh3nRS9vRBYk8w@mail.gmail.com>
Fortunately, none of the old use cases seem affected, unlike the
previous lei change to ensure consistent SIGPIPE handling.
---
lib/PublicInbox/Daemon.pm | 4 ++--
script/public-inbox-watch | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 4b738b7c..f5543c85 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -514,7 +514,7 @@ EOF
CHLD => \&reap_children,
};
my $sigfd = PublicInbox::Sigfd->new($sig, 0);
- local %SIG = (%SIG, %$sig) if !$sigfd;
+ local @SIG{keys %$sig} = values(%$sig) unless $sigfd;
PublicInbox::DS::sig_setmask($oldset) if !$sigfd;
while (1) { # main loop
my $n = scalar keys %pids;
@@ -628,7 +628,7 @@ sub daemon_loop ($$$$) {
PublicInbox::Listener->new($_, $tls_cb || $post_accept)
} @listeners;
my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK);
- local %SIG = (%SIG, %$sig) if !$sigfd;
+ local @SIG{keys %$sig} = values(%$sig) unless $sigfd;
if (!$sigfd) {
# wake up every second to accept signals if we don't
# have signalfd or IO::KQueue:
diff --git a/script/public-inbox-watch b/script/public-inbox-watch
index 10c7cd6f..86349d71 100755
--- a/script/public-inbox-watch
+++ b/script/public-inbox-watch
@@ -58,7 +58,7 @@ if ($watch) {
PublicInbox::DS::requeue($scan) if $do_scan;
my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK);
- local %SIG = (%SIG, %$sig) if !$sigfd;
+ local @SIG{keys %$sig} = values(%$sig) unless $sigfd;
if (!$sigfd) {
PublicInbox::DS::sig_setmask($oldset);
PublicInbox::DS->SetLoopTimeout(1000);
^ permalink raw reply related [relevance 7%]
* [PATCH 00/14] lei: another pile of changes
@ 2021-01-14 7:06 5% Eric Wong
2021-01-14 7:06 7% ` [PATCH 03/14] daemon+watch: fix localization of %SIG for non-signalfd users Eric Wong
0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2021-01-14 7:06 UTC (permalink / raw)
To: meta
PATCH 2/14 took forever to figure out; turns out I was hunting
an old bug in Perl :x (and led to PATCH 3/14, too)
We could probably go farther on 5/14 and eliminate the
need for @TO_CLOSE_ATFORK_CHILD completely, but my brain
was fried from 2/14 :x.
The "ts:" => "rt:" change is technically user-visible,
but "ts:" was never publicly documented so I doubt it
affects anybody. "rt:" (received time) may be documented
in the future.
Eric Wong (14):
cmd_ipc: support + test EINTR + EAGAIN, no FDs
lei: test SIGPIPE, stop xsearch workers on client abort
daemon+watch: fix localization of %SIG for non-signalfd users
lei: do not unlink socket path at exit
lei: reduce live FD references in wq child
lei: rely on localized $current_lei for warnings
lei_dedupe+shared_kv: ensure round-tripping serialization
lei q: reinstate smsg dedupe
search: rename "ts:" prefix to "rt:"
lei_overview: rename "references" to "refs"
lei: q: lock stdout on overview output
leixsearch: remove some commented out code
lei: remove temporary var on open
lei: pass FD to CWD via cmsg, use fchdir on server
MANIFEST | 2 +
lib/PublicInbox/CmdIPC4.pm | 6 +-
lib/PublicInbox/Daemon.pm | 4 +-
lib/PublicInbox/IMAPsearchqp.pm | 6 +-
lib/PublicInbox/IPC.pm | 45 +++-----
lib/PublicInbox/LEI.pm | 182 +++++++++++++++++---------------
lib/PublicInbox/LeiDedupe.pm | 29 ++---
lib/PublicInbox/LeiOverview.pm | 43 +++++++-
lib/PublicInbox/LeiQuery.pm | 27 ++---
lib/PublicInbox/LeiXSearch.pm | 60 +++++++----
lib/PublicInbox/Lock.pm | 2 +-
lib/PublicInbox/Search.pm | 2 +-
lib/PublicInbox/SharedKV.pm | 12 ++-
lib/PublicInbox/Spawn.pm | 13 ++-
script/lei | 88 +++++++++------
script/public-inbox-watch | 2 +-
t/cmd_ipc.t | 32 ++++++
t/imap_searchqp.t | 6 +-
t/lei.t | 33 +-----
t/lei_dedupe.t | 13 +++
t/lei_overview.t | 33 ++++++
xt/lei-sigpipe.t | 32 ++++++
22 files changed, 417 insertions(+), 255 deletions(-)
create mode 100644 t/lei_overview.t
create mode 100644 xt/lei-sigpipe.t
^ permalink raw reply [relevance 5%]
Results 1-3 of 3 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-01-14 7:06 5% [PATCH 00/14] lei: another pile of changes Eric Wong
2021-01-14 7:06 7% ` [PATCH 03/14] daemon+watch: fix localization of %SIG for non-signalfd users Eric Wong
2021-09-22 2:24 [PATCH 0/7] lei bugfixes and other fixes Eric Wong
2021-09-22 2:24 4% ` [PATCH 2/7] treewide: fix %SIG localization, harder Eric Wong
Code repositories for project(s) associated with this public 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).