lib/Proc/Spawner.pm

filter: Statementstmt 42.8% 187 / 436 Branchbran 26.7% 84 / 314 Conditioncond 27.7% 80 / 288 MC/DCmcdc 8.1% 13 / 159 Subroutinesub 55.5% 25 / 45 Podpod 0.0% 0 / 21 totaltotal 30.8% 389 / 1263 CC 276 SCAR 80.6
CC
276
Cov
34%
spawn
6935.3
emulate_actions
1260.0
run_redirs
272.0
CRAP 3154.9
↑ Summary lib/Proc/Spawner/Graph.pm »
1 package Proc::Spawner;
2 # EXPERIMENTAL. Starts child processes with posix_spawn(3), and runs the one event loop that
3 # reports what happened: a child ended, an fd became readable or writable. Nothing else: what the
4 # children are connected to, and what to do when one ends, is the business of the caller
5 # (Proc::Spawner::Graph, the companion module, keeps that as a graph).
6 #
7 # start(PATH, ARGV, ENVP, FDS, %opt) a pid, or undef with $!; with pidfd => 1 in list context, the pid
8 # and a pidfd. FDS: { CHILD_FD => PARENT_FD, or [PATH, FLAGS, MODE] opened in the child, or undef
9 # for closed }; an fd not listed is inherited as it is (if it is not close-on-exec).
10 # %opt: every setting posix_spawn has (glibc 2.39), and umask, unsupported:
11 # chdir => DIR, fchdir => FD the child's current directory (FD: the parent's fd), set
12 # before the fds, so FDS paths are relative to it
13 # sigdefault => [SIGNALS] back to the default action in the child (names or numbers)
14 # sigmask => [SIGNALS] blocked in the child; default: none
15 # pgroup => PGID its process group (0: a new one, led by the child)
16 # setsid => 1 a new session
17 # tcsetpgrp => FD its group becomes the terminal's foreground, through FD as
18 # the child has it
19 # resetids => 1, sched => [POLICY, PRIORITY], cgroup => FD (a cgroup v2 directory)
20 # search => 1 look PATH up in the PATH of the parent's %ENV (posix_spawnp)
21 # pidfd => 1 also a pidfd (pidfd_spawn)
22 # umask => N posix_spawn has none: set in Perl just around the call, so
23 # bullet-proof only in non-threaded execution (the umask is the
24 # whole process's)
25 # sigignore => [SIGNALS] ignored in the child
26 # rlimit => { NAME => SOFT | [SOFT, HARD] } the child's resource limits (NOFILE, CORE, ...; a number
27 # or 'unlimited'; undef: as ours)
28 # nice => INCREMENT as nice(1)
29 # posix_spawn has none of these three: they are set right around
30 # the call, in C, and put back (M1, post-0.08); one that could not
31 # be put back is unsupported (spawn's POD)
32 # unsupported => { OPTION => 'drop' | 'fail' } passed on to spawn
33 # on_exit => CODE gets the wait status; undef if other code collected it
34 # first (finding C2)
35 # spawn(FILE, ARGV, ENVP, ACTIONS, ATTR, UNSUPPORTED) the raw call, see the POD at the end. Meant to
36 # have one interface on POSIX and on Windows: it wraps the XSUB __posix_spawn (on Windows: win_spawn.h's
37 # posix_spawn on CreateProcessW) and does what that lacks around the call ($MISSING, below). UNSUPPORTED
38 # (optional): { OPTION => 'drop' | 'fail' }, what a port lacking an option (Windows) does with it;
39 # options not listed there take %UNSUPPORTED's value, and '*' there covers the rest. It applies here
40 # too, to the posix_spawn extensions this build's libc lacks (chdir, fchdir, closefrom, tcsetpgrp,
41 # pidfd, cgroup; Makefile.PL compiles a call to each): 'fail' fails with ENOTSUP. EXPERIMENTAL
42 # on_read(FD, N, CODE), on_write(FD, BYTES, CODE), defer(CODE, ARGS), poll(), wait_until(CODE), loop()
43 # the one event loop, Proc::Spawner::Loop (W5, post-0.10: one interface on POSIX and on Windows), under its
44 # old names; loop() is the loop object (read, write, child, after, pipe, ...: its POD). The rules
45 # (decisions R1, D1-D3 of the page "Child Exit Wake-up"): every callback runs from the queue, one at a time,
46 # never inside a signal or inside another callback; a callback never waits; SIGCHLD is ours only while
47 # wait_until runs. Background: the document perl-signals-findings.md.
48 #
49 # Process-wide state flipped for a while, so bullet-proof only in non-threaded execution: the umask,
50 # around start's call (umask => N); the SIGCHLD action, while wait_until runs (D3). Between waits a
51 # caller may move things on with poll(), for example from its own deferred SIGCHLD handler, as
52 # Proc::ShellSpawn does while background jobs remain (K3, the user's choice B, post-0.04).
53 488 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
54 488 ▶use POSIX (); use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
55 488 ▶use Fcntl qw(F_SETFD FD_CLOEXEC F_GETFL F_SETFL O_NONBLOCK);
Subroutine BEGIN: called CC=1 SCAR=0.0
56 488 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 488 our $VERSION = '0.11';
58 488 require XSLoader; XSLoader::load(__PACKAGE__, $VERSION); # __posix_spawn, fpe_at_exec, chld_to_fd, chld_restore
59 488 our %UNSUPPORTED = ('*' => 'fail'); # the defaults for spawn's UNSUPPORTED (EXPERIMENTAL: '*' => 'fail')
60  
61 # ------------------------------------------------------------------ settings the spawn primitive lacks (EXPERIMENTAL, post-0.06)
62 # $MISSING: a bitmap of the settings the primitive (posix_spawn here; CreateProcessW in a Windows port) does not do itself:
63 # what this build's libc lacks, plus $ENV{PROC_SPAWNER_MISSING} (names, for tests: the suite runs "as if"). spawn
64 # does the missing ones in this process, around the call, and undoes them after (bullet-proof only with one thread):
65 # chdir, fchdir this process changes directory, then comes back
66 # dup2, close, open, this process arranges its own fds as the child should have them (close: close-on-exec),
67 # closefrom then puts them back; one missing means all four, and chdir and fchdir too (the order)
68 # sigmask this process's mask, set around the call (the child inherits it)
69 # sigdefault an ignored signal's action set back to the default around the call
70 # pgroup => PGID (> 0) this process joins the group around the call (the child inherits it)
71 # resetids the effective ids set to the real ones around the call
72 # search PATH looked up here; pidfd: pidfd_open right after the call
73 # Not possible so: setsid (no way back), tcsetpgrp and pgroup => 0 (the child's pid is known only after), sched
74 # and cgroup (not undone reliably): these are unsupported (drop or fail, as UNSUPPORTED says). While this
75 # process's fds or directory are changed, every signal is blocked, so no handler of ours sees them; the child's mask
76 # is set by the primitive. If sigmask is missing too, signals cannot be blocked without the child inheriting it: then
77 # a handler that runs in that moment sees the changed fds.
78 #
79 # rlimit, sigignore and nice (M1, post-0.08), which POSIX's posix_spawn has no option for, are done by the XSUB itself
80 # right around its call, in C (Spawner.xs, around_parse), so they count as native; not on Windows.
81 #
82 # No posix_spawn at all (M2, post-0.08; Makefile.PL found none, or PROC_SPAWNER_MISSING has 'posix_spawn'), as Run
83 # 0.06's spawn_nowait: the primitive is __spawn_nowait, fork and exec with nothing in between; where there is no fork
84 # either (Windows, OS/2, VMS; on Linux in tests, PROC_SPAWNER_MISSING="posix_spawn fork": $PRIMITIVE 'system1') the
85 # redirections are delegated to Run (0.07; the user, 2026-11-07), whose start() applies them around Perl's own spawn,
86 # system { FILE } 1, ARGV (P_NOWAIT; on Unix Run emulates it by fork and exec) and puts our fds back; chdir and fchdir
87 # are done here. Everything but rlimit, sigignore and nice (fork only) is then missing, and done around the call as
88 # above. On Windows Perl's spawn passes the child fds 0-2 only, as its standard handles, always in a new process group;
89 # the arguments go to Perl as they are (its command line does not quote them as the C runtime parses them back:
90 # ❰BUG❱ in Perl, reported; the tests of exact argv there are TODO until Perl is fixed).
91 488 our @FEATURES = qw(chdir fchdir dup2 close open closefrom tcsetpgrp sigmask sigdefault pgroup setsid resetids sched cgroup pidfd search rlimit sigignore nice);
92 488 our %BIT; @BIT{@FEATURES} = map 1 << $_, 0 .. $#FEATURES;
93 488 our %NATIVE = map +($_ => 1), __native();
94 488 our %EMULABLE = map +($_ => 1), qw(chdir fchdir dup2 close open closefrom sigmask sigdefault pgroup resetids search pidfd);
95 488 ▶my @ASKED = grep length, split /[\s,]+/, $ENV{PROC_SPAWNER_MISSING} // '';
Condition50%1/2
$ENV{"PROC_SPAWNER_MISSING"} // ""
l!l
0488
MC/DC0%0/1
$ENV{"PROC_SPAWNER_MISSING"} // ""
$ENV{"PROC_SPAWNER_MISSING"}
Truth table50%1/2
A
A= $ENV{"PROC_SPAWNER_MISSING"}
Aresult
11
00
96 488 ▶our $FALLBACK = !$NATIVE{posix_spawn} || grep /^(?:posix_spawn|fork)\z/, @ASKED; # no posix_spawn: __spawn_nowait or system1
Condition33%1/3
!$Proc::Spawner::NATIVE{'posix_spawn'} || grep(/^(?:posix_spawn|fork)\z/, @ASKED)
l!l&&r!l&&!r
00488
MC/DC0%0/2
!$Proc::Spawner::NATIVE{'posix_spawn'} || grep(/^(?:posix_spawn|fork)\z/, @ASKED)
!$Proc::Spawner::NATIVE{'posix_spawn'} grep(/^(?:posix_spawn|fork)\z/, @ASKED)
Truth table33%1/3
not(A) || B
A= !$Proc::Spawner::NATIVE{'posix_spawn'}B= grep(/^(?:posix_spawn|fork)\z/, @ASKED)
ABresult
1X1
011
000
97 488 my $NOFORK = grep $_ eq 'fork', @ASKED;
98 488 our %WINDOWS = ( # Windows only (EXPERIMENTAL, post-0.07): how every child is started (win_spawn.h, WIN_OPT_*)
99 new_group => 1, # in a process group of its own: Ctrl-C at the console reaches the parent, not the children
100 kill_with_parent => 1, # in a job object that Windows ends when this process ends, however it ends
101 new_console => 1); # a child with none of fds 0-2 gets a console of its own (as Perl's own spawn does)
102 488 our $WIN = $^O eq 'MSWin32'; # EXPERIMENTAL (post-0.07): no SIGCHLD, no fcntl; the loop's Windows backend (W5, post-0.10):
103 # Proc::Spawner::Loop::Win32
104 488 my %SIGNUM; @SIGNUM{split ' ', $Config{sig_name}} = split ' ', $Config{sig_num};
105 488 our $DOSISH = $^O =~ /^(?:MSWin32|os2|VMS)\z/;
106 488 ▶our $PRIMITIVE = !$FALLBACK ? 'posix_spawn' : defined &__spawn_nowait && !$DOSISH && !$NOFORK ? 'fork' : 'system1';
Branch: 2 branches
BranchTrueFalseTotal
!$Proc::Spawner::FALLBACK ? : 488 0 488
defined &Proc::Spawner::__spawn_nowait && !$Proc::Spawner::DOSISH && !$NOFORK ? : 0 0 0
Condition0%0/6
defined &Proc::Spawner::__spawn_nowait and not $Proc::Spawner::DOSISH and not $NOFORK
!ll&&!rl&&r
000
defined &Proc::Spawner::__spawn_nowait and not $Proc::Spawner::DOSISH
!ll&&!rl&&r
000
MC/DC0%0/3
defined &Proc::Spawner::__spawn_nowait and not $Proc::Spawner::DOSISH and not $NOFORK
defined &Proc::Spawner::__spawn_nowait not $Proc::Spawner::DOSISH not $NOFORK
Truth table0%0/4
A and not(B) and not(C)
A= defined &Proc::Spawner::__spawn_nowaitB= not $Proc::Spawner::DOSISHC= not $NOFORK
ABCresult
0XX0
10X0
1100
1111
107 488 ▶%NATIVE = $PRIMITIVE eq 'fork' ? (map +($_ => 1), grep $NATIVE{$_}, qw(rlimit sigignore nice)) : () if $FALLBACK;
Branch: 2 branches
BranchTrueFalseTotal
if $Proc::Spawner::FALLBACK 0 488 488
$Proc::Spawner::PRIMITIVE eq 'fork' ? : 0 0 0
108 488 our $MISSING = 0; $MISSING |= $BIT{$_} for grep !$NATIVE{$_}, @FEATURES;
109 488 for (grep !/^(?:posix_spawn|fork)\z/, @ASKED) {
110 0 ▶ exists $BIT{$_} or die "Proc::Spawner: PROC_SPAWNER_MISSING: unknown setting '$_' (known: posix_spawn fork @FEATURES)\n";
Branch: 1 branch
BranchTrueFalseTotal
exists $Proc::Spawner::BIT{$_} or die "Proc::Spawner: PROC_SPAWNER_MISSING: unknown setting '${_}' (known: posix_spawn fork @Proc::Spawner::FEATURES)\n" 0 0 0
111 0 $MISSING |= $BIT{$_} }
112 2 ▶sub missing { my $m = @_ ? shift : $MISSING; grep $m & $BIT{$_}, @FEATURES } # the names in a bitmap
Subroutine missing: called CC=2 SCAR=7.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 2 2
113  
114 488 our %WINJOB = (AS => 'ProcessMemoryLimit', DATA => 'ProcessMemoryLimit', CPU => 'PerProcessUserTimeLimit',
115 NPROC => 'ActiveProcessLimit'); # W4's mapping of rlimit (approximate: see the POD)
116 488 my %CLASS_NICE = (idle => 19, below_normal => 5, normal => 0, above_normal => -5, high => -10, realtime => -20);
117 1 ▶sub win_job_for_rlimit { # W4: rlimit entries as win_job limits (approximate); also the resources with no counterpart
Subroutine win_job_for_rlimit: called CC=10 SCAR=23.4
Pod undocumented
118 1 my (%job, @none);
119 1 for (@{+shift}) {
120 5 ▶ my ($res, $soft, $hard) = @$_; (my $k = uc($res // '')) =~ s/^RLIMIT_//;
Condition50%1/2
$res // ""
l!l
50
MC/DC0%0/1
$res // ""
$res
Truth table50%1/2
A
A= $res
Aresult
11
00
121 5 ▶ my ($lim) = grep defined && $_ ne 'unlimited' && $_ ne 'infinity', $soft, $hard; # the one that acts first
Condition83%5/6
defined $_ && $_ ne 'unlimited' && $_ ne 'infinity'
!ll&&!rl&&r
307
defined $_ and $_ ne "unlimited"
!ll&&!rl&&r
217
MC/DC66%2/3
defined $_ && $_ ne 'unlimited' && $_ ne 'infinity'
defined $_ $_ ne "unlimited" $_ ne 'infinity'
Truth table75%3/4
A and B && C
A= defined $_B= $_ ne "unlimited"C= $_ ne 'infinity'
ABCresult
0XX0
10X0
1100
1111
122 5 ▶ my $w = $WINJOB{$k} or do { push @none, $k; next };
Branch: 1 branch
BranchTrueFalseTotal
my $w = $Proc::Spawner::WINJOB{$k} or do { push @none, $k; next } 4 1 5
123 4 ▶ next unless defined $lim;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lim 0 4 4
124 4 ▶ $lim *= 10_000_000 if $k eq 'CPU'; # seconds -> 100-ns units
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "CPU" 1 3 4
125 4 ▶ $job{$w} = defined $job{$w} && $job{$w} < $lim ? $job{$w} : $lim }
Branch: 1 branch
BranchTrueFalseTotal
defined $job{$w} && $job{$w} < $lim ? : 0 4 4
Condition66%2/3
defined $job{$w} and $job{$w} < $lim
!ll&&!rl&&r
310
MC/DC0%0/2
defined $job{$w} and $job{$w} < $lim
defined $job{$w} $job{$w} < $lim
Truth table66%2/3
A and B
A= defined $job{$w}B= $job{$w} < $lim
ABresult
0X0
100
111
126 1 (\%job, @none) }
127 6 ▶sub win_class_for_nice { # W4: a nice increment as a priority class, from ours (approximate; never realtime)
Subroutine win_class_for_nice: called CC=7 SCAR=19.7
Pod undocumented
128 6 ▶ my $n = ($CLASS_NICE{defined &__win_priority_class ? __win_priority_class() : 'normal'} // 0) + shift;
Branch: 1 branch
BranchTrueFalseTotal
defined &Proc::Spawner::__win_priority_class ? : 0 6 6
Condition50%1/2
$CLASS_NICE{defined &Proc::Spawner::__win_priority_class ? __win_priority_class() : "normal"} // 0
l!l
60
MC/DC0%0/1
$CLASS_NICE{defined &Proc::Spawner::__win_priority_class ? __win_priority_class() : "normal"} // 0
$CLASS_NICE{defined &Proc::Spawner::__win_priority_class ? __win_priority_class() : "normal"}
Truth table50%1/2
A
A= $CLASS_NICE{defined &Proc::Spawner::__win_priority_class ? __win_priority_class() : "normal"}
Aresult
11
00
129 6 ▶ $n >= 10 ? 'idle' : $n >= 1 ? 'below_normal' : $n == 0 ? 'normal' : $n > -10 ? 'above_normal' : 'high' }
Branch: 4 branches
BranchTrueFalseTotal
$n >= 10 ? : 1 5 6
$n >= 1 ? : 2 3 5
$n == 0 ? : 1 2 3
$n > -10 ? : 1 1 2
130  
131 346 ▶sub spawn { # the raw call: the primitive (__posix_spawn, or __spawn_nowait), with what it lacks done around it
Subroutine spawn: called CC=138 SCAR=88.4
Pod undocumented
132 346 my ($file, $argv, $envp, $acts, $attr, $uns) = @_;
133 346 ▶ if (!$FALLBACK) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $Proc::Spawner::FALLBACK) { } 346 0 346
134 346 ▶ my $winonly = !$WIN && ref $attr eq 'HASH' && grep defined $attr->{$_}, qw(win_priority win_job); # (W4: refused here)
Condition50%3/6
!$Proc::Spawner::WIN && ref $attr eq 'HASH' && grep(defined($attr->{$_}), ('win_priority', 'win_job'))
!ll&&!rl&&r
03442
not $Proc::Spawner::WIN and ref $attr eq "HASH"
!ll&&!rl&&r
00346
MC/DC33%1/3
!$Proc::Spawner::WIN && ref $attr eq 'HASH' && grep(defined($attr->{$_}), ('win_priority', 'win_job'))
not $Proc::Spawner::WIN ref $attr eq "HASH" grep(defined($attr->{$_}), ('win_priority', 'win_job'))
Truth table50%2/4
not(A) and B && C
A= not $Proc::Spawner::WINB= ref $attr eq "HASH"C= grep(defined($attr->{$_}), ('win_priority', 'win_job'))
ABCresult
0XX0
10X0
1100
1111
135 346 ▶ return __posix_spawn(@_) unless ($MISSING || $winonly) && (!defined $uns || ref $uns eq 'HASH'); # (its errors)
Branch: 1 branch
BranchTrueFalseTotal
unless $Proc::Spawner::MISSING || $winonly and !defined($uns) || ref $uns eq "HASH" 344 2 346
Condition66%6/9
$Proc::Spawner::MISSING || $winonly and !defined($uns) || ref $uns eq "HASH"
!ll&&!rl&&r
34402
$Proc::Spawner::MISSING or $winonly
l!l&&r!l&&!r
02344
not defined $uns or ref $uns eq "HASH"
l!l&&r!l&&!r
110
MC/DC25%1/4
$Proc::Spawner::MISSING || $winonly and !defined($uns) || ref $uns eq "HASH"
$Proc::Spawner::MISSING $winonly not defined $uns ref $uns eq "HASH"
Truth table42%3/7
A or B and not(C) or D
A= $Proc::Spawner::MISSINGB= $winonlyC= not defined $unsD= ref $uns eq "HASH"
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
136 2 ▶ ref $acts eq 'ARRAY' && (!defined $attr || ref $attr eq 'HASH') or return __posix_spawn(@_) } # its errors
Branch: 1 branch
BranchTrueFalseTotal
ref $acts eq "ARRAY" and !defined($attr) || ref $attr eq "HASH" or return __posix_spawn(@_) 2 0 2
Condition33%2/6
ref $acts eq "ARRAY" and !defined($attr) || ref $attr eq "HASH"
!ll&&!rl&&r
002
not defined $attr or ref $attr eq "HASH"
l!l&&r!l&&!r
020
MC/DC0%0/3
ref $acts eq "ARRAY" and !defined($attr) || ref $attr eq "HASH"
ref $acts eq "ARRAY" not defined $attr ref $attr eq "HASH"
Truth table25%1/4
A and not(B) or C
A= ref $acts eq "ARRAY"B= not defined $attrC= ref $attr eq "HASH"
ABCresult
0XX0
1000
11X1
1011
137 else { # the same errors as __posix_spawn's
138 0 ▶ !defined $uns || ref $uns eq 'HASH' or die "Proc::Spawner::spawn: unsupported must be a hash reference\n";
Branch: 1 branch
BranchTrueFalseTotal
not defined $uns or ref $uns eq "HASH" or die "Proc::Spawner::spawn: unsupported must be a hash reference\n" 0 0 0
Condition0%0/3
not defined $uns or ref $uns eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $uns or ref $uns eq "HASH"
not defined $uns ref $uns eq "HASH"
Truth table0%0/3
not(A) or B
A= not defined $unsB= ref $uns eq "HASH"
ABresult
1X1
011
000
139 0 ▶ ref $acts eq 'ARRAY' or die "Proc::Spawner::spawn: actions must be an array reference\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $acts eq "ARRAY" or die "Proc::Spawner::spawn: actions must be an array reference\n" 0 0 0
140 0 ▶ !defined $attr || ref $attr eq 'HASH' or die "Proc::Spawner::spawn: attr must be a hash reference\n";
Branch: 1 branch
BranchTrueFalseTotal
not defined $attr or ref $attr eq "HASH" or die "Proc::Spawner::spawn: attr must be a hash reference\n" 0 0 0
Condition0%0/3
not defined $attr or ref $attr eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $attr or ref $attr eq "HASH"
not defined $attr ref $attr eq "HASH"
Truth table0%0/3
not(A) or B
A= not defined $attrB= ref $attr eq "HASH"
ABresult
1X1
011
000
141 0 ▶ ref eq 'ARRAY' or die "Proc::Spawner::spawn: an action is not an array reference\n" for @$acts }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "ARRAY" or die "Proc::Spawner::spawn: an action is not an array reference\n" 0 0 0
142 2 my %m = map +($_ => 1), missing();
143 2 ▶ my %at = %{$attr // {}}; my @acts = @$acts;
Condition50%1/2
$attr // {}
l!l
20
MC/DC0%0/1
$attr // {}
$attr
Truth table50%1/2
A
A= $attr
Aresult
11
00
144 2 ▶ my $refuse = sub { # an unsupported setting: true (and $! = ENOTSUP) to fail, false to drop it
Subroutine __ANON__: called CC=6 SCAR=18.5
145 2 ▶ my $n = shift; my $v = ($uns && $uns->{$n}) // $UNSUPPORTED{$n} // $UNSUPPORTED{'*'} // 'fail';
Condition63%7/11
(($uns && $uns->{$n} // $Proc::Spawner::UNSUPPORTED{$n}) // $Proc::Spawner::UNSUPPORTED{"*"}) // "fail"
l!l
20
($uns && $uns->{$n} // $Proc::Spawner::UNSUPPORTED{$n}) // $Proc::Spawner::UNSUPPORTED{"*"}
l!l&&r!l&&!r
110
$uns && $uns->{$n} // $Proc::Spawner::UNSUPPORTED{$n}
l!l&&r!l&&!r
101
$uns and $uns->{$n}
!ll&&!rl&&r
101
MC/DC0%0/4
(($uns && $uns->{$n} // $Proc::Spawner::UNSUPPORTED{$n}) // $Proc::Spawner::UNSUPPORTED{"*"}) // "fail"
$uns $uns->{$n} $Proc::Spawner::UNSUPPORTED{$n} $Proc::Spawner::UNSUPPORTED{"*"}
Truth table28%2/7
A and B // C // D
A= $unsB= $uns->{$n}C= $Proc::Spawner::UNSUPPORTED{$n}D= $Proc::Spawner::UNSUPPORTED{"*"}
ABCDresult
11XX1
0X1X1
101X1
0X011
10011
0X000
10000
146 2 ▶ $v eq 'drop' ? 0 : do { $! = POSIX::ENOTSUP(); 1 } };
Branch: 1 branch
BranchTrueFalseTotal
$v eq 'drop' ? : 1 1 2
147 2 ▶ if ($WIN) { # W4 (the user, 2026-11-08: "(c) and (b); (c) beats (b) if present"): nice and rlimit mapped to what Windows
Branch: 2 branches
BranchTrueFalseTotal
if ($Proc::Spawner::WIN) { } 0 2 2
elsif (grep defined($at{$_}), ('win_priority', 'win_job')) { } 2 0 2
148 # has per child, approximately; win_priority and win_job, Windows' own settings, exact, win over the mapping
149 0 ▶ if ($at{nice}) { $at{win_priority} //= win_class_for_nice($at{nice}) } delete $at{nice};
Branch: 1 branch
BranchTrueFalseTotal
if ($at{"nice"}) 0 0 0
Condition0%0/3
$at{"win_priority"} //= win_class_for_nice($at{"nice"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$at{"win_priority"} //= win_class_for_nice($at{"nice"})
$at{"win_priority"} win_class_for_nice($at{"nice"})
Truth table0%0/3
A //= B
A= $at{"win_priority"}B= win_class_for_nice($at{"nice"})
ABresult
1X1
011
000
150 0 ▶ if (ref $at{rlimit} eq 'ARRAY' && @{$at{rlimit}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $at{"rlimit"} eq "ARRAY" and @{$at{"rlimit"};}) 0 0 0
Condition0%0/3
ref $at{"rlimit"} eq "ARRAY" and @{$at{"rlimit"};}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $at{"rlimit"} eq "ARRAY" and @{$at{"rlimit"};}
ref $at{"rlimit"} eq "ARRAY" @{$at{"rlimit"};}
Truth table0%0/3
A and B
A= ref $at{"rlimit"} eq "ARRAY"B= @{$at{"rlimit"};}
ABresult
0X0
100
111
151 0 my ($job, @none) = win_job_for_rlimit($at{rlimit});
152 0 ▶ for (@none) { return if $refuse->('rlimit') } # (no Windows counterpart; drop: the rest still mapped)
Branch: 1 branch
BranchTrueFalseTotal
if &$refuse("rlimit") 0 0 0
153 0 ▶ $at{win_job} = { %$job, %{$at{win_job} // {}} } if %$job }
Branch: 1 branch
BranchTrueFalseTotal
if %$job 0 0 0
Condition0%0/2
$at{"win_job"} // {}
l!l
00
MC/DC0%0/1
$at{"win_job"} // {}
$at{"win_job"}
Truth table0%0/2
A
A= $at{"win_job"}
Aresult
11
00
154 0 delete $at{rlimit} }
155 elsif (grep defined $at{$_}, qw(win_priority win_job)) { # Windows' own settings elsewhere
156 2 ▶ for (qw(win_priority win_job)) { next unless defined $at{$_}; return if $refuse->($_); delete $at{$_} } }
Branch: 2 branches
BranchTrueFalseTotal
unless defined $at{$_} 1 2 3
if &$refuse($_) 1 1 2
157 1 ▶ if ($WIN && ref $at{sigignore} eq 'ARRAY') { # what a Windows child does anyway (post-0.08): there is no SIGPIPE, and
Branch: 1 branch
BranchTrueFalseTotal
if ($Proc::Spawner::WIN and ref $at{"sigignore"} eq "ARRAY") 0 1 1
Condition33%1/3
$Proc::Spawner::WIN and ref $at{"sigignore"} eq "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
$Proc::Spawner::WIN and ref $at{"sigignore"} eq "ARRAY"
$Proc::Spawner::WIN ref $at{"sigignore"} eq "ARRAY"
Truth table33%1/3
A and B
A= $Proc::Spawner::WINB= ref $at{"sigignore"} eq "ARRAY"
ABresult
0X0
100
111
158 # Ctrl-C is off in a new process group (Perl's kill INT, GenerateConsoleCtrlEvent, does not reach it either)
159 0 ▶ my $group = $PRIMITIVE eq 'system1' || $WINDOWS{new_group} || defined $at{pgroup} && !$at{pgroup};
Condition0%0/9
$Proc::Spawner::PRIMITIVE eq 'system1' || $Proc::Spawner::WINDOWS{'new_group'} || defined $at{'pgroup'} && !$at{'pgroup'}
l!l&&r!l&&!r
000
$Proc::Spawner::PRIMITIVE eq "system1" or $Proc::Spawner::WINDOWS{"new_group"}
l!l&&r!l&&!r
000
defined $at{"pgroup"} and not $at{"pgroup"}
!ll&&!rl&&r
000
MC/DC0%0/4
$Proc::Spawner::PRIMITIVE eq 'system1' || $Proc::Spawner::WINDOWS{'new_group'} || defined $at{'pgroup'} && !$at{'pgroup'}
$Proc::Spawner::PRIMITIVE eq "system1" $Proc::Spawner::WINDOWS{"new_group"} defined $at{"pgroup"} not $at{"pgroup"}
Truth table0%0/5
A or B || C and not(D)
A= $Proc::Spawner::PRIMITIVE eq "system1"B= $Proc::Spawner::WINDOWS{"new_group"}C= defined $at{"pgroup"}D= not $at{"pgroup"}
ABCDresult
1XXX1
01XX1
00111
000X0
00100
160 0 ▶ $at{sigignore} = [grep !($_ == $SIGNUM{PIPE} || $group && $_ == $SIGNUM{INT}), @{$at{sigignore}}] }
Condition0%0/6
$_ == $SIGNUM{'PIPE'} || $group && $_ == $SIGNUM{'INT'}
l!l&&r!l&&!r
000
$group and $_ == $SIGNUM{"INT"}
!ll&&!rl&&r
000
MC/DC0%0/3
$_ == $SIGNUM{'PIPE'} || $group && $_ == $SIGNUM{'INT'}
$_ == $SIGNUM{'PIPE'} $group $_ == $SIGNUM{"INT"}
Truth table0%0/4
A || B and C
A= $_ == $SIGNUM{'PIPE'}B= $groupC= $_ == $SIGNUM{"INT"}
ABCresult
1XX1
0111
00X0
0100
161 1 ▶ if ($PRIMITIVE eq 'system1' && $WIN) { # Perl's own spawn on Windows: what it does anyway, and what it cannot
Branch: 1 branch
BranchTrueFalseTotal
if ($Proc::Spawner::PRIMITIVE eq "system1" and $Proc::Spawner::WIN) 0 1 1
Condition33%1/3
$Proc::Spawner::PRIMITIVE eq "system1" and $Proc::Spawner::WIN
!ll&&!rl&&r
100
MC/DC0%0/2
$Proc::Spawner::PRIMITIVE eq "system1" and $Proc::Spawner::WIN
$Proc::Spawner::PRIMITIVE eq "system1" $Proc::Spawner::WIN
Truth table33%1/3
A and B
A= $Proc::Spawner::PRIMITIVE eq "system1"B= $Proc::Spawner::WIN
ABresult
0X0
100
111
162 0 delete @at{qw(sigdefault resetids)}; # nothing is inherited, no set-user-id
163 0 ▶ delete $at{sigmask} if ref $at{sigmask} eq 'ARRAY' && !@{$at{sigmask}};
Branch: 1 branch
BranchTrueFalseTotal
if ref $at{"sigmask"} eq "ARRAY" and not @{$at{"sigmask"};} 0 0 0
Condition0%0/3
ref $at{"sigmask"} eq "ARRAY" and not @{$at{"sigmask"};}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $at{"sigmask"} eq "ARRAY" and not @{$at{"sigmask"};}
ref $at{"sigmask"} eq "ARRAY" not @{$at{"sigmask"};}
Truth table0%0/3
A and not(B)
A= ref $at{"sigmask"} eq "ARRAY"B= not @{$at{"sigmask"};}
ABresult
0X0
100
111
164 0 ▶ delete $at{pgroup} if defined $at{pgroup} && !$at{pgroup}; # always a new group
Branch: 1 branch
BranchTrueFalseTotal
if defined $at{"pgroup"} and not $at{"pgroup"} 0 0 0
Condition0%0/3
defined $at{"pgroup"} and not $at{"pgroup"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $at{"pgroup"} and not $at{"pgroup"}
defined $at{"pgroup"} not $at{"pgroup"}
Truth table0%0/3
A and not(B)
A= defined $at{"pgroup"}B= not $at{"pgroup"}
ABresult
0X0
100
111
165 0 ▶ for my $n (qw(sigmask pgroup pidfd)) { next unless defined $at{$n} && $at{$n}; return if $refuse->($n); delete $at{$n} }
Branch: 2 branches
BranchTrueFalseTotal
unless defined $at{$n} and $at{$n} 0 0 0
if &$refuse($n) 0 0 0
Condition0%0/3
defined $at{$n} and $at{$n}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $at{$n} and $at{$n}
defined $at{$n} $at{$n}
Truth table0%0/3
A and B
A= defined $at{$n}B= $at{$n}
ABresult
0X0
100
111
166 0 my @k; # the child sees fds 0-2 only
167 0 for my $x (@acts) {
168 0 my ($op, @a) = @$x;
169 0 ▶ if ($op eq 'close' && $a[0] >= 3) { next }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "close" and $a[0] >= 3) 0 0 0
Condition0%0/3
$op eq "close" and $a[0] >= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$op eq "close" and $a[0] >= 3
$op eq "close" $a[0] >= 3
Truth table0%0/3
A and B
A= $op eq "close"B= $a[0] >= 3
ABresult
0X0
100
111
170 0 ▶ if ($op eq 'closefrom') { push @k, map [close => $_], $a[0] .. 2; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "closefrom") 0 0 0
171 0 ▶ if ($op eq 'dup2' && $a[1] >= 3 || $op eq 'open' && $a[0] >= 3 || $op eq 'fchdir') { return if $refuse->($op); next }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq "dup2" and $a[1] >= 3 or $op eq "open" and $a[0] >= 3 or $op eq "fchdir") 0 0 0
if &$refuse($op) 0 0 0
Condition0%0/12
$op eq "dup2" and $a[1] >= 3 or $op eq "open" and $a[0] >= 3 or $op eq "fchdir"
l!l&&r!l&&!r
000
$op eq "dup2" and $a[1] >= 3 or $op eq "open" and $a[0] >= 3
l!l&&r!l&&!r
000
$op eq "dup2" and $a[1] >= 3
!ll&&!rl&&r
000
$op eq "open" and $a[0] >= 3
!ll&&!rl&&r
000
MC/DC0%0/5
$op eq "dup2" and $a[1] >= 3 or $op eq "open" and $a[0] >= 3 or $op eq "fchdir"
$op eq "dup2" $a[1] >= 3 $op eq "open" $a[0] >= 3 $op eq "fchdir"
Truth table0%0/11
A and B or C and D or E
A= $op eq "dup2"B= $a[1] >= 3C= $op eq "open"D= $a[0] >= 3E= $op eq "fchdir"
ABCDEresult
11XXX1
0X11X1
1011X1
0X0X11
0X1011
100X11
101011
0X0X00
0X1000
100X00
101000
172 0 push @k, $x }
173 0 @acts = @k }
174 1 ▶ if (ref $at{sigignore} eq 'ARRAY' && ref $at{sigdefault} eq 'ARRAY') { # ignored and set to the default: which?
Branch: 1 branch
BranchTrueFalseTotal
if (ref $at{"sigignore"} eq "ARRAY" and ref $at{"sigdefault"} eq "ARRAY") 0 1 1
Condition33%1/3
ref $at{"sigignore"} eq "ARRAY" and ref $at{"sigdefault"} eq "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
ref $at{"sigignore"} eq "ARRAY" and ref $at{"sigdefault"} eq "ARRAY"
ref $at{"sigignore"} eq "ARRAY" ref $at{"sigdefault"} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $at{"sigignore"} eq "ARRAY"B= ref $at{"sigdefault"} eq "ARRAY"
ABresult
0X0
100
111
175 0 ▶ my %d = map +($_ => 1), @{$at{sigdefault}}; if (grep $d{$_}, @{$at{sigignore}}) { $! = POSIX::EINVAL(); return } }
Branch: 1 branch
BranchTrueFalseTotal
if (grep $d{$_}, @{$at{"sigignore"};}) 0 0 0
176 0 ▶ if (grep $m{$_}, qw(dup2 close open closefrom)) { $m{$_} = 1 for qw(dup2 close open closefrom chdir fchdir) }
Branch: 1 branch
BranchTrueFalseTotal
if (grep $m{$_}, ("dup2", "close", "open", "closefrom")) 0 1 1
177 0 ▶ my %given = (setsid => sub { $at{setsid} }, nice => sub { $at{nice} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
178 0 ▶ sigignore => sub { ref $at{sigignore} eq 'ARRAY' && @{$at{sigignore}} });
Subroutine __ANON__: not called CC=2 SCAR=14.0
Branch: 1 branch
BranchTrueFalseTotal
ref $at{"sigignore"} eq "ARRAY" and @{$at{"sigignore"};} 0 0 0
179 1 for my $n (qw(setsid sched cgroup rlimit sigignore nice)) {
180 6 ▶ next unless $m{$n} && ($given{$n} ? $given{$n}->() : defined $at{$n});
Branch: 2 branches
BranchTrueFalseTotal
unless $m{$n} and $given{$n} ? $given{$n}->() : defined $at{$n} 6 0 6
$given{$n} ? : 0 0 0
Condition33%1/3
$m{$n} and $given{$n} ? $given{$n}->() : defined $at{$n}
!ll&&!rl&&r
600
MC/DC0%0/2
$m{$n} and $given{$n} ? $given{$n}->() : defined $at{$n}
$m{$n} $given{$n} ? $given{$n}->() : defined $at{$n}
Truth table33%1/3
A and B
A= $m{$n}B= $given{$n} ? $given{$n}->() : defined $at{$n}
ABresult
0X0
100
111
181 0 ▶ return if $refuse->($n); delete $at{$n} }
Branch: 1 branch
BranchTrueFalseTotal
if &$refuse($n) 0 0 0
182 0 ▶ if ($m{pgroup} && defined $at{pgroup} && !$at{pgroup}) { return if $refuse->('pgroup'); delete $at{pgroup} }
Branch: 2 branches
BranchTrueFalseTotal
if ($m{"pgroup"} and defined $at{"pgroup"} and not $at{"pgroup"}) 0 1 1
if &$refuse("pgroup") 0 0 0
Condition33%2/6
$m{"pgroup"} and defined $at{"pgroup"} and not $at{"pgroup"}
!ll&&!rl&&r
100
$m{"pgroup"} and defined $at{"pgroup"}
!ll&&!rl&&r
100
MC/DC0%0/3
$m{"pgroup"} and defined $at{"pgroup"} and not $at{"pgroup"}
$m{"pgroup"} defined $at{"pgroup"} not $at{"pgroup"}
Truth table25%1/4
A and B and not(C)
A= $m{"pgroup"}B= defined $at{"pgroup"}C= not $at{"pgroup"}
ABCresult
0XX0
10X0
1100
1111
183 1 ▶ if ($m{tcsetpgrp} && grep ref eq 'ARRAY' && ($_->[0] // '') eq 'tcsetpgrp', @acts) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m{"tcsetpgrp"} and grep((ref $_ eq "ARRAY" && ($_->[0] // "") eq "tcsetpgrp"), @acts)) 0 1 1
Condition12%1/8
$m{"tcsetpgrp"} and grep((ref $_ eq "ARRAY" && ($_->[0] // "") eq "tcsetpgrp"), @acts)
!ll&&!rl&&r
100
ref $_ eq 'ARRAY' && ($_->[0] // '') eq 'tcsetpgrp'
!ll&&!rl&&r
000
$_->[0] // ""
l!l
00
MC/DC0%0/2
$m{"tcsetpgrp"} and grep((ref $_ eq "ARRAY" && ($_->[0] // "") eq "tcsetpgrp"), @acts)
$m{"tcsetpgrp"} grep((ref $_ eq "ARRAY" && ($_->[0] // "") eq "tcsetpgrp"), @acts)
MC/DC0%0/2
ref $_ eq 'ARRAY' && ($_->[0] // '') eq 'tcsetpgrp'
ref $_ eq 'ARRAY' $_->[0]
Truth table33%1/3
A and B
A= $m{"tcsetpgrp"}B= grep((ref $_ eq "ARRAY" && ($_->[0] // "") eq "tcsetpgrp"), @acts)
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= ref $_ eq 'ARRAY'B= $_->[0]
ABresult
0X0
100
111
184 0 ▶ return if $refuse->('tcsetpgrp'); @acts = grep !(ref eq 'ARRAY' && ($_->[0] // '') eq 'tcsetpgrp'), @acts }
Branch: 1 branch
BranchTrueFalseTotal
if &$refuse("tcsetpgrp") 0 0 0
Condition0%0/5
ref $_ eq 'ARRAY' && ($_->[0] // '') eq 'tcsetpgrp'
!ll&&!rl&&r
000
$_->[0] // ""
l!l
00
MC/DC0%0/2
ref $_ eq 'ARRAY' && ($_->[0] // '') eq 'tcsetpgrp'
ref $_ eq 'ARRAY' $_->[0]
Truth table0%0/3
A && B
A= ref $_ eq 'ARRAY'B= $_->[0]
ABresult
0X0
100
111
185 1 my %kind = (chdir => 'dir', fchdir => 'dir', dup2 => 'fd', close => 'fd', open => 'fd', closefrom => 'fd');
186 1 my (@here, @there); # actions done here (in order), and those left to the primitive
187 0 ▶ for my $x (@acts) { my $k = ref $x eq 'ARRAY' ? $x->[0] // '' : ''; if ($m{$k} && $kind{$k}) { push @here, $x } else { push @there, $x } }
Branch: 2 branches
BranchTrueFalseTotal
ref $x eq 'ARRAY' ? : 0 0 0
if ($m{$k} and $kind{$k}) { } 0 0 0
Condition0%0/5
$x->[0] // ""
l!l
00
$m{$k} and $kind{$k}
!ll&&!rl&&r
000
MC/DC0%0/1
$x->[0] // ""
$x->[0]
MC/DC0%0/2
$m{$k} and $kind{$k}
$m{$k} $kind{$k}
Truth table0%0/2
A
A= $x->[0]
Aresult
11
00
Truth table0%0/3
A and B
A= $m{$k}B= $kind{$k}
ABresult
0X0
100
111
188 1 ▶ if (@here && @there) { # what is done here happens first: so no action done there may come before one done here
Branch: 1 branch
BranchTrueFalseTotal
if (@here and @there) 0 1 1
Condition33%1/3
@here and @there
!ll&&!rl&&r
100
MC/DC0%0/2
@here and @there
@here @there
Truth table33%1/3
A and B
A= @hereB= @there
ABresult
0X0
100
111
189 0 my %pos; @pos{map 0 + $_, @acts} = 0 .. $#acts;
190 0 my $first_there = (sort { $a <=> $b } map $pos{0 + $_}, @there)[0];
191 0 my $last_here = (sort { $b <=> $a } map $pos{0 + $_}, @here)[0];
192 0 ▶ if ($first_there < $last_here) { $! = POSIX::EINVAL(); return } } # (start() puts chdir first)
Branch: 1 branch
BranchTrueFalseTotal
if ($first_there < $last_here) 0 0 0
193 0 ▶ if ($FALLBACK && @there) { $! = POSIX::EINVAL(); return } # (an action the emulation does not know)
Branch: 1 branch
BranchTrueFalseTotal
if ($Proc::Spawner::FALLBACK and @there) 0 1 1
Condition33%1/3
$Proc::Spawner::FALLBACK and @there
!ll&&!rl&&r
100
MC/DC0%0/2
$Proc::Spawner::FALLBACK and @there
$Proc::Spawner::FALLBACK @there
Truth table33%1/3
A and B
A= $Proc::Spawner::FALLBACKB= @there
ABresult
0X0
100
111
194 1 ▶ my $sigmask = $m{sigmask} ? delete $at{sigmask} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$m{'sigmask'} ? : 0 1 1
195 1 ▶ my $sigdef = $m{sigdefault} ? delete $at{sigdefault} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$m{'sigdefault'} ? : 0 1 1
196 1 ▶ my $pg = $m{pgroup} && defined $at{pgroup} ? delete $at{pgroup} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$m{'pgroup'} && defined $at{'pgroup'} ? : 0 1 1
Condition33%1/3
$m{"pgroup"} and defined $at{"pgroup"}
!ll&&!rl&&r
100
MC/DC0%0/2
$m{"pgroup"} and defined $at{"pgroup"}
$m{"pgroup"} defined $at{"pgroup"}
Truth table33%1/3
A and B
A= $m{"pgroup"}B= defined $at{"pgroup"}
ABresult
0X0
100
111
197 1 ▶ my $reset = $m{resetids} && delete $at{resetids};
Condition33%1/3
$m{'resetids'} && delete $at{'resetids'}
!ll&&!rl&&r
100
MC/DC0%0/2
$m{'resetids'} && delete $at{'resetids'}
$m{'resetids'} delete $at{'resetids'}
Truth table33%1/3
A && B
A= $m{'resetids'}B= delete $at{'resetids'}
ABresult
0X0
100
111
198 1 ▶ my $pidfd = $m{pidfd} && delete $at{pidfd};
Condition33%1/3
$m{'pidfd'} && delete $at{'pidfd'}
!ll&&!rl&&r
100
MC/DC0%0/2
$m{'pidfd'} && delete $at{'pidfd'}
$m{'pidfd'} delete $at{'pidfd'}
Truth table33%1/3
A && B
A= $m{'pidfd'}B= delete $at{'pidfd'}
ABresult
0X0
100
111
199 1 ▶ my $search = $m{search} && delete $at{search};
Condition33%1/3
$m{'search'} && delete $at{'search'}
!ll&&!rl&&r
100
MC/DC0%0/2
$m{'search'} && delete $at{'search'}
$m{'search'} delete $at{'search'}
Truth table33%1/3
A && B
A= $m{'search'}B= delete $at{'search'}
ABresult
0X0
100
111
200 1 ▶ if ($search && !$WIN and $file !~ m{/}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($search and not $Proc::Spawner::WIN and not $file =~ m[/]) 0 1 1
Condition33%2/6
$search and not $Proc::Spawner::WIN and not $file =~ m[/]
!ll&&!rl&&r
100
$search and not $Proc::Spawner::WIN
!ll&&!rl&&r
100
MC/DC0%0/3
$search and not $Proc::Spawner::WIN and not $file =~ m[/]
$search not $Proc::Spawner::WIN not $file =~ m[/]
Truth table25%1/4
A and not(B) and not(C)
A= $searchB= not $Proc::Spawner::WINC= not $file =~ m[/]
ABCresult
0XX0
10X0
1100
1111
201 0 ▶ my ($p) = grep -x && !-d, map +(length ? $_ : '.') . "/$file", path_split($ENV{PATH});
Branch: 1 branch
BranchTrueFalseTotal
length $_ ? : 0 0 0
Condition0%0/3
-x $_ && !(-d $_)
!ll&&!rl&&r
000
MC/DC0%0/2
-x $_ && !(-d $_)
-x $_ !(-d $_)
Truth table0%0/3
A && not(B)
A= -x $_B= !(-d $_)
ABresult
0X0
100
111
202 0 ▶ defined $p or do { $! = POSIX::ENOENT(); return }; $file = $p }
Branch: 1 branch
BranchTrueFalseTotal
defined $p or do { $! = 2; return } 0 0 0
203 1 my @undo; my $err; my @r;
204 1 my $ok = eval {
205 1 ▶ if (!$m{sigmask} && (@here || $sigdef || defined $pg || $reset)) { # no handler of ours while this process is changed
Branch: 1 branch
BranchTrueFalseTotal
if (not $m{"sigmask"} and @here || $sigdef || defined $pg || $reset) 0 1 1
Condition33%4/12
not $m{"sigmask"} and @here || $sigdef || defined $pg || $reset
!ll&&!rl&&r
010
@here or $sigdef or defined $pg or $reset
l!l&&r!l&&!r
001
@here or $sigdef or defined $pg
l!l&&r!l&&!r
001
@here or $sigdef
l!l&&r!l&&!r
001
MC/DC0%0/5
not $m{"sigmask"} and @here || $sigdef || defined $pg || $reset
not $m{"sigmask"} @here $sigdef defined $pg $reset
Truth table16%1/6
not(A) and B or C or D or E
A= not $m{"sigmask"}B= @hereC= $sigdefD= defined $pgE= $reset
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
206 0 my ($all, $old) = (POSIX::SigSet->new, POSIX::SigSet->new); $all->fillset;
207 0 ▶ POSIX::sigprocmask(POSIX::SIG_BLOCK(), $all, $old); unshift @undo, sub { POSIX::sigprocmask(POSIX::SIG_SETMASK(), $old) } }
Subroutine __ANON__: not called CC=1 SCAR=6.9
208 1 ▶ if ($sigmask) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sigmask) 0 1 1
209 0 my ($set, $old) = (POSIX::SigSet->new(signums($sigmask)), POSIX::SigSet->new);
210 0 ▶ POSIX::sigprocmask(POSIX::SIG_SETMASK(), $set, $old) or die $!; unshift @undo, sub { POSIX::sigprocmask(POSIX::SIG_SETMASK(), $old) } }
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
POSIX::sigprocmask(2, $set, $old) or die $! 0 0 0
211 1 ▶ for my $sig ($sigdef ? signums($sigdef) : ()) {
Branch: 1 branch
BranchTrueFalseTotal
$sigdef ? : 0 1 1
212 0 my $old = POSIX::SigAction->new; POSIX::sigaction($sig, undef, $old);
213 0 ▶ next unless ($old->{HANDLER} // '') eq 'IGNORE'; # a caught signal is reset by exec anyway
Branch: 1 branch
BranchTrueFalseTotal
unless ($old->{"HANDLER"} // "") eq "IGNORE" 0 0 0
Condition0%0/2
$old->{"HANDLER"} // ""
l!l
00
MC/DC0%0/1
$old->{"HANDLER"} // ""
$old->{"HANDLER"}
Truth table0%0/2
A
A= $old->{"HANDLER"}
Aresult
11
00
214 0 ▶ POSIX::sigaction($sig, POSIX::SigAction->new('DEFAULT')) or die $!; unshift @undo, sub { POSIX::sigaction($sig, $old) } }
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
POSIX::sigaction($sig, "POSIX::SigAction"->new("DEFAULT")) or die $! 0 0 0
215 0 ▶ if (defined $pg) { my $old = getpgrp; POSIX::setpgid(0, $pg) or die $!; unshift @undo, sub { POSIX::setpgid(0, $old) } }
Subroutine __ANON__: not called CC=1 SCAR=3.9
Branch: 2 branches
BranchTrueFalseTotal
if (defined $pg) 0 1 1
POSIX::setpgid(0, $pg) or die $! 0 0 0
216 1 ▶ if ($reset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reset) 0 1 1
217 0 ▶ if ($> != $<) { my $e = $>; $> = $<; $> == $< or die $!; unshift @undo, sub { $> = $e } }
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 2 branches
BranchTrueFalseTotal
if ($> != $<) 0 0 0
$> == $< or die $! 0 0 0
218 0 my ($eg, $rg) = ((split ' ', $))[0], (split ' ', $()[0]);
219 0 ▶ if ($eg != $rg) { my $o = $); $) = $rg; unshift @undo, sub { $) = $o } } }
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($eg != $rg) 0 0 0
220 1 ▶ my $redirs = $PRIMITIVE eq 'system1' ? run_redirs(\@here, \@undo) : do { emulate_actions(\@here, \@undo) if @here; undef };
Branch: 2 branches
BranchTrueFalseTotal
$Proc::Spawner::PRIMITIVE eq 'system1' ? : 0 1 1
if @here 0 1 1
221 @r = $PRIMITIVE eq 'posix_spawn' ? __posix_spawn($file, $argv, $envp, \@there, \%at, $uns)
222 1 ▶ : $PRIMITIVE eq 'fork' ? __spawn_nowait($file, $argv, $envp, { map +($_ => $at{$_}), grep exists $at{$_}, qw(rlimit sigignore nice) }, $uns)
Branch: 2 branches
BranchTrueFalseTotal
$Proc::Spawner::PRIMITIVE eq 'posix_spawn' ? : 1 0 1
$Proc::Spawner::PRIMITIVE eq 'fork' ? : 0 0 0
223 : system1($file, $argv, $envp, $search, $redirs);
224 1 $err = $!;
225 0 ▶ if (@r && $pidfd) { my $fd = __pidfd_open($r[0]); push @r, $fd >= 0 ? $fd : undef }
Branch: 2 branches
BranchTrueFalseTotal
if (@r and $pidfd) 0 1 1
$fd >= 0 ? : 0 0 0
Condition33%1/3
@r and $pidfd
!ll&&!rl&&r
010
MC/DC0%0/2
@r and $pidfd
@r $pidfd
Truth table33%1/3
A and B
A= @rB= $pidfd
ABresult
0X0
100
111
226 1 1 };
227 1 ▶ my $died = !$ok && $@ !~ /^Proc::Spawner: errno (\d+)/ && $@; # not ours (Run missing, ...): passed on, after the undo
Condition33%2/6
!($ok || $@ =~ /^Proc::Spawner: errno (\d+)/) && $@
!ll&&!rl&&r
100
$ok || $@ =~ /^Proc::Spawner: errno (\d+)/
l!l&&r!l&&!r
100
MC/DC0%0/3
!($ok || $@ =~ /^Proc::Spawner: errno (\d+)/) && $@
$ok $@ =~ /^Proc::Spawner: errno (\d+)/ $@
Truth table25%1/4
not(A || B) && C
A= $okB= $@ =~ /^Proc::Spawner: errno (\d+)/C= $@
ABCresult
1XX0
01X0
0000
0011
228 1 ▶ $err = $@ =~ /^Proc::Spawner: errno (\d+)/ ? $1 : ($! + 0 || POSIX::EINVAL()) unless $ok;
Branch: 2 branches
BranchTrueFalseTotal
unless $ok 0 1 1
$@ =~ /^Proc::Spawner: errno (\d+)/ ? : 0 0 0
Condition0%0/2
$! + 0 or 22
l!l
00
MC/DC0%0/1
$! + 0 or 22
$! + 0
Truth table0%0/2
A
A= $! + 0
Aresult
11
00
229 1 $_->() for @undo;
230 1 ▶ die $died if $died;
Branch: 1 branch
BranchTrueFalseTotal
if $died 0 1 1
231 1 ▶ $! = $err; $ok && @r or return; wantarray ? @r : $r[0] } # (scalar context: the pid, as the XSUB gives it)
Branch: 2 branches
BranchTrueFalseTotal
$ok and @r or return 1 0 1
wantarray ? : 0 1 1
Condition33%1/3
$ok and @r
!ll&&!rl&&r
001
MC/DC0%0/2
$ok and @r
$ok @r
Truth table33%1/3
A and B
A= $okB= @r
ABresult
0X0
100
111
232  
233 488 our $PATH_SEP = $Config{path_sep};
234 269 ▶sub path_split { # a PATH value's entries, split at $PATH_SEP (post-0.10: $Config{path_sep}, ';' on Windows). POSIX: an empty
Subroutine path_split: called CC=3 SCAR=11.1
Pod undocumented
235 # entry is the current directory. Windows (as Perl's own win32.c reads PATH): a "quoted" part is taken whole, its quotes
236 # dropped (an unclosed one runs to the end); empty entries are dropped
237 269 ▶ my $p = shift // ''; my $s = quotemeta $PATH_SEP;
Condition50%1/2
shift() // ""
l!l
2690
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
238 269 ▶ $WIN ? grep(length, map tr/"//dr, $p =~ /((?:"[^"]*(?:"|$)|[^"$s])*)/g) : split /$s/, $p, -1 }
Branch: 1 branch
BranchTrueFalseTotal
$Proc::Spawner::WIN ? : 1 268 269
239  
240 0 ▶sub win_find { # posix_spawnp's lookup on Windows, as win_spawn.h's: a name with no directory through PATH (path_split),
Subroutine win_find: not called CC=9 SCAR=45.0
Pod undocumented
241 # PATHEXT's extensions before the bare name; a path as it is (relative: to the directory now)
242 0 my ($file, $search) = @_;
243 0 ▶ my @ext = ((grep length, split /;/, $ENV{PATHEXT} // '.COM;.EXE;.BAT;.CMD'), ''); # (PATHEXT: Windows' own, always ';')
Condition0%0/2
$ENV{"PATHEXT"} // ".COM;.EXE;.BAT;.CMD"
l!l
00
MC/DC0%0/1
$ENV{"PATHEXT"} // ".COM;.EXE;.BAT;.CMD"
$ENV{"PATHEXT"}
Truth table0%0/2
A
A= $ENV{"PATHEXT"}
Aresult
11
00
244 0 ▶ my @dirs = $search && $file !~ m{[/\\:]} ? path_split($ENV{PATH}) : ('');
Branch: 1 branch
BranchTrueFalseTotal
$search && !($file =~ m[[/\\:]]) ? : 0 0 0
Condition0%0/3
$search and not $file =~ m[[/\\:]]
!ll&&!rl&&r
000
MC/DC0%0/2
$search and not $file =~ m[[/\\:]]
$search not $file =~ m[[/\\:]]
Truth table0%0/3
A and not(B)
A= $searchB= not $file =~ m[[/\\:]]
ABresult
0X0
100
111
245 0 for my $d (@dirs) { for my $e (@ext) {
246 0 ▶ my $p = length $d ? "$d\\$file$e" : "$file$e"; return File::Spec->rel2abs($p) if -f $p && -x _ } }
Branch: 2 branches
BranchTrueFalseTotal
length $d ? : 0 0 0
if -f $p and -x _ 0 0 0
Condition0%0/3
-f $p and -x _
!ll&&!rl&&r
000
MC/DC0%0/2
-f $p and -x _
-f $p -x _
Truth table0%0/3
A and B
A= -f $pB= -x _
ABresult
0X0
100
111
247 0 return }
248  
249 0 ▶sub system1 { # the primitive without posix_spawn and fork (M2): Run::start around Perl's own spawn; the pid, or empty with $!
Subroutine system1: not called CC=12 SCAR=50.5
Pod undocumented
250 0 my ($file, $argv, $envp, $search, $redirs) = @_;
251 0 require Run; Run->VERSION('0.07'); # (Run::start with a program, {fd => M}, {close => 1})
252 0 local $Run::Forkless = 1;
253 0 ▶ if ($WIN) { # posix_spawn's meaning of FILE (with search: PATH and PATHEXT), not Perl's
Branch: 1 branch
BranchTrueFalseTotal
if ($Proc::Spawner::WIN) 0 0 0
254 0 ▶ $file = win_find($file, $search) // do { $! = -e $file && !-d _ ? POSIX::EACCES() : POSIX::ENOENT(); return } }
Branch: 1 branch
BranchTrueFalseTotal
-e $file && !-d(_) ? : 0 0 0
Condition0%0/6
win_find($file, $search) // do { $! = -e $file && !-d(_) ? 13 : 2; return }
l!l&&r!l&&!r
000
-e $file and not -d _
!ll&&!rl&&r
000
MC/DC0%0/2
win_find($file, $search) // do { $! = -e $file && !-d(_) ? 13 : 2; return }
win_find($file, $search) do { $! = -e $file && !-d(_) ? 13 : 2; return }
MC/DC0%0/2
-e $file and not -d _
-e $file not -d _
Truth table0%0/3
A // B
A= win_find($file, $search)B= do { $! = -e $file && !-d(_) ? 13 : 2; return }
ABresult
1X1
011
000
Truth table0%0/3
A and not(B)
A= -e $fileB= not -d _
ABresult
0X0
100
111
255 0 ▶ local %ENV = map { /^([^=]+)=(.*)\z/s ? ($1, $2) : () } @$envp if $envp;
Branch: 2 branches
BranchTrueFalseTotal
if $envp 0 0 0
/^([^=]+)=(.*)\z/s ? : 0 0 0
256 # X38 (post-0.10): Perl's spawn on Windows passes the child every inheritable handle, and Perl makes its handles
257 # inheritable (no close-on-exec by $^F there): our fds from 3 up are made not inheritable for the call, then put back,
258 # as POSIX has it. Not thread-safe: another thread's spawn meanwhile does not pass these fds either.
259 0 ▶ my @off = $WIN ? grep(__fd_cloexec($_) == 0, 3 .. __fd_limit() - 1) : (); __set_cloexec($_, 1) for @off;
Branch: 1 branch
BranchTrueFalseTotal
$Proc::Spawner::WIN ? : 0 0 0
260 0 my @errs; my $pid = eval { Run::start(1, $argv, $redirs, \@errs, $file) }; my ($died, $err) = ($@, $!);
261 0 ▶ __set_cloexec($_, 0) for @off; die $died if $died; $! = $err;
Branch: 1 branch
BranchTrueFalseTotal
if $died 0 0 0
262 0 ▶ $pid or return; $pid }
Branch: 1 branch
BranchTrueFalseTotal
$pid or return 0 0 0
263  
264 0 ▶sub run_redirs { # system1 (M2): the fd actions as Run's redirections (Run::start applies them around the call and puts
Subroutine run_redirs: not called CC=16 SCAR=56.1
Pod undocumented
265 # our fds back); chdir and fchdir done here, in order, so that an open's relative path is taken from the directory then;
266 # the way back pushed on @$undo
267 0 my ($acts, $undo) = @_;
268 0 my (@r, $here, @opened);
269 0 ▶ my $die = sub { die "Proc::Spawner: errno " . (0 + $!) . "\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
270 0 ▶ unshift @$undo, sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
271 0 close $_ for @opened;
272 0 ▶ if (defined $here) { if ($WIN) { chdir $here } else { __fchdir($here); POSIX::close($here) } } };
Branch: 2 branches
BranchTrueFalseTotal
if (defined $here) 0 0 0
if ($Proc::Spawner::WIN) { } 0 0 0
273 0 for my $x (@$acts) {
274 0 my ($op, @a) = @$x;
275 0 ▶ if ($op eq 'chdir' || $op eq 'fchdir') {
Branch: 5 branches
BranchTrueFalseTotal
if ($op eq 'chdir' or $op eq 'fchdir') { } 0 0 0
elsif ($op eq 'dup2') { } 0 0 0
elsif ($op eq 'close') { } 0 0 0
elsif ($op eq 'open') { } 0 0 0
elsif ($op eq 'closefrom') { } 0 0 0
Condition0%0/3
$op eq "chdir" or $op eq "fchdir"
l!l&&r!l&&!r
000
MC/DC0%0/2
$op eq "chdir" or $op eq "fchdir"
$op eq "chdir" $op eq "fchdir"
Truth table0%0/3
A or B
A= $op eq "chdir"B= $op eq "fchdir"
ABresult
1X1
011
000
276 0 ▶ $here //= $WIN ? do { require Cwd; Cwd::getcwd() // $die->() }
Condition0%0/3
Cwd::getcwd() // &$die()
l!l&&r!l&&!r
000
MC/DC0%0/2
Cwd::getcwd() // &$die()
Cwd::getcwd() &$die()
Truth table0%0/3
A // B
A= Cwd::getcwd()B= &$die()
ABresult
1X1
011
000
277 0 ▶ : do { my $h = POSIX::open('.', POSIX::O_RDONLY()); defined $h or $die->(); __set_cloexec($h, 1); $h };
Branch: 2 branches
BranchTrueFalseTotal
$Proc::Spawner::WIN ? : 0 0 0
defined $h or &$die() 0 0 0
Condition0%0/3
$here //= $Proc::Spawner::WIN ? do { require Cwd; Cwd::getcwd() // &$die() } : do { my $h = POSIX::open(".", 0); defined $h or &$die(); __set_cloexec($h, 1); $h }
l!l&&r!l&&!r
000
MC/DC0%0/2
$here //= $Proc::Spawner::WIN ? do { require Cwd; Cwd::getcwd() // &$die() } : do { my $h = POSIX::open(".", 0); defined $h or &$die(); __set_cloexec($h, 1); $h }
$here $Proc::Spawner::WIN ? do { require Cwd; Cwd::getcwd() // &$die() } : do { my $h = POSIX::open(".", 0); defined $h or &$die(); __set_cloexec($h, 1); $h }
Truth table0%0/3
A //= B
A= $hereB= $Proc::Spawner::WIN ? do { require Cwd; Cwd::getcwd() // &$die() } : do { my $h = POSIX::open(".", 0); defined $h or &$die(); __set_cloexec($h, 1); $h }
ABresult
1X1
011
000
278 0 ▶ ($op eq 'chdir' ? chdir $a[0] : __fchdir($a[0])) or $die->() }
Branch: 2 branches
BranchTrueFalseTotal
$op eq "chdir" ? chdir $a[0] : __fchdir($a[0]) or &$die() 0 0 0
$op eq 'chdir' ? : 0 0 0
279 0 elsif ($op eq 'dup2') { push @r, $a[1] => { fd => $a[0] } }
280 0 elsif ($op eq 'close') { push @r, $a[0] => { close => 1 } }
281 elsif ($op eq 'open') {
282 0 ▶ sysopen my $fh, $a[1], $a[2], $a[3] // 0666 or $die->(); push @opened, $fh;
Branch: 1 branch
BranchTrueFalseTotal
sysopen my $fh, $a[1], $a[2], $a[3] // 438 or &$die() 0 0 0
Condition0%0/2
$a[3] // 438
l!l
00
MC/DC0%0/1
$a[3] // 438
$a[3]
Truth table0%0/2
A
A= $a[3]
Aresult
11
00
283 0 push @r, $a[0] => { filehandle => $fh, pin => 1 } }
284 0 elsif ($op eq 'closefrom') { push @r, map +($_ => { close => 1 }), grep __fd_cloexec($_) == 0, $a[0] .. __fd_limit() - 1 }
285 0 else { $! = POSIX::EINVAL(); $die->() } }
286 0 \@r }
287  
288 0 ▶sub emulate_actions { # the file actions, done on this process's own fds in order; the way back pushed on @$undo
Subroutine emulate_actions: not called CC=35 SCAR=71.4
Pod undocumented
289 0 my ($acts, $undo) = @_;
290 0 my $top = 10; # above every fd the actions name (not an open's flags or mode)
291 0 ▶ for my $x (@$acts) { for (@$x[1 .. ($x->[0] eq 'dup2' ? 2 : 1)]) { $top = $_ + 1 if defined && /^[0-9]+\z/ && $_ >= $top } }
Branch: 2 branches
BranchTrueFalseTotal
$x->[0] eq 'dup2' ? : 0 0 0
if defined $_ and /^[0-9]+\z/ and $_ >= $top 0 0 0
Condition0%0/6
defined $_ and /^[0-9]+\z/ and $_ >= $top
!ll&&!rl&&r
000
defined $_ and /^[0-9]+\z/
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_ and /^[0-9]+\z/ and $_ >= $top
defined $_ /^[0-9]+\z/ $_ >= $top
Truth table0%0/4
A and B and C
A= defined $_B= /^[0-9]+\z/C= $_ >= $top
ABCresult
0XX0
10X0
1100
1111
292 0 my (%flag, %save, %ours); # an fd's close-on-exec before (-1: was not open); its contents before (a copy; undef: none)
293 0 ▶ my $die = sub { die "Proc::Spawner: errno " . (0 + $!) . "\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
294 0 ▶ my $flag_touch = sub { my $fd = shift; $flag{$fd} //= __fd_cloexec($fd) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
$flag{$fd} //= __fd_cloexec($fd)
l!l&&r!l&&!r
000
MC/DC0%0/2
$flag{$fd} //= __fd_cloexec($fd)
$flag{$fd} __fd_cloexec($fd)
Truth table0%0/3
A //= B
A= $flag{$fd}B= __fd_cloexec($fd)
ABresult
1X1
011
000
295 0 ▶ my $content_touch = sub { my $fd = shift; return if exists $save{$fd}; $flag_touch->($fd);
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if exists $save{$fd} 0 0 0
296 0 ▶ $save{$fd} = $flag{$fd} >= 0 ? do { my $c = __dup_high($fd, $top + 1); $c >= 0 or $die->(); $ours{$c} = 1; $c } : undef };
Branch: 2 branches
BranchTrueFalseTotal
$flag{$fd} >= 0 ? : 0 0 0
$c >= 0 or &$die() 0 0 0
297 0 my $here; # this process's directory before
298 0 ▶ unshift @$undo, sub { # contents first, then the flags, then the directory
Subroutine __ANON__: not called CC=8 SCAR=42.8
299 0 ▶ for my $fd (keys %save) { my $c = $save{$fd}; defined $c ? (POSIX::dup2($c, $fd), POSIX::close($c)) : POSIX::close($fd) }
Branch: 1 branch
BranchTrueFalseTotal
defined $c ? : 0 0 0
300 0 ▶ for my $fd (keys %flag) { __set_cloexec($fd, $flag{$fd}) if $flag{$fd} >= 0 }
Branch: 1 branch
BranchTrueFalseTotal
if $flag{$fd} >= 0 0 0 0
301 0 ▶ if ($WIN) { chdir $here if defined $here } # (no directory fds there)
Branch: 3 branches
BranchTrueFalseTotal
if ($Proc::Spawner::WIN) { } 0 0 0
elsif ($here) { } 0 0 0
if defined $here 0 0 0
302 0 elsif ($here) { __fchdir($here); POSIX::close($here) } };
303 0 for my $x (@$acts) {
304 0 my ($op, @a) = @$x;
305 0 ▶ if ($op eq 'chdir' || $op eq 'fchdir') {
Branch: 6 branches
BranchTrueFalseTotal
if ($op eq 'chdir' or $op eq 'fchdir') { } 0 0 0
elsif ($op eq 'dup2') { } 0 0 0
elsif ($op eq 'close' and $Proc::Spawner::WIN) { } 0 0 0
elsif ($op eq 'close') { } 0 0 0
elsif ($op eq 'closefrom') { } 0 0 0
elsif ($op eq 'open') { } 0 0 0
Condition0%0/3
$op eq "chdir" or $op eq "fchdir"
l!l&&r!l&&!r
000
MC/DC0%0/2
$op eq "chdir" or $op eq "fchdir"
$op eq "chdir" $op eq "fchdir"
Truth table0%0/3
A or B
A= $op eq "chdir"B= $op eq "fchdir"
ABresult
1X1
011
000
306 0 ▶ $here //= $WIN ? do { require Cwd; Cwd::getcwd() // $die->() }
Condition0%0/3
Cwd::getcwd() // &$die()
l!l&&r!l&&!r
000
MC/DC0%0/2
Cwd::getcwd() // &$die()
Cwd::getcwd() &$die()
Truth table0%0/3
A // B
A= Cwd::getcwd()B= &$die()
ABresult
1X1
011
000
307 0 ▶ : do { my $h = POSIX::open('.', POSIX::O_RDONLY()); defined $h or $die->(); __set_cloexec($h, 1); $ours{$h} = 1; $h };
Branch: 2 branches
BranchTrueFalseTotal
$Proc::Spawner::WIN ? : 0 0 0
defined $h or &$die() 0 0 0
Condition0%0/3
$here //= $Proc::Spawner::WIN ? do { require Cwd; Cwd::getcwd() // &$die() } : do { my $h = POSIX::open(".", 0); defined $h or &$die(); __set_cloexec($h, 1); $ours{$h} = 1; $h }
l!l&&r!l&&!r
000
MC/DC0%0/2
$here //= $Proc::Spawner::WIN ? do { require Cwd; Cwd::getcwd() // &$die() } : do { my $h = POSIX::open(".", 0); defined $h or &$die(); __set_cloexec($h, 1); $ours{$h} = 1; $h }
$here $Proc::Spawner::WIN ? do { require Cwd; Cwd::getcwd() // &$die() } : do { my $h = POSIX::open(".", 0); defined $h or &$die(); __set_cloexec($h, 1); $ours{$h} = 1; $h }
Truth table0%0/3
A //= B
A= $hereB= $Proc::Spawner::WIN ? do { require Cwd; Cwd::getcwd() // &$die() } : do { my $h = POSIX::open(".", 0); defined $h or &$die(); __set_cloexec($h, 1); $ours{$h} = 1; $h }
ABresult
1X1
011
000
308 0 ▶ ($op eq 'chdir' ? chdir $a[0] : __fchdir($a[0])) or $die->() }
Branch: 2 branches
BranchTrueFalseTotal
$op eq "chdir" ? chdir $a[0] : __fchdir($a[0]) or &$die() 0 0 0
$op eq 'chdir' ? : 0 0 0
309 elsif ($op eq 'dup2') {
310 0 my ($from, $to) = @a;
311 0 ▶ if ($from == $to) { __fd_cloexec($from) >= 0 or do { $! = POSIX::EBADF(); $die->() }; $flag_touch->($to); __set_cloexec($to, 0) }
Branch: 2 branches
BranchTrueFalseTotal
if ($from == $to) { } 0 0 0
__fd_cloexec($from) >= 0 or do { $! = 9; &$die() } 0 0 0
312 0 ▶ else { __fd_cloexec($from) >= 0 or do { $! = POSIX::EBADF(); $die->() }; $content_touch->($to); defined POSIX::dup2($from, $to) or $die->() } }
Branch: 2 branches
BranchTrueFalseTotal
__fd_cloexec($from) >= 0 or do { $! = 9; &$die() } 0 0 0
defined POSIX::dup2($from, $to) or &$die() 0 0 0
313 0 ▶ elsif ($op eq 'close' && $WIN) { $content_touch->($a[0]); POSIX::close($a[0]) if defined $save{$a[0]} } # (fds 0-2: Perl's
Branch: 1 branch
BranchTrueFalseTotal
if defined $save{$a[0]} 0 0 0
Condition0%0/3
$op eq "close" and $Proc::Spawner::WIN
!ll&&!rl&&r
000
MC/DC0%0/2
$op eq "close" and $Proc::Spawner::WIN
$op eq "close" $Proc::Spawner::WIN
Truth table0%0/3
A and B
A= $op eq "close"B= $Proc::Spawner::WIN
ABresult
0X0
100
111
314 # spawn passes the standard handles, inheritable or not)
315 0 ▶ elsif ($op eq 'close') { $flag_touch->($a[0]); __set_cloexec($a[0], 1) if __fd_cloexec($a[0]) >= 0 }
Branch: 1 branch
BranchTrueFalseTotal
if __fd_cloexec($a[0]) >= 0 0 0 0
316 elsif ($op eq 'closefrom') {
317 0 ▶ for my $fd ($a[0] .. __fd_limit() - 1) { next if $ours{$fd} || __fd_cloexec($fd) < 0; $flag_touch->($fd); __set_cloexec($fd, 1) } }
Branch: 1 branch
BranchTrueFalseTotal
if $ours{$fd} or __fd_cloexec($fd) < 0 0 0 0
Condition0%0/3
$ours{$fd} or __fd_cloexec($fd) < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$ours{$fd} or __fd_cloexec($fd) < 0
$ours{$fd} __fd_cloexec($fd) < 0
Truth table0%0/3
A or B
A= $ours{$fd}B= __fd_cloexec($fd) < 0
ABresult
1X1
011
000
318 elsif ($op eq 'open') {
319 0 my ($fd, $path, $fl, $mode) = @a; $content_touch->($fd);
320 0 ▶ my $o = POSIX::open($path, $fl, $mode // 0666); defined $o or $die->();
Branch: 1 branch
BranchTrueFalseTotal
defined $o or &$die() 0 0 0
Condition0%0/2
$mode // 438
l!l
00
MC/DC0%0/1
$mode // 438
$mode
Truth table0%0/2
A
A= $mode
Aresult
11
00
321 0 ▶ if ($o == $fd) { __set_cloexec($fd, 0) } else { my $r = POSIX::dup2($o, $fd); my $e = $!; POSIX::close($o); defined $r or do { $! = $e; $die->() } } }
Branch: 2 branches
BranchTrueFalseTotal
if ($o == $fd) { } 0 0 0
defined $r or do { $! = $e; &$die() } 0 0 0
322 0 else { $! = POSIX::EINVAL(); $die->() } } }
323  
324 # The loop is Proc::Spawner::Loop (W5, post-0.10); these are its variables, and the functions below its old names.
325 488 ▶use Proc::Spawner::Loop ();
Subroutine BEGIN: called CC=1 SCAR=0.0
326 488 our ($TRACE, $CAUSE, $REACTING, $DEPTH); # undef or a code ref given one line per operation; the caller's cause (Graph)
327 488 *TRACE = \$Proc::Spawner::Loop::TRACE; *CAUSE = \$Proc::Spawner::Loop::CAUSE;
328 488 *REACTING = \$Proc::Spawner::Loop::REACTING; *DEPTH = \$Proc::Spawner::Loop::DEPTH;
329  
330 950 ▶sub tr_ { $TRACE->(join '', @_) if $TRACE }
Subroutine tr_: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::Spawner::TRACE 0 950 950
331  
332 # ------------------------------------------------------------------ spawning
333 329 ▶sub actions { # the file actions giving a child exactly %$fds, whatever the parent's own fd numbers
Subroutine actions: called CC=14 SCAR=26.4
Pod undocumented
334 329 my $fds = shift; my @t = sort { $a <=> $b } keys %$fds;
335 329 ▶ my @src = grep defined && !ref, values %$fds;
Condition100%3/3
defined $_ && !ref($_)
!ll&&!rl&&r
41255
MC/DC100%2/2
defined $_ && !ref($_)
defined $_ !ref($_)
Truth table100%3/3
A && not(B)
A= defined $_B= !ref($_)
ABresult
0X0
100
111
336 329 ▶ my $top = 9; for (@t, @src) { $top = $_ if $_ > $top }
Branch: 1 branch
BranchTrueFalseTotal
if $_ > $top 11 504 515
337 329 my (@a, @open, %via, @scratch);
338 329 for my $f (@src) { # a source fd the child gets something else on: copy it first
339 255 ▶ next if $via{$f} or !exists $fds->{$f} or !ref $fds->{$f} && ($fds->{$f} // -1) == $f;
Branch: 1 branch
BranchTrueFalseTotal
if $via{$f} or not exists $fds->{$f} or not ref $fds->{$f} and ($fds->{$f} // -1) == $f 251 4 255
Condition90%10/11
$via{$f} or not exists $fds->{$f} or not ref $fds->{$f} and ($fds->{$f} // -1) == $f
l!l&&r!l&&!r
24654
$via{$f} or not exists $fds->{$f}
l!l&&r!l&&!r
22449
not ref $fds->{$f} and ($fds->{$f} // -1) == $f
!ll&&!rl&&r
045
$fds->{$f} // -1
l!l
81
MC/DC75%3/4
$via{$f} or not exists $fds->{$f} or not ref $fds->{$f} and ($fds->{$f} // -1) == $f
$via{$f} not exists $fds->{$f} not ref $fds->{$f} $fds->{$f}
Truth table80%4/5
A or not(B) or not(C) and D
A= $via{$f}B= not exists $fds->{$f}C= not ref $fds->{$f}D= $fds->{$f}
ABCDresult
1XXX1
01XX1
00111
000X0
00100
340 4 push @a, [dup2 => $f, $via{$f} = ++$top]; push @scratch, $top }
341 329 for my $t (@t) { # dup2 to itself too: it clears close-on-exec
342 260 ▶ my $f = $fds->{$t} // next; ref $f ? push @open, [open => $t, @$f] : push @a, [dup2 => $via{$f} // $f, $t] }
Branch: 1 branch
BranchTrueFalseTotal
ref $f ? : 1 255 256
Condition80%4/5
$fds->{$t} // (next)
l!l
2564
$via{$f} // $f
l!l&&r!l&&!r
62490
MC/DC100%1/1
$fds->{$t} // (next)
$fds->{$t}
MC/DC0%0/2
$via{$f} // $f
$via{$f} $f
Truth table100%2/2
A
A= $fds->{$t}
Aresult
11
00
Truth table66%2/3
A // B
A= $via{$f}B= $f
ABresult
1X1
011
000
343 329 @a, @open, map [close => $_], (grep !defined $fds->{$_}, @t), @scratch }
344  
345 659 ▶sub signums { map $SIGNUM{$_} // (/^[0-9]+\z/ ? $_ : die "Proc::Spawner: unknown signal '$_'\n"), @{$_[0] // []} }
Subroutine signums: called CC=4 SCAR=14.3
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
/^[0-9]+\z/ ? : 0 1 1
Condition80%4/5
$SIGNUM{$_} // (/^[0-9]+\z/ ? $_ : die("Proc::Spawner: unknown signal '${_}'\n"))
l!l&&r!l&&!r
101801
$_[0] // []
l!l
276383
MC/DC0%0/2
$SIGNUM{$_} // (/^[0-9]+\z/ ? $_ : die("Proc::Spawner: unknown signal '${_}'\n"))
$SIGNUM{$_} (/^[0-9]+\z/ ? $_ : die("Proc::Spawner: unknown signal '${_}'\n"))
MC/DC100%1/1
$_[0] // []
$_[0]
Truth table33%1/3
A // B
A= $SIGNUM{$_}B= (/^[0-9]+\z/ ? $_ : die("Proc::Spawner: unknown signal '${_}'\n"))
ABresult
1X1
011
000
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
346 488 ▶my %RLIMIT = defined &__rlimits ? __rlimits() : ();
Branch: 1 branch
BranchTrueFalseTotal
defined &Proc::Spawner::__rlimits ? : 488 0 488
347 1 ▶sub rlimits { # { NAME => SOFT | [SOFT, HARD] } as spawn's [[RESOURCE, SOFT, HARD], ...]; NAME: NOFILE, RLIMIT_NOFILE or a number
Subroutine rlimits: called CC=5 SCAR=18.9
Pod undocumented
348 1 my $h = shift;
349 1 map { my ($n, $v) = ($_, $h->{$_}); (my $k = uc $n) =~ s/^RLIMIT_//;
350 1 ▶ my $r = $WIN ? $k : $RLIMIT{$k} // ($n =~ /^[0-9]+\z/ ? $n : die "Proc::Spawner: unknown resource '$n'\n"); # (Windows: the name, W4)
Branch: 2 branches
BranchTrueFalseTotal
$Proc::Spawner::WIN ? : 0 1 1
$n =~ /^[0-9]+\z/ ? : 0 0 0
Condition33%1/3
$RLIMIT{$k} // ($n =~ /^[0-9]+\z/ ? $n : die("Proc::Spawner: unknown resource '${n}'\n"))
l!l&&r!l&&!r
100
MC/DC0%0/2
$RLIMIT{$k} // ($n =~ /^[0-9]+\z/ ? $n : die("Proc::Spawner: unknown resource '${n}'\n"))
$RLIMIT{$k} ($n =~ /^[0-9]+\z/ ? $n : die("Proc::Spawner: unknown resource '${n}'\n"))
Truth table33%1/3
A // B
A= $RLIMIT{$k}B= ($n =~ /^[0-9]+\z/ ? $n : die("Proc::Spawner: unknown resource '${n}'\n"))
ABresult
1X1
011
000
351 1 ▶ [$r, ref $v ? @$v[0, 1] : ($v, undef)] } sort keys %$h }
Branch: 1 branch
BranchTrueFalseTotal
ref $v ? : 0 1 1
352 329 ▶sub start {
Subroutine start: called CC=10 SCAR=23.2
Pod undocumented
353 329 my ($path, $argv, $envp, $fds, %o) = @_;
354 my @a = ((map [$_ => $o{$_}], grep defined $o{$_}, qw(chdir fchdir)), actions($fds),
355 329 ▶ defined $o{tcsetpgrp} ? [tcsetpgrp => $o{tcsetpgrp}] : ());
Branch: 1 branch
BranchTrueFalseTotal
defined $o{'tcsetpgrp'} ? : 0 329 329
356 my %attr = (sigmask => [signums($o{sigmask})], sigdefault => [signums($o{sigdefault})],
357 329 map +($_ => $o{$_}), grep exists $o{$_}, qw(pgroup setsid resetids sched cgroup search pidfd nice win_priority win_job));
358 328 ▶ $attr{sigignore} = [signums($o{sigignore})] if $o{sigignore};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"sigignore"} 1 327 328
359 328 ▶ $attr{rlimit} = [rlimits($o{rlimit})] if $o{rlimit};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"rlimit"} 1 327 328
360 328 ▶ my $um = defined $o{umask} && umask $o{umask};
Condition66%2/3
defined $o{'umask'} && umask $o{'umask'}
!ll&&!rl&&r
540274
MC/DC50%1/2
defined $o{'umask'} && umask $o{'umask'}
defined $o{'umask'} umask $o{'umask'}
Truth table66%2/3
A && B
A= defined $o{'umask'}B= umask $o{'umask'}
ABresult
0X0
100
111
361 328 my ($pid, $pidfd) = spawn($path, $argv, $envp, \@a, \%attr, $o{unsupported});
362 328 ▶ { local $!; umask $um if defined $o{umask} }
Branch: 1 branch
BranchTrueFalseTotal
if defined $o{"umask"} 274 54 328
363 328 my $how = join ', ', map "$$_[0] " . join('->', @$_[1 .. $#$_]), @a;
364 328 ▶ $pid or return tr_("spawn failed: @$argv: $!"), undef;
Branch: 1 branch
BranchTrueFalseTotal
$pid or return tr_("spawn failed: @${argv}: $!"), undef 324 4 328
365 324 ▶ tr_("spawn $pid: $path [@$argv]", @a ? "; $how" : '');
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 206 118 324
366 324 my $cb = $o{on_exit}; # (Windows: the kept process handle is released once the status is taken, post-0.08)
367 324 ▶ loop()->child($pid, sub { __win_spawn_forget($pid) if $WIN; $cb->(@_) if $cb });
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 2 branches
BranchTrueFalseTotal
if $Proc::Spawner::WIN 0 324 324
if $cb 324 0 324
368 324 ▶ $o{pidfd} && wantarray ? ($pid, $pidfd) : $pid }
Branch: 1 branch
BranchTrueFalseTotal
$o{'pidfd'} && wantarray ? : 1 323 324
Condition66%2/3
$o{"pidfd"} and wantarray
!ll&&!rl&&r
32301
MC/DC50%1/2
$o{"pidfd"} and wantarray
$o{"pidfd"} wantarray
Truth table66%2/3
A and B
A= $o{"pidfd"}B= wantarray
ABresult
0X0
100
111
369  
370 # ------------------------------------------------------------------ the loop: Proc::Spawner::Loop under its old names
371 6228 ▶sub loop { Proc::Spawner::Loop->new }
Subroutine loop: called CC=1 SCAR=0.0
Pod undocumented
372 2763 ▶sub defer { loop()->defer(@_) }
Subroutine defer: called CC=1 SCAR=0.0
Pod undocumented
373 515 ▶sub wait_until { loop()->wait_until(@_) }
Subroutine wait_until: called CC=1 SCAR=0.0
Pod undocumented
374 13 ▶sub poll { loop()->poll }
Subroutine poll: called CC=1 SCAR=0.0
Pod undocumented
375 0 ▶sub turn { loop()->turn(@_) }
Subroutine turn: not called CC=1 SCAR=6.9
Pod undocumented
376 1844 ▶sub on_read { my ($fd, $n, $cb) = @_; loop()->read($fd, $n, $cb) }
Subroutine on_read: called CC=1 SCAR=0.0
Pod undocumented
377 768 ▶sub on_write { my ($fd, $bytes, $cb, $chunk) = @_; loop()->write($fd, $bytes, $cb, chunk => $chunk) }
Subroutine on_write: called CC=1 SCAR=0.0
Pod undocumented
378  
379 488 1;
380  
381 __END__
↑ Summary lib/Proc/Spawner/Graph.pm »