]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
test_common: start_script: set default signals
authorEric Wong <e@80x24.org>
Mon, 4 Sep 2023 10:36:07 +0000 (10:36 +0000)
committerEric Wong <e@80x24.org>
Tue, 5 Sep 2023 03:01:43 +0000 (03:01 +0000)
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

index a90e89d1f21fae70cd982b16628397b30e754ef4..b2774f5847aa5c60957566549969f1b9965ec35d 100644 (file)
@@ -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;