about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-31 13:51:51 +0000
committerEric Wong <e@80x24.org>2021-01-01 05:00:40 +0000
commitc3bdb8f03474d35ec8904f1758c4302159adfa57 (patch)
tree51bca9494e132dbb6bcf4c9c5fcef16929632f42 /lib/PublicInbox
parent52df89ced31a5685d37e17c62ccccd3db5aa3e62 (diff)
downloadpublic-inbox-c3bdb8f03474d35ec8904f1758c4302159adfa57.tar.gz
Spawn was designed to speed up process spawning inside
long-lived daemons with largish memory usage.  It does not help
for short-lived scripts which only exist to start and connect to
a daemon.

This change actually speeds up initial lei startup from
~190ms to ~140ms(!).  Normal usage once the daemon is running
is unaffected, at <20ms for help text.

While we're in the area, simplify Cwd error message generation,
too.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/LEI.pm10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 03302f8a..b84e24ef 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -675,7 +675,7 @@ sub lazy_start {
         require IO::FDPass;
         require PublicInbox::Listener;
         require PublicInbox::EOFpipe;
-        (-p STDOUT && -p STDERR) or die "E: stdout+stderr must be pipes\n";
+        (-p STDOUT) or die "E: stdout must be a pipe\n";
         open(STDIN, '+<', '/dev/null') or die "redirect stdin failed: $!";
         POSIX::setsid() > 0 or die "setsid: $!";
         my $pid = fork // die "fork: $!";
@@ -740,10 +740,9 @@ sub lazy_start {
                 $n; # true: continue, false: stop
         });
 
-        # STDIN was redirected to /dev/null above, closing STDOUT and
-        # STDERR will cause the calling `lei' client process to finish
-        # reading <$daemon> pipe.
-        open STDOUT, '>&STDIN' or die "redirect stdout failed: $!";
+        # STDIN was redirected to /dev/null above, closing STDERR and
+        # STDOUT will cause the calling `lei' client process to finish
+        # reading the <$daemon> pipe.
         openlog($path, 'pid', 'user');
         local $SIG{__WARN__} = sub { syslog('warning', "@_") };
         my $owner_pid = $$;
@@ -751,6 +750,7 @@ sub lazy_start {
                 syslog('crit', "$@") if $@ && $$ == $owner_pid;
         });
         open STDERR, '>&STDIN' or die "redirect stderr failed: $!";
+        open STDOUT, '>&STDIN' or die "redirect stdout failed: $!";
         # $daemon pipe to `lei' closed, main loop begins:
         PublicInbox::DS->EventLoop;
         @$on_destroy = (); # cancel on_destroy if we get here