]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: get rid of client {pid} field
authorEric Wong <e@80x24.org>
Sun, 10 Jan 2021 12:15:15 +0000 (12:15 +0000)
committerEric Wong <e@80x24.org>
Tue, 12 Jan 2021 03:51:42 +0000 (03:51 +0000)
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.

lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiQuery.pm
script/lei

index f8b8cd4a0f62b962bc8f687f38ccb9a5d5a041a3..0cbf342cd52583eab8f6fda6fa2b83160cea9a38 100644 (file)
@@ -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 {
index 040c284d5d08075f040cac2392d136dcd8fe82c1..d5376be51f59cd630293f1e3d6b823edc3af9ae3 100644 (file)
@@ -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);
        }
index 5e30f4d7dec277d2ac7d0f0ccff12670126a6d66..bea06b2c0f6edbe4ce5bc810c62bb26c76e0451c 100755 (executable)
@@ -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;