From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 06/12] lei: always keep cwd fd {3} for ->fchdir
Date: Sat, 16 Oct 2021 01:00:57 +0000 [thread overview]
Message-ID: <20211016010103.30825-7-e@80x24.org> (raw)
In-Reply-To: <20211016010103.30825-1-e@80x24.org>
The extra FD shouldn't cause noticeable overhead in short-lived
workers, and it lets us simplify lei->rel2abs. Get rid of a
2-argument form of open() while we're at it, since it's been
considered for warning+deprecation by Perl for safety reasons.
---
lib/PublicInbox/LEI.pm | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index e7f37efaf0a3..0cdcf4492885 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -77,19 +77,16 @@ sub rel2abs {
return $p;
}
my $pwd = $self->{env}->{PWD};
- my $cwd;
if (defined $pwd) {
- my $xcwd = $self->{3} //
- ($cwd = getcwd() // die "getcwd(PWD=$pwd): $!");
if (my @st_pwd = stat($pwd)) {
- my @st_cwd = stat($xcwd) or die "stat($xcwd): $!";
+ my @st_cwd = stat($self->{3}) or die "stat({3}): $!";
"@st_pwd[1,0]" eq "@st_cwd[1,0]" or
$self->{env}->{PWD} = $pwd = undef;
} else { # PWD was invalid
$self->{env}->{PWD} = $pwd = undef;
}
}
- $pwd //= $self->{env}->{PWD} = $cwd // getcwd() // die "getcwd: $!";
+ $pwd //= $self->{env}->{PWD} = getcwd() // die "getcwd: $!";
File::Spec->rel2abs($p, $pwd);
}
@@ -558,7 +555,8 @@ sub _lei_atfork_child {
my ($self, $persist) = @_;
# we need to explicitly close things which are on stack
if ($persist) {
- chdir '/' or die "chdir(/): $!";
+ open $self->{3}, '<', '/' or die "open(/) $!";
+ fchdir($self) or die;
close($_) for (grep(defined, delete @$self{qw(0 1 2 sock)}));
if (my $cfg = $self->{cfg}) {
delete @$cfg{qw(-lei_store -watches -lei_note_event)};
@@ -568,7 +566,7 @@ sub _lei_atfork_child {
STDERR->autoflush(1);
POSIX::setpgid(0, $$) // die "setpgid(0, $$): $!";
}
- close($_) for (grep(defined, delete @$self{qw(3 old_1 au_done)}));
+ close($_) for (grep(defined, delete @$self{qw(old_1 au_done)}));
delete $self->{-socks};
if (my $op_c = delete $self->{pkt_op_c}) {
close(delete $op_c->{sock});
@@ -1190,7 +1188,7 @@ sub cfg2lei ($) {
open($lei->{0}, '<&', \*STDIN) or die "dup 0: $!";
open($lei->{1}, '>>&', \*STDOUT) or die "dup 1: $!";
open($lei->{2}, '>>&', \*STDERR) or die "dup 2: $!";
- open($lei->{3}, '/') or die "open /: $!";
+ open($lei->{3}, '<', '/') or die "open /: $!";
my ($x, $y);
socketpair($x, $y, AF_UNIX, SOCK_SEQPACKET, 0) or die "socketpair: $!";
$lei->{sock} = $x;
next prev parent reply other threads:[~2021-10-16 1:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-16 1:00 [PATCH 00/16] some yak-shaving and annoyance fixes Eric Wong
2021-10-16 1:00 ` [PATCH 01/12] smsg: add ->oidbin method Eric Wong
2021-10-16 1:00 ` [PATCH 02/12] dir_idle: do not add watches in ->new Eric Wong
2021-10-16 1:00 ` [PATCH 03/12] imapd+nntpd: drop timer-based expiration Eric Wong
2021-10-16 1:00 ` [PATCH 04/12] httpd: move pipeline logic into event_step Eric Wong
2021-10-16 1:00 ` [PATCH 05/12] lei: golf PATH2CFG cleanup Eric Wong
2021-10-16 1:00 ` Eric Wong [this message]
2021-10-16 1:00 ` [PATCH 07/12] lei: more eval guards for die on failure Eric Wong
2021-10-16 1:00 ` [PATCH 08/12] extindex: prune invalid alternate entries on --gc Eric Wong
2021-10-16 1:01 ` [PATCH 09/12] lei_overview: die rather than lei->fail Eric Wong
2021-10-16 1:01 ` [PATCH 10/12] lei_to_mail: quiet down abort messages Eric Wong
2021-10-16 1:01 ` [PATCH 11/12] inbox + search: use 5.10.1 and do some golfing Eric Wong
2021-10-16 1:01 ` [PATCH 12/12] httpd/async: switch to level-triggered epoll Eric Wong
2021-10-16 1:42 ` [PATCH 00/12] some yak-shaving and annoyance fixes Eric Wong
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=20211016010103.30825-7-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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).