diff options
author | Eric Wong <e@80x24.org> | 2021-01-03 11:24:50 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-03 18:24:08 +0000 |
commit | b156cb4ef176b41131154a6d7632aed92b143fa0 (patch) | |
tree | 46b13794fbc87a2b0133a1f450328f0b35e0539d /lib/PublicInbox/LEI.pm | |
parent | 0939882b8a883e3f034bd059cdec4984d36f4ac7 (diff) | |
download | public-inbox-b156cb4ef176b41131154a6d7632aed92b143fa0.tar.gz |
We'll always be transferring stdin, stdout, and stderr together for lei. Perhaps I lack imagination or foresight, but I can't think of a reason to send more or less FDs.
Diffstat (limited to 'lib/PublicInbox/LEI.pm')
-rw-r--r-- | lib/PublicInbox/LEI.pm | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 6f98c934..3ad5e01a 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -25,7 +25,7 @@ use Text::Wrap qw(wrap); use File::Path qw(mkpath); use File::Spec; our $quit = \&CORE::exit; -my $recv_fd; +my $recv_3fds; my $GLP = Getopt::Long::Parser->new; $GLP->configure(qw(gnu_getopt no_ignore_case auto_abbrev)); my $GLP_PASS = Getopt::Long::Parser->new; @@ -614,25 +614,26 @@ sub accept_dispatch { # Listener {post_accept} callback my $self = bless { sock => $sock }, __PACKAGE__; vec(my $rin = '', fileno($sock), 1) = 1; # `say $sock' triggers "die" in lei(1) - for my $i (0..2) { - if (select(my $rout = $rin, undef, undef, 1)) { - my $fd = $recv_fd->(fileno($sock)); - if ($fd >= 0) { - my $rdr = ($fd == 0 ? '<&=' : '>&='); + if (select(my $rout = $rin, undef, undef, 1)) { + my @fds = $recv_3fds->(fileno($sock)); + if (scalar(@fds) == 3) { + my $i = 0; + for my $rdr (qw(<&= >&= >&=)) { + my $fd = shift(@fds); if (open(my $fh, $rdr, $fd)) { - $self->{$i} = $fh; - } else { + $self->{$i++} = $fh; + } else { say $sock "open($rdr$fd) (FD=$i): $!"; return; } - } else { - say $sock "recv FD=$i: $!"; - return; } } else { - say $sock "timed out waiting to recv FD=$i"; + say $sock "recv_3fds failed: $!"; return; } + } else { + say $sock "timed out waiting to recv FDs"; + return; } # $ARGV_STR = join("]\0[", @ARGV); # $ENV_STR = join('', map { "$_=$ENV{$_}\0" } keys %ENV); @@ -672,7 +673,7 @@ sub lazy_start { my $dev_ino_expect = pack('dd', $st[0], $st[1]); # dev+ino pipe(my ($eof_r, $eof_w)) or die "pipe: $!"; my $oldset = PublicInbox::Sigfd::block_signals(); - $recv_fd = PublicInbox::Spawn->can('recv_fd') or die + $recv_3fds = PublicInbox::Spawn->can('recv_3fds') or die "Inline::C not installed/configured or IO::FDPass missing\n"; require PublicInbox::Listener; require PublicInbox::EOFpipe; |