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-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,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 BEE941F9F4 for ; Fri, 28 May 2021 09:45:21 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/3] lei: restore working directory in more places Date: Fri, 28 May 2021 09:45:20 +0000 Message-Id: <20210528094521.26490-3-e@80x24.org> In-Reply-To: <20210528094521.26490-1-e@80x24.org> References: <20210528094521.26490-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Every tick of the event loop can change the working directory, so we need to restore it for every client if they operate in different directories. This would be easier if we had openat(2) and friends in Perl; but Inline::C is practically required for lei, now. --- lib/PublicInbox/LEI.pm | 6 ++++++ lib/PublicInbox/LeiLcat.pm | 4 +--- lib/PublicInbox/LeiQuery.pm | 4 +--- lib/PublicInbox/LeiXSearch.pm | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 07378ca7..e5ff9e5d 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -1239,6 +1239,12 @@ sub wq_done_wait { # dwaitpid callback $lei->dclose; } +sub fchdir { + my ($lei) = @_; + my $dh = $lei->{3} // die 'BUG: lei->{3} (CWD) gone'; + chdir($dh) || $lei->fail("fchdir: $!"); +} + sub wq_eof { # EOF callback for main daemon my ($lei) = @_; my $wq1 = delete $lei->{wq1} // return $lei->fail; # already failed diff --git a/lib/PublicInbox/LeiLcat.pm b/lib/PublicInbox/LeiLcat.pm index 0f585ff5..f9d9633a 100644 --- a/lib/PublicInbox/LeiLcat.pm +++ b/lib/PublicInbox/LeiLcat.pm @@ -89,9 +89,7 @@ sub _stdin { # PublicInbox::InputPipe::consume callback for --stdin my ($lei) = @_; # $_[1] = $rbuf if (defined($_[1])) { $_[1] eq '' and return eval { - if (my $dfd = $lei->{3}) { - chdir($dfd) or return $lei->fail("fchdir: $!"); - } + $lei->fchdir or return; my @argv = split(/\s+/, $lei->{mset_opt}->{qstr}); $lei->{mset_opt}->{qstr} = extract_all($lei, @argv) or return; diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm index 1999a534..0435a516 100644 --- a/lib/PublicInbox/LeiQuery.pm +++ b/lib/PublicInbox/LeiQuery.pm @@ -51,9 +51,7 @@ sub qstr_add { # PublicInbox::InputPipe::consume callback for --stdin my ($self) = @_; # $_[1] = $rbuf if (defined($_[1])) { $_[1] eq '' and return eval { - if (my $dfd = $self->{3}) { - chdir($dfd) or return $self->fail("fchdir: $!"); - } + $self->fchdir or return; $self->{mset_opt}->{q_raw} = $self->{mset_opt}->{qstr}; $self->{lse}->query_approxidate($self->{lse}->git, $self->{mset_opt}->{qstr}); diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index e2a8e8e3..760f9718 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -394,6 +394,7 @@ Error closing $lei->{ovv}->{dst}: $! sub do_post_augment { my ($lei) = @_; my $l2m = $lei->{l2m} or return; # client disconnected + $lei->fchdir or return; my $err; eval { $l2m->post_augment($lei) }; $err = $@;