about summary refs log tree commit homepage
path: root/script
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 /script
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 'script')
-rwxr-xr-xscript/lei18
1 files changed, 3 insertions, 15 deletions
diff --git a/script/lei b/script/lei
index 9610a876..a4a0217b 100755
--- a/script/lei
+++ b/script/lei
@@ -6,7 +6,7 @@ use v5.10.1;
 use Socket qw(AF_UNIX SOCK_SEQPACKET MSG_EOR pack_sockaddr_un);
 use Errno qw(EINTR ECONNRESET);
 use PublicInbox::CmdIPC4;
-my $narg = 4;
+my $narg = 5;
 my ($sock, $pwd);
 my $recv_cmd = PublicInbox::CmdIPC4->can('recv_cmd4');
 my $send_cmd = PublicInbox::CmdIPC4->can('send_cmd4') // do {
@@ -74,25 +74,13 @@ connect($path): $! (after attempted daemon start)
 Falling back to (slow) one-shot mode
 
         }
-        require Cwd;
-        $pwd = $ENV{PWD} // '';
-        my $cwd = Cwd::fastcwd() // die "fastcwd(PWD=$pwd): $!";
-        if ($pwd ne $cwd) { # prefer ENV{PWD} if it's a symlink to real cwd
-                my @st_cwd = stat($cwd) or die "stat(cwd=$cwd): $!";
-                my @st_pwd = stat($pwd); # PWD invalid, use cwd
-                # make sure st_dev/st_ino match for {PWD} to be valid
-                $pwd = $cwd if (!@st_pwd || $st_pwd[1] != $st_cwd[1] ||
-                                        $st_pwd[0] != $st_cwd[0]);
-        } else {
-                $pwd = $cwd;
-        }
         1;
 }) { # (Socket::MsgHdr|Inline::C), $sock, $pwd are all available:
-        $ENV{PWD} = $pwd;
+        open my $dh, '<', '.' or die "open(.) $!";
         my $buf = join("\0", scalar(@ARGV), @ARGV);
         while (my ($k, $v) = each %ENV) { $buf .= "\0$k=$v" }
         $buf .= "\0\0";
-        $send_cmd->($sock, [ 0, 1, 2 ], $buf, MSG_EOR);
+        $send_cmd->($sock, [ 0, 1, 2, fileno($dh) ], $buf, MSG_EOR);
         $SIG{TERM} = $SIG{INT} = $SIG{QUIT} = sub {
                 my ($sig) = @_; # 'TERM', not an integer :<
                 $SIG{$sig} = 'DEFAULT';