From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 9A09F1F55F for ; Thu, 14 Sep 2023 23:10:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1694733005; bh=cT50osyM1+S19SeJl1/gaP1aQ3yeTjhxGoVo6tfc2Bo=; h=From:To:Subject:Date:From; b=oJWwREKVX6HsvQhoBYquc8lAIDyLklx1yLpwy3sGXngcrEDU07nkflRksoSo9/1WO TxRuuky/Xrudk2F5EhkfKIaXzMhqx0BxN+NcO5/aiSAyWz8ER2voQx41BJhcwkk2LX r/jXP8A2+h3GJx3mpurN1r1iSWV7xHYt9xizmZzQ= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] lei: ensure --stdin sets %ENV and $current_lei Date: Thu, 14 Sep 2023 23:10:05 +0000 Message-ID: <20230914231005.1969671-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --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 | 3 +++ lib/PublicInbox/LeiLcat.pm | 2 ++ lib/PublicInbox/LeiQuery.pm | 2 ++ 3 files changed, 7 insertions(+) diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm index d1dca4ef..0455e739 100644 --- a/lib/PublicInbox/LeiInspect.pm +++ b/lib/PublicInbox/LeiInspect.pm @@ -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); diff --git a/lib/PublicInbox/LeiLcat.pm b/lib/PublicInbox/LeiLcat.pm index 8d89cb73..7ed191c3 100644 --- a/lib/PublicInbox/LeiLcat.pm +++ b/lib/PublicInbox/LeiLcat.pm @@ -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; diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm index 26cfb3fd..a23354f0 100644 --- a/lib/PublicInbox/LeiQuery.pm +++ b/lib/PublicInbox/LeiQuery.pm @@ -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});