From: Eric Wong Date: Sun, 10 Jan 2021 12:15:15 +0000 (+0000) Subject: lei: get rid of client {pid} field X-Git-Tag: v1.7.0~1381 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=2e755e0b5e3bc25b06055dce53009bfba4c0504b lei: get rid of client {pid} field 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. --- 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;