about summary refs log tree commit homepage
path: root/lib/PublicInbox/XapHelper.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-17 23:37:55 +0000
committerEric Wong <e@80x24.org>2023-10-18 20:50:26 +0000
commite029ce7fd62de79e57e665e19f25c7ae1a94dcc7 (patch)
tree65c2ac3ea97fe89d1403364d8ac9083ea748a4b1 /lib/PublicInbox/XapHelper.pm
parent33fe12fa12259c61bd15efc54446334e2e28d67b (diff)
downloadpublic-inbox-e029ce7fd62de79e57e665e19f25c7ae1a94dcc7.tar.gz
We can just close the socket FD to ensure things fail ASAP
when a SIGTERM hits instead of wasting time making getppid(2)
syscalls.
Diffstat (limited to 'lib/PublicInbox/XapHelper.pm')
-rw-r--r--lib/PublicInbox/XapHelper.pm7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/PublicInbox/XapHelper.pm b/lib/PublicInbox/XapHelper.pm
index fe8d20f4..c31fe9a2 100644
--- a/lib/PublicInbox/XapHelper.pm
+++ b/lib/PublicInbox/XapHelper.pm
@@ -17,7 +17,7 @@ use autodie qw(open);
 use POSIX qw(:signal_h);
 use Fcntl qw(LOCK_UN LOCK_EX);
 my $X = \%PublicInbox::Search::X;
-our (%SRCH, %WORKERS, $parent_pid, $alive, $nworker, $workerset);
+our (%SRCH, %WORKERS, $alive, $nworker, $workerset);
 our $stderr = \*STDERR;
 
 # only short options for portability in C++ implementation
@@ -177,7 +177,8 @@ sub recv_loop {
         local $SIG{__WARN__} = sub { print $stderr @_ };
         my $rbuf;
         my $in = \*STDIN;
-        while (!defined($parent_pid) || getppid == $parent_pid) {
+        local $SIG{TERM} = sub { undef $in };
+        while (defined($in)) {
                 PublicInbox::DS::sig_setmask($workerset);
                 my @fds = $PublicInbox::IPC::recv_cmd->($in, $rbuf, 4096*33);
                 scalar(@fds) or exit(66); # EX_NOINPUT
@@ -218,7 +219,6 @@ sub start_worker ($) {
         if ($pid == 0) {
                 undef %WORKERS;
                 PublicInbox::DS::Reset();
-                $SIG{TERM} = sub { $parent_pid = -1 };
                 $SIG{TTIN} = $SIG{TTOU} = 'IGNORE';
                 $SIG{CHLD} = 'DEFAULT'; # Xapian may use this
                 recv_loop();
@@ -267,7 +267,6 @@ sub start (@) {
         for (POSIX::SIGTERM, POSIX::SIGCHLD) {
                 $workerset->delset($_) or die "delset($_): $!";
         }
-        local $parent_pid = $$;
         my $sig = {
                 TTIN => sub {
                         if ($alive) {