about summary refs log tree commit homepage
path: root/lib/PublicInbox/TestCommon.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-09-04 10:36:07 +0000
committerEric Wong <e@80x24.org>2023-09-05 03:01:43 +0000
commitb914e67f82eeeadc223d2ba0f7c2ad5979819b02 (patch)
tree4417663b31193c56727ab7bd1a7edbff84977e7c /lib/PublicInbox/TestCommon.pm
parent2232ff9a7d99b567618f27380603ca52dd296144 (diff)
downloadpublic-inbox-b914e67f82eeeadc223d2ba0f7c2ad5979819b02.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/TestCommon.pm')
-rw-r--r--lib/PublicInbox/TestCommon.pm11
1 files changed, 9 insertions, 2 deletions
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;