]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: restore working directory in more places
authorEric Wong <e@80x24.org>
Fri, 28 May 2021 09:45:20 +0000 (09:45 +0000)
committerEric Wong <e@80x24.org>
Fri, 28 May 2021 18:28:05 +0000 (18:28 +0000)
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
lib/PublicInbox/LeiLcat.pm
lib/PublicInbox/LeiQuery.pm
lib/PublicInbox/LeiXSearch.pm

index 07378ca7bd1e1bc3be6bab0c95ccf897f373c35f..e5ff9e5daca1a3b283dfbf6e2639f8ade6facdc2 100644 (file)
@@ -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
index 0f585ff5a6293f51009483fdf722d0100573aa1f..f9d9633acd49033f18adfb51800c67d442b0a7f8 100644 (file)
@@ -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;
index 1999a5344885f22799b666459579d04d88aa9831..0435a5163137a4f0693bf7374bf544041aa0ace0 100644 (file)
@@ -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});
index e2a8e8e3b6881a360c6db2458c5c6c9466c6ea6b..760f9718ce7bfda89bad1265873c694b3530211a 100644 (file)
@@ -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 = $@;