]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/lei
lei: simple WQ workers use {wq1} field
[public-inbox.git] / script / lei
index 76217ab9ba575e4e580aba0a789a67f634619dce..90a9383928f875faae25fa065a48a071a3273fef 100755 (executable)
@@ -33,6 +33,9 @@ my $exec_cmd = sub {
                push @rdr, shift(@old), $newfh;
        }
        my $do_exec = sub {
+               while (my ($io, $newfh) = splice(@rdr, 0, 2)) {
+                       open $io, '+<&', $newfh or die "open +<&=: $!";
+               }
                my %env = map { split(/=/, $_, 2) } splice(@argv, $argc);
                @ENV{keys %env} = values %env;
                exec(@argv);
@@ -42,26 +45,24 @@ my $exec_cmd = sub {
        $SIG{CHLD} = $sigchld;
        my $pid = fork // die "fork: $!";
        if ($pid == 0) {
-               while (my ($io, $newfh) = splice(@rdr, 0, 2)) {
-                       open $io, '+<&', $newfh or die "open +<&=: $!";
-               }
-               $do_exec->() if scalar(@$fds); # git-credential, pager
+               $do_exec->() if $fds->[1]; # git-credential, pager
 
                # parent backgrounds on MUA
                POSIX::setsid() > 0 or die "setsid: $!";
                @parent = ($parent);
                return; # continue $recv_cmd in background
        }
-       if (scalar(@$fds)) {
+       if ($fds->[1]) {
                $pids{$pid} = undef;
        } else {
-               $do_exec->(); # MUA reuses all FDs
+               $do_exec->(); # MUA reuses stdout
        }
 };
 
 if ($send_cmd && eval {
        my $path = do {
                my $runtime_dir = ($ENV{XDG_RUNTIME_DIR} // '') . '/lei';
+               die \0 if $runtime_dir eq '/dev/null/lei'; # oneshot forced
                if ($runtime_dir eq '/lei') {
                        require File::Spec;
                        $runtime_dir = File::Spec->tmpdir."/lei-$<";
@@ -115,10 +116,10 @@ Falling back to (slow) one-shot mode
                } elsif ($buf eq '-WINCH') {
                        kill($buf, @parent); # for MUA
                } elsif ($buf =~ /\Ax_it ([0-9]+)\z/) {
-                       $x_it_code = $1 + 0;
+                       $x_it_code ||= $1 + 0;
                        last;
                } elsif ($buf =~ /\Achild_error ([0-9]+)\z/) {
-                       $x_it_code = $1 + 0;
+                       $x_it_code ||= $1 + 0;
                } else {
                        $sigchld->();
                        die $buf;
@@ -131,7 +132,7 @@ Falling back to (slow) one-shot mode
        }
        exit($x_it_code >> 8);
 } else { # for systems lacking Socket::MsgHdr or Inline::C
-       warn $@ if $@;
+       warn $@ if $@ && !ref($@);
        require PublicInbox::LEI;
        PublicInbox::LEI::oneshot(__PACKAGE__);
 }