about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-10 12:15:15 +0000
committerEric Wong <e@80x24.org>2021-01-12 03:51:42 +0000
commit2e755e0b5e3bc25b06055dce53009bfba4c0504b (patch)
treeca9b02aa13016ae789396e3a61d5efccc613f634
parenta1e00c6bca403ffea74a5e169fa0d2f715c69051 (diff)
downloadpublic-inbox-2e755e0b5e3bc25b06055dce53009bfba4c0504b.tar.gz
Using kill(2) is too dangerous since extremely long
queries may mean the original PID of the aborted lei(1)
client process to be recycled by a new process.  It would
be bad if the lei_xsearch worker process issued a kill
on the wrong process.

So just rely on sending the exit message via socket.
-rw-r--r--lib/PublicInbox/LEI.pm18
-rw-r--r--lib/PublicInbox/LeiQuery.pm2
-rwxr-xr-xscript/lei2
3 files changed, 9 insertions, 13 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index f8b8cd4a..0cbf342c 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -240,15 +240,12 @@ my %CONFIG_KEYS = (
 sub x_it ($$) { # pronounced "exit"
         my ($self, $code) = @_;
         $self->{1}->autoflush(1); # make sure client sees stdout before exit
-        if (my $sig = ($code & 127)) {
-                kill($sig, $self->{pid} // $$);
-        } else {
-                $code >>= 8;
-                if (my $sock = $self->{sock}) {
-                        say $sock "exit=$code";
-                } else { # for oneshot
-                        $quit->($code);
-                }
+        my $sig = ($code & 127);
+        $code >>= 8 unless $sig;
+        if (my $sock = $self->{sock}) {
+                say $sock "exit=$code";
+        } else { # for oneshot
+                $quit->($code);
         }
 }
 
@@ -675,13 +672,12 @@ sub accept_dispatch { # Listener {post_accept} callback
                 say $sock "request command truncated";
                 return;
         }
-        my ($client_pid, $argc, @argv) = split(/\0/, $buf, -1);
+        my ($argc, @argv) = split(/\0/, $buf, -1);
         undef $buf;
         my %env = map { split(/=/, $_, 2) } splice(@argv, $argc);
         if (chdir($env{PWD})) {
                 local %ENV = %env;
                 $self->{env} = \%env;
-                $self->{pid} = $client_pid + 0;
                 eval { dispatch($self, @argv) };
                 say $sock $@ if $@;
         } else {
diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm
index 040c284d..d5376be5 100644
--- a/lib/PublicInbox/LeiQuery.pm
+++ b/lib/PublicInbox/LeiQuery.pm
@@ -76,7 +76,7 @@ sub lei_q {
         }
         my $j = $opt->{jobs} // scalar(@srcs) > 4 ? 4 : scalar(@srcs);
         $j = 1 if !$opt->{thread};
-        if ($self->{pid}) {
+        if ($self->{sock}) {
                 $lxs->wq_workers_start('lei_xsearch', $j, $self->oldset)
                         // $self->wq_workers($j);
         }
diff --git a/script/lei b/script/lei
index 5e30f4d7..bea06b2c 100755
--- a/script/lei
+++ b/script/lei
@@ -62,7 +62,7 @@ Falling back to (slow) one-shot mode
         1;
 }) { # (Socket::MsgHdr|IO::FDPass|Inline::C), $sock, $pwd are all available:
         local $ENV{PWD} = $pwd;
-        my $buf = join("\0", $$, scalar(@ARGV), @ARGV);
+        my $buf = join("\0", scalar(@ARGV), @ARGV);
         while (my ($k, $v) = each %ENV) { $buf .= "\0$k=$v" }
         $buf .= "\0\0";
         select $sock;