]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/lei
update copyrights for 2021
[public-inbox.git] / script / lei
index ceaf1e004666474308c37c34d59e2719941e3c0c..ff4dcd45e06b26b5a3b99ce5208a52b4d9dca9d2 100755 (executable)
@@ -1,5 +1,5 @@
 #!perl -w
-# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
@@ -21,18 +21,13 @@ if (my ($sock, $pwd) = eval {
        my $addr = pack_sockaddr_un($path);
        socket(my $sock, AF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
        unless (connect($sock, $addr)) { # start the daemon if not started
-               my $cmd = [ $^X, qw[-MPublicInbox::LEI
+               local $ENV{PERL5LIB} = join(':', @INC);
+               open(my $daemon, '-|', $^X, qw[-MPublicInbox::LEI
                        -E PublicInbox::LEI::lazy_start(@ARGV)],
-                       $path, $! + 0 ];
-               my $env = { PERL5LIB => join(':', @INC) };
-               pipe(my ($daemon, $w)) or die "pipe: $!";
-               my $opt = { 1 => $w, 2 => $w };
-               require PublicInbox::Spawn;
-               my $pid = PublicInbox::Spawn::spawn($cmd, $env, $opt);
-               $opt = $w = undef;
+                       $path, $! + 0) or die "popen: $!";
                while (<$daemon>) { warn $_ } # EOF when STDERR is redirected
-               waitpid($pid, 0) or warn <<"";
-lei-daemon could not start, PID:$pid exited with \$?=$?
+               close($daemon) or warn <<"";
+lei-daemon could not start, exited with \$?=$?
 
                # try connecting again anyways, unlink+bind may be racy
                unless (connect($sock, $addr)) {
@@ -43,8 +38,8 @@ Falling back to (slow) one-shot mode
                }
        }
        require Cwd;
-       my $cwd = Cwd::fastcwd() // die "fastcwd(PWD=".($ENV{PWD}//'').": $!";
        my $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