From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] lei: ensure --stdin sets %ENV and $current_lei
Date: Thu, 14 Sep 2023 23:10:05 +0000 [thread overview]
Message-ID: <20230914231005.1969671-1-e@80x24.org> (raw)
--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});
reply other threads:[~2023-09-14 23:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230914231005.1969671-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).