1 # Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
13 while (defined(my $chunk = $body->getline)) {
21 IO::Socket::INET->new(
22 LocalAddr => '127.0.0.1',
25 Type => Socket::SOCK_STREAM(),
31 IO::Socket::UNIX->new(
33 Type => Socket::SOCK_STREAM(),
39 my ($env, $cmd, $socks) = @_;
41 defined $pid or die "fork failed: $!\n";
43 # pretend to be systemd (cf. sd_listen_fds(3))
44 my $fd = 3; # 3 == SD_LISTEN_FDS_START
45 foreach my $s (@$socks) {
46 my $fl = fcntl($s, F_GETFD, 0);
47 if (($fl & FD_CLOEXEC) != FD_CLOEXEC) {
48 warn "got FD:".fileno($s)." w/o CLOEXEC\n";
50 fcntl($s, F_SETFD, $fl &= ~FD_CLOEXEC);
51 dup2(fileno($s), $fd++) or die "dup2 failed: $!\n";
53 $ENV{LISTEN_PID} = $$;
54 $ENV{LISTEN_FDS} = scalar @$socks;
55 %ENV = (%ENV, %$env) if $env;
57 die "FAIL: ",join(' ', @$cmd), ": $!\n";
62 sub require_git ($;$) {
63 my ($req, $maybe) = @_;
64 my ($req_maj, $req_min) = split(/\./, $req);
65 my ($cur_maj, $cur_min) = (`git --version` =~ /version (\d+)\.(\d+)/);
67 my $req_int = ($req_maj << 24) | ($req_min << 16);
68 my $cur_int = ($cur_maj << 24) | ($cur_min << 16);
69 if ($cur_int < $req_int) {
71 plan skip_all => "git $req+ required, have $cur_maj.$cur_min";