LibTmux/Platform/Linux.pm

filter: Statementstmt 91.1% 41 / 45 Branchbran 54.5% 12 / 22 Conditioncond 46.6% 7 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 70.1% 68 / 97 CC 20 SCAR 22.6
CC
20
Cov
73%
_close_fds_except
13.9
_subreaper
11.5
_signal_handle
4.7
CRAP 9.6
« LibTmux/Codec.pm ↑ Summary LibTmux/Selection.pm »
1 package LibTmux::Platform::Linux;
2 3 ▶use v5.44;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use LibTmux::X;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Errno qw(EBADF);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Linux v6.18: arch/x86/entry/syscalls/syscall_64.tbl and uapi/linux/prctl.h.
9 3 ▶sub _subreaper () {
Subroutine _subreaper: called CC=6 SCAR=24.4
10 LibTmux::X::Unsupported->throw(
11 message =>
12 'supervised execution is qualified only for Linux x86_64 LP64',
13 dispatched => false
14 )
15 unless $^O eq 'linux'
16 && $Config{archname} =~ /\Ax86_64-linux(?:-|\z)/
17 && $Config{ptrsize} == 8
18 3 ▶ && $Config{longsize} == 8;
Branch: 1 branch
BranchTrueFalseTotal
unless $^O eq "linux" and $LibTmux::Platform::Linux::Config{"archname"} =~ /\Ax86_64-linux(?:-|\z)/u and $LibTmux::Platform::Linux::Config{"ptrsize"} == 8 and $LibTmux::Platform::Linux::Config{"longsize"} == 8 0 3 3
Condition33%3/9
$^O eq "linux" and $LibTmux::Platform::Linux::Config{"archname"} =~ /\Ax86_64-linux(?:-|\z)/u and $LibTmux::Platform::Linux::Config{"ptrsize"} == 8 and $LibTmux::Platform::Linux::Config{"longsize"} == 8
!ll&&!rl&&r
003
$^O eq "linux" and $LibTmux::Platform::Linux::Config{"archname"} =~ /\Ax86_64-linux(?:-|\z)/u and $LibTmux::Platform::Linux::Config{"ptrsize"} == 8
!ll&&!rl&&r
003
$^O eq "linux" and $LibTmux::Platform::Linux::Config{"archname"} =~ /\Ax86_64-linux(?:-|\z)/u
!ll&&!rl&&r
003
MC/DC0%0/4
$^O eq "linux" and $LibTmux::Platform::Linux::Config{"archname"} =~ /\Ax86_64-linux(?:-|\z)/u and $LibTmux::Platform::Linux::Config{"ptrsize"} == 8 and $LibTmux::Platform::Linux::Config{"longsize"} == 8
$^O eq "linux" $LibTmux::Platform::Linux::Config{"archname"} =~ /\Ax86_64-linux(?:-|\z)/u $LibTmux::Platform::Linux::Config{"ptrsize"} == 8 $LibTmux::Platform::Linux::Config{"longsize"} == 8
Truth table20%1/5
A and B and C and D
A= $^O eq "linux"B= $LibTmux::Platform::Linux::Config{"archname"} =~ /\Ax86_64-linux(?:-|\z)/uC= $LibTmux::Platform::Linux::Config{"ptrsize"} == 8D= $LibTmux::Platform::Linux::Config{"longsize"} == 8
ABCDresult
0XXX0
10XX0
110X0
11100
11111
19 3 ▶ LibTmux::X::Transport->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless syscall(157, 36, 1, 0, 0, 0) == 0 0 3 3
20 message => "enable isolated child subreaper: $!",
21 dispatched => false
22 ) unless syscall(157, 36, 1, 0, 0, 0) == 0;
23 }
24  
25 3 ▶sub _signal_handle (@signals) {
Subroutine _signal_handle: called CC=4 SCAR=15.5
26  
27 # Called only inside the ABI-qualified private supervisor. The kernel
28 # mask has one 64-bit word; libc's larger sigset_t is not the syscall ABI.
29 3 my $bits = 0;
30 3 $bits |= 1 << ($_ - 1) for @signals;
31 3 my $mask = pack('Q<', $bits);
32  
33 # Linux v6.18 asm-generic/fcntl.h: NONBLOCK | CLOEXEC, on this ABI.
34 3 my $fd = syscall(289, -1, $mask, length($mask), 00004000 | 02000000);
35 3 ▶ LibTmux::X::Transport->throw(
Branch: 1 branch
BranchTrueFalseTotal
if $fd < 0 0 3 3
36 message => "create supervisor signal descriptor: $!",
37 dispatched => false
38 ) if $fd < 0;
39 3 ▶ unless (open my $handle, '<&=', $fd) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $handle, '<&=', $fd) { } 3 0 3
40 0 my $error = "$!";
41 0 POSIX::close($fd);
42 0 LibTmux::X::Transport->throw(
43 message => "open supervisor signal descriptor: $error",
44 dispatched => false
45 );
46 }
47 3 else { return $handle }
48 }
49  
50 6 ▶sub _close_fds_except (@handles) {
Subroutine _close_fds_except: called CC=12 SCAR=26.3
51 6 my %keep = map { $_ => true } (0, 1, 2);
52 6 for my $handle (@handles) {
53 45 my $fd = fileno($handle);
54 45 ▶ LibTmux::X::Transport->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fd 0 45 45
55 message => 'missing owned protocol descriptor',
56 dispatched => false
57 ) unless defined $fd;
58 45 $keep{$fd} = true;
59 }
60 6 ▶ opendir my $directory,
Branch: 1 branch
BranchTrueFalseTotal
opendir my $directory, "/proc/self/fd" or 6 0 6
61 '/proc/self/fd'
62 or LibTmux::X::Transport->throw(
63 message => "enumerate inherited descriptors: $!",
64 dispatched => false
65 );
66 6 $! = 0;
67 6 my @fds = grep { /\A[0-9]+\z/ } readdir $directory;
68 6 ▶ my $read_error = $! ? "$!" : undef;
Branch: 1 branch
BranchTrueFalseTotal
$! ? : 0 6 6
69 6 ▶ closedir $directory
Branch: 1 branch
BranchTrueFalseTotal
closedir $directory or 6 0 6
70 or LibTmux::X::Transport->throw(
71 message => "close descriptor directory: $!",
72 dispatched => false
73 );
74 6 ▶ LibTmux::X::Transport->throw(
Branch: 1 branch
BranchTrueFalseTotal
if defined $read_error 0 6 6
75 message => "read inherited descriptors: $read_error",
76 dispatched => false
77 ) if defined $read_error;
78 6 for my $fd (@fds) {
79 91 ▶ next if $keep{$fd};
Branch: 1 branch
BranchTrueFalseTotal
if $keep{$fd} 63 28 91
80 28 my $closed = POSIX::close($fd);
81  
82 # The enumeration descriptor is already closed. Linux also releases
83 # descriptors on close errors, so retrying could close a reused one.
84 28 ▶ next if defined($closed) && $closed == 0 || $! == EBADF;
Branch: 1 branch
BranchTrueFalseTotal
if defined $closed and $closed == 0 or $! == 9 28 0 28
Condition66%4/6
defined $closed and $closed == 0 or $! == 9
l!l&&r!l&&!r
2260
defined $closed and $closed == 0
!ll&&!rl&&r
6022
MC/DC0%0/3
defined $closed and $closed == 0 or $! == 9
defined $closed $closed == 0 $! == 9
Truth table40%2/5
A and B or C
A= defined $closedB= $closed == 0C= $! == 9
ABCresult
11X1
0X11
1011
0X00
1000
85 0 LibTmux::X::Transport->throw(
86 message => "close inherited descriptor $fd: $!",
87 dispatched => false
88 );
89 }
90 }
91 3 1;
« LibTmux/Codec.pm ↑ Summary LibTmux/Selection.pm »