about summary refs log tree commit homepage
path: root/script/lei
diff options
context:
space:
mode:
Diffstat (limited to 'script/lei')
-rwxr-xr-xscript/lei14
1 files changed, 10 insertions, 4 deletions
diff --git a/script/lei b/script/lei
index 1b5af3a1..637c1951 100755
--- a/script/lei
+++ b/script/lei
@@ -21,13 +21,19 @@ if (eval { require IO::FDPass; 1 }) { # use daemon to reduce load time
         };
         my $sock = IO::Socket::UNIX->new(Peer => $path, Type => SOCK_STREAM);
         unless ($sock) { # start the daemon if not started
-                my $err = $!;
-                require PublicInbox::LeiDaemon;
-                $err = PublicInbox::LeiDaemon::lazy_start($path, $err);
+                my $err = $! + 0;
+                my $env = { PERL5LIB => join(':', @INC) };
+                my $cmd = [ $^X, qw[-MPublicInbox::LeiDaemon
+                        -E PublicInbox::LeiDaemon::lazy_start(@ARGV)],
+                        $path, $err ];
+                require PublicInbox::Spawn;
+                waitpid(PublicInbox::Spawn::spawn($cmd, $env), 0);
+                warn "lei-daemon exited with \$?=$?\n" if $?;
+
                 # try connecting again anyways, unlink+bind may be racy
                 $sock = IO::Socket::UNIX->new(Peer => $path,
                                                 Type => SOCK_STREAM) // die
-                        "connect($path): $! (bind($path): $err)";
+                        "connect($path): $! (after attempted daemon start)";
         }
         my $pwd = $ENV{PWD};
         my $cwd = cwd();