LibTmux/Transport.pm

filter: Statementstmt 50.2% 125 / 249 Branchbran 15.5% 23 / 148 Conditioncond 15.0% 32 / 213 MC/DCmcdc 1.8% 2 / 110 Subroutinesub 86.3% 19 / 22 Podpod 100% 2 / 2 totaltotal 27.2% 203 / 744 CC 159 SCAR 85.9
CC
159
Cov
30%
_supervise
8143.5
_configuration
74.9
_arguments
43.0
CRAP 5351.0
↑ Summary LibTmux/Server.pm »
1 package LibTmux::Transport;
2 8 ▶use v5.44;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use POSIX qw(:sys_wait_h :signal_h setpgid _exit);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK F_SETFD FD_CLOEXEC);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use Errno qw(EINTR EAGAIN EWOULDBLOCK ECHILD EPIPE ESRCH);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use MIME::Base64 qw(encode_base64 decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Encode qw(encode FB_CROAK LEAVE_SRC);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use LibTmux::X;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use LibTmux::CommandResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 0 ▶sub _now () { clock_gettime(CLOCK_MONOTONIC) }
Subroutine _now: not called CC=1 SCAR=6.9
16  
17 25 ▶sub _nonblock ($fh) {
Subroutine _nonblock: called CC=3 SCAR=13.1
18 25 my $flags = fcntl($fh, F_GETFL, 0);
19 25 ▶ die "fcntl: $!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags and defined fcntl($fh, 4, $flags | 2048) 0 25 25
Condition33%1/3
defined $flags and defined fcntl($fh, 4, $flags | 2048)
!ll&&!rl&&r
0025
MC/DC0%0/2
defined $flags and defined fcntl($fh, 4, $flags | 2048)
defined $flags defined fcntl($fh, 4, $flags | 2048)
Truth table33%1/3
A and B
A= defined $flagsB= defined fcntl($fh, 4, $flags | 2048)
ABresult
0X0
100
111
20 unless defined($flags)
21 && defined fcntl($fh, F_SETFL, $flags | O_NONBLOCK);
22 }
23  
24 36 ▶sub _pipe () {
Subroutine _pipe: called CC=4 SCAR=14.3
25 36 ▶ pipe(my $read, my $write) or die "pipe: $!";
Branch: 1 branch
BranchTrueFalseTotal
pipe my $read, my $write or die "pipe: $!" 36 0 36
26 36 binmode $read;
27 36 binmode $write;
28 fcntl($_, F_SETFD, FD_CLOEXEC) // die "close-on-exec: $!"
29 36 ▶ for ($read, $write);
Condition50%1/2
fcntl($_, 2, 1) // die("close-on-exec: $!")
l!l
720
MC/DC0%0/1
fcntl($_, 2, 1) // die("close-on-exec: $!")
fcntl($_, 2, 1)
Truth table50%1/2
A
A= fcntl($_, 2, 1)
Aresult
11
00
30 36 return ($read, $write);
31 }
32  
33 12 ▶sub _configuration ($class, %args) {
Subroutine _configuration: called CC=19 SCAR=43.2
34 12 ▶ $args{timeout} //= 5;
Condition100%2/2
$args{"timeout"} //= 5
l!l
57
MC/DC100%1/1
$args{"timeout"} //= 5
$args{"timeout"}
Truth table100%2/2
A
A= $args{"timeout"}
Aresult
11
00
35 12 ▶ $args{max_output} //= 8 * 1024 * 1024;
Condition50%1/2
$args{"max_output"} //= 8388608
l!l
012
MC/DC0%0/1
$args{"max_output"} //= 8388608
$args{"max_output"}
Truth table50%1/2
A
A= $args{"max_output"}
Aresult
11
00
36 LibTmux::X::InvalidArgument->throw(
37 message => 'timeout must be positive decimal seconds, at most 86400')
38 unless !ref($args{timeout})
39 && "$args{timeout}" =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/
40 && $args{timeout} > 0
41 12 ▶ && $args{timeout} <= 86400;
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $args{"timeout"} and qq[$args{"timeout"}] =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u and $args{"timeout"} > 0 and $args{"timeout"} <= 86400 1 11 12
Condition66%6/9
not ref $args{"timeout"} and qq[$args{"timeout"}] =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u and $args{"timeout"} > 0 and $args{"timeout"} <= 86400
!ll&&!rl&&r
1011
not ref $args{"timeout"} and qq[$args{"timeout"}] =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u and $args{"timeout"} > 0
!ll&&!rl&&r
1011
not ref $args{"timeout"} and qq[$args{"timeout"}] =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u
!ll&&!rl&&r
0111
MC/DC25%1/4
not ref $args{"timeout"} and qq[$args{"timeout"}] =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u and $args{"timeout"} > 0 and $args{"timeout"} <= 86400
not ref $args{"timeout"} qq[$args{"timeout"}] =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u $args{"timeout"} > 0 $args{"timeout"} <= 86400
Truth table40%2/5
not(A) and B and C and D
A= not ref $args{"timeout"}B= qq[$args{"timeout"}] =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/uC= $args{"timeout"} > 0D= $args{"timeout"} <= 86400
ABCDresult
0XXX0
10XX0
110X0
11100
11111
42 LibTmux::X::InvalidArgument->throw(
43 message => 'max_output must be an integer from 1 to 1073741824')
44 unless !ref($args{max_output})
45 && "$args{max_output}" =~ /\A[1-9][0-9]*\z/
46 && length("$args{max_output}") <= 10
47 11 ▶ && $args{max_output} <= 1073741824;
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $args{"max_output"} and qq[$args{"max_output"}] =~ /\A[1-9][0-9]*\z/u and length qq[$args{"max_output"}] <= 10 and $args{"max_output"} <= 1073741824 0 11 11
Condition33%3/9
not ref $args{"max_output"} and qq[$args{"max_output"}] =~ /\A[1-9][0-9]*\z/u and length qq[$args{"max_output"}] <= 10 and $args{"max_output"} <= 1073741824
!ll&&!rl&&r
0011
not ref $args{"max_output"} and qq[$args{"max_output"}] =~ /\A[1-9][0-9]*\z/u and length qq[$args{"max_output"}] <= 10
!ll&&!rl&&r
0011
not ref $args{"max_output"} and qq[$args{"max_output"}] =~ /\A[1-9][0-9]*\z/u
!ll&&!rl&&r
0011
MC/DC0%0/4
not ref $args{"max_output"} and qq[$args{"max_output"}] =~ /\A[1-9][0-9]*\z/u and length qq[$args{"max_output"}] <= 10 and $args{"max_output"} <= 1073741824
not ref $args{"max_output"} qq[$args{"max_output"}] =~ /\A[1-9][0-9]*\z/u length qq[$args{"max_output"}] <= 10 $args{"max_output"} <= 1073741824
Truth table20%1/5
not(A) and B and C and D
A= not ref $args{"max_output"}B= qq[$args{"max_output"}] =~ /\A[1-9][0-9]*\z/uC= length qq[$args{"max_output"}] <= 10D= $args{"max_output"} <= 1073741824
ABCDresult
0XXX0
10XX0
110X0
11100
11111
48 11 ▶ $args{env} //= {};
Condition50%1/2
$args{"env"} //= {}
l!l
011
MC/DC0%0/1
$args{"env"} //= {}
$args{"env"}
Truth table50%1/2
A
A= $args{"env"}
Aresult
11
00
49 LibTmux::X::InvalidArgument->throw(
50 message => 'env must be a hash reference')
51 11 ▶ unless ref($args{env}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"env"} eq "HASH" 0 11 11
52 11 for my $key (keys $args{env}->%*) {
53 0 my $value = $args{env}{$key};
54 0 ▶ LibTmux::X::InvalidArgument->throw(
Branch: 1 branch
BranchTrueFalseTotal
if not length $key or $key =~ /[=\0]/u or not defined $value or ref $value or $value =~ /\0/u 0 0 0
Condition0%0/12
not length $key or $key =~ /[=\0]/u or not defined $value or ref $value or $value =~ /\0/u
l!l&&r!l&&!r
000
not length $key or $key =~ /[=\0]/u or not defined $value or ref $value
l!l&&r!l&&!r
000
not length $key or $key =~ /[=\0]/u or not defined $value
l!l&&r!l&&!r
000
not length $key or $key =~ /[=\0]/u
l!l&&r!l&&!r
000
MC/DC0%0/5
not length $key or $key =~ /[=\0]/u or not defined $value or ref $value or $value =~ /\0/u
not length $key $key =~ /[=\0]/u not defined $value ref $value $value =~ /\0/u
Truth table0%0/6
not(A) or B or not(C) or D or E
A= not length $keyB= $key =~ /[=\0]/uC= not defined $valueD= ref $valueE= $value =~ /\0/u
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
55 message => 'environment names and values must be NUL-free scalars')
56 if !length($key)
57 || $key =~ /[=\0]/
58 || !defined($value)
59 || ref($value)
60 || $value =~ /\0/;
61 }
62 11 return %args;
63 }
64  
65 7 ▶sub _arguments ($class, %args) {
Subroutine _arguments: called CC=18 SCAR=37.6
66 7 %args = $class->_configuration(%args);
67 7 my $argv = $args{argv};
68 7 ▶ LibTmux::X::InvalidArgument->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $argv eq "ARRAY" and @$argv 0 7 7
Condition33%1/3
ref $argv eq "ARRAY" and @$argv
!ll&&!rl&&r
007
MC/DC0%0/2
ref $argv eq "ARRAY" and @$argv
ref $argv eq "ARRAY" @$argv
Truth table33%1/3
A and B
A= ref $argv eq "ARRAY"B= @$argv
ABresult
0X0
100
111
69 message => 'argv must be a nonempty array')
70 unless ref($argv) eq 'ARRAY' && @$argv;
71 7 my @argv;
72 7 for my $arg (@$argv) {
73 25 ▶ LibTmux::X::InvalidArgument->throw(
Branch: 1 branch
BranchTrueFalseTotal
if not defined $arg or ref $arg or index($arg, "\0") != -1 0 25 25
Condition33%2/6
not defined $arg or ref $arg or index($arg, "\0") != -1
l!l&&r!l&&!r
0025
not defined $arg or ref $arg
l!l&&r!l&&!r
0025
MC/DC0%0/3
not defined $arg or ref $arg or index($arg, "\0") != -1
not defined $arg ref $arg index($arg, "\0") != -1
Truth table25%1/4
not(A) or B or C
A= not defined $argB= ref $argC= index($arg, "\0") != -1
ABCresult
1XX1
01X1
0011
0000
74 message => 'arguments must be defined NUL-free scalars')
75 if !defined($arg) || ref($arg) || index($arg, "\0") >= 0;
76 25 ▶ push @argv,
Branch: 1 branch
BranchTrueFalseTotal
utf8::is_utf8($arg) ? : 0 25 25
77 utf8::is_utf8($arg)
78 ? encode('UTF-8', $arg, FB_CROAK | LEAVE_SRC)
79 : "$arg";
80 }
81 7 $args{argv} = \@argv;
82 7 ▶ $args{timeout} //= 5;
Condition50%1/2
$args{"timeout"} //= 5
l!l
70
MC/DC0%0/1
$args{"timeout"} //= 5
$args{"timeout"}
Truth table50%1/2
A
A= $args{"timeout"}
Aresult
11
00
83 7 ▶ $args{max_output} //= 8 * 1024 * 1024;
Condition50%1/2
$args{"max_output"} //= 8388608
l!l
70
MC/DC0%0/1
$args{"max_output"} //= 8388608
$args{"max_output"}
Truth table50%1/2
A
A= $args{"max_output"}
Aresult
11
00
84 7 ▶ $args{stdin} //= '';
Condition50%1/2
$args{"stdin"} //= ""
l!l
07
MC/DC0%0/1
$args{"stdin"} //= ""
$args{"stdin"}
Truth table50%1/2
A
A= $args{"stdin"}
Aresult
11
00
85 LibTmux::X::InvalidArgument->throw(message => 'stdin must contain octets')
86 7 ▶ if ref($args{stdin}) || utf8::is_utf8($args{stdin});
Branch: 1 branch
BranchTrueFalseTotal
if ref $args{"stdin"} or utf8::is_utf8($args{"stdin"}) 0 7 7
Condition33%1/3
ref $args{"stdin"} or utf8::is_utf8($args{"stdin"})
l!l&&r!l&&!r
007
MC/DC0%0/2
ref $args{"stdin"} or utf8::is_utf8($args{"stdin"})
ref $args{"stdin"} utf8::is_utf8($args{"stdin"})
Truth table33%1/3
A or B
A= ref $args{"stdin"}B= utf8::is_utf8($args{"stdin"})
ABresult
1X1
011
000
87 LibTmux::X::Unsupported->throw(
88 message => 'SIGCHLD=IGNORE prevents reliable process status')
89 7 ▶ if defined($SIG{CHLD}) && !ref($SIG{CHLD}) && $SIG{CHLD} eq 'IGNORE';
Branch: 1 branch
BranchTrueFalseTotal
if defined $SIG{"CHLD"} and not ref $SIG{"CHLD"} and $SIG{"CHLD"} eq "IGNORE" 0 7 7
Condition33%2/6
defined $SIG{"CHLD"} and not ref $SIG{"CHLD"} and $SIG{"CHLD"} eq "IGNORE"
!ll&&!rl&&r
700
defined $SIG{"CHLD"} and not ref $SIG{"CHLD"}
!ll&&!rl&&r
700
MC/DC0%0/3
defined $SIG{"CHLD"} and not ref $SIG{"CHLD"} and $SIG{"CHLD"} eq "IGNORE"
defined $SIG{"CHLD"} not ref $SIG{"CHLD"} $SIG{"CHLD"} eq "IGNORE"
Truth table25%1/4
A and not(B) and C
A= defined $SIG{"CHLD"}B= not ref $SIG{"CHLD"}C= $SIG{"CHLD"} eq "IGNORE"
ABCresult
0XX0
10X0
1100
1111
90 LibTmux::X::InvalidArgument->throw(
91 message => 'cancel_fh must be an open handle')
92 7 ▶ if exists($args{cancel_fh}) && !defined(fileno($args{cancel_fh}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"cancel_fh"} and not defined fileno $args{"cancel_fh"} 0 7 7
Condition33%1/3
exists $args{"cancel_fh"} and not defined fileno $args{"cancel_fh"}
!ll&&!rl&&r
700
MC/DC0%0/2
exists $args{"cancel_fh"} and not defined fileno $args{"cancel_fh"}
exists $args{"cancel_fh"} not defined fileno $args{"cancel_fh"}
Truth table33%1/3
A and not(B)
A= exists $args{"cancel_fh"}B= not defined fileno $args{"cancel_fh"}
ABresult
0X0
100
111
93 7 return %args;
94 }
95  
96 7 ▶sub start ($class, %args) {
Subroutine start: called CC=1 SCAR=0.0
Pod documented
97 7 require LibTmux::ProcessJob;
98 7 return LibTmux::ProcessJob->start(%args);
99 }
100 4 ▶sub run ($class, %args) { $class->start(%args)->wait }
Subroutine run: called CC=1 SCAR=0.0
Pod documented
101  
102 3 ▶sub _supervise ($args, $alive_r, $result_w) {
Subroutine _supervise: called CC=118 SCAR=90.0
103 3 require LibTmux::Platform::Linux;
104 3 LibTmux::Platform::Linux::_subreaper();
105 3 my ($in_r, $in_w) = _pipe();
106 3 my ($out_r, $out_w) = _pipe();
107 3 my ($err_r, $err_w) = _pipe();
108 3 my ($exec_r, $exec_w) = _pipe();
109 3 my ($go_r, $go_w) = _pipe();
110 3 my @signals = (SIGCHLD, SIGINT, SIGTERM);
111 3 my $block = POSIX::SigSet->new(@signals);
112 3 my $old = POSIX::SigSet->new;
113 3 ▶ POSIX::sigprocmask(SIG_BLOCK, $block, $old)
Condition50%1/2
POSIX::sigprocmask(0, $block, $old) // die("block supervisor signals: $!")
l!l
30
MC/DC0%0/1
POSIX::sigprocmask(0, $block, $old) // die("block supervisor signals: $!")
POSIX::sigprocmask(0, $block, $old)
Truth table50%1/2
A
A= POSIX::sigprocmask(0, $block, $old)
Aresult
11
00
114 // die "block supervisor signals: $!";
115 3 local $SIG{CHLD} = 'DEFAULT';
116 3 local $SIG{INT} = 'DEFAULT';
117 3 local $SIG{TERM} = 'DEFAULT';
118 3 my $notice_r = LibTmux::Platform::Linux::_signal_handle(@signals);
119 3 ▶ fcntl($notice_r, F_SETFD, FD_CLOEXEC) // die "signal close-on-exec: $!";
Condition50%1/2
fcntl($notice_r, 2, 1) // die("signal close-on-exec: $!")
l!l
30
MC/DC0%0/1
fcntl($notice_r, 2, 1) // die("signal close-on-exec: $!")
fcntl($notice_r, 2, 1)
Truth table50%1/2
A
A= fcntl($notice_r, 2, 1)
Aresult
11
00
120 _nonblock($_)
121 3 for ($in_w, $out_r, $err_r, $exec_r, $notice_r, $alive_r);
122 3 my $reason;
123  
124 # Allocate every pipe before raw descriptor closure. PerlIO still tracks
125 # inherited handles; reusing their numbers can retain protocol pipe ends.
126 LibTmux::Platform::Linux::_close_fds_except(
127 $alive_r, $result_w,
128 $args->{_cancel_r}, $in_r,
129 $in_w, $out_r,
130 $out_w, $err_r,
131 $err_w, $exec_r,
132 $exec_w, $go_r,
133 $go_w, $notice_r,
134 3 ▶ exists($args->{cancel_fh}) ? ($args->{cancel_fh}) : ()
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'cancel_fh'} ? : 0 3 3
135 );
136 3 my $pid = fork();
137 3 ▶ die "fork program: $!" unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 3 3
138 3 ▶ if (!$pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 3 0 3
139 3 $SIG{CHLD} = 'DEFAULT';
140 3 $SIG{INT} = 'DEFAULT';
141 3 $SIG{TERM} = 'DEFAULT';
142 3 $SIG{PIPE} = 'DEFAULT';
143 3 close $in_w;
144 3 close $out_r;
145 3 close $err_r;
146 3 close $exec_r;
147 3 close $go_w;
148 3 close $notice_r;
149 3 close $alive_r;
150 3 ▶ close $args->{_cancel_r} if $args->{_cancel_r};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"_cancel_r"} 3 0 3
151 my $fail =
152 0 ▶ sub ($message) { syswrite($exec_w, 'E' . $message); _exit(127) };
Subroutine __ANON__: not called CC=1 SCAR=2.6
153 3 ▶ POSIX::sigprocmask(SIG_SETMASK, $old)
Condition33%1/3
POSIX::sigprocmask(2, $old) // &$fail("restore program signal mask: $!")
l!l&&r!l&&!r
300
MC/DC0%0/2
POSIX::sigprocmask(2, $old) // &$fail("restore program signal mask: $!")
POSIX::sigprocmask(2, $old) &$fail("restore program signal mask: $!")
Truth table33%1/3
A // B
A= POSIX::sigprocmask(2, $old)B= &$fail("restore program signal mask: $!")
ABresult
1X1
011
000
154 // $fail->("restore program signal mask: $!");
155 3 my $group = setpgid(0, 0);
156 3 ▶ $fail->("setpgid: $!") unless defined($group) && $group == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $group and $group == 0 0 3 3
Condition33%1/3
defined $group and $group == 0
!ll&&!rl&&r
003
MC/DC0%0/2
defined $group and $group == 0
defined $group $group == 0
Truth table33%1/3
A and B
A= defined $groupB= $group == 0
ABresult
0X0
100
111
157 3 ▶ syswrite($exec_w, 'G') == 1 or _exit(127);
Branch: 1 branch
BranchTrueFalseTotal
syswrite($exec_w, "G") == 1 or _exit(127) 3 0 3
158 3 my $n;
159 3 ▶ do { $n = sysread($go_r, my $unused, 1) }
Branch: 1 branch
BranchTrueFalseTotal
not defined $n and $! == 4 and do { do { $n = sysread($go_r, my $unused, 1) } } 0 3 3
Condition33%1/3
not defined $n and $! == 4
!ll&&!rl&&r
300
MC/DC0%0/2
not defined $n and $! == 4
not defined $n $! == 4
Truth table33%1/3
not(A) and B
A= not defined $nB= $! == 4
ABresult
0X0
100
111
160 while (!defined($n) && $! == EINTR);
161 3 ▶ _exit(127) unless defined($n) && $n == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n and $n == 1 0 3 3
Condition33%1/3
defined $n and $n == 1
!ll&&!rl&&r
003
MC/DC0%0/2
defined $n and $n == 1
defined $n $n == 1
Truth table33%1/3
A and B
A= defined $nB= $n == 1
ABresult
0X0
100
111
162 3 close $go_r;
163 3 ▶ open STDIN, '<&', $in_r or $fail->("stdin: $!");
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, "<&", $in_r or &$fail("stdin: $!") 3 0 3
164 3 ▶ open STDOUT, '>&', $out_w or $fail->("stdout: $!");
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&", $out_w or &$fail("stdout: $!") 3 0 3
165 3 ▶ open STDERR, '>&', $err_w or $fail->("stderr: $!");
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", $err_w or &$fail("stderr: $!") 3 0 3
166 3 close $in_r;
167 3 close $out_w;
168 3 close $err_w;
169 3 try { LibTmux::Platform::Linux::_close_fds_except($exec_w) }
170 0 catch ($error) { $fail->("$error") }
171 3 ▶ %ENV = (%ENV, %{$args->{env} // {}});
Condition50%1/2
$args->{"env"} // {}
l!l
30
MC/DC0%0/1
$args->{"env"} // {}
$args->{"env"}
Truth table50%1/2
A
A= $args->{"env"}
Aresult
11
00
172 3 delete @ENV{qw(TMUX TMUX_PANE)};
173 3 ▶ exec {$args->{argv}[0]} $args->{argv}->@* or $fail->("exec: $!");
Branch: 1 branch
BranchTrueFalseTotal
exec {$args->{"argv"}[0];} @{$args->{"argv"}} or &$fail("exec: $!") 0 0 0
174 }
175 0 close $in_r;
176 0 close $out_w;
177 0 close $err_w;
178 0 close $exec_w;
179 0 close $go_r;
180 0 setpgid($pid, $pid);
181  
182 # Kernel signal readiness survives the final Perl safe point before
183 # select. A deferred Perl handler writing a self-pipe does not.
184 0 my $reads = IO::Select->new($out_r, $err_r, $exec_r, $notice_r, $alive_r);
185 0 ▶ $reads->add($args->{cancel_fh}) if exists $args->{cancel_fh};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"cancel_fh"} 0 0 0
186 0 ▶ $reads->add($args->{_cancel_r}) if $args->{_cancel_r};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"_cancel_r"} 0 0 0
187 0 my $writes = IO::Select->new;
188 0 ▶ if (length $args->{stdin}) { $writes->add($in_w) }
Branch: 1 branch
BranchTrueFalseTotal
if (length $args->{'stdin'}) { } 0 0 0
189 0 else { close $in_w }
190 0 my %stream = (
191 fileno($out_r) => 'stdout',
192 fileno($err_r) => 'stderr',
193 fileno($exec_r) => 'exec'
194 );
195 0 my %data = (stdout => '', stderr => '', exec => '');
196 0 my ($offset, $done, $group_ready, $released, $killed) = (0, 0, 0, 0, 0);
197 0 my ($raw_status, $grace, $cleanup_deadline);
198 0 my ($group_complete, $direct_reaped) = (false, false);
199 0 my $deadline = _now() + $args->{timeout};
200 my $terminate =
201 0 ▶ sub ($signal) { kill $signal, ($group_ready ? -$pid : $pid) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$group_ready ? : 0 0 0
202  
203 0 ▶ while (!$done || keys %stream || !$group_complete) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $done or keys %stream or not $group_complete) 0 0 0
Condition0%0/6
not $done or keys %stream or not $group_complete
l!l&&r!l&&!r
000
not $done or keys %stream
l!l&&r!l&&!r
000
MC/DC0%0/3
not $done or keys %stream or not $group_complete
not $done keys %stream not $group_complete
Truth table0%0/4
not(A) or B or not(C)
A= not $doneB= keys %streamC= not $group_complete
ABCresult
1XX1
01X1
0011
0000
204 0 my $waited = waitpid($pid, WNOHANG);
205 0 ▶ if ($waited == $pid) {
Branch: 2 branches
BranchTrueFalseTotal
if ($waited == $pid) { } 0 0 0
elsif ($waited < 0 and $! == 10 and not $done) { } 0 0 0
206 0 $raw_status = $?;
207 0 $done = 1;
208 0 $direct_reaped = true;
209 }
210 ▶ elsif ($waited < 0 && $! == ECHILD && !$done) {
Condition0%0/6
$waited < 0 and $! == 10 and not $done
!ll&&!rl&&r
000
$waited < 0 and $! == 10
!ll&&!rl&&r
000
MC/DC0%0/3
$waited < 0 and $! == 10 and not $done
$waited < 0 $! == 10 not $done
Truth table0%0/4
A and B and not(C)
A= $waited < 0B= $! == 10C= not $done
ABCresult
0XX0
10X0
1100
1111
211 0 ▶ $reason //= 'Transport';
Condition0%0/2
$reason //= "Transport"
l!l
00
MC/DC0%0/1
$reason //= "Transport"
$reason
Truth table0%0/2
A
A= $reason
Aresult
11
00
212 0 $raw_status = undef;
213 0 $done = 1;
214 }
215 0 my $now = _now();
216 0 ▶ if ($done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done) 0 0 0
217 0 ▶ if (!$group_ready) { $group_complete = true }
Branch: 1 branch
BranchTrueFalseTotal
if (not $group_ready) { } 0 0 0
218 else {
219 0 my $adopted;
220 0 ▶ do { $adopted = waitpid(-$pid, WNOHANG) }
Branch: 1 branch
BranchTrueFalseTotal
$adopted > 0 || $adopted < 0 && $! == 4 and do { do { $adopted = waitpid(-$pid, 1) } } 0 0 0
Condition0%0/6
$adopted > 0 or $adopted < 0 and $! == 4
l!l&&r!l&&!r
000
$adopted < 0 and $! == 4
!ll&&!rl&&r
000
MC/DC0%0/3
$adopted > 0 or $adopted < 0 and $! == 4
$adopted > 0 $adopted < 0 $! == 4
Truth table0%0/4
A or B and C
A= $adopted > 0B= $adopted < 0C= $! == 4
ABCresult
1XX1
0111
00X0
0100
221 while $adopted > 0 || ($adopted < 0 && $! == EINTR);
222 0 ▶ $group_complete = true
Branch: 1 branch
BranchTrueFalseTotal
if $adopted < 0 and $! == 10 and not kill(0, -$pid) and $! == 3 0 0 0
Condition0%0/9
$adopted < 0 and $! == 10 and not kill(0, -$pid) and $! == 3
!ll&&!rl&&r
000
$adopted < 0 and $! == 10 and not kill(0, -$pid)
!ll&&!rl&&r
000
$adopted < 0 and $! == 10
!ll&&!rl&&r
000
MC/DC0%0/4
$adopted < 0 and $! == 10 and not kill(0, -$pid) and $! == 3
$adopted < 0 $! == 10 not kill(0, -$pid) $! == 3
Truth table0%0/5
A and B and not(C) and D
A= $adopted < 0B= $! == 10C= not kill(0, -$pid)D= $! == 3
ABCDresult
0XXX0
10XX0
110X0
11100
11111
223 if $adopted < 0
224 && $! == ECHILD
225 && !kill(0, -$pid)
226 && $! == ESRCH;
227 0 ▶ $reason //= 'Transport' unless $group_complete;
Branch: 1 branch
BranchTrueFalseTotal
unless $group_complete 0 0 0
Condition0%0/2
$reason //= "Transport"
l!l
00
MC/DC0%0/1
$reason //= "Transport"
$reason
Truth table0%0/2
A
A= $reason
Aresult
11
00
228 }
229 }
230 0 ▶ $reason //= 'Timeout' if $now >= $deadline;
Branch: 1 branch
BranchTrueFalseTotal
if $now >= $deadline 0 0 0
Condition0%0/2
$reason //= "Timeout"
l!l
00
MC/DC0%0/1
$reason //= "Timeout"
$reason
Truth table0%0/2
A
A= $reason
Aresult
11
00
231 0 ▶ if ($reason && !defined $grace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reason and not defined $grace) 0 0 0
Condition0%0/3
$reason and not defined $grace
!ll&&!rl&&r
000
MC/DC0%0/2
$reason and not defined $grace
$reason not defined $grace
Truth table0%0/3
A and not(B)
A= $reasonB= not defined $grace
ABresult
0X0
100
111
232 0 $terminate->('TERM');
233 0 $grace = $now + 0.05;
234 0 $cleanup_deadline = $now + 0.55;
235 0 ▶ if ($writes->count) { $writes->remove($in_w); close $in_w }
Branch: 1 branch
BranchTrueFalseTotal
if ($writes->count) 0 0 0
236 0 ▶ close $go_w if !$released && defined fileno($go_w);
Branch: 1 branch
BranchTrueFalseTotal
if not $released and defined fileno $go_w 0 0 0
Condition0%0/3
not $released and defined fileno $go_w
!ll&&!rl&&r
000
MC/DC0%0/2
not $released and defined fileno $go_w
not $released defined fileno $go_w
Truth table0%0/3
not(A) and B
A= not $releasedB= defined fileno $go_w
ABresult
0X0
100
111
237 }
238 0 ▶ if (defined($grace) && $now >= $grace && !$killed) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grace and $now >= $grace and not $killed) 0 0 0
Condition0%0/6
defined $grace and $now >= $grace and not $killed
!ll&&!rl&&r
000
defined $grace and $now >= $grace
!ll&&!rl&&r
000
MC/DC0%0/3
defined $grace and $now >= $grace and not $killed
defined $grace $now >= $grace not $killed
Truth table0%0/4
A and B and not(C)
A= defined $graceB= $now >= $graceC= not $killed
ABCresult
0XX0
10X0
1100
1111
239 0 $terminate->('KILL');
240 0 $killed = 1;
241 }
242 0 ▶ last if $done && $group_complete && ($reason || !keys(%stream));
Branch: 1 branch
BranchTrueFalseTotal
if $done and $group_complete and $reason || !keys(%stream) 0 0 0
Condition0%0/9
$done and $group_complete and $reason || !keys(%stream)
!ll&&!rl&&r
000
$done and $group_complete
!ll&&!rl&&r
000
$reason or not keys %stream
l!l&&r!l&&!r
000
MC/DC0%0/4
$done and $group_complete and $reason || !keys(%stream)
$done $group_complete $reason not keys %stream
Truth table0%0/5
A and B and C or not(D)
A= $doneB= $group_completeC= $reasonD= not keys %stream
ABCDresult
0XXX0
10XX0
11000
111X1
11011
243 0 ▶ if (defined($cleanup_deadline) && $now >= $cleanup_deadline) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cleanup_deadline and $now >= $cleanup_deadline) 0 0 0
Condition0%0/3
defined $cleanup_deadline and $now >= $cleanup_deadline
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cleanup_deadline and $now >= $cleanup_deadline
defined $cleanup_deadline $now >= $cleanup_deadline
Truth table0%0/3
A and B
A= defined $cleanup_deadlineB= $now >= $cleanup_deadline
ABresult
0X0
100
111
244 0 $reason = 'Transport';
245 0 last;
246 }
247 0 ▶ my $until =
Branch: 2 branches
BranchTrueFalseTotal
defined $grace ? : 0 0 0
$killed ? : 0 0 0
248 defined($grace)
249 ? ($killed ? $cleanup_deadline : $grace)
250 : $deadline;
251 0 ▶ my ($ready_r, $ready_w) = IO::Select->select($reads, $writes, undef,
Branch: 1 branch
BranchTrueFalseTotal
$until > $now ? : 0 0 0
252 ($until > $now ? $until - $now : 0));
253 0 ▶ next unless defined $ready_r;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ready_r 0 0 0
254 0 for my $fh (@$ready_r) {
255 0 my $fd = fileno($fh);
256 0 my $n = sysread($fh, my $chunk, 65536);
257 next
258 0 ▶ if !defined($n)
Branch: 1 branch
BranchTrueFalseTotal
if not defined $n and $! == 11 || $! == 11 || $! == 4 0 0 0
Condition0%0/9
not defined $n and $! == 11 || $! == 11 || $! == 4
!ll&&!rl&&r
000
$! == 11 or $! == 11 or $! == 4
l!l&&r!l&&!r
000
$! == 11 or $! == 11
l!l&&r!l&&!r
000
MC/DC0%0/4
not defined $n and $! == 11 || $! == 11 || $! == 4
not defined $n $! == 11 $! == 11 $! == 4
Truth table0%0/5
not(A) and B or C or D
A= not defined $nB= $! == 11C= $! == 11D= $! == 4
ABCDresult
0XXX0
10000
11XX1
101X1
10011
259 && ($! == EAGAIN || $! == EWOULDBLOCK || $! == EINTR);
260 0 ▶ if ($fd == fileno($alive_r)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fd == fileno $alive_r) 0 0 0
261 0 ▶ $reason //= 'Cancelled' unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 0 0
Condition0%0/2
$reason //= "Cancelled"
l!l
00
MC/DC0%0/1
$reason //= "Cancelled"
$reason
Truth table0%0/2
A
A= $reason
Aresult
11
00
262 0 ▶ $reads->remove($fh) unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 0 0
263 0 next;
264 }
265 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"cancel_fh"} and $fd == fileno $args->{"cancel_fh"} or $args->{"_cancel_r"} and $fd == fileno $args->{"_cancel_r"}) 0 0 0
Condition0%0/9
exists $args->{"cancel_fh"} and $fd == fileno $args->{"cancel_fh"} or $args->{"_cancel_r"} and $fd == fileno $args->{"_cancel_r"}
l!l&&r!l&&!r
000
exists $args->{"cancel_fh"} and $fd == fileno $args->{"cancel_fh"}
!ll&&!rl&&r
000
$args->{"_cancel_r"} and $fd == fileno $args->{"_cancel_r"}
!ll&&!rl&&r
000
MC/DC0%0/4
exists $args->{"cancel_fh"} and $fd == fileno $args->{"cancel_fh"} or $args->{"_cancel_r"} and $fd == fileno $args->{"_cancel_r"}
exists $args->{"cancel_fh"} $fd == fileno $args->{"cancel_fh"} $args->{"_cancel_r"} $fd == fileno $args->{"_cancel_r"}
Truth table0%0/7
A and B or C and D
A= exists $args->{"cancel_fh"}B= $fd == fileno $args->{"cancel_fh"}C= $args->{"_cancel_r"}D= $fd == fileno $args->{"_cancel_r"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
266 (
267 exists($args->{cancel_fh})
268 && $fd == fileno($args->{cancel_fh})
269 )
270 || ($args->{_cancel_r} && $fd == fileno($args->{_cancel_r}))
271 )
272 {
273 0 ▶ $reason //= 'Cancelled';
Condition0%0/2
$reason //= "Cancelled"
l!l
00
MC/DC0%0/1
$reason //= "Cancelled"
$reason
Truth table0%0/2
A
A= $reason
Aresult
11
00
274 0 $reads->remove($fh);
275 0 next;
276 }
277 0 ▶ if ($fd == fileno($notice_r)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fd == fileno $notice_r) 0 0 0
278 0 ▶ if (!defined($n) || !$n || $n % 128) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $n && $n or $n % 128) { } 0 0 0
Condition0%0/6
not defined $n && $n or $n % 128
l!l&&r!l&&!r
000
defined $n && $n
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $n && $n or $n % 128
defined $n $n $n % 128
Truth table0%0/4
not(A && B) or C
A= defined $nB= $nC= $n % 128
ABCresult
0XX1
10X1
1111
1100
279 0 ▶ $reason //= 'Transport';
Condition0%0/2
$reason //= "Transport"
l!l
00
MC/DC0%0/1
$reason //= "Transport"
$reason
Truth table0%0/2
A
A= $reason
Aresult
11
00
280 0 $reads->remove($fh);
281 }
282 else {
283 0 ▶ for (my $offset = 0 ; $offset < $n ; $offset += 128) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < $n) 0 0 0
284 0 my $signal = unpack('L<', substr($chunk, $offset, 4));
285 0 ▶ $reason //= 'Cancelled'
Branch: 1 branch
BranchTrueFalseTotal
if $signal == 2 or $signal == 15 0 0 0
Condition0%0/5
$signal == 2 or $signal == 15
l!l&&r!l&&!r
000
$reason //= "Cancelled"
l!l
00
MC/DC0%0/2
$signal == 2 or $signal == 15
$signal == 2 $signal == 15
MC/DC0%0/1
$reason //= "Cancelled"
$reason
Truth table0%0/3
A or B
A= $signal == 2B= $signal == 15
ABresult
1X1
011
000
Truth table0%0/2
A
A= $reason
Aresult
11
00
286 if $signal == SIGINT || $signal == SIGTERM;
287 }
288 }
289 0 next;
290 }
291 0 ▶ if (!defined($n) || !$n) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $n and $n) 0 0 0
Condition0%0/3
defined $n and $n
!ll&&!rl&&r
000
MC/DC0%0/2
defined $n and $n
defined $n $n
Truth table0%0/3
A and B
A= defined $nB= $n
ABresult
0X0
100
111
292 0 $reads->remove($fh);
293 0 delete $stream{$fd};
294 0 close $fh;
295 0 next;
296 }
297 0 my $which = $stream{$fd};
298 0 ▶ if ($which eq 'stdout' || $which eq 'stderr') {
Branch: 1 branch
BranchTrueFalseTotal
if ($which eq 'stdout' or $which eq 'stderr') { } 0 0 0
Condition0%0/3
$which eq "stdout" or $which eq "stderr"
l!l&&r!l&&!r
000
MC/DC0%0/2
$which eq "stdout" or $which eq "stderr"
$which eq "stdout" $which eq "stderr"
Truth table0%0/3
A or B
A= $which eq "stdout"B= $which eq "stderr"
ABresult
1X1
011
000
299 my $remaining =
300 $args->{max_output} -
301 length($data{stdout}) -
302 0 length($data{stderr});
303 0 $data{$which} .= substr($chunk, 0, $remaining);
304 0 ▶ $reason //= 'OutputLimit' if length($chunk) > $remaining;
Branch: 1 branch
BranchTrueFalseTotal
if length $chunk > $remaining 0 0 0
Condition0%0/2
$reason //= "OutputLimit"
l!l
00
MC/DC0%0/1
$reason //= "OutputLimit"
$reason
Truth table0%0/2
A
A= $reason
Aresult
11
00
305 }
306 else {
307 $data{$which} .=
308 0 substr($chunk, 0, 65536 - length($data{$which}));
309 $reason //= 'Transport'
310 0 ▶ if length($chunk) + length($data{$which}) > 131072;
Branch: 1 branch
BranchTrueFalseTotal
if length($chunk) + length($data{$which}) > 131072 0 0 0
Condition0%0/2
$reason //= "Transport"
l!l
00
MC/DC0%0/1
$reason //= "Transport"
$reason
Truth table0%0/2
A
A= $reason
Aresult
11
00
311 }
312 0 ▶ if ($which eq 'exec' && !$group_ready && $data{exec} =~ s/^G//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($which eq "exec" and not $group_ready and $data{"exec"} =~ s/^G//u) 0 0 0
Condition0%0/6
$which eq "exec" and not $group_ready and $data{"exec"} =~ s/^G//u
!ll&&!rl&&r
000
$which eq "exec" and not $group_ready
!ll&&!rl&&r
000
MC/DC0%0/3
$which eq "exec" and not $group_ready and $data{"exec"} =~ s/^G//u
$which eq "exec" not $group_ready $data{"exec"} =~ s/^G//u
Truth table0%0/4
A and not(B) and C
A= $which eq "exec"B= not $group_readyC= $data{"exec"} =~ s/^G//u
ABCresult
0XX0
10X0
1100
1111
313 0 $group_ready = 1;
314 0 ▶ unless ($reason) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($reason) 0 0 0
315 0 ▶ if (syswrite($go_w, '1') == 1) { $released = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if (syswrite($go_w, '1') == 1) { } 0 0 0
316 0 ▶ else { $reason //= 'Spawn' }
Condition0%0/2
$reason //= "Spawn"
l!l
00
MC/DC0%0/1
$reason //= "Spawn"
$reason
Truth table0%0/2
A
A= $reason
Aresult
11
00
317 }
318 0 ▶ close $go_w if defined fileno($go_w);
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno $go_w 0 0 0
319 }
320 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (length($data{"stdout"}) + length($data{"stderr"}) > $args->{"max_output"}) 0 0 0
321 length($data{stdout}) + length($data{stderr}) >
322 $args->{max_output})
323 {
324 0 ▶ $reason //= 'OutputLimit';
Condition0%0/2
$reason //= "OutputLimit"
l!l
00
MC/DC0%0/1
$reason //= "OutputLimit"
$reason
Truth table0%0/2
A
A= $reason
Aresult
11
00
325 }
326 }
327 0 for my $fh (@$ready_w) {
328 my $n =
329 0 syswrite($fh, $args->{stdin}, length($args->{stdin}) - $offset,
330 $offset);
331 next
332 0 ▶ if !defined($n)
Branch: 1 branch
BranchTrueFalseTotal
if not defined $n and $! == 4 || $! == 11 || $! == 11 0 0 0
Condition0%0/9
not defined $n and $! == 4 || $! == 11 || $! == 11
!ll&&!rl&&r
000
$! == 4 or $! == 11 or $! == 11
l!l&&r!l&&!r
000
$! == 4 or $! == 11
l!l&&r!l&&!r
000
MC/DC0%0/4
not defined $n and $! == 4 || $! == 11 || $! == 11
not defined $n $! == 4 $! == 11 $! == 11
Truth table0%0/5
not(A) and B or C or D
A= not defined $nB= $! == 4C= $! == 11D= $! == 11
ABCDresult
0XXX0
10000
11XX1
101X1
10011
333 && ($! == EINTR || $! == EAGAIN || $! == EWOULDBLOCK);
334 0 ▶ if (!defined($n) || !$n) { $writes->remove($fh); close $fh; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $n and $n) 0 0 0
Condition0%0/3
defined $n and $n
!ll&&!rl&&r
000
MC/DC0%0/2
defined $n and $n
defined $n $n
Truth table0%0/3
A and B
A= defined $nB= $n
ABresult
0X0
100
111
335 0 $offset += $n;
336 0 ▶ if ($offset == length($args->{stdin})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset == length $args->{"stdin"}) 0 0 0
337 0 $writes->remove($fh);
338 0 close $fh;
339 }
340 }
341 }
342 my $record = {
343 cleanup_complete => $direct_reaped && $group_complete ? true : false,
344 stdout => encode_base64($data{stdout}, ''),
345 0 ▶ stderr => encode_base64($data{stderr}, ''),
Branch: 3 branches
BranchTrueFalseTotal
$direct_reaped && $group_complete ? : 0 0 0
defined $raw_status ? : 0 0 0
defined $raw_status ? : 0 0 0
Condition0%0/3
$direct_reaped and $group_complete
!ll&&!rl&&r
000
MC/DC0%0/2
$direct_reaped and $group_complete
$direct_reaped $group_complete
Truth table0%0/3
A and B
A= $direct_reapedB= $group_complete
ABresult
0X0
100
111
346 raw_status => $raw_status,
347 exit_code => (defined($raw_status) ? $raw_status >> 8 : undef),
348 signal => (defined($raw_status) ? $raw_status & 127 : undef)
349 };
350 0 ▶ if ($data{exec} =~ s/^E//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data{"exec"} =~ s/^E//u) 0 0 0
351 $record->{error} =
352 0 {type => 'Spawn', message => $data{exec}, dispatched => false};
353 0 return $record;
354 }
355 0 ▶ if ($reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reason) 0 0 0
356 $record->{error} = {
357 0 ▶ type => $reason,
Branch: 1 branch
BranchTrueFalseTotal
$released ? : 0 0 0
358 message => lc($reason) . ' during process execution',
359 dispatched => $released ? true : false
360 };
361 0 return $record;
362 }
363 0 return $record;
364 }
365  
366 =head1 NAME
367  
368 LibTmux::Transport - Supervised literal process execution
369  
370 =head1 METHODS
371  
372 =head2 run
373  
374 C<run(argv =E<gt> [...], stdin =E<gt> $octets, timeout =E<gt> $seconds,
375 max_output =E<gt> $bytes, cancel_fh =E<gt> $handle)> returns a
376 L<LibTmux::CommandResult>.
377 Stdout/stderr are separate octet strings. Nonzero exits are results; spawn,
378 timeout, cancellation, output limits, and supervision failures throw
379 L<LibTmux::X> exceptions. C<timeout> bounds one command's execution loop,
380 excluding supervisor setup, async queue waiting, and separate cleanup time.
381  
382 =head2 start
383  
384 Return a L<LibTmux::ProcessJob> for an executor adapter.
385  
386 =head1 RESULTS
387  
388 L<LibTmux::CommandResult> exposes stdout, stderr, exit_code, signal, raw_status,
389 and success. Output remains octets.
390  
391 The private supervisor owns program signals/groups and reaps the program.
392 It receives CHLD, INT and TERM through a Linux signal descriptor, so child
393 exit cannot wait for a deferred Perl handler. This mask belongs only to the
394 supervisor; the command restores its inherited mask before execution.
395 Application SIGCHLD handlers remain intact; SIGCHLD=IGNORE is refused.
396 Cancellation handles are borrowed and remain open. Cancellation after release
397 can have effects and never implies rollback. Parent death triggers cleanup.
398  
399 Owned supervisor and command branches close unrelated inherited descriptors
400 through Linux C</proc/self/fd>, preserving the caller's handles. Native
401 descriptors without close-on-exec cannot leak into a newly started tmux daemon.
402 Only standard streams and each branch's required protocol/cancellation pipes
403 remain open. Enumeration or closure failures prevent execution and throw
404 L<LibTmux::X/Transport> or L<LibTmux::X/Spawn>. No arbitrary descriptor-passing
405 API is selected. Forking hosts with native threads remains unqualified.
406  
407 =cut
↑ Summary LibTmux/Server.pm »