about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-13 19:06:27 -1200
committerEric Wong <e@80x24.org>2021-01-15 00:19:12 +0000
commitd1b9582872d1824f166a038dcf32b6ae8c6dc735 (patch)
treeccaef6fb415731b23d83fa9e8a3526d660c5ad18 /lib/PublicInbox
parent9ecd339fc32ff9c6b8ddcc98a992f5bcc682077e (diff)
downloadpublic-inbox-d1b9582872d1824f166a038dcf32b6ae8c6dc735.tar.gz
Perl chdir() automatically does fchdir(2) if given a file
or directory handle since 5.8.8/5.10.0, so we can safely
rely on it given our 5.10.1+ requirement.

This means we no longer have to waste several milliseconds
loading the Cwd.so and making stat() calls to ensure
ENV{PWD} is correct and usable in the server.  It also lets
us work in directories that are no longer accessible via
pathname.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/LEI.pm14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 9786e7ac..1f4a3082 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -674,9 +674,9 @@ sub accept_dispatch { # Listener {post_accept} callback
         select($rvec, undef, undef, 1) or
                 return send($sock, 'timed out waiting to recv FDs', MSG_EOR);
         my @fds = $recv_cmd->($sock, my $buf, 4096 * 33); # >MAX_ARG_STRLEN
-        if (scalar(@fds) == 3) {
+        if (scalar(@fds) == 4) {
                 my $i = 0;
-                for my $rdr (qw(<&= >&= >&=)) {
+                for my $rdr (qw(<&= >&= >&= <&=)) {
                         my $fd = shift(@fds);
                         open($self->{$i++}, $rdr, $fd) and next;
                         send($sock, "open($rdr$fd) (FD=$i): $!", MSG_EOR);
@@ -692,13 +692,13 @@ sub accept_dispatch { # Listener {post_accept} callback
         my ($argc, @argv) = split(/\0/, $buf, -1);
         undef $buf;
         my %env = map { split(/=/, $_, 2) } splice(@argv, $argc);
-        if (chdir($env{PWD})) {
+        if (chdir(delete($self->{3}))) {
                 local %ENV = %env;
                 $self->{env} = \%env;
                 eval { dispatch($self, @argv) };
                 send($sock, $@, MSG_EOR) if $@;
         } else {
-                send($sock, "chdir($env{PWD}): $!", MSG_EOR); # implicit close
+                send($sock, "fchdir: $!", MSG_EOR); # implicit close
         }
 }
 
@@ -746,7 +746,7 @@ our $oldset; sub oldset { $oldset }
 
 # lei(1) calls this when it can't connect
 sub lazy_start {
-        my ($path, $errno, $nfd) = @_;
+        my ($path, $errno, $narg) = @_;
         if ($errno == ECONNREFUSED) {
                 unlink($path) or die "unlink($path): $!";
         } elsif ($errno != ENOENT) {
@@ -761,7 +761,7 @@ sub lazy_start {
         my $dev_ino_expect = pack('dd', $st[0], $st[1]); # dev+ino
         pipe(my ($eof_r, $eof_w)) or die "pipe: $!";
         local $oldset = PublicInbox::DS::block_signals();
-        if ($nfd == 4) {
+        if ($narg == 5) {
                 $send_cmd = PublicInbox::Spawn->can('send_cmd4');
                 $recv_cmd = PublicInbox::Spawn->can('recv_cmd4') // do {
                         require PublicInbox::CmdIPC4;
@@ -770,7 +770,7 @@ sub lazy_start {
                 };
         }
         $recv_cmd or die <<"";
-(Socket::MsgHdr || Inline::C) missing/unconfigured (nfd=$nfd);
+(Socket::MsgHdr || Inline::C) missing/unconfigured (narg=$narg);
 
         require PublicInbox::Listener;
         require PublicInbox::EOFpipe;