From b914e67f82eeeadc223d2ba0f7c2ad5979819b02 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 4 Sep 2023 10:36:07 +0000 Subject: test_common: start_script: set default signals 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. Drop a redundant DS->Reset while we're at it. --- lib/PublicInbox/TestCommon.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/TestCommon.pm') diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index a90e89d1..b2774f58 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 $tmp_mask = 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 $tmp_mask; 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 $tmp_mask; require PublicInbox::AutoReap; my $td = PublicInbox::AutoReap->new($pid); $td->{-extra} = $tail; -- cgit v1.2.3-24-ge0c7