]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei: ensure --stdin sets %ENV and $current_lei
authorEric Wong <e@80x24.org>
Thu, 14 Sep 2023 23:10:05 +0000 (23:10 +0000)
committerEric Wong <e@80x24.org>
Fri, 15 Sep 2023 01:24:23 +0000 (01:24 +0000)
--stdin usage means the current request can be delayed
indefinitely while other requests with different %ENV
come in.  So make sure our warnings and %ENV can match
non-stdin behavior.

This probably fix segfaults during process cleanup on OpenBSD
since _lei_atfork_child use non-localized assignment of
$current_lei.  But it could be another red herring.  Either way,
it's the right thing to do from an environment replication
perspective.

lib/PublicInbox/LeiInspect.pm
lib/PublicInbox/LeiLcat.pm
lib/PublicInbox/LeiQuery.pm

index d1dca4ef28d43854858fa7d7a7b17ea41c548f31..0455e739ae27a783f676c59c506e70cd29476ed5 100644 (file)
@@ -255,6 +255,9 @@ sub ins_add { # InputPipe->consume callback
        my ($lei) = @_; # $_[1] = $rbuf
        if (defined $_[1]) {
                $_[1] eq '' and return eval {
+                       $lei->fchdir;
+                       local %ENV = %{$lei->{env}};
+                       local $PublicInbox::LEI::current_lei = $lei;
                        my $str = delete $lei->{istr};
                        $str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
                        my $eml = PublicInbox::Eml->new(\$str);
index 8d89cb7303f2b081b8005daea1dfdf2875f1747b..7ed191c3aee05281e20f50d9ae5a7b9622a4fc83 100644 (file)
@@ -128,6 +128,8 @@ sub _stdin { # PublicInbox::InputPipe::consume callback for --stdin
        return $lei->{mset_opt}->{qstr} .= $_[1] if $_[1] ne '';
        eval {
                $lei->fchdir;
+               local %ENV = %{$lei->{env}};
+               local $PublicInbox::LEI::current_lei = $lei;
                my @argv = split(/\s+/, $lei->{mset_opt}->{qstr});
                $lei->{mset_opt}->{qstr} = extract_all($lei, @argv) or return;
                $lei->_start_query;
index 26cfb3fdc7700f35b15744d241e980cdfa2eb95b..a23354f02cdad62eac549f792b561cf2c871b5f1 100644 (file)
@@ -65,6 +65,8 @@ sub qstr_add { # PublicInbox::InputPipe::consume callback for --stdin
        return $lei->{mset_opt}->{qstr} .= $_[1] if $_[1] ne '';
        eval {
                $lei->fchdir;
+               local %ENV = %{$lei->{env}};
+               local $PublicInbox::LEI::current_lei = $lei;
                $lei->{mset_opt}->{q_raw} = $lei->{mset_opt}->{qstr};
                $lei->{lse}->query_approxidate($lei->{lse}->git,
                                                $lei->{mset_opt}->{qstr});