From b156cb4ef176b41131154a6d7632aed92b143fa0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 3 Jan 2021 11:24:50 +0000 Subject: send and receive all 3 FDs at once 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. --- lib/PublicInbox/LEI.pm | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'lib/PublicInbox/LEI.pm') 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; -- cgit v1.2.3-24-ge0c7