From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id DAEE71FFA6 for ; Sun, 10 Jan 2021 12:15:20 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 18/22] lei: get rid of client {pid} field Date: Sun, 10 Jan 2021 12:15:15 +0000 Message-Id: <20210110121519.17044-19-e@80x24.org> In-Reply-To: <20210110121519.17044-1-e@80x24.org> References: <20210110121519.17044-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 18 +++++++----------- lib/PublicInbox/LeiQuery.pm | 2 +- script/lei | 2 +- 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;