# lei(1) calls this when it can't connect
sub lazy_start {
- my ($path, $errno) = @_;
+ my ($path, $errno, $nfd) = @_;
if ($errno == ECONNREFUSED) {
unlink($path) or die "unlink($path): $!";
} elsif ($errno != ENOENT) {
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_3fds = PublicInbox::Spawn->can('recv_3fds') or die
- "Inline::C not installed/configured or IO::FDPass missing\n";
+ if ($nfd == 1) {
+ require IO::FDPass;
+ $recv_3fds = sub { map { IO::FDPass::recv($_[0]) } (0..2) };
+ } elsif ($nfd == 3) {
+ $recv_3fds = PublicInbox::Spawn->can('recv_3fds');
+ }
+ $recv_3fds or die
+ "IO::FDPass missing or Inline::C not installed/configured\n";
require PublicInbox::Listener;
require PublicInbox::EOFpipe;
(-p STDOUT) or die "E: stdout must be a pipe\n";
*nodatacow_fd = \&PublicInbox::NDC_PP::nodatacow_fd;
*nodatacow_dir = \&PublicInbox::NDC_PP::nodatacow_dir;
}
-unless (__PACKAGE__->can('recv_3fds')) {
- eval { # try the XS IO::FDPass package
- require IO::FDPass;
- no warnings 'once';
- *recv_3fds = sub { map { IO::FDPass::recv($_[0]) } (0..2) };
- *send_3fds = sub ($$$$) {
- my $sockfd = shift;
- IO::FDPass::send($sockfd, shift) for (0..2);
- };
- };
-}
undef $set_nodatacow;
undef $vfork_spawn;
use strict;
use v5.10.1;
use Socket qw(AF_UNIX SOCK_STREAM pack_sockaddr_un);
-my $send_3fds;
+my ($send_3fds, $nfd);
if (my ($sock, $pwd) = eval {
- require PublicInbox::Spawn;
- $send_3fds = PublicInbox::Spawn->can('send_3fds') or die
- "Inline::C not installed/configured or IO::FDPass missing\n";
+ $send_3fds = eval {
+ require IO::FDPass;
+ $nfd = 1; # 1 FD per-sendmsg
+ sub { IO::FDPass::send($_[0], $_[$_]) for (1..3) }
+ } // do {
+ require PublicInbox::Spawn; # takes ~50ms even if built *sigh*
+ $nfd = 3; # 3 FDs per-sendmsg(2)
+ PublicInbox::Spawn->can('send_3fds');
+ } // die "IO::FDPass missing or Inline::C not installed/configured\n";
my $path = do {
my $runtime_dir = ($ENV{XDG_RUNTIME_DIR} // '') . '/lei';
if ($runtime_dir eq '/lei') {
require File::Path;
File::Path::mkpath($runtime_dir, 0, 0700);
}
- "$runtime_dir/sock";
+ "$runtime_dir/$nfd.sock";
};
my $addr = pack_sockaddr_un($path);
socket(my $sock, AF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
local $ENV{PERL5LIB} = join(':', @INC);
open(my $daemon, '-|', $^X, qw[-MPublicInbox::LEI
-E PublicInbox::LEI::lazy_start(@ARGV)],
- $path, $! + 0) or die "popen: $!";
+ $path, $! + 0, $nfd) or die "popen: $!";
while (<$daemon>) { warn $_ } # EOF when STDERR is redirected
close($daemon) or warn <<"";
lei-daemon could not start, exited with \$?=$?
SKIP: { # real socket
require_mods(qw(Cwd), my $nr = 46);
- require PublicInbox::Spawn;
- skip "Inline::C not installed/configured or IO::FDPass missing", $nr
- unless PublicInbox::Spawn->can('send_3fds');
+ my $nfd = eval { require IO::FDPass; 1 } // do {
+ require PublicInbox::Spawn;
+ PublicInbox::Spawn->can('send_3fds') ? 3 : undef;
+ } //
+ skip 'IO::FDPass missing or Inline::C not installed/configured', $nr;
local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
- my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/sock";
+ my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/$nfd.sock";
ok($lei->('daemon-pid'), 'daemon-pid');
is($err, '', 'no error from daemon-pid');