t/common.perl | 27 +++++++++++++++++++++++++++
t/git-http-backend.t | 15 ++++-----------
t/git.t | 33 +++++++--------------------------
t/httpd-corner.t | 51 ++++++++++++---------------------------------------
t/httpd-unix.t | 1 -
t/httpd.t | 23 +++--------------------
t/nntpd.t | 22 +++-------------------
t/perf-nntpd.t | 21 ++++-----------------
t/v2mirror.t | 50 ++++++++++++--------------------------------------
t/v2writable.t | 26 ++++----------------------
diff --git a/t/common.perl b/t/common.perl
index 5c5fcd84890dbef23a07c2529c28b8341acc6bd7..688e30ad99cbee6c39a186c289a42eca4d3465e3 100644
--- a/t/common.perl
+++ b/t/common.perl
@@ -1,6 +1,9 @@
# Copyright (C) 2015-2018 all contributors
# License: AGPL-3.0+
+use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
+use POSIX qw(dup2);
+
sub stream_to_string {
my ($res) = @_;
my $body = $res->[2];
@@ -10,6 +13,30 @@ $str .= $chunk;
}
$body->close;
$str;
+}
+
+sub spawn_listener {
+ my ($env, $cmd, $socks) = @_;
+ my $pid = fork;
+ defined $pid or die "fork failed: $!\n";
+ if ($pid == 0) {
+ # pretend to be systemd (cf. sd_listen_fds(3))
+ my $fd = 3; # 3 == SD_LISTEN_FDS_START
+ foreach my $s (@$socks) {
+ my $fl = fcntl($s, F_GETFD, 0);
+ if (($fl & FD_CLOEXEC) != FD_CLOEXEC) {
+ warn "got FD:".fileno($s)." w/o CLOEXEC\n";
+ }
+ fcntl($s, F_SETFD, $fl &= ~FD_CLOEXEC);
+ dup2(fileno($s), $fd++) or die "dup2 failed: $!\n";
+ }
+ $ENV{LISTEN_PID} = $$;
+ $ENV{LISTEN_FDS} = scalar @$socks;
+ %ENV = (%ENV, %$env) if $env;
+ exec @$cmd;
+ die "FAIL: ",join(' ', @$cmd), ": $!\n";
+ }
+ $pid;
}
1;
diff --git a/t/git-http-backend.t b/t/git-http-backend.t
index 046a77849fe2e43f758de4c2a481206d412cedd0..4e51f2bf6bfc88d2b7eac758ebf32ce12db1fb00 100644
--- a/t/git-http-backend.t
+++ b/t/git-http-backend.t
@@ -5,7 +5,6 @@ use warnings;
use Test::More;
use File::Temp qw/tempdir/;
use IO::Socket;
-use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
use POSIX qw(dup2 setsid);
use Cwd qw(getcwd);
@@ -18,6 +17,7 @@ HTTP::Date HTTP::Status Net::HTTP)) {
eval "require $mod";
plan skip_all => "$mod missing for git-http-backend.t" if $@;
}
+require './t/common.perl';
my $psgi = getcwd()."/t/git-http-backend.psgi";
my $tmpdir = tempdir('pi-git-http-backend-XXXXXX', TMPDIR => 1, CLEANUP => 1);
my $err = "$tmpdir/stderr.log";
@@ -51,16 +51,9 @@ };
{
ok($sock, 'sock created');
- $pid = fork;
- if ($pid == 0) { # pretend to be systemd
- fcntl($sock, F_SETFD, 0);
- dup2(fileno($sock), 3) or die "dup2 failed: $!\n";
- $ENV{LISTEN_PID} = $$;
- $ENV{LISTEN_FDS} = 1;
- exec $httpd, "--stdout=$out", "--stderr=$err", $psgi;
- die "FAIL: $!\n";
- }
- ok(defined $pid, 'forked httpd process successfully');
+ my $cmd = [ $httpd, "--stdout=$out", "--stderr=$err", $psgi ];
+ ok(defined($pid = spawn_listener(undef, $cmd, [$sock])),
+ 'forked httpd process successfully');
}
my $mem_a = $get_maxrss->();
diff --git a/t/git.t b/t/git.t
index 7f96293fb25a1511452ce1e242822afa5791b49f..5069ae2c42c68202aea2a0120dbfbd908e86a9a3 100644
--- a/t/git.t
+++ b/t/git.t
@@ -9,20 +9,15 @@ use Cwd qw/getcwd/;
use PublicInbox::Spawn qw(popen_rd);
use_ok 'PublicInbox::Git';
+eval { require IPC::Run } or plan skip_all => 'IPC::Run missing';
+
{
is(system(qw(git init -q --bare), $dir), 0, 'created git directory');
- my @cmd = ('git', "--git-dir=$dir", 'fast-import', '--quiet');
+ my $cmd = [ 'git', "--git-dir=$dir", 'fast-import', '--quiet' ];
my $fi_data = getcwd().'/t/git.fast-import-data';
ok(-r $fi_data, "fast-import data readable (or run test at top level)");
- my $pid = fork;
- defined $pid or die "fork failed: $!\n";
- if ($pid == 0) {
- open STDIN, '<', $fi_data or die "open $fi_data: $!\n";
- exec @cmd;
- die "failed exec: ",join(' ', @cmd),": $!\n";
- }
- waitpid $pid, 0;
+ IPC::Run::run($cmd, '<', $fi_data);
is($?, 0, 'fast-import succeeded');
}
@@ -69,8 +64,7 @@ is(${$gcf->cat_file($f)}, $$raw, 'not broken after partial read');
}
if (1) {
- use POSIX qw(dup2);
- my @cmd = ('git', "--git-dir=$dir", qw(hash-object -w --stdin));
+ my $cmd = [ 'git', "--git-dir=$dir", qw(hash-object -w --stdin) ];
# need a big file, use the AGPL-3.0 :p
my $big_data = getcwd().'/COPYING';
@@ -78,21 +72,8 @@ ok(-r $big_data, 'COPYING readable');
my $size = -s $big_data;
ok($size > 8192, 'file is big enough');
- my ($r, $w);
- ok(pipe($r, $w), 'created pipe');
-
- my $pid = fork;
- defined $pid or die "fork failed: $!\n";
- if ($pid == 0) {
- close $r;
- open STDIN, '<', $big_data or die "open $big_data: $!\n";
- dup2(fileno($w), 1);
- exec @cmd;
- die "failed exec: ",join(' ', @cmd),": $!\n";
- }
- close $w;
- my $n = read $r, my $buf, 41;
- waitpid $pid, 0;
+ my $buf = '';
+ IPC::Run::run($cmd, '<', $big_data, '>', \$buf);
is(0, $?, 'hashed object successfully');
chomp $buf;
diff --git a/t/httpd-corner.t b/t/httpd-corner.t
index a720670ec774e00a651db8767b89ac263de1b04c..aa0698d3cd2b830f0bfc73ec350f74fffc721ca8 100644
--- a/t/httpd-corner.t
+++ b/t/httpd-corner.t
@@ -8,7 +8,7 @@ use Test::More;
use Time::HiRes qw(gettimeofday tv_interval);
foreach my $mod (qw(Plack::Util Plack::Builder Danga::Socket
- HTTP::Date HTTP::Status)) {
+ HTTP::Date HTTP::Status IPC::Run)) {
eval "require $mod";
plan skip_all => "$mod missing for httpd-corner.t" if $@;
}
@@ -18,9 +18,10 @@ use File::Temp qw/tempdir/;
use Cwd qw/getcwd/;
use IO::Socket;
use IO::Socket::UNIX;
-use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD :seek);
+use Fcntl qw(:seek);
use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
-use POSIX qw(dup2 mkfifo :sys_wait_h);
+use POSIX qw(mkfifo :sys_wait_h);
+require './t/common.perl';
my $tmpdir = tempdir('httpd-corner-XXXXXX', TMPDIR => 1, CLEANUP => 1);
my $fifo = "$tmpdir/fifo";
ok(defined mkfifo($fifo, 0777), 'created FIFO');
@@ -47,33 +48,13 @@ my $pid;
END { kill 'TERM', $pid if defined $pid };
my $spawn_httpd = sub {
my (@args) = @_;
- $! = 0;
- my $fl = fcntl($sock, F_GETFD, 0);
- ok(! $!, 'no error from fcntl(F_GETFD)');
- is($fl, FD_CLOEXEC, 'cloexec set by default (Perl behavior)');
- $pid = fork;
- if ($pid == 0) {
- # pretend to be systemd
- dup2(fileno($sock), 3) or die "dup2 failed: $!\n";
- dup2(fileno($unix), 4) or die "dup2 failed: $!\n";
- my $t = IO::Handle->new_from_fd(3, 'r');
- $t->fcntl(F_SETFD, 0);
- my $u = IO::Handle->new_from_fd(4, 'r');
- $u->fcntl(F_SETFD, 0);
- $ENV{LISTEN_PID} = $$;
- $ENV{LISTEN_FDS} = 2;
- exec $httpd, @args, "--stdout=$out", "--stderr=$err", $psgi;
- die "FAIL: $!\n";
- }
+ my $cmd = [ $httpd, @args, "--stdout=$out", "--stderr=$err", $psgi ];
+ $pid = spawn_listener(undef, $cmd, [ $sock, $unix ]);
ok(defined $pid, 'forked httpd process successfully');
};
{
ok($sock, 'sock created');
- $! = 0;
- my $fl = fcntl($sock, F_GETFD, 0);
- ok(! $!, 'no error from fcntl(F_GETFD)');
- is($fl, FD_CLOEXEC, 'cloexec set by default (Perl behavior)');
$spawn_httpd->('-W0');
}
@@ -242,7 +223,6 @@ is($body, sha1_hex($str), 'read expected body');
};
SKIP: {
- use POSIX qw(dup2);
my $have_curl = 0;
foreach my $p (split(':', $ENV{PATH})) {
-x "$p/curl" or next;
@@ -254,15 +234,9 @@ $have_curl or skip('curl(1) missing', $ntest);
my $url = 'http://' . $sock->sockhost . ':' . $sock->sockport . '/sha1';
my ($r, $w);
pipe($r, $w) or die "pipe: $!";
- open(my $tout, '+>', undef) or die "open temporary file: $!";
- my $pid = fork;
- defined $pid or die "fork: $!";
- my @cmd = (qw(curl --tcp-nodelay --no-buffer -T- -HExpect: -sS), $url);
- if ($pid == 0) {
- dup2(fileno($r), 0) or die "redirect stdin failed: $!\n";
- dup2(fileno($tout), 1) or die "redirect stdout failed: $!\n";
- exec(@cmd) or die 'exec `' . join(' '). "' failed: $!\n";
- }
+ my $cmd = [qw(curl --tcp-nodelay --no-buffer -T- -HExpect: -sS), $url];
+ my ($out, $err) = ('', '');
+ my $h = IPC::Run::start($cmd, $r, \$out, \$err);
$w->autoflush(1);
foreach my $c ('a'..'z') {
print $w $c or die "failed to write to curl: $!";
@@ -270,11 +244,10 @@ delay();
}
close $w or die "close write pipe: $!";
close $r or die "close read pipe: $!";
- my $kid = waitpid $pid, 0;
+ IPC::Run::finish($h);
is($?, 0, 'curl exited successfully');
- $tout->sysseek(0, SEEK_SET);
- $tout->sysread(my $buf, 100);
- is($buf, sha1_hex($str), 'read expected body');
+ is($err, '', 'no errors from curl');
+ is($out, sha1_hex($str), 'read expected body');
}
{
diff --git a/t/httpd-unix.t b/t/httpd-unix.t
index b3cf8693118b66cf67f350d7366fd4c3566333de..0a93f204618de2cc59bdcea2fc446fcd08229a45 100644
--- a/t/httpd-unix.t
+++ b/t/httpd-unix.t
@@ -14,7 +14,6 @@
use File::Temp qw/tempdir/;
use IO::Socket::UNIX;
use Cwd qw/getcwd/;
-use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD :seek);
my $tmpdir = tempdir('httpd-unix-XXXXXX', TMPDIR => 1, CLEANUP => 1);
my $unix = "$tmpdir/unix.sock";
my $httpd = 'blib/script/public-inbox-httpd';
diff --git a/t/httpd.t b/t/httpd.t
index f33c0969b5f4bf2174af6fd1ffc6ae14c157969c..44df1642cc51699d407b5285e386b4c0ffe506e7 100644
--- a/t/httpd.t
+++ b/t/httpd.t
@@ -12,8 +12,8 @@ }
use File::Temp qw/tempdir/;
use Cwd qw/getcwd/;
use IO::Socket;
-use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
+require './t/common.perl';
# FIXME: too much setup
my $tmpdir = tempdir('pi-httpd-XXXXXX', TMPDIR => 1, CLEANUP => 1);
@@ -64,25 +64,8 @@ $im->add($mime);
$im->done($mime);
}
ok($sock, 'sock created');
- $! = 0;
- my $fl = fcntl($sock, F_GETFD, 0);
- ok(! $!, 'no error from fcntl(F_GETFD)');
- is($fl, FD_CLOEXEC, 'cloexec set by default (Perl behavior)');
- $pid = fork;
- if ($pid == 0) {
- use POSIX qw(dup2);
- # pretend to be systemd
- fcntl($sock, F_SETFD, $fl &= ~FD_CLOEXEC);
- dup2(fileno($sock), 3) or die "dup2 failed: $!\n";
- $ENV{LISTEN_PID} = $$;
- $ENV{LISTEN_FDS} = 1;
- exec $httpd, "--stdout=$out", "--stderr=$err";
- die "FAIL: $!\n";
- }
- ok(defined $pid, 'forked httpd process successfully');
- $! = 0;
- fcntl($sock, F_SETFD, $fl |= FD_CLOEXEC);
- ok(! $!, 'no error from fcntl(F_SETFD)');
+ my $cmd = [ $httpd, "--stdout=$out", "--stderr=$err" ];
+ $pid = spawn_listener(undef, $cmd, [$sock]);
my $host = $sock->sockhost;
my $port = $sock->sockport;
my $conn = IO::Socket::INET->new(PeerAddr => $host,
diff --git a/t/nntpd.t b/t/nntpd.t
index ffed437631cde2926e0d7e7efa9ebe6aa1c9cc20..d227b74d1835407507f1f83ba776d5dae796a804 100644
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -12,11 +12,11 @@ require PublicInbox::Msgmap;
use Cwd;
use Email::Simple;
use IO::Socket;
-use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
use File::Temp qw/tempdir/;
use Net::NNTP;
use Sys::Hostname;
+require './t/common.perl';
my $tmpdir = tempdir('pi-nntpd-XXXXXX', TMPDIR => 1, CLEANUP => 1);
my $home = "$tmpdir/pi-home";
@@ -101,25 +101,9 @@ }
}
ok($sock, 'sock created');
- $! = 0;
- my $fl = fcntl($sock, F_GETFD, 0);
- ok(! $!, 'no error from fcntl(F_GETFD)');
- is($fl, FD_CLOEXEC, 'cloexec set by default (Perl behavior)');
- $pid = fork;
- if ($pid == 0) {
- use POSIX qw(dup2);
- # pretend to be systemd
- fcntl($sock, F_SETFD, $fl &= ~FD_CLOEXEC);
- dup2(fileno($sock), 3) or die "dup2 failed: $!\n";
- $ENV{LISTEN_PID} = $$;
- $ENV{LISTEN_FDS} = 1;
- exec $nntpd, "--stdout=$out", "--stderr=$err";
- die "FAIL: $!\n";
- }
+ my $cmd = [ $nntpd, "--stdout=$out", "--stderr=$err" ];
+ $pid = spawn_listener(undef, $cmd, [ $sock ]);
ok(defined $pid, 'forked nntpd process successfully');
- $! = 0;
- fcntl($sock, F_SETFD, $fl |= FD_CLOEXEC);
- ok(! $!, 'no error from fcntl(F_SETFD)');
my $host_port = $sock->sockhost . ':' . $sock->sockport;
my $n = Net::NNTP->new($host_port);
my $list = $n->list;
diff --git a/t/perf-nntpd.t b/t/perf-nntpd.t
index f7890d1c3868d04bfee3f55224aeaa62f01d6bea..3ca1ce335768454dc4ea2f22f4d99912833474ee 100644
--- a/t/perf-nntpd.t
+++ b/t/perf-nntpd.t
@@ -6,13 +6,13 @@ use Test::More;
use Benchmark qw(:all :hireswallclock);
use PublicInbox::Inbox;
use File::Temp qw/tempdir/;
-use POSIX qw(dup2);
-use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
use Net::NNTP;
my $pi_dir = $ENV{GIANT_PI_DIR};
plan skip_all => "GIANT_PI_DIR not defined for $0" unless $pi_dir;
eval { require PublicInbox::Search };
my ($host_port, $group, %opts, $s, $pid);
+require './t/common.perl';
+
END {
if ($s) {
$s->print("QUIT\r\n");
@@ -53,21 +53,8 @@ );
my $sock = IO::Socket::INET->new(%opts);
ok($sock, 'sock created');
- $! = 0;
- $pid = fork;
- if ($pid == 0) {
- # pretend to be systemd
- my $fl = fcntl($sock, F_GETFD, 0);
- dup2(fileno($sock), 3) or die "dup2 failed: $!\n";
- dup2(1, 2) or die "dup2 failed: $!\n";
- fcntl($sock, F_SETFD, $fl &= ~FD_CLOEXEC);
- $ENV{LISTEN_PID} = $$;
- $ENV{LISTEN_FDS} = 1;
- $ENV{PI_CONFIG} = $pi_config;
- exec $nntpd, '-W0';
- die "FAIL: $!\n";
- }
- ok(defined $pid, 'forked nntpd process successfully');
+ my $cmd = [ $nntpd, '-W0' ];
+ $pid = spawn_listener({ PI_CONFIG => $pi_config }, $cmd, [$sock]);
$host_port = $sock->sockhost . ':' . $sock->sockport;
}
%opts = (
diff --git a/t/v2mirror.t b/t/v2mirror.t
index f95ad0f54b5e527261757ebdc35b6b8129faba03..283b2b228852f132f5ab3a3bb2480d81fa3f876f 100644
--- a/t/v2mirror.t
+++ b/t/v2mirror.t
@@ -3,10 +3,12 @@ # License: AGPL-3.0+
use strict;
use warnings;
use Test::More;
+require './t/common.perl';
# Integration tests for HTTP cloning + mirroring
foreach my $mod (qw(Plack::Util Plack::Builder Danga::Socket
- HTTP::Date HTTP::Status Search::Xapian DBD::SQLite)) {
+ HTTP::Date HTTP::Status Search::Xapian DBD::SQLite
+ IPC::Run)) {
eval "require $mod";
plan skip_all => "$mod missing for v2mirror.t" if $@;
}
@@ -16,7 +18,6 @@ use POSIX qw(dup2);
use_ok 'PublicInbox::V2Writable';
use PublicInbox::MIME;
use PublicInbox::Config;
-use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
# FIXME: too much setup
my $tmpdir = tempdir('pi-v2mirror-XXXXXX', TMPDIR => 1, CLEANUP => 1);
my $script = 'blib/script/public-inbox';
@@ -69,18 +70,9 @@
$! = 0;
$sock = IO::Socket::INET->new(%opts);
ok($sock, 'sock created');
-my $fl = fcntl($sock, F_GETFD, 0);
-$pid = fork;
-if ($pid == 0) {
- # pretend to be systemd
- fcntl($sock, F_SETFD, $fl &= ~FD_CLOEXEC);
- dup2(fileno($sock), 3) or die "dup2 failed: $!\n";
- $ENV{LISTEN_PID} = $$;
- $ENV{LISTEN_FDS} = 1;
- exec "$script-httpd", "--stdout=$tmpdir/out", "--stderr=$tmpdir/err";
- die "FAIL: $!\n";
-}
-ok(defined $pid, 'forked httpd process successfully');
+my $cmd = [ "$script-httpd", "--stdout=$tmpdir/out", "--stderr=$tmpdir/err" ];
+ok(defined($pid = spawn_listener(undef, $cmd, [ $sock ])),
+ 'spawned httpd process successfully');
my ($host, $port) = ($sock->sockhost, $sock->sockport);
$sock = undef;
@@ -150,18 +142,9 @@ is(scalar($mset->items), 0, 'purged message gone from origin');
fetch_each_epoch();
{
- open my $err, '+>', "$tmpdir/index-err" or die "open: $!";
- my $ipid = fork;
- if ($ipid == 0) {
- dup2(fileno($err), 2) or die "dup2 failed: $!";
- exec("$script-index", '--prune', "$tmpdir/m");
- die "exec fail: $!";
- }
- ok($ipid, 'running index..');
- is(waitpid($ipid, 0), $ipid, 'index --prune done');
- is($?, 0, 'no error from index');
- ok(seek($err, 0, 0), 'rewound stderr');
- $err = eval { local $/; <$err> };
+ my $cmd = [ "$script-index", '--prune', "$tmpdir/m" ];
+ my ($in, $out, $err) = ('', '', '');
+ ok(IPC::Run::run($cmd, \$in, \$out, \$err), '-index --prune');
like($err, qr/discontiguous range/, 'warned about discontiguous range');
unlike($err, qr/fatal/, 'no scary fatal error shown');
}
@@ -192,18 +175,9 @@ ok($v2w->remove($mime), 'removed <1@example.com> from source');
$v2w->done;
fetch_each_epoch();
- open my $err, '+>', "$tmpdir/index-err" or die "open: $!";
- my $ipid = fork;
- if ($ipid == 0) {
- dup2(fileno($err), 2) or die "dup2 failed: $!";
- exec("$script-index", "$tmpdir/m");
- die "exec fail: $!";
- }
- ok($ipid, 'running index');
- is(waitpid($ipid, 0), $ipid, 'index done');
- is($?, 0, 'no error from index');
- ok(seek($err, 0, 0), 'rewound stderr');
- $err = eval { local $/; <$err> };
+ my ($in, $out, $err) = ('', '', '');
+ my $cmd = [ "$script-index", "$tmpdir/m" ];
+ ok(IPC::Run::run($cmd, \$in, \$out, \$err), 'index ran');
is($err, '', 'no errors reported by index');
$mset = $mibx->search->reopen->query('m:1@example.com', {mset => 1});
is(scalar($mset->items), 0, '1@example.com no longer visible in mirror');
diff --git a/t/v2writable.t b/t/v2writable.t
index b3cdbd3e6c0ff2d336852108ed7aef874e2b0d2b..c7eeee997bb7c189c71de5902c3a6105f74c3ec5 100644
--- a/t/v2writable.t
+++ b/t/v2writable.t
@@ -6,6 +6,7 @@ use Test::More;
use PublicInbox::MIME;
use PublicInbox::ContentId qw(content_digest);
use File::Temp qw/tempdir/;
+require './t/common.perl';
foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
eval "require $mod";
plan skip_all => "$mod missing for nntpd.t" if $@;
@@ -129,7 +130,6 @@ 'same document') if ($mset1->size);
}
SKIP: {
- use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
use Net::NNTP;
use IO::Socket;
use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
@@ -161,27 +161,9 @@ ok($sock, 'sock created');
my $pid;
my $len;
END { kill 'TERM', $pid if defined $pid };
- $! = 0;
- my $fl = fcntl($sock, F_GETFD, 0);
- ok(! $!, 'no error from fcntl(F_GETFD)');
- is($fl, FD_CLOEXEC, 'cloexec set by default (Perl behavior)');
- $pid = fork;
- if ($pid == 0) {
- use POSIX qw(dup2);
- $ENV{PI_CONFIG} = $pi_config;
- # pretend to be systemd
- fcntl($sock, F_SETFD, $fl &= ~FD_CLOEXEC);
- dup2(fileno($sock), 3) or die "dup2 failed: $!\n";
- $ENV{LISTEN_PID} = $$;
- $ENV{LISTEN_FDS} = 1;
- my $nntpd = 'blib/script/public-inbox-nntpd';
- exec $nntpd, "--stdout=$out", "--stderr=$err";
- die "FAIL: $!\n";
- }
- ok(defined $pid, 'forked nntpd process successfully');
- $! = 0;
- fcntl($sock, F_SETFD, $fl |= FD_CLOEXEC);
- ok(! $!, 'no error from fcntl(F_SETFD)');
+ my $nntpd = 'blib/script/public-inbox-nntpd';
+ my $cmd = [ $nntpd, "--stdout=$out", "--stderr=$err" ];
+ $pid = spawn_listener({ PI_CONFIG => $pi_config }, $cmd, [ $sock ]);
my $host_port = $sock->sockhost . ':' . $sock->sockport;
my $n = Net::NNTP->new($host_port);
$n->group($group);