From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 10/10] test_common: start_script: set default signals
Date: Sat, 2 Sep 2023 23:11:21 +0000 [thread overview]
Message-ID: <20230902231121.1821101-10-e@80x24.org> (raw)
In-Reply-To: <20230902231121.1821101-1-e@80x24.org>
We need to ensure signal handlers in the child process aren't
inherited from the parent. This change was originally intended
to block signals all the way until PublicInbox::Daemon and
PublicInbox::Watch were fully ready to handle them (preferably
via EVFILT_SIGNAL or signalfd); but that proved unrealistic.
Now, all signal handlers are restored to their default values
before signals are unblocked.
---
lib/PublicInbox/TestCommon.pm | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index a90e89d1..30d48470 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -478,7 +478,11 @@ sub start_script {
}
$tail = tail_f(@paths);
}
- my $pid = fork // die "fork: $!\n";
+ my $oset = PublicInbox::DS::block_signals();
+ require PublicInbox::OnDestroy;
+ my $restore = PublicInbox::OnDestroy->new(
+ \&PublicInbox::DS::sig_setmask, $oset);
+ my $pid = fork // die "fork: $!";
if ($pid == 0) {
eval { PublicInbox::DS->Reset };
for (@{delete($opt->{-CLOFORK}) // []}) {
@@ -504,8 +508,10 @@ sub start_script {
}
if ($opt->{-C}) { chdir($opt->{-C}) or die "chdir: $!" }
$0 = join(' ', @$cmd);
+ local @SIG{keys %SIG} = map { undef } values %SIG;
+ local $SIG{FPE} = 'IGNORE'; # Perl default
+ undef $restore;
if ($sub) {
- eval { PublicInbox::DS->Reset };
_run_sub($sub, $key, \@argv);
POSIX::_exit($? >> 8);
} else {
@@ -513,6 +519,7 @@ sub start_script {
die "FAIL: ",join(' ', $key, @argv), ": $!\n";
}
}
+ undef $restore;
require PublicInbox::AutoReap;
my $td = PublicInbox::AutoReap->new($pid);
$td->{-extra} = $tail;
prev parent reply other threads:[~2023-09-02 23:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-02 23:11 [PATCH 01/10] ds: don't block important signals we don't use Eric Wong
2023-09-02 23:11 ` [PATCH 02/10] t/sigfd: test EVFILT_SIGNAL vs signalfd differences Eric Wong
2023-09-02 23:11 ` [PATCH 03/10] t/sigfd: better checks related to SIGWINCH Eric Wong
2023-09-02 23:11 ` [PATCH 04/10] update devel/syscall-list to devel/sysdefs-list Eric Wong
2023-09-02 23:11 ` [PATCH 05/10] daemon: workaround pre-EVFILT_SIGNAL signals Eric Wong
2023-09-02 23:11 ` [PATCH 06/10] watch: ensure children can use signal handlers Eric Wong
2023-09-02 23:11 ` [PATCH 07/10] xap_helper: support SIGTTIN+SIGTTOU worker adjustments Eric Wong
2023-09-02 23:11 ` [PATCH 08/10] xap_helper.h: include signal.h for sig* functions Eric Wong
2023-09-02 23:11 ` [PATCH 09/10] tests: add `+SCM_RIGHTS' as a require_mods target Eric Wong
2023-09-02 23:11 ` Eric Wong [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230902231121.1821101-10-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).