blib/lib/Langertha/Holmgang/Sim/Linux.pm

filter: Statementstmt 87.6% 6947 / 7925 Branchbran 69.6% 4119 / 5918 Conditioncond 57.4% 3296 / 5737 MC/DCmcdc 29.6% 881 / 2974 Subroutinesub 91.0% 468 / 514 Podpod 100% 11 / 11 totaltotal 68.1% 15722 / 23079 CC 5505 SCAR 50.8
CC
5505
Cov
73%
_systemctl
1192.3
_curl
838.8
_command
669.2
CRAP 160.4
« blib/lib/Langertha/Holmgang/Shell/Filter.pm ↑ Summary blib/lib/Langertha/Holmgang/Structure.pm »
1 package Langertha::Holmgang::Sim::Linux;
2 # ABSTRACT: The simulator of device type linux — a Debian shell with ip, nft, wg, sysctl, systemctl, nmcli, files
3  
4 82 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 82 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 82 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 82 ▶use Langertha::Holmgang::Shell ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 82 ▶use Langertha::Holmgang::Shell::Filter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 82 ▶use Langertha::Holmgang::Sim::Linux::Nft ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 82 ▶use Langertha::Holmgang::Sim::Linux::Calendar ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 82 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 82 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 82 ▶use Module::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 82 with 'Langertha::Holmgang::Role::Simulator';
17  
18 82 our $VERSION = '0.001';
19  
20  
21 # --- IPv4 ------------------------------------------------------------------------
22  
23 588 ▶sub _ip2n {
Subroutine _ip2n: called CC=4 SCAR=14.0
24 588 my ($ip) = @_;
25 588 ▶ return undef unless defined $ip && $ip =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip and $ip =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/ 6 582 588
Condition66%2/3
defined $ip and $ip =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/
!ll&&!rl&&r
06582
MC/DC50%1/2
defined $ip and $ip =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/
defined $ip $ip =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/
Truth table66%2/3
A and B
A= defined $ipB= $ip =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/
ABresult
0X0
100
111
26 582 ▶ return undef if grep { $_ > 255 } $1, $2, $3, $4;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ > 255;} $1, $2, $3, $4 0 582 582
27 582 return ( ( $1 * 256 + $2 ) * 256 + $3 ) * 256 + $4;
28 }
29  
30 107 ▶sub _n2ip { my ($n) = @_; return join '.', map { ( $n >> ( 8 * $_ ) ) & 255 } 3, 2, 1, 0 }
Subroutine _n2ip: called CC=1 SCAR=0.0
31  
32 # "10.1.0.0/24" | "default" | "10.1.0.5" -> ( netz, laenge ) oder ()
33 340 ▶sub _prefix {
Subroutine _prefix: called CC=8 SCAR=22.6
34 340 my ($p) = @_;
35 340 ▶ return ( 0, 0 ) if $p eq 'default' || $p eq '0.0.0.0/0';
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "default" or $p eq "0.0.0.0/0" 8 332 340
Condition66%2/3
$p eq "default" or $p eq "0.0.0.0/0"
l!l&&r!l&&!r
80332
MC/DC50%1/2
$p eq "default" or $p eq "0.0.0.0/0"
$p eq "default" $p eq "0.0.0.0/0"
Truth table66%2/3
A or B
A= $p eq "default"B= $p eq "0.0.0.0/0"
ABresult
1X1
011
000
36 332 ▶ my ( $ip, $len ) = $p =~ m{\A([\d.]+)(?:/(\d{1,2}))?\z} or return ();
Branch: 1 branch
BranchTrueFalseTotal
() = $p =~ m[\A([\d.]+)(?:/(\d{1,2}))?\z] or return () 332 0 332
37 332 ▶ $len //= 32;
Condition50%1/2
$len //= 32
l!l
3320
MC/DC0%0/1
$len //= 32
$len
Truth table50%1/2
A
A= $len
Aresult
11
00
38 332 my $n = _ip2n($ip);
39 332 ▶ return () unless defined $n && $len <= 32;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n and $len <= 32 0 332 332
Condition33%1/3
defined $n and $len <= 32
!ll&&!rl&&r
00332
MC/DC0%0/2
defined $n and $len <= 32
defined $n $len <= 32
Truth table33%1/3
A and B
A= defined $nB= $len <= 32
ABresult
0X0
100
111
40 332 ▶ my $mask = $len ? ( 0xFFFFFFFF << ( 32 - $len ) ) & 0xFFFFFFFF : 0;
Branch: 1 branch
BranchTrueFalseTotal
$len ? : 332 0 332
41 332 return ( $n & $mask, $len, $n );
42 }
43  
44 209 ▶sub _in {
Subroutine _in: called CC=5 SCAR=16.3
45 209 my ( $ip, $pfx ) = @_;
46 209 ▶ my $n = _ip2n($ip) // return 0;
Condition50%1/2
_ip2n($ip) // (return 0)
l!l
2090
MC/DC0%0/1
_ip2n($ip) // (return 0)
_ip2n($ip)
Truth table50%1/2
A
A= _ip2n($ip)
Aresult
11
00
47 209 ▶ my ( $net, $len ) = _prefix($pfx) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
() = _prefix($pfx) or return 0 209 0 209
48 209 ▶ my $mask = $len ? ( 0xFFFFFFFF << ( 32 - $len ) ) & 0xFFFFFFFF : 0;
Branch: 1 branch
BranchTrueFalseTotal
$len ? : 205 4 209
49 209 ▶ return ( $n & $mask ) == $net ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($n & $mask) == $net ? : 186 23 209
50 }
51  
52 119 ▶sub _canon_dst {
Subroutine _canon_dst: called CC=6 SCAR=18.3
53 119 my ($p) = @_;
54 119 ▶ return 'default' if $p eq 'default' || $p eq '0.0.0.0/0';
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "default" or $p eq "0.0.0.0/0" 19 100 119
Condition66%2/3
$p eq "default" or $p eq "0.0.0.0/0"
l!l&&r!l&&!r
190100
MC/DC50%1/2
$p eq "default" or $p eq "0.0.0.0/0"
$p eq "default" $p eq "0.0.0.0/0"
Truth table66%2/3
A or B
A= $p eq "default"B= $p eq "0.0.0.0/0"
ABresult
1X1
011
000
55 100 ▶ return $p if $p =~ /:/; # IPv6: nur speichern
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ /:/ 0 100 100
56 100 ▶ my ( $net, $len ) = _prefix($p) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = _prefix($p) or return undef 100 0 100
57 100 ▶ return $len == 32 ? _n2ip($net) : _n2ip($net) . "/$len";
Branch: 1 branch
BranchTrueFalseTotal
$len == 32 ? : 48 52 100
58 }
59  
60 # --- Ablauf ------------------------------------------------------------------------
61  
62 82 our @GAPS;
63  
64 # Aufrufkontext (fuer Dienste, die andere Geraete beruehren) und Login-Benutzer von su
65 82 our ( $CTX, $LOGIN_USER );
66  
67 # Aktuelles Verzeichnis (cd, je Aufruf frisch: eine SSH-Sitzung beginnt in /root) und
68 # Umgebung eines einzelnen Befehls (NAME=wert befehl …)
69 82 our ( $CWD_DIR, $SHENV );
70 82 our %EXT_NEED; # Befehl eines Zusatz-Simulators (Code-Referenz) => Pakete im Zustand, ohne die er fehlt (which)
71  
72 82 our $AS_USER;
73 82 our $IN_TIMEOUT; # unter timeout: eine haengende Verbindung endet still mit Status 124
74 82 our $START_RC; # $? zu Beginn einer Befehlszeile (Kette der Welt mit Beobachtungen)
75 82 our $ERRNULL; # innerhalb eines Glieds: { programm => 1 } mit 2>/dev/null (_errnull_progs)
76 82 our $SH; # Shell des laufenden Aufrufs: { vars, rc, args, arg0, ctl, errexit, defaults }
77 82 our $EXIT; # Status der zuletzt beendeten (Sub-)Shell, fuer $? nach bash -c / Skript
78  
79 # Gibt es im Zustand Webserver, Container, Anwendungen oder Proben
80 # (Langertha::Holmgang::Sim::Linux::Http)? Nur dann laufen dessen Haken.
81 2357 ▶sub _web_world {
Subroutine _web_world: called CC=9 SCAR=22.4
82 2357 my ($ctx) = @_;
83 2357 ▶ my $s = $ctx && $ctx->{state};
Condition33%1/3
$ctx && $$ctx{'state'}
!ll&&!rl&&r
002357
MC/DC0%0/2
$ctx && $$ctx{'state'}
$ctx $$ctx{'state'}
Truth table33%1/3
A && B
A= $ctxB= $$ctx{'state'}
ABresult
0X0
100
111
84 2357 ▶ return 0 unless ref $s eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $s eq "HASH" 0 2357 2357
85 2357 ▶ return 0 unless grep { ref $_ eq 'HASH' && ( $_->{nginx} || $_->{docker} || $_->{http} || $_->{probes} || $_->{pki} ) } values %$s;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {ref $_ eq "HASH" and $$_{"nginx"} || $$_{"docker"} || $$_{"http"} || $$_{"probes"} || $$_{"pki"};} values %$s 2178 179 2357
Condition86%13/15
ref $_ eq 'HASH' && ($$_{'nginx'} || $$_{'docker'} || $$_{'http'} || $$_{'probes'} || $$_{'pki'})
!ll&&!rl&&r
02722343
$$_{"nginx"} or $$_{"docker"} or $$_{"http"} or $$_{"probes"} or $$_{"pki"}
l!l&&r!l&&!r
34302722
$$_{"nginx"} or $$_{"docker"} or $$_{"http"} or $$_{"probes"}
l!l&&r!l&&!r
2431002722
$$_{"nginx"} or $$_{"docker"} or $$_{"http"}
l!l&&r!l&&!r
179642822
$$_{"nginx"} or $$_{"docker"}
l!l&&r!l&&!r
100792886
MC/DC66%4/6
ref $_ eq 'HASH' && ($$_{'nginx'} || $$_{'docker'} || $$_{'http'} || $$_{'probes'} || $$_{'pki'})
ref $_ eq 'HASH' $$_{"nginx"} $$_{"docker"} $$_{"http"} $$_{"probes"} $$_{"pki"}
Truth table71%5/7
A && B or C or D or E or F
A= ref $_ eq 'HASH'B= $$_{"nginx"}C= $$_{"docker"}D= $$_{"http"}E= $$_{"probes"}F= $$_{"pki"}
ABCDEFresult
0XXXXX0
1000000
11XXXX1
101XXX1
1001XX1
10001X1
1000011
86 179 _part('Http');
87 179 return 1;
88 }
89  
90 # Werkzeuge der Server-Suiten: nur auf Geraeten mit passendem Zustand
91 # installiert (sonst bleibt es beim Verhalten ohne sie).
92 7042 ▶sub _web_cmd {
Subroutine _web_cmd: called CC=18 SCAR=29.0
93 7042 my ( $dev, $cmd ) = @_;
94 7042 ▶ return undef unless ref $dev eq 'HASH' && defined $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $dev eq "HASH" and defined $cmd 0 7042 7042
Condition33%1/3
ref $dev eq "HASH" and defined $cmd
!ll&&!rl&&r
007042
MC/DC0%0/2
ref $dev eq "HASH" and defined $cmd
ref $dev eq "HASH" defined $cmd
Truth table33%1/3
A and B
A= ref $dev eq "HASH"B= defined $cmd
ABresult
0X0
100
111
95 7042 ▶ my $web = $dev->{nginx} || $dev->{docker} || $dev->{http} || $dev->{probes} || $dev->{pki};
Condition91%11/12
$$dev{'nginx'} || $$dev{'docker'} || $$dev{'http'} || $$dev{'probes'} || $$dev{'pki'}
l!l&&r!l&&!r
20406838
$$dev{"nginx"} or $$dev{"docker"} or $$dev{"http"} or $$dev{"probes"}
l!l&&r!l&&!r
173316838
$$dev{"nginx"} or $$dev{"docker"} or $$dev{"http"}
l!l&&r!l&&!r
17216869
$$dev{"nginx"} or $$dev{"docker"}
l!l&&r!l&&!r
531196870
MC/DC80%4/5
$$dev{'nginx'} || $$dev{'docker'} || $$dev{'http'} || $$dev{'probes'} || $$dev{'pki'}
$$dev{"nginx"} $$dev{"docker"} $$dev{"http"} $$dev{"probes"} $$dev{'pki'}
Truth table83%5/6
A or B or C or D || E
A= $$dev{"nginx"}B= $$dev{"docker"}C= $$dev{"http"}D= $$dev{"probes"}E= $$dev{'pki'}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
96 7042 ▶ if ( $cmd eq 'curl' && $web ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "curl" and $web) 26 7016 7042
Condition100%3/3
$cmd eq "curl" and $web
!ll&&!rl&&r
70021426
MC/DC100%2/2
$cmd eq "curl" and $web
$cmd eq "curl" $web
Truth table100%3/3
A and B
A= $cmd eq "curl"B= $web
ABresult
0X0
100
111
97 26 _part('Http');
98 26 return \&Langertha::Holmgang::Sim::Linux::Http::curl;
99 }
100 7016 ▶ if ( $cmd eq 'docker' && $dev->{docker} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "docker" and $$dev{"docker"}) 57 6959 7016
Condition100%3/3
$cmd eq "docker" and $$dev{"docker"}
!ll&&!rl&&r
69481157
MC/DC100%2/2
$cmd eq "docker" and $$dev{"docker"}
$cmd eq "docker" $$dev{"docker"}
Truth table100%3/3
A and B
A= $cmd eq "docker"B= $$dev{"docker"}
ABresult
0X0
100
111
101 57 _part('Docker');
102 57 return \&Langertha::Holmgang::Sim::Linux::Docker::docker;
103 }
104 6959 ▶ if ( $cmd eq 'nginx' && $dev->{nginx} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "nginx" and $$dev{"nginx"}) 13 6946 6959
Condition100%3/3
$cmd eq "nginx" and $$dev{"nginx"}
!ll&&!rl&&r
69291713
MC/DC100%2/2
$cmd eq "nginx" and $$dev{"nginx"}
$cmd eq "nginx" $$dev{"nginx"}
Truth table100%3/3
A and B
A= $cmd eq "nginx"B= $$dev{"nginx"}
ABresult
0X0
100
111
105 13 _part('Nginx');
106 13 return \&Langertha::Holmgang::Sim::Linux::Nginx::nginx;
107 }
108 6946 ▶ if ( ( $cmd eq 'openssl' || $cmd eq 'update-ca-certificates' ) && ( $dev->{pki} || $dev->{nginx} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "openssl" || $cmd eq "update-ca-certificates" and $$dev{"pki"} || $$dev{"nginx"}) 25 6921 6946
Condition88%8/9
$cmd eq "openssl" || $cmd eq "update-ca-certificates" and $$dev{"pki"} || $$dev{"nginx"}
!ll&&!rl&&r
69091225
$cmd eq "openssl" or $cmd eq "update-ca-certificates"
l!l&&r!l&&!r
3346909
$$dev{"pki"} or $$dev{"nginx"}
l!l&&r!l&&!r
25012
MC/DC75%3/4
$cmd eq "openssl" || $cmd eq "update-ca-certificates" and $$dev{"pki"} || $$dev{"nginx"}
$cmd eq "openssl" $cmd eq "update-ca-certificates" $$dev{"pki"} $$dev{"nginx"}
Truth table57%4/7
A or B and C or D
A= $cmd eq "openssl"B= $cmd eq "update-ca-certificates"C= $$dev{"pki"}D= $$dev{"nginx"}
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
109 25 _part('Pki');
110 25 ▶ return $cmd eq 'openssl' ? \&Langertha::Holmgang::Sim::Linux::Pki::openssl : \&Langertha::Holmgang::Sim::Linux::Pki::update_ca_certificates;
Branch: 1 branch
BranchTrueFalseTotal
$cmd eq 'openssl' ? : 21 4 25
111 }
112 6921 return undef;
113 }
114  
115 # Start, Neustart, reload eines Dienstes mit eigener Simulation (nginx):
116 # Fehlertext oder undef.
117 100 ▶sub _svc_hook {
Subroutine _svc_hook: called CC=3 SCAR=11.0
118 100 my ( $dev, $n, $verb ) = @_;
119 100 ▶ return undef unless $n eq 'nginx' && $dev->{nginx};
Branch: 1 branch
BranchTrueFalseTotal
unless $n eq "nginx" and $$dev{"nginx"} 88 12 100
Condition100%3/3
$n eq "nginx" and $$dev{"nginx"}
!ll&&!rl&&r
86212
MC/DC100%2/2
$n eq "nginx" and $$dev{"nginx"}
$n eq "nginx" $$dev{"nginx"}
Truth table100%3/3
A and B
A= $n eq "nginx"B= $$dev{"nginx"}
ABresult
0X0
100
111
120 12 _part('Nginx');
121 12 return Langertha::Holmgang::Sim::Linux::Nginx::service( $dev, $verb, $CTX );
122 }
123  
124  
125 7 ▶sub cwd_path { return _absp( $_[0] ) }
Subroutine cwd_path: called CC=1 SCAR=0.0
Pod documented
126  
127  
128 47 ▶sub shell_env {
Subroutine shell_env: called CC=4 SCAR=14.6
Pod documented
129 0 ▶ return ( ( map { $_ => $SH->{vars}{$_} } grep { defined $SH->{vars}{$_} } keys %{ ( $SH || {} )->{exported} || {} } ), %{ $SHENV || {} } );
Condition83%5/6
($Langertha::Holmgang::Sim::Linux::SH || {})->{'exported'} || {}
l!l
047
$Langertha::Holmgang::Sim::Linux::SH || {}
l!l
3017
$Langertha::Holmgang::Sim::Linux::SHENV || {}
l!l
3017
MC/DC100%1/1
($Langertha::Holmgang::Sim::Linux::SH || {})->{'exported'} || {}
$Langertha::Holmgang::Sim::Linux::SH
MC/DC100%1/1
$Langertha::Holmgang::Sim::Linux::SHENV || {}
$Langertha::Holmgang::Sim::Linux::SHENV
Truth table100%2/2
A
A= $Langertha::Holmgang::Sim::Linux::SH
Aresult
11
00
Truth table100%2/2
A
A= $Langertha::Holmgang::Sim::Linux::SHENV
Aresult
11
00
130 }
131  
132 2265 ▶sub _new_shell { my (%o) = @_; return { vars => {}, rc => 0, args => [], %o } }
Subroutine _new_shell: called CC=1 SCAR=0.0
133  
134 # Skript bzw. bash -c in einer neuen Shell; ihr Exit-Status wird $? des Aufrufers
135 26 ▶sub _run_shell {
Subroutine _run_shell: called CC=4 SCAR=14.0
136 26 my ( $dev, $text, $ctx, %o ) = @_;
137 26 my @r = __PACKAGE__->_run_inner( $dev, $text, $ctx, _new_shell(%o) );
138 26 ▶ $SH->{code} = $EXIT if $SH && !$r[1] && $EXIT;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH and not $r[1] and $Langertha::Holmgang::Sim::Linux::EXIT 14 12 26
Condition66%4/6
$Langertha::Holmgang::Sim::Linux::SH and not $r[1] and $Langertha::Holmgang::Sim::Linux::EXIT
!ll&&!rl&&r
12014
$Langertha::Holmgang::Sim::Linux::SH and not $r[1]
!ll&&!rl&&r
01214
MC/DC33%1/3
$Langertha::Holmgang::Sim::Linux::SH and not $r[1] and $Langertha::Holmgang::Sim::Linux::EXIT
$Langertha::Holmgang::Sim::Linux::SH not $r[1] $Langertha::Holmgang::Sim::Linux::EXIT
Truth table50%2/4
A and not(B) and C
A= $Langertha::Holmgang::Sim::Linux::SHB= not $r[1]C= $Langertha::Holmgang::Sim::Linux::EXIT
ABCresult
0XX0
10X0
1100
1111
139 26 return @r;
140 }
141  
142 # --- Plugin contract ---------------------------------------------------------------
143  
144 # parts this call needed and could not load (see _part); localised per call
145 82 our @MISSING;
146  
147 145 ▶sub device_type { 'linux' }
Subroutine device_type: called CC=1 SCAR=0.0
Pod documented
148  
149  
150 2198 ▶sub run_command {
Subroutine run_command: called CC=5 SCAR=16.1
Pod documented
151 2198 my ( $self, $dev, $line, $ctx ) = @_;
152 2198 local $EXIT;
153 2198 ▶ my @r = $self->_guarded( sub { $self->run( $dev, $line, $ctx ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
154 2198 ▶ if ( !$r[1] && $EXIT && $EXIT != 1 ) { $#r = 2 if @r < 3; $r[3] = $EXIT }
Branch: 2 branches
BranchTrueFalseTotal
if (not $r[1] and $Langertha::Holmgang::Sim::Linux::EXIT and $Langertha::Holmgang::Sim::Linux::EXIT != 1) 11 2187 2198
if @r < 3 2 9 11
Condition100%6/6
not $r[1] and $Langertha::Holmgang::Sim::Linux::EXIT and $Langertha::Holmgang::Sim::Linux::EXIT != 1
!ll&&!rl&&r
178440311
not $r[1] and $Langertha::Holmgang::Sim::Linux::EXIT
!ll&&!rl&&r
17786414
MC/DC100%3/3
not $r[1] and $Langertha::Holmgang::Sim::Linux::EXIT and $Langertha::Holmgang::Sim::Linux::EXIT != 1
not $r[1] $Langertha::Holmgang::Sim::Linux::EXIT $Langertha::Holmgang::Sim::Linux::EXIT != 1
Truth table100%4/4
not(A) and B and C
A= not $r[1]B= $Langertha::Holmgang::Sim::Linux::EXITC= $Langertha::Holmgang::Sim::Linux::EXIT != 1
ABCresult
0XX0
10X0
1100
1111
155 2198 return @r;
156 }
157  
158  
159 163 ▶sub write_file {
Subroutine write_file: called CC=1 SCAR=0.0
Pod documented
160 163 my ( $self, $dev, $path, $content, $ctx ) = @_;
161 163 ▶ return $self->_guarded( sub { $self->write( $dev, $path, $content, $ctx ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
162 }
163  
164  
165 11 ▶sub packet_verdict {
Subroutine packet_verdict: called CC=3 SCAR=11.0
Pod documented
166 11 my ( $self, $dev, $pkt, $boot ) = @_;
167 11 local @MISSING;
168 11 ▶ return Langertha::Holmgang::Sim::Linux::Nft::verdict( $dev, $pkt ) unless $boot;
Branch: 1 branch
BranchTrueFalseTotal
unless $boot 7 4 11
169 4 ▶ return Langertha::Holmgang::Sim::Linux::Nft::boot_verdict( $dev, $pkt, $boot =~ m{\A/} ? $boot : undef );
Branch: 1 branch
BranchTrueFalseTotal
$boot =~ m[\A/] ? : 4 0 4
170 }
171  
172  
173 3 ▶sub login_check {
Subroutine login_check: called CC=1 SCAR=0.0
Pod documented
174 3 my ( $self, $dev, $attempt, $host ) = @_;
175 3 local @MISSING;
176 3 return _part('SshAccess')->can('check')->( $dev, $attempt, $host );
177 }
178  
179  
180 2361 ▶sub _guarded {
Subroutine _guarded: called CC=3 SCAR=11.0
181 2361 my ( $self, $code ) = @_;
182 2361 local @MISSING;
183 2361 my @r;
184 2361 my $ok = eval { @r = $code->(); 1 };
185 2361 ▶ if ( @MISSING ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@Langertha::Holmgang::Sim::Linux::MISSING) 2 2359 2361
186 2 my %seen;
187 2 return ( '', 0, join( '; ', map { $_.' is not installed' } grep { !$seen{$_}++ } @MISSING ) );
188 }
189 2359 ▶ die $@ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 2359 2359
190 2359 return @r;
191 }
192  
193 # load a module the first time it is needed; a module that is not installed is noted in
194 # @MISSING and ends the call (_guarded), a module that does not compile dies as it is
195 1632 ▶sub _need {
Subroutine _need: called CC=4 SCAR=13.9
196 1632 my ( $class ) = @_;
197 1632 my $file = Module::Runtime::module_notional_filename($class);
198 1632 ▶ return $class if $INC{$file};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{$file} 1607 25 1632
199 25 ▶ return $class if eval { Module::Runtime::require_module($class); 1 };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { &Module::Runtime::require_module($class); 1 } } 21 4 25
200 4 my $err = $@;
201 4 ▶ die $err unless $err =~ /\ACan't locate \Q$file\E in \@INC/;
Branch: 1 branch
BranchTrueFalseTotal
unless $err =~ /\ACan't locate \Q$file\E in \@INC/ 0 4 4
202 4 push @MISSING, $class;
203 4 die $class.' is not installed'."\n";
204 }
205  
206 1610 ▶sub _part { return _need( __PACKAGE__.'::'.$_[0] ) }
Subroutine _part: called CC=1 SCAR=0.0
207  
208 # expectations and templates belong to the World (k2); only a service whose state needs
209 # them loads them
210 19 ▶sub _condition {
Subroutine _condition: called CC=1 SCAR=0.0
211 19 my ( $data, $c ) = @_;
212 19 return _need('Langertha::Holmgang::Expectation')->can('condition')->( $data, $c );
213 }
214  
215 3 ▶sub _render {
Subroutine _render: called CC=3 SCAR=11.4
216 3 my ( $tmpl, $state ) = @_;
217 3 ▶ return 'ok' unless defined $tmpl;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tmpl 0 3 3
218 3 ▶ return $tmpl unless $tmpl =~ /<:|^\s*:/m;
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpl =~ /<:|^\s*:/m 0 3 3
219 3 return _need('Langertha::Holmgang::Template')->can('render')->( $tmpl, $state, {} );
220 }
221  
222 82 my $CLONE_JSON = JSON::MaybeXS->new( utf8 => 0, canonical => 1, allow_nonref => 1 );
223  
224  
225 34 ▶sub clone_state { my ( $d ) = @_; return $CLONE_JSON->decode( $CLONE_JSON->encode($d) ) }
Subroutine clone_state: called CC=1 SCAR=0.0
Pod documented
226  
227  
228 2202 ▶sub run {
Subroutine run: called CC=11 SCAR=24.0
Pod documented
229 2202 my ( $class, $dev, $line, $ctx ) = @_;
230 2202 ▶ _ssh_access()->can('remember')->($dev) if ref $dev->{files} eq 'HASH' && exists $dev->{files}{'/etc/ssh/sshd_config'};
Branch: 1 branch
BranchTrueFalseTotal
if ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"} 173 2029 2202
Condition100%3/3
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"}
!ll&&!rl&&r
921937173
MC/DC100%2/2
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"}
ref $$dev{"files"} eq "HASH" exists $$dev{"files"}{"/etc/ssh/sshd_config"}
Truth table100%3/3
A and B
A= ref $$dev{"files"} eq "HASH"B= exists $$dev{"files"}{"/etc/ssh/sshd_config"}
ABresult
0X0
100
111
231 2202 ▶ if ( my $cut = _locked_out( $dev, $ctx ) ) { return ( $cut, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $cut = _locked_out($dev, $ctx)) 2 2200 2202
232 2200 ▶ if ( $dev->{ssh_login} ) { my $no = _sshd_sim()->can('login_denied')->( $dev, $ctx->{host} ); return ( $no, 0 ) if defined $no }
Branch: 2 branches
BranchTrueFalseTotal
if ($$dev{"ssh_login"}) 145 2055 2200
if defined $no 4 141 145
233 2196 local @GAPS;
234 2196 local $CTX = $ctx;
235 2196 local $CWD_DIR;
236 2196 ▶ local $Langertha::Holmgang::Sim::Linux::Calendar::LOCAL = ref $dev eq 'HASH' && $dev->{timezone} ? $dev->{timezone} : 'Europe/Berlin';
Branch: 1 branch
BranchTrueFalseTotal
ref $dev eq 'HASH' && $$dev{'timezone'} ? : 1 2195 2196
Condition66%2/3
ref $dev eq "HASH" and $$dev{"timezone"}
!ll&&!rl&&r
021951
MC/DC50%1/2
ref $dev eq "HASH" and $$dev{"timezone"}
ref $dev eq "HASH" $$dev{"timezone"}
Truth table66%2/3
A and B
A= ref $dev eq "HASH"B= $$dev{"timezone"}
ABresult
0X0
100
111
237 # $? aus dem vorigen Glied einer Kette, die die Welt Glied fuer Glied ausfuehrt (_rc)
238 2196 ▶ local $START_RC = ref $dev eq 'HASH' ? delete $dev->{_rc} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $dev eq 'HASH' ? : 2196 0 2196
239 2196 my $web = _web_world($ctx);
240 2196 ▶ Langertha::Holmgang::Sim::Linux::Http::before( $ctx->{state} ) if $web;
Branch: 1 branch
BranchTrueFalseTotal
if $web 158 2038 2196
241 2196 my @r = $class->_run_inner( $dev, $line, $ctx );
242 2196 ▶ Langertha::Holmgang::Sim::Linux::Http::after( $ctx->{state} ) if $web;
Branch: 1 branch
BranchTrueFalseTotal
if $web 158 2038 2196
243 2196 return @r;
244 }
245  
246 # trap [--] BEFEHLE SIGNAL… | trap - SIGNAL… | trap -p | trap -l: gemerkt je Shell; EXIT
247 # (bzw. 0) laeuft am Ende der Shell (_run_inner), Signale kommen in der Simulation nicht vor
248 9 ▶sub _trap_cmd {
Subroutine _trap_cmd: called CC=12 SCAR=26.2
249 9 my @a = @_;
250 9 my %name = map { $_ => $_ } qw( EXIT HUP INT QUIT TERM ERR DEBUG RETURN USR1 USR2 PIPE ALRM CHLD );
251 9 ▶ my $sig = sub { my $s = uc shift; $s =~ s/\ASIG//; return $s eq '0' ? 'EXIT' : $s =~ /\A\d+\z/ ? { 1 => 'HUP', 2 => 'INT', 3 => 'QUIT', 15 => 'TERM' }->{$s} : $name{$s} };
Subroutine __ANON__: called CC=3 SCAR=11.4
Branch: 2 branches
BranchTrueFalseTotal
$s eq '0' ? : 0 11 11
$s =~ /\A\d+\z/ ? : 0 11 11
252 9 ▶ if ( !@a || $a[0] eq '-p' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @a or $a[0] eq "-p") 1 8 9
Condition66%2/3
not @a or $a[0] eq "-p"
l!l&&r!l&&!r
018
MC/DC50%1/2
not @a or $a[0] eq "-p"
not @a $a[0] eq "-p"
Truth table66%2/3
not(A) or B
A= not @aB= $a[0] eq "-p"
ABresult
1X1
011
000
253 1 ▶ my $t = $SH->{traps} || {};
Condition50%1/2
$$Langertha::Holmgang::Sim::Linux::SH{'traps'} || {}
l!l
10
MC/DC0%0/1
$$Langertha::Holmgang::Sim::Linux::SH{'traps'} || {}
$$Langertha::Holmgang::Sim::Linux::SH{'traps'}
Truth table50%1/2
A
A= $$Langertha::Holmgang::Sim::Linux::SH{'traps'}
Aresult
11
00
254 1 ▶ return ( join( "\n", map { "trap -- '" . ( $t->{$_} =~ s/'/'\\''/gr ) . "' " . ( $_ eq 'EXIT' ? 'EXIT' : "SIG$_" ) } sort { ( $a eq 'EXIT' ) <=> ( $b eq 'EXIT' ) || $a cmp $b } keys %$t ), 1 );
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'EXIT' ? : 0 2 2
Condition33%1/3
($a eq 'EXIT') <=> ($b eq 'EXIT') || $a cmp $b
l!l&&r!l&&!r
010
MC/DC0%0/2
($a eq 'EXIT') <=> ($b eq 'EXIT') || $a cmp $b
($a eq 'EXIT') <=> ($b eq 'EXIT') $a cmp $b
Truth table33%1/3
A || B
A= ($a eq 'EXIT') <=> ($b eq 'EXIT')B= $a cmp $b
ABresult
1X1
011
000
255 }
256 8 ▶ return ( ' 1) SIGHUP 2) SIGINT 3) SIGQUIT 9) SIGKILL 15) SIGTERM', 1 ) if $a[0] eq '-l';
Branch: 1 branch
BranchTrueFalseTotal
if $a[0] eq "-l" 0 8 8
257 8 ▶ shift @a if $a[0] eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if $a[0] eq "--" 0 8 8
258 8 my $act = shift @a;
259 8 ▶ return ( '', 1 ) unless @a; # trap ARG ohne Signal: nichts zu tun (selten)
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 8 8
260 8 for my $s (@a) {
261 11 ▶ my $n = $sig->($s) // return ( "bash: trap: $s: invalid signal specification", 0 );
Condition50%1/2
&$sig($s) // (return "bash: trap: ${s}: invalid signal specification", 0)
l!l
110
MC/DC0%0/1
&$sig($s) // (return "bash: trap: ${s}: invalid signal specification", 0)
&$sig($s)
Truth table50%1/2
A
A= &$sig($s)
Aresult
11
00
262 11 ▶ if ( $act eq '-' ) { delete $SH->{traps}{$n} }
Branch: 1 branch
BranchTrueFalseTotal
if ($act eq '-') { } 1 10 11
263 10 else { $SH->{traps}{$n} = $act }
264 }
265 8 return ( '', 1 );
266 }
267  
268 # Zugang ueber die eigene Firewall (nft_login: Weg der SSH-Verbindung des
269 # Modells): jeder Aufruf ist eine neue Verbindung. Verwirft der Regelsatz sie,
270 # ist das Geraet nicht mehr erreichbar — fuer den Rest des Falls (locked_out).
271 2365 ▶sub _locked_out {
Subroutine _locked_out: called CC=12 SCAR=25.6
272 2365 my ( $dev, $ctx ) = @_;
273 2365 my $l = $dev->{nft_login};
274 2365 ▶ return undef unless ref $l eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $l eq "HASH" 2359 6 2365
275 6 ▶ my $host = ( $ctx || {} )->{host} // 'host';
Condition50%2/4
($ctx || {})->{"host"} // "host"
l!l
60
$ctx || {}
l!l
60
MC/DC0%0/1
($ctx || {})->{"host"} // "host"
$ctx
Truth table50%1/2
A
A= $ctx
Aresult
11
00
276 6 ▶ my $msg = "ssh: connect to host $host port " . ( $l->{dport} // 22 ) . ': Connection timed out';
Condition50%1/2
$$l{"dport"} // 22
l!l
06
MC/DC0%0/1
$$l{"dport"} // 22
$$l{"dport"}
Truth table50%1/2
A
A= $$l{"dport"}
Aresult
11
00
277 6 ▶ return $msg if $dev->{locked_out};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"locked_out"} 1 5 6
278 5 my ($v) = Langertha::Holmgang::Sim::Linux::Nft::verdict( $dev, { hook => 'input', proto => 'tcp', dport => 22, ct => 'new', %$l } );
279 5 ▶ if ( !defined $v || $v ne 'drop' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $v or $v ne "drop") 4 1 5
Condition66%2/3
not defined $v or $v ne "drop"
l!l&&r!l&&!r
041
MC/DC50%1/2
not defined $v or $v ne "drop"
not defined $v $v ne "drop"
Truth table66%2/3
not(A) or B
A= not defined $vB= $v ne "drop"
ABresult
1X1
011
000
280 # die Antworten der Sitzung muessen auch hinaus (Hook output)
281 my %r = ( hook => 'output', proto => 'tcp', sport => $l->{dport} // 22, dport => 50022, ct => 'established',
282 4 ▶ saddr => $l->{daddr}, daddr => $l->{saddr}, ( defined $l->{iif} ? ( oif => $l->{iif} ) : () ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $$l{'iif'} ? : 4 0 4
Condition50%1/2
$$l{"dport"} // 22
l!l
04
MC/DC0%0/1
$$l{"dport"} // 22
$$l{"dport"}
Truth table50%1/2
A
A= $$l{"dport"}
Aresult
11
00
283 4 ($v) = Langertha::Holmgang::Sim::Linux::Nft::verdict( $dev, \%r );
284 }
285 5 ▶ return undef unless defined $v && $v eq 'drop';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and $v eq "drop" 3 2 5
Condition66%2/3
defined $v and $v eq "drop"
!ll&&!rl&&r
032
MC/DC50%1/2
defined $v and $v eq "drop"
defined $v $v eq "drop"
Truth table66%2/3
A and B
A= defined $vB= $v eq "drop"
ABresult
0X0
100
111
286 2 $dev->{locked_out} = JSON::MaybeXS::true();
287 2 return $msg;
288 }
289  
290 # Eine Befehlszeile bzw. ein Skript in einer Shell ($sh: geteilt, sonst eine neue)
291 2278 ▶sub _run_inner {
Subroutine _run_inner: called CC=20 SCAR=30.1
292 2278 my ( $class, $dev, $line, $ctx, $sh ) = @_;
293 2278 my $outer = scalar @GAPS;
294 2278 ▶ local $SH = $sh // _new_shell( defined $START_RC ? ( rc => $START_RC ) : () );
Branch: 1 branch
BranchTrueFalseTotal
defined $Langertha::Holmgang::Sim::Linux::START_RC ? : 10 2229 2239
Condition66%2/3
$sh // _new_shell(defined $Langertha::Holmgang::Sim::Linux::START_RC ? ("rc", $Langertha::Holmgang::Sim::Linux::START_RC) : ())
l!l&&r!l&&!r
3922390
MC/DC0%0/2
$sh // _new_shell(defined $Langertha::Holmgang::Sim::Linux::START_RC ? ("rc", $Langertha::Holmgang::Sim::Linux::START_RC) : ())
$sh _new_shell(defined $Langertha::Holmgang::Sim::Linux::START_RC ? ("rc", $Langertha::Holmgang::Sim::Linux::START_RC) : ())
Truth table66%2/3
A // B
A= $shB= _new_shell(defined $Langertha::Holmgang::Sim::Linux::START_RC ? ("rc", $Langertha::Holmgang::Sim::Linux::START_RC) : ())
ABresult
1X1
011
000
295 2278 $START_RC = undef;
296 2278 my $owner = !$SH->{_started}; # die Shell beginnt hier (nicht source, nicht Kopie fuer $( ) bzw. ( ))
297 2278 $SH->{_started} = 1;
298 2278 $EXIT = 2;
299 2278 my @items = eval { Langertha::Holmgang::Shell::split_items($line) };
300 2278 ▶ if ( my $e = $@ ) { $e =~ s/\s+\z//; return ( $e, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 1 2277 2278
301 2277 my $nodes = Langertha::Holmgang::Shell::parse( \@items );
302 2277 ▶ return ( $nodes, 0 ) unless ref $nodes;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $nodes 1 2276 2277
303 2276 my ( $out, $ok ) = $class->_exec_nodes( $dev, $nodes, $ctx );
304 2276 ▶ if ( ( $SH->{ctl} // [''] )->[0] eq 'exit' ) { $ok = !$SH->{rc} } elsif ( !$sh ) { delete $SH->{ctl} }
Branch: 2 branches
BranchTrueFalseTotal
if (($$Langertha::Holmgang::Sim::Linux::SH{'ctl'} // [''])->[0] eq 'exit') { } 9 2267 2276
elsif (not $sh) { } 2236 31 2267
Condition100%2/2
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
l!l
92267
MC/DC100%1/1
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"}
Truth table100%2/2
A
A= $$Langertha::Holmgang::Sim::Linux::SH{"ctl"}
Aresult
11
00
305 # trap … EXIT: am Ende der Shell, auch nach exit und set -e; der Status bleibt
306 2276 ▶ if ( $owner && defined( my $h = delete( ( $SH->{traps} || {} )->{EXIT} ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($owner and defined(my $h = delete(($$Langertha::Holmgang::Sim::Linux::SH{"traps"} || {})->{"EXIT"}))) 5 2271 2276
Condition100%5/5
$owner and defined(my $h = delete(($$Langertha::Holmgang::Sim::Linux::SH{"traps"} || {})->{"EXIT"}))
!ll&&!rl&&r
1322585
$$Langertha::Holmgang::Sim::Linux::SH{'traps'} || {}
l!l
72256
MC/DC100%2/2
$owner and defined(my $h = delete(($$Langertha::Holmgang::Sim::Linux::SH{"traps"} || {})->{"EXIT"}))
$owner $$Langertha::Holmgang::Sim::Linux::SH{'traps'}
Truth table100%3/3
A and B
A= $ownerB= $$Langertha::Holmgang::Sim::Linux::SH{'traps'}
ABresult
0X0
100
111
307 5 my ( $rc, $ctl, $ee ) = ( $SH->{rc}, delete $SH->{ctl}, $SH->{errexit} );
308 5 $SH->{errexit} = 0;
309 5 my @hi = eval { Langertha::Holmgang::Shell::split_items($h) };
310 5 ▶ my $hn = @hi ? Langertha::Holmgang::Shell::parse( \@hi ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@hi ? : 5 0 5
311 5 ▶ if ( ref $hn ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hn) 5 0 5
312 5 my ($ho) = $class->_exec_nodes( $dev, $hn, $ctx );
313 5 push @$out, @$ho;
314 }
315 0 ▶ if ( ( $SH->{ctl} // [''] )->[0] eq 'exit' ) { $ok = !$SH->{rc} } # exit im Handler setzt den Status
Branch: 1 branch
BranchTrueFalseTotal
if (($$Langertha::Holmgang::Sim::Linux::SH{'ctl'} // [''])->[0] eq 'exit') { } 0 5 5
Condition50%1/2
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
l!l
05
MC/DC0%0/1
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"}
Truth table50%1/2
A
A= $$Langertha::Holmgang::Sim::Linux::SH{"ctl"}
Aresult
11
00
316 5 ▶ else { ( $SH->{rc}, $SH->{ctl} ) = ( $rc, $ctl ); delete $SH->{ctl} unless defined $ctl }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctl 3 2 5
317 5 $SH->{errexit} = $ee;
318 }
319 2276 ▶ $EXIT = $ok ? 0 : $SH->{rc} || 1;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 1834 442 2276
Condition50%1/2
$$Langertha::Holmgang::Sim::Linux::SH{"rc"} or 1
l!l
4420
MC/DC0%0/1
$$Langertha::Holmgang::Sim::Linux::SH{"rc"} or 1
$$Langertha::Holmgang::Sim::Linux::SH{"rc"}
Truth table50%1/2
A
A= $$Langertha::Holmgang::Sim::Linux::SH{"rc"}
Aresult
11
00
320 2276 my @new = @GAPS[ $outer .. $#GAPS ];
321 2276 ▶ return ( join( "\n", @$out ), $ok ? 1 : 0, @new ? join( '; ', @new ) : undef );
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 1834 442 2276
@new ? : 49 2227 2276
322 }
323  
324 # Glieder ausfuehren (&&, ||, ;), mit $?, set -e, break/continue/exit
325 4377 ▶sub _exec_nodes {
Subroutine _exec_nodes: called CC=22 SCAR=31.2
326 4377 my ( $class, $dev, $nodes, $ctx ) = @_;
327 4377 my ( @out, $ok ) = ();
328 4377 $ok = 1;
329 4377 for my $i ( 0 .. $#$nodes ) {
330 4784 ▶ last if $SH->{ctl};
Branch: 1 branch
BranchTrueFalseTotal
if $$Langertha::Holmgang::Sim::Linux::SH{"ctl"} 9 4775 4784
331 4775 my $nd = $nodes->[$i];
332 4775 ▶ my $op = $nd->{op} // ';';
Condition50%1/2
$$nd{"op"} // ";"
l!l
47750
MC/DC0%0/1
$$nd{"op"} // ";"
$$nd{"op"}
Truth table50%1/2
A
A= $$nd{"op"}
Aresult
11
00
333 4775 ▶ next if $op eq '&&' && !$ok || $op eq '||' && $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "&&" and not $ok or $op eq "||" and $ok 20 4755 4775
Condition100%9/9
$op eq "&&" and not $ok or $op eq "||" and $ok
l!l&&r!l&&!r
1644755
$op eq "&&" and not $ok
!ll&&!rl&&r
456319616
$op eq "||" and $ok
!ll&&!rl&&r
475054
MC/DC100%4/4
$op eq "&&" and not $ok or $op eq "||" and $ok
$op eq "&&" not $ok $op eq "||" $ok
Truth table71%5/7
A and not(B) or C and D
A= $op eq "&&"B= not $okC= $op eq "||"D= $ok
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
334 4755 delete $SH->{code};
335 4755 my ( $o, $k ) = $class->_exec_node( $dev, $nd, $ctx );
336 4755 ▶ push @out, $o if defined $o && length $o;
Branch: 1 branch
BranchTrueFalseTotal
if defined $o and length $o 1778 2977 4755
Condition66%2/3
defined $o and length $o
!ll&&!rl&&r
029771778
MC/DC50%1/2
defined $o and length $o
defined $o length $o
Truth table66%2/3
A and B
A= defined $oB= length $o
ABresult
0X0
100
111
337 4755 ▶ $ok = $k ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 4275 480 4755
338 4755 ▶ $SH->{rc} = $ok ? 0 : $SH->{code} // 1 unless ( $SH->{ctl} // [''] )->[0] eq 'exit';
Branch: 2 branches
BranchTrueFalseTotal
unless ($$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""])->[0] eq "exit" 4749 6 4755
$ok ? : 4275 474 4749
Condition100%4/4
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
l!l
144741
$$Langertha::Holmgang::Sim::Linux::SH{"code"} // 1
l!l
45429
MC/DC100%1/1
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"}
MC/DC100%1/1
$$Langertha::Holmgang::Sim::Linux::SH{"code"} // 1
$$Langertha::Holmgang::Sim::Linux::SH{"code"}
Truth table100%2/2
A
A= $$Langertha::Holmgang::Sim::Linux::SH{"ctl"}
Aresult
11
00
Truth table100%2/2
A
A= $$Langertha::Holmgang::Sim::Linux::SH{"code"}
Aresult
11
00
339 4755 ▶ if ( !$ok && $SH->{errexit} && !$SH->{in_cond} && $op eq ';' && ( ( $nodes->[ $i + 1 ] // {} )->{op} // ';' ) eq ';' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok and $$Langertha::Holmgang::Sim::Linux::SH{"errexit"} and not $$Langertha::Holmgang::Sim::Linux::SH{"in_cond"} and $op eq ";" and (($$nodes[$i + 1] // {})->{"op"} // ";") eq ";") 3 4752 4755
Condition68%11/16
not $ok and $$Langertha::Holmgang::Sim::Linux::SH{"errexit"} and not $$Langertha::Holmgang::Sim::Linux::SH{"in_cond"} and $op eq ";" and (($$nodes[$i + 1] // {})->{"op"} // ";") eq ";"
!ll&&!rl&&r
475203
not $ok and $$Langertha::Holmgang::Sim::Linux::SH{"errexit"} and not $$Langertha::Holmgang::Sim::Linux::SH{"in_cond"} and $op eq ";"
!ll&&!rl&&r
475203
not $ok and $$Langertha::Holmgang::Sim::Linux::SH{"errexit"} and not $$Langertha::Holmgang::Sim::Linux::SH{"in_cond"}
!ll&&!rl&&r
475203
not $ok and $$Langertha::Holmgang::Sim::Linux::SH{"errexit"}
!ll&&!rl&&r
42754773
($$nodes[$i + 1] // {})->{"op"} // ";"
l!l
30
$$nodes[$i + 1] // {}
l!l
30
MC/DC40%2/5
not $ok and $$Langertha::Holmgang::Sim::Linux::SH{"errexit"} and not $$Langertha::Holmgang::Sim::Linux::SH{"in_cond"} and $op eq ";" and (($$nodes[$i + 1] // {})->{"op"} // ";") eq ";"
not $ok $$Langertha::Holmgang::Sim::Linux::SH{"errexit"} not $$Langertha::Holmgang::Sim::Linux::SH{"in_cond"} $op eq ";" $$nodes[$i + 1]
Truth table50%3/6
not(A) and B and not(C) and D and E
A= not $okB= $$Langertha::Holmgang::Sim::Linux::SH{"errexit"}C= not $$Langertha::Holmgang::Sim::Linux::SH{"in_cond"}D= $op eq ";"E= $$nodes[$i + 1]
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
340 3 $SH->{ctl} = ['exit'];
341 }
342 }
343 4377 return ( \@out, $ok );
344 }
345  
346 # Befehlsersetzung $( ) in einer Kopie der Shell (Subshell)
347 4751 ▶sub _cmdsub {
Subroutine _cmdsub: called CC=1 SCAR=0.0
348 4751 my ( $class, $dev, $ctx ) = @_;
349 8 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
350 8 my ($text) = @_;
351 8 my $sub = { %$SH, vars => { %{ $SH->{vars} } }, ctl => undef };
352 8 my ($o) = $class->_run_inner( $dev, $text, $ctx, $sub );
353 8 ▶ return $o // '';
Condition50%1/2
$o // ""
l!l
80
MC/DC0%0/1
$o // ""
$o
Truth table50%1/2
A
A= $o
Aresult
11
00
354 4751 };
355 }
356  
357 4751 ▶sub _sh_expand {
Subroutine _sh_expand: called CC=6 SCAR=19.2
358 4751 my ( $class, $dev, $raw, $ctx ) = @_;
359 $SH->{defaults} = { HOME => '/root', USER => $AS_USER // 'root', LOGNAME => $AS_USER // 'root', SHELL => '/bin/bash',
360 4751 ▶ PWD => $CWD_DIR // '/root', HOSTNAME => $dev->{hostname} // $ctx->{host} // 'localhost', LANG => 'C.UTF-8',
Condition63%7/11
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
04751
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
04751
$Langertha::Holmgang::Sim::Linux::CWD_DIR // "/root"
l!l
1654586
($$dev{"hostname"} // $$ctx{"host"}) // "localhost"
l!l
47510
$$dev{"hostname"} // $$ctx{"host"}
l!l&&r!l&&!r
253222190
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
$Langertha::Holmgang::Sim::Linux::AS_USER
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
$Langertha::Holmgang::Sim::Linux::AS_USER
MC/DC100%1/1
$Langertha::Holmgang::Sim::Linux::CWD_DIR // "/root"
$Langertha::Holmgang::Sim::Linux::CWD_DIR
MC/DC0%0/2
($$dev{"hostname"} // $$ctx{"host"}) // "localhost"
$$dev{"hostname"} $$ctx{"host"}
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::AS_USER
Aresult
11
00
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::AS_USER
Aresult
11
00
Truth table100%2/2
A
A= $Langertha::Holmgang::Sim::Linux::CWD_DIR
Aresult
11
00
Truth table66%2/3
A // B
A= $$dev{"hostname"}B= $$ctx{"host"}
ABresult
1X1
011
000
361 PATH => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', IFS => " \t\n" };
362 4751 return Langertha::Holmgang::Shell::expand( $raw, $SH, $class->_cmdsub( $dev, $ctx ) );
363 }
364  
365 # Ein Glied: Ausdruck expandieren, in Woerter zerlegen, ungequotete Muster globben (relativ
366 # bleibt relativ wie in bash; ohne Treffer bleibt das Wort). $noglob: case-Muster, [[ ]].
367 4748 ▶sub _words_of {
Subroutine _words_of: called CC=11 SCAR=24.0
368 4748 my ( $class, $dev, $raw, $ctx, $noglob ) = @_;
369 4748 my $x = $class->_sh_expand( $dev, $raw, $ctx );
370 4748 my @g;
371 4748 my @w = Langertha::Holmgang::Shell::shell_words( $x, \@g );
372 4748 ▶ return \@w if $noglob;
Branch: 1 branch
BranchTrueFalseTotal
if $noglob 16 4732 4748
373 4732 my @out;
374 4732 for my $i ( 0 .. $#w ) {
375 12600 my $w = $w[$i];
376 12600 ▶ if ( ref $w || !$g[$i] || $w =~ /\A-/ || $w =~ /\A[A-Za-z_]\w*=/ ) { push @out, $w; next }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $w or not $g[$i] or $w =~ /\A-/ or $w =~ /\A[A-Za-z_]\w*=/) 12561 39 12600
Condition77%7/9
ref $w or not $g[$i] or $w =~ /\A-/ or $w =~ /\A[A-Za-z_]\w*=/
l!l&&r!l&&!r
12561039
ref $w or not $g[$i] or $w =~ /\A-/
l!l&&r!l&&!r
12561039
ref $w or not $g[$i]
l!l&&r!l&&!r
3191224239
MC/DC50%2/4
ref $w or not $g[$i] or $w =~ /\A-/ or $w =~ /\A[A-Za-z_]\w*=/
ref $w not $g[$i] $w =~ /\A-/ $w =~ /\A[A-Za-z_]\w*=/
Truth table60%3/5
A or not(B) or C or D
A= ref $wB= not $g[$i]C= $w =~ /\A-/D= $w =~ /\A[A-Za-z_]\w*=/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
377 39 my $abs = _absp($w);
378 39 my @hit = _glob( $dev, $abs );
379 39 ▶ if ( @hit == 1 && $hit[0] eq $abs ) { push @out, $w; next }
Branch: 1 branch
BranchTrueFalseTotal
if (@hit == 1 and $hit[0] eq $abs) 30 9 39
Condition100%3/3
@hit == 1 and $hit[0] eq $abs
!ll&&!rl&&r
8130
MC/DC100%2/2
@hit == 1 and $hit[0] eq $abs
@hit == 1 $hit[0] eq $abs
Truth table100%3/3
A and B
A= @hit == 1B= $hit[0] eq $abs
ABresult
0X0
100
111
380 9 my $cut = length($abs) - length( $w =~ s{\A\./}{}r );
381 9 ▶ push @out, $w =~ m{\A/} ? @hit : map { ( $w =~ m{\A\./} ? './' : '' ) . substr( $_, $cut ) } @hit;
Branch: 2 branches
BranchTrueFalseTotal
$w =~ m[\A/] ? : 7 2 9
$w =~ m[\A\./] ? : 0 9 9
382 }
383 4732 return \@out;
384 }
385  
386 4755 ▶sub _exec_node {
Subroutine _exec_node: called CC=18 SCAR=29.5
387 4755 my ( $class, $dev, $nd, $ctx ) = @_;
388 4755 my $t = $nd->{type};
389 4755 my @r = eval {
390 4755 ▶ return $class->_exec_cmd( $dev, $nd, $ctx ) if $t eq 'cmd';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "cmd" 4704 51 4755
391 51 ▶ return $class->_exec_if( $dev, $nd, $ctx ) if $t eq 'if';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "if" 8 43 51
392 43 ▶ return $class->_exec_for( $dev, $nd, $ctx ) if $t eq 'for';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "for" 14 29 43
393 29 ▶ return $class->_exec_while( $dev, $nd, $ctx ) if $t eq 'while';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "while" 9 20 29
394 20 ▶ return $class->_exec_case( $dev, $nd, $ctx ) if $t eq 'case';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "case" 3 17 20
395 17 ▶ if ( $t eq 'group' && $nd->{subshell} ) { # ( liste ): Variablen, cd, exit bleiben drinnen
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "group" and $$nd{"subshell"}) 6 11 17
Condition100%3/3
$t eq "group" and $$nd{"subshell"}
!ll&&!rl&&r
926
MC/DC100%2/2
$t eq "group" and $$nd{"subshell"}
$t eq "group" $$nd{"subshell"}
Truth table100%3/3
A and B
A= $t eq "group"B= $$nd{"subshell"}
ABresult
0X0
100
111
396 6 my ( $o, $k );
397 {
398 6 local $CWD_DIR = $CWD_DIR;
399 6 local $SH = { %$SH, vars => { %{ $SH->{vars} } }, ctl => undef };
400 6 ( $o, $k ) = $class->_exec_nodes( $dev, $nd->{body}, $ctx );
401 6 ▶ $k = !$SH->{rc} if ( $SH->{ctl} // [''] )->[0] eq 'exit';
Branch: 1 branch
BranchTrueFalseTotal
if ($$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""])->[0] eq "exit" 0 6 6
Condition50%1/2
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
l!l
06
MC/DC0%0/1
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"}
Truth table50%1/2
A
A= $$Langertha::Holmgang::Sim::Linux::SH{"ctl"}
Aresult
11
00
402 }
403 6 my ( $po, $pk ) = $class->_post( $dev, $nd->{post}, $ctx, $o, $k );
404 6 return ( join( "\n", @$po ), $pk );
405 }
406 11 ▶ if ( $t eq 'group' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "group") 2 9 11
407 2 my ( $o, $k ) = $class->_exec_nodes( $dev, $nd->{body}, $ctx );
408 2 my ( $po, $pk ) = $class->_post( $dev, $nd->{post}, $ctx, $o, $k );
409 2 return ( join( "\n", @$po ), $pk );
410 }
411 9 ▶ if ( $t eq 'func' ) { $SH->{funcs}{ $nd->{name} } = $nd->{body}; return ( '', 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "func") 4 5 9
412 5 ▶ if ( $t eq 'break' || $t eq 'continue' ) { $SH->{ctl} = [ $t, $nd->{n} ] if $SH->{loop}; return ( '', 1 ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($t eq "break" or $t eq "continue") 5 0 5
if $$Langertha::Holmgang::Sim::Linux::SH{"loop"} 5 0 5
Condition66%2/3
$t eq "break" or $t eq "continue"
l!l&&r!l&&!r
140
MC/DC0%0/2
$t eq "break" or $t eq "continue"
$t eq "break" $t eq "continue"
Truth table66%2/3
A or B
A= $t eq "break"B= $t eq "continue"
ABresult
1X1
011
000
413 0 push @GAPS, $nd->{raw}; # Funktionen, { }, ( ), for (( )): nicht nachgebildet
414 0 return ( '', 0 );
415 };
416 4755 ▶ if ( my $e = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 2 4753 4755
417 2 ▶ if ( $e =~ /\Agap: / ) { push @GAPS, $nd->{raw} // $t; return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /\Agap: /) 2 0 2
Condition66%2/3
$$nd{"raw"} // $t
l!l&&r!l&&!r
110
MC/DC0%0/2
$$nd{"raw"} // $t
$$nd{"raw"} $t
Truth table66%2/3
A // B
A= $$nd{"raw"}B= $t
ABresult
1X1
011
000
418 0 $e =~ s/\s+\z//;
419 0 return ( $e, 0 );
420 }
421 4753 return @r;
422 }
423  
424 # Eingabe eines Glieds aus Heredoc bzw. Here-String
425 4618 ▶sub _doc_input {
Subroutine _doc_input: called CC=5 SCAR=16.1
426 4618 my ( $class, $dev, $nd, $ctx ) = @_;
427 4618 ▶ if ( defined $nd->{heredoc} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$nd{"heredoc"}) 6 4612 4618
428 6 ▶ return $nd->{heredoc} unless $nd->{expand_doc};
Branch: 1 branch
BranchTrueFalseTotal
unless $$nd{"expand_doc"} 3 3 6
429 3 ( my $b = $nd->{heredoc} ) =~ s/(?<!\\)"/\\"/g;
430 3 my @w = Langertha::Holmgang::Shell::shell_words( $class->_sh_expand( $dev, qq{"$b"}, $ctx ) );
431 3 ▶ return $w[0] // '';
Condition50%1/2
$w[0] // ""
l!l
30
MC/DC0%0/1
$w[0] // ""
$w[0]
Truth table50%1/2
A
A= $w[0]
Aresult
11
00
432 }
433 4612 ▶ if ( defined $nd->{herestring} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$nd{"herestring"}) 1 4611 4612
434 1 my $w = $class->_words_of( $dev, $nd->{herestring}, $ctx );
435 1 return join( ' ', grep { !ref } @$w ) . "\n";
436 }
437 4611 return undef;
438 }
439  
440 4706 ▶sub _exec_cmd {
Subroutine _exec_cmd: called CC=94 SCAR=59.8
441 4706 my ( $class, $dev, $nd, $ctx ) = @_;
442 4706 my $raw = $nd->{raw};
443 # ! befehl: der Status umgekehrt
444 4706 ▶ if ( $raw =~ /\A!\s+(\S.*)\z/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /\A!\s+(\S.*)\z/s) 2 4704 4706
445 2 my ( $o, $k ) = $class->_exec_cmd( $dev, { %$nd, raw => $1 }, $ctx );
446 2 ▶ $SH->{code} = $k ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 0 2 2
447 2 ▶ return ( $o, $k ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 0 2 2
448 }
449 4704 ▶ if ( $raw =~ /\A\[\[\s(.*)\s\]\]\s*\z/s ) { # [[ … ]]: eigene Grammatik (&&, ||, <, > ohne Umleitung)
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /\A\[\[\s(.*)\s\]\]\s*\z/s) 6 4698 4704
450 6 my $w = $class->_words_of( $dev, $1, $ctx, 1 );
451 6 ▶ my @a = map { ref $_ ? $_->{op} : $_ } @$w;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 7 15 22
452 0 ▶ my ( $st, $err ) = Langertha::Holmgang::Shell::test_expr( \@a, sub { _fileinfo( $dev, $_[0] ) }, 1 );
Subroutine __ANON__: not called CC=1 SCAR=1.2
453 6 $SH->{code} = $st;
454 6 ▶ return ( $err // '', $st == 0 ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$st == 0 ? : 4 2 6
Condition50%1/2
$err // ""
l!l
06
MC/DC0%0/1
$err // ""
$err
Truth table50%1/2
A
A= $err
Aresult
11
00
455 }
456 4698 my $w = $class->_words_of( $dev, $raw, $ctx );
457 4698 ▶ return ( '', 1 ) unless @$w;
Branch: 1 branch
BranchTrueFalseTotal
unless @$w 0 4698 4698
458 # nur Zuweisungen: Variablen der Shell
459 4698 ▶ if ( !grep { ref $_ || !/\A[A-Za-z_]\w*\+?=/s } @$w ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {ref $_ or not /\A[A-Za-z_]\w*\+?=/s;} @$w) 47 4651 4698
Condition100%3/3
ref $_ || !/\A[A-Za-z_]\w*\+?=/s
l!l&&r!l&&!r
31212055134
MC/DC100%2/2
ref $_ || !/\A[A-Za-z_]\w*\+?=/s
ref $_ !/\A[A-Za-z_]\w*\+?=/s
Truth table100%3/3
A || not(B)
A= ref $_B= !/\A[A-Za-z_]\w*\+?=/s
ABresult
1X1
011
000
460 47 ▶ for (@$w) { my ( $k, $plus, $v ) = /\A([A-Za-z_]\w*)(\+?)=(.*)\z/s; $SH->{vars}{$k} = $plus ? ( $SH->{vars}{$k} // '' ) . $v : $v }
Branch: 1 branch
BranchTrueFalseTotal
$plus ? : 0 47 47
Condition0%0/2
$$Langertha::Holmgang::Sim::Linux::SH{"vars"}{$k} // ""
l!l
00
MC/DC0%0/1
$$Langertha::Holmgang::Sim::Linux::SH{"vars"}{$k} // ""
$$Langertha::Holmgang::Sim::Linux::SH{"vars"}{$k}
Truth table0%0/2
A
A= $$Langertha::Holmgang::Sim::Linux::SH{"vars"}{$k}
Aresult
11
00
461 47 return ( '', 1 );
462 }
463 4651 my @a = @$w;
464 4651 my $cmd = $a[0];
465 4651 ▶ if ( !ref $cmd && $cmd eq 'exec' && @a > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $cmd and $cmd eq "exec" and @a > 1) 3 4648 4651
Condition83%5/6
not ref $cmd and $cmd eq "exec" and @a > 1
!ll&&!rl&&r
464803
not ref $cmd and $cmd eq "exec"
!ll&&!rl&&r
146473
MC/DC66%2/3
not ref $cmd and $cmd eq "exec" and @a > 1
not ref $cmd $cmd eq "exec" @a > 1
Truth table75%3/4
not(A) and B and C
A= not ref $cmdB= $cmd eq "exec"C= @a > 1
ABCresult
0XX0
10X0
1100
1111
466 3 my @r = @a[ 1 .. $#a ];
467 3 my $only_fd = 1;
468 3 my @files;
469 3 ▶ while (@r) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r) 3 3 6
470 3 my $x = shift @r;
471 3 ▶ if ( !ref $x && $x =~ /\A\d+\z/ && ref $r[0] && $r[0]{op} =~ /\A(?:>|>>|<)\z/ && defined $r[1] && !ref $r[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $x and $x =~ /\A\d+\z/ and ref $r[0] and $r[0]{"op"} =~ /\A(?:>|>>|<)\z/ and defined $r[1] and not ref $r[1]) 2 1 3
Condition66%10/15
not ref $x and $x =~ /\A\d+\z/ and ref $r[0] and $r[0]{"op"} =~ /\A(?:>|>>|<)\z/ and defined $r[1] and not ref $r[1]
!ll&&!rl&&r
102
not ref $x and $x =~ /\A\d+\z/ and ref $r[0] and $r[0]{"op"} =~ /\A(?:>|>>|<)\z/ and defined $r[1]
!ll&&!rl&&r
102
not ref $x and $x =~ /\A\d+\z/ and ref $r[0] and $r[0]{"op"} =~ /\A(?:>|>>|<)\z/
!ll&&!rl&&r
102
not ref $x and $x =~ /\A\d+\z/ and ref $r[0]
!ll&&!rl&&r
102
not ref $x and $x =~ /\A\d+\z/
!ll&&!rl&&r
012
MC/DC16%1/6
not ref $x and $x =~ /\A\d+\z/ and ref $r[0] and $r[0]{"op"} =~ /\A(?:>|>>|<)\z/ and defined $r[1] and not ref $r[1]
not ref $x $x =~ /\A\d+\z/ ref $r[0] $r[0]{"op"} =~ /\A(?:>|>>|<)\z/ defined $r[1] not ref $r[1]
Truth table28%2/7
not(A) and B and C and D and E and not(F)
A= not ref $xB= $x =~ /\A\d+\z/C= ref $r[0]D= $r[0]{"op"} =~ /\A(?:>|>>|<)\z/E= defined $r[1]F= not ref $r[1]
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
472 2 my $op = ( shift @r )->{op};
473 2 push @files, [ $op, shift @r ];
474 2 next;
475 }
476 1 ▶ if ( !ref $x && $x =~ /\A\d*[<>]&-\z/ ) { next } # N>&- / N<&-: schliesst
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $x and $x =~ /\A\d*[<>]&-\z/) 1 0 1
Condition33%1/3
not ref $x and $x =~ /\A\d*[<>]&-\z/
!ll&&!rl&&r
001
MC/DC0%0/2
not ref $x and $x =~ /\A\d*[<>]&-\z/
not ref $x $x =~ /\A\d*[<>]&-\z/
Truth table33%1/3
not(A) and B
A= not ref $xB= $x =~ /\A\d*[<>]&-\z/
ABresult
0X0
100
111
477 0 $only_fd = 0;
478 0 last;
479 }
480 3 ▶ if ($only_fd) { # exec N>datei: oeffnet (legt an), haelt keine Sperre
Branch: 1 branch
BranchTrueFalseTotal
if ($only_fd) 3 0 3
481 3 for my $f (@files) {
482 2 my $pth = _absp( $f->[1] );
483 0 ▶ if ( $f->[0] eq '<' ) { return ( "bash: $f->[1]: No such file or directory", 0 ) unless defined _file_text( $dev, $pth ); next }
Branch: 2 branches
BranchTrueFalseTotal
if ($$f[0] eq "<") 0 2 2
unless defined _file_text($dev, $pth) 0 0 0
484 2 ▶ next if _file_entry( $dev, $pth ) && $f->[0] eq '>>';
Branch: 1 branch
BranchTrueFalseTotal
if _file_entry($dev, $pth) and $$f[0] eq ">>" 0 2 2
Condition33%1/3
_file_entry($dev, $pth) and $$f[0] eq ">>"
!ll&&!rl&&r
200
MC/DC0%0/2
_file_entry($dev, $pth) and $$f[0] eq ">>"
_file_entry($dev, $pth) $$f[0] eq ">>"
Truth table33%1/3
A and B
A= _file_entry($dev, $pth)B= $$f[0] eq ">>"
ABresult
0X0
100
111
485 2 my ( $e, $wok ) = _write_path( $dev, $pth, '', $f->[0] eq '>>', $ctx );
486 2 ▶ return ( $e, 0 ) unless $wok;
Branch: 1 branch
BranchTrueFalseTotal
unless $wok 0 2 2
487 }
488 3 return ( '', 1 );
489 }
490 }
491 4648 ▶ if ( !ref $cmd && !grep { ref $_ && $_->{op} =~ /\A(?:\||>|>>)\z/ } @a ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $cmd or grep {ref $_ and $$_{"op"} =~ /\A(?:\||>|>>)\z/;} @a) 4352 296 4648
Condition100%6/6
ref $cmd or grep {ref $_ and $$_{"op"} =~ /\A(?:\||>|>>)\z/;} @a
l!l&&r!l&&!r
12954352
ref $_ && $$_{'op'} =~ /\A(?:\||>|>>)\z/
!ll&&!rl&&r
121334305
MC/DC100%2/2
ref $cmd or grep {ref $_ and $$_{"op"} =~ /\A(?:\||>|>>)\z/;} @a
ref $cmd grep {ref $_ and $$_{"op"} =~ /\A(?:\||>|>>)\z/;} @a
MC/DC100%2/2
ref $_ && $$_{'op'} =~ /\A(?:\||>|>>)\z/
ref $_ $$_{'op'} =~ /\A(?:\||>|>>)\z/
Truth table100%3/3
A or B
A= ref $cmdB= grep {ref $_ and $$_{"op"} =~ /\A(?:\||>|>>)\z/;} @a
ABresult
1X1
011
000
Truth table100%3/3
A && B
A= ref $_B= $$_{'op'} =~ /\A(?:\||>|>>)\z/
ABresult
0X0
100
111
492 4352 ▶ if ( $cmd =~ /\A(?:export|declare|typeset|local|readonly)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /\A(?:export|declare|typeset|local|readonly)\z/) 3 4349 4352
493 3 for my $x ( @a[ 1 .. $#a ] ) {
494 4 ▶ next if $x =~ /\A-[xrgil]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /\A-[xrgil]+\z/ 0 4 4
495 4 ▶ die "gap: $cmd $x\n" if $x =~ /\A-/;
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /\A-/ 0 4 4
496 4 ▶ my ( $k, $v ) = $x =~ /\A([A-Za-z_]\w*)(?:=(.*))?\z/s or return ( "bash: $cmd: `$x': not a valid identifier", 0 );
Branch: 1 branch
BranchTrueFalseTotal
() = $x =~ /\A([A-Za-z_]\w*)(?:=(.*))?\z/s or return "bash: ${cmd}: `${x}': not a valid identifier", 0 4 0 4
497 4 ▶ $SH->{vars}{$k} = $v if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 3 1 4
498 4 ▶ $SH->{vars}{$k} //= '' if $cmd ne 'export';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd ne "export" 0 4 4
Condition0%0/2
$$Langertha::Holmgang::Sim::Linux::SH{"vars"}{$k} //= ""
l!l
00
MC/DC0%0/1
$$Langertha::Holmgang::Sim::Linux::SH{"vars"}{$k} //= ""
$$Langertha::Holmgang::Sim::Linux::SH{"vars"}{$k}
Truth table0%0/2
A
A= $$Langertha::Holmgang::Sim::Linux::SH{"vars"}{$k}
Aresult
11
00
499 0 ▶ $SH->{exported}{$k} = 1 if $cmd eq 'export' || grep { $_ eq '-x' } @a;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "export" or grep {$_ eq "-x";} @a 4 0 4
Condition33%1/3
$cmd eq "export" or grep {$_ eq "-x";} @a
l!l&&r!l&&!r
400
MC/DC0%0/2
$cmd eq "export" or grep {$_ eq "-x";} @a
$cmd eq "export" grep {$_ eq "-x";} @a
Truth table33%1/3
A or B
A= $cmd eq "export"B= grep {$_ eq "-x";} @a
ABresult
1X1
011
000
500 }
501 3 return ( '', 1 );
502 }
503 0 ▶ if ( $cmd eq 'unset' ) { delete $SH->{vars}{$_} for grep { !/\A-/ } @a[ 1 .. $#a ]; return ( '', 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "unset") 0 4349 4349
504 4349 ▶ if ( $cmd eq 'set' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "set") 4 4345 4349
505 4 my @o = @a[ 1 .. $#a ];
506 4 ▶ while ( defined( my $x = shift @o ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $x = shift @o)) 4 4 8
507 0 ▶ if ( $x eq '--' ) { $SH->{args} = [@o]; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "--") 0 4 4
508 0 ▶ if ( $x eq '-o' || $x eq '+o' ) { my $n = shift(@o) // ''; $SH->{errexit} = $x eq '-o' ? 1 : 0 if $n eq 'errexit'; next }
Branch: 3 branches
BranchTrueFalseTotal
if ($x eq "-o" or $x eq "+o") 0 4 4
if $n eq "errexit" 0 0 0
$x eq '-o' ? : 0 0 0
Condition20%1/5
$x eq "-o" or $x eq "+o"
l!l&&r!l&&!r
004
shift @o // ""
l!l
00
MC/DC0%0/2
$x eq "-o" or $x eq "+o"
$x eq "-o" $x eq "+o"
MC/DC0%0/1
shift @o // ""
shift @o
Truth table33%1/3
A or B
A= $x eq "-o"B= $x eq "+o"
ABresult
1X1
011
000
Truth table0%0/2
A
A= shift @o
Aresult
11
00
509 4 ▶ if ( my ( $sg, $fl ) = $x =~ /\A([-+])([a-zA-Z]+)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $x =~ /\A([-+])([a-zA-Z]+)\z/) 4 0 4
510 4 ▶ $SH->{errexit} = $sg eq q{-} ? 1 : 0 if $fl =~ /e/;
Branch: 2 branches
BranchTrueFalseTotal
if $fl =~ /e/ 4 0 4
$sg eq '-' ? : 4 0 4
511 4 ▶ if ( $fl =~ /o/ ) { my $n = shift(@o) // ''; $SH->{errexit} = $sg eq q{-} ? 1 : 0 if $n eq 'errexit' } # set -euo pipefail
Branch: 3 branches
BranchTrueFalseTotal
if ($fl =~ /o/) 1 3 4
if $n eq "errexit" 0 1 1
$sg eq '-' ? : 0 0 0
Condition50%1/2
shift @o // ""
l!l
10
MC/DC0%0/1
shift @o // ""
shift @o
Truth table50%1/2
A
A= shift @o
Aresult
11
00
512 4 next;
513 }
514 0 $SH->{args} = [ $x, @o ];
515 0 last;
516 }
517 4 return ( '', 1 );
518 }
519 0 ▶ if ( $cmd eq 'shift' ) { splice @{ $SH->{args} }, 0, $a[1] // 1; return ( '', 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "shift") 0 4345 4345
Condition0%0/2
$a[1] // 1
l!l
00
MC/DC0%0/1
$a[1] // 1
$a[1]
Truth table0%0/2
A
A= $a[1]
Aresult
11
00
520 4345 ▶ if ( $cmd eq 'umask' ) { return _umask( @a[ 1 .. $#a ] ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "umask") 7 4338 4345
521 4338 ▶ if ( $cmd eq 'exit' || $cmd eq 'return' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "exit" or $cmd eq "return") 7 4331 4338
Condition100%3/3
$cmd eq "exit" or $cmd eq "return"
l!l&&r!l&&!r
614331
MC/DC100%2/2
$cmd eq "exit" or $cmd eq "return"
$cmd eq "exit" $cmd eq "return"
Truth table100%3/3
A or B
A= $cmd eq "exit"B= $cmd eq "return"
ABresult
1X1
011
000
522 7 ▶ my $n = $a[1] // $SH->{rc} // 0;
Condition40%2/5
($a[1] // $$Langertha::Holmgang::Sim::Linux::SH{"rc"}) // 0
l!l
70
$a[1] // $$Langertha::Holmgang::Sim::Linux::SH{"rc"}
l!l&&r!l&&!r
700
MC/DC0%0/2
($a[1] // $$Langertha::Holmgang::Sim::Linux::SH{"rc"}) // 0
$a[1] $$Langertha::Holmgang::Sim::Linux::SH{"rc"}
Truth table33%1/3
A // B
A= $a[1]B= $$Langertha::Holmgang::Sim::Linux::SH{"rc"}
ABresult
1X1
011
000
523 7 ▶ $n = 2 unless $n =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $n =~ /\A\d+\z/ 0 7 7
524 7 ▶ $SH->{ctl} = [ $cmd eq 'return' && $SH->{in_func} ? 'return' : 'exit' ];
Branch: 1 branch
BranchTrueFalseTotal
$cmd eq 'return' && $$Langertha::Holmgang::Sim::Linux::SH{'in_func'} ? : 1 6 7
Condition66%2/3
$cmd eq "return" and $$Langertha::Holmgang::Sim::Linux::SH{"in_func"}
!ll&&!rl&&r
601
MC/DC50%1/2
$cmd eq "return" and $$Langertha::Holmgang::Sim::Linux::SH{"in_func"}
$cmd eq "return" $$Langertha::Holmgang::Sim::Linux::SH{"in_func"}
Truth table66%2/3
A and B
A= $cmd eq "return"B= $$Langertha::Holmgang::Sim::Linux::SH{"in_func"}
ABresult
0X0
100
111
525 7 $SH->{rc} = $SH->{code} = $n % 256;
526 7 ▶ return ( '', $n ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$n ? : 7 0 7
527 }
528 4331 ▶ if ( $cmd eq 'read' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "read") 0 4331 4331
529 0 my $in = $class->_doc_input( $dev, $nd, $ctx );
530 0 ▶ die "gap: read\n" unless defined $in;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in 0 0 0
531 0 ▶ return _read_into( [ @a[ 1 .. $#a ] ], ( split /\n/, $in, 2 )[0] // '' ) ? ( '', 1 ) : ( '', 0 );
Branch: 1 branch
BranchTrueFalseTotal
_read_into([@a[1 .. $#a]], (split(/\n/, $in, 2))[0] // '') ? : 0 0 0
Condition0%0/2
(split(/\n/, $in, 2))[0] // ""
l!l
00
MC/DC0%0/1
(split(/\n/, $in, 2))[0] // ""
(split(/\n/, $in, 2))[0]
Truth table0%0/2
A
A= (split(/\n/, $in, 2))[0]
Aresult
11
00
532 }
533 4331 ▶ if ( $cmd eq 'source' || $cmd eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "source" or $cmd eq ".") 0 4331 4331
Condition33%1/3
$cmd eq "source" or $cmd eq "."
l!l&&r!l&&!r
004331
MC/DC0%0/2
$cmd eq "source" or $cmd eq "."
$cmd eq "source" $cmd eq "."
Truth table33%1/3
A or B
A= $cmd eq "source"B= $cmd eq "."
ABresult
1X1
011
000
534 0 ▶ my $t = defined $a[1] ? _file_text( $dev, _absp( $a[1] ) ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $a[1] ? : 0 0 0
535 0 ▶ return ( "bash: " . ( $a[1] // '' ) . ": No such file or directory", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 0 0
Condition0%0/2
$a[1] // ""
l!l
00
MC/DC0%0/1
$a[1] // ""
$a[1]
Truth table0%0/2
A
A= $a[1]
Aresult
11
00
536 0 my ( $o, $k ) = $class->_run_inner( $dev, $t, $ctx, $SH );
537 0 return ( $o, $k );
538 }
539 4331 ▶ return _trap_cmd( @a[ 1 .. $#a ] ) if $cmd eq 'trap';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "trap" 9 4322 4331
540 4322 ▶ die "gap: $cmd\n" if $cmd =~ /\A(?:eval|exec|wait|getopts|let|mapfile|readarray|pushd|popd|alias)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd =~ /\A(?:eval|exec|wait|getopts|let|mapfile|readarray|pushd|popd|alias)\z/ 0 4322 4322
541 }
542 # Shell-Funktion (name() { … }): ihr Rumpf mit den Argumenten, return endet sie
543 4618 ▶ if ( !ref $cmd && ( my $fb = ( $SH->{funcs} || {} )->{$cmd} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $cmd and my $fb = ($$Langertha::Holmgang::Sim::Linux::SH{"funcs"} || {})->{$cmd}) 6 4612 4618
Condition100%5/5
not ref $cmd and my $fb = ($$Langertha::Holmgang::Sim::Linux::SH{"funcs"} || {})->{$cmd}
!ll&&!rl&&r
146116
$$Langertha::Holmgang::Sim::Linux::SH{'funcs'} || {}
l!l
154602
MC/DC100%2/2
not ref $cmd and my $fb = ($$Langertha::Holmgang::Sim::Linux::SH{"funcs"} || {})->{$cmd}
not ref $cmd $$Langertha::Holmgang::Sim::Linux::SH{'funcs'}
Truth table100%3/3
not(A) and B
A= not ref $cmdB= $$Langertha::Holmgang::Sim::Linux::SH{'funcs'}
ABresult
0X0
100
111
544 6 ▶ die "gap: $cmd (Funktion mit Pipe oder Umleitung)\n" if grep { ref } @a;
Branch: 1 branch
BranchTrueFalseTotal
if grep {ref $_;} @a 0 6 6
545 6 local $SH->{args} = [ @a[ 1 .. $#a ] ];
546 6 local $SH->{in_func} = 1;
547 6 my ( $o, $k ) = $class->_exec_nodes( $dev, $fb, $ctx );
548 6 ▶ if ( ( $SH->{ctl} // [''] )->[0] eq 'return' ) { delete $SH->{ctl}; $k = !$SH->{rc} }
Branch: 1 branch
BranchTrueFalseTotal
if (($$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""])->[0] eq "return") 1 5 6
Condition100%2/2
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
l!l
15
MC/DC100%1/1
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"}
Truth table100%2/2
A
A= $$Langertha::Holmgang::Sim::Linux::SH{"ctl"}
Aresult
11
00
549 6 ▶ $SH->{code} = $SH->{rc} unless $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $k 1 5 6
550 6 return ( join( "\n", @$o ), $k );
551 }
552 4612 my $in = $class->_doc_input( $dev, $nd, $ctx );
553 # 2>/dev/null an einem Befehl: seine Fehlermeldungen ("prog: …") verschwinden — die
554 # Simulation kennt nur einen Ausgabestrom, Meldungen tragen den Namen des Programms
555 4612 my %quiet = map { $_ => 1 } _errnull_progs($raw);
556 4612 ▶ local $ERRNULL = %quiet ? \%quiet : undef;
Branch: 1 branch
BranchTrueFalseTotal
%quiet ? : 13 4599 4612
557 4612 my ( $o, $k ) = $class->_pipeline( $dev, \@a, $ctx, $in );
558 4611 ▶ $o = _errnull_cut( $o, [ keys %quiet ] ) if %quiet;
Branch: 1 branch
BranchTrueFalseTotal
if %quiet 13 4598 4611
559 4611 return ( $o, $k );
560 }
561  
562 # Fehlermeldungen dieser Programme aus einer Ausgabe entfernen ("ls: …", "bash: cd: …")
563 15 ▶sub _errnull_cut {
Subroutine _errnull_cut: called CC=7 SCAR=20.4
564 15 my ( $o, $names ) = @_;
565 15 ▶ return $o unless defined $o && length $o && @$names;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o and length $o and @$names 0 15 15
Condition33%2/6
defined $o and length $o and @$names
!ll&&!rl&&r
0015
defined $o and length $o
!ll&&!rl&&r
0015
MC/DC0%0/3
defined $o and length $o and @$names
defined $o length $o @$names
Truth table25%1/4
A and B and C
A= defined $oB= length $oC= @$names
ABCresult
0XX0
10X0
1100
1111
566 15 my %q = map { $_ => 1 } @$names;
567 15 ▶ my $t = join "\n", grep { !( /\A([\w.\[-]+): / && $q{$1} || /\Abash: ([\w.\[-]+): / && $q{$1} ) } split /\n/, $o, -1;
Condition88%8/9
/\A([\w.\[-]+): / && $q{$1} || /\Abash: ([\w.\[-]+): / && $q{$1}
l!l&&r!l&&!r
8133
/\A([\w.\[-]+): / and $q{$1}
!ll&&!rl&&r
3318
/\Abash: ([\w.\[-]+): / and $q{$1}
!ll&&!rl&&r
3301
MC/DC25%1/4
/\A([\w.\[-]+): / && $q{$1} || /\Abash: ([\w.\[-]+): / && $q{$1}
/\A([\w.\[-]+): / $q{$1} /\Abash: ([\w.\[-]+): / $q{$1}
Truth table42%3/7
A and B || C and D
A= /\A([\w.\[-]+): /B= $q{$1}C= /\Abash: ([\w.\[-]+): /D= $q{$1}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
568 15 $t =~ s/\A\n+//;
569 15 return $t;
570 }
571  
572 # Programme einer Pipeline, deren Fehlerausgabe nach /dev/null geht (2>/dev/null, 2>>/dev/null)
573 4612 ▶sub _errnull_progs {
Subroutine _errnull_progs: called CC=18 SCAR=29.6
574 4612 my ($raw) = @_;
575 4612 ▶ return () unless $raw =~ m{2>>?\s*/dev/null};
Branch: 1 branch
BranchTrueFalseTotal
unless $raw =~ m[2>>?\s*/dev/null] 4599 13 4612
576 13 my ( @seg, $cur, $q ) = ();
577 13 $cur = '';
578 13 for my $c ( split //, $raw ) {
579 513 ▶ if ($q) { $q = '' if $c eq $q; $cur .= $c; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($q) 28 485 513
if $c eq $q 1 27 28
580 485 ▶ if ( $c eq "'" || $c eq '"' ) { $q = $c; $cur .= $c; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "'" or $c eq "\"") 1 484 485
Condition66%2/3
$c eq "'" or $c eq "\""
l!l&&r!l&&!r
01484
MC/DC50%1/2
$c eq "'" or $c eq "\""
$c eq "'" $c eq "\""
Truth table66%2/3
A or B
A= $c eq "'"B= $c eq "\""
ABresult
1X1
011
000
581 484 ▶ if ( $c eq '|' ) { push @seg, $cur; $cur = ''; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "|") 2 482 484
582 482 $cur .= $c;
583 }
584 13 push @seg, $cur;
585 13 my @p;
586 13 for my $s ( grep { m{(?:\A|\s)2>>?\s*/dev/null} } @seg ) {
587 13 my @w = grep { !/\A[A-Za-z_]\w*=/ } split ' ', $s;
588 13 ▶ shift @w while @w && ( $w[0] eq 'sudo' || $w[0] =~ /\A-/ );
Branch: 1 branch
BranchTrueFalseTotal
@w and $w[0] eq "sudo" || $w[0] =~ /\A-/ and do { shift @w } 0 13 13
Condition33%2/6
@w and $w[0] eq "sudo" || $w[0] =~ /\A-/
!ll&&!rl&&r
0130
$w[0] eq "sudo" or $w[0] =~ /\A-/
l!l&&r!l&&!r
0013
MC/DC0%0/3
@w and $w[0] eq "sudo" || $w[0] =~ /\A-/
@w $w[0] eq "sudo" $w[0] =~ /\A-/
Truth table25%1/4
A and B or C
A= @wB= $w[0] eq "sudo"C= $w[0] =~ /\A-/
ABCresult
0XX0
1000
11X1
1011
589 13 ▶ if ( @w && $w[0] eq 'timeout' ) { shift @w; shift @w while @w && $w[0] =~ /\A-/; shift @w } # timeout DAUER befehl
Branch: 2 branches
BranchTrueFalseTotal
if (@w and $w[0] eq "timeout") 1 12 13
@w and $w[0] =~ /\A-/ and do { shift @w } 0 1 1
Condition50%3/6
@w and $w[0] eq "timeout"
!ll&&!rl&&r
0121
@w and $w[0] =~ /\A-/
!ll&&!rl&&r
010
MC/DC50%1/2
@w and $w[0] eq "timeout"
@w $w[0] eq "timeout"
MC/DC0%0/2
@w and $w[0] =~ /\A-/
@w $w[0] =~ /\A-/
Truth table66%2/3
A and B
A= @wB= $w[0] eq "timeout"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= @wB= $w[0] =~ /\A-/
ABresult
0X0
100
111
590 13 ▶ next unless @w;
Branch: 1 branch
BranchTrueFalseTotal
unless @w 0 13 13
591 13 ( my $n = $w[0] ) =~ s{.*/}{};
592 13 push @p, $n;
593 13 ▶ push @p, 'bash' if $n =~ /\A(?:ba)?sh\z/; # bash -c '…': Meldungen der bash
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ /\A(?:ba)?sh\z/ 1 12 13
594 }
595 13 return @p;
596 }
597  
598 # read [-r] [-p prompt] [var …] aus einer Zeile; IFS aus der Shell
599 12 ▶sub _read_into {
Subroutine _read_into: called CC=16 SCAR=28.4
600 12 my ( $av, $line ) = @_;
601 12 my @a = @$av;
602 12 my ( $raw, @names );
603 12 ▶ while ( defined( my $x = shift @a ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $x = shift @a)) 31 12 43
604 31 ▶ if ( $x eq '-r' ) { $raw = 1 }
Branch: 4 branches
BranchTrueFalseTotal
if ($x eq '-r') { } 9 22 31
elsif ($x =~ /\A-[ptd]\z/) { } 5 17 22
elsif ($x =~ /\A-r([d])\z/) { } 0 17 17
elsif ($x =~ /\A-/) { } 0 17 17
605 5 elsif ( $x =~ /\A-[ptd]\z/ ) { shift @a } # -d: Saetze kommen hier schon getrennt (find -print0 wie -print)
606 0 elsif ( $x =~ /\A-r([d])\z/ ) { $raw = 1; shift @a }
607 0 elsif ( $x =~ /\A-/ ) { die "gap: read $x\n" }
608 17 else { push @names, $x }
609 }
610 12 ▶ @names = ('REPLY') unless @names;
Branch: 1 branch
BranchTrueFalseTotal
unless @names 0 12 12
611 12 ▶ $line =~ s/\\(.)/$1/g unless $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $raw 3 9 12
612 12 ▶ my $ifs = $SHENV && exists $SHENV->{IFS} ? $SHENV->{IFS} : exists $SH->{vars}{IFS} ? $SH->{vars}{IFS} : " \t\n";
Branch: 2 branches
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::SHENV && exists $$Langertha::Holmgang::Sim::Linux::SHENV{'IFS'} ? : 6 6 12
exists $$Langertha::Holmgang::Sim::Linux::SH{'vars'}{'IFS'} ? : 0 6 6
Condition66%2/3
$Langertha::Holmgang::Sim::Linux::SHENV and exists $$Langertha::Holmgang::Sim::Linux::SHENV{"IFS"}
!ll&&!rl&&r
066
MC/DC50%1/2
$Langertha::Holmgang::Sim::Linux::SHENV and exists $$Langertha::Holmgang::Sim::Linux::SHENV{"IFS"}
$Langertha::Holmgang::Sim::Linux::SHENV exists $$Langertha::Holmgang::Sim::Linux::SHENV{"IFS"}
Truth table66%2/3
A and B
A= $Langertha::Holmgang::Sim::Linux::SHENVB= exists $$Langertha::Holmgang::Sim::Linux::SHENV{"IFS"}
ABresult
0X0
100
111
613 12 my @v;
614 12 ▶ if ( $ifs eq '' ) { @v = ($line) }
Branch: 1 branch
BranchTrueFalseTotal
if ($ifs eq '') { } 5 7 12
615 else {
616 7 my $ws = join '', grep { /\s/ } split //, $ifs;
617 7 my $cls = '[' . quotemeta($ifs) . ']';
618 7 ▶ $line =~ s/\A[\Q$ws\E]+|[\Q$ws\E]+\z//g if length $ws;
Branch: 1 branch
BranchTrueFalseTotal
if length $ws 6 1 7
619 7 @v = split /$cls/, $line, scalar @names;
620 7 ▶ @v = split( ' ', $line, scalar @names ) if $ifs eq " \t\n";
Branch: 1 branch
BranchTrueFalseTotal
if $ifs eq " \t\n" 6 1 7
621 }
622 12 ▶ $SH->{vars}{ $names[$_] } = $v[$_] // '' for 0 .. $#names;
Condition50%1/2
$v[$_] // ""
l!l
170
MC/DC0%0/1
$v[$_] // ""
$v[$_]
Truth table50%1/2
A
A= $v[$_]
Aresult
11
00
623 12 return 1;
624 }
625  
626 19 ▶sub _fileinfo {
Subroutine _fileinfo: called CC=10 SCAR=31.1
627 19 my ( $dev, $p ) = @_;
628 19 $p = _absp($p);
629 19 ▶ if ( my $e = _file_entry( $dev, $p ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = _file_entry($dev, $p)) 12 7 19
630 12 my $l = defined $e->{link};
631 12 ▶ my $tk = $l ? ( _is_dir( $dev, $p ) ? 'd' : _file_entry( $dev, _link_target( $p, $e->{link} ) ) ? 'f' : undef ) : undef;
Branch: 3 branches
BranchTrueFalseTotal
$l ? : 0 12 12
_is_dir($dev, $p) ? : 0 0 0
_file_entry($dev, _link_target($p, $$e{'link'})) ? : 0 0 0
632 12 ▶ return { kind => $l ? 'l' : 'f', target_kind => $tk, size => _file_size($e), mode => _mode_of($e), mtime => _mtime($e) };
Branch: 1 branch
BranchTrueFalseTotal
$l ? : 0 12 12
633 }
634 7 ▶ return { kind => 'd', size => 4096, mode => oct( ( ( $dev->{dirs} || {} )->{$p} || {} )->{mode} // '0755' ), mtime => 0 } if _is_dir( $dev, $p );
Branch: 1 branch
BranchTrueFalseTotal
if _is_dir($dev, $p) 0 7 7
Condition0%0/6
(($$dev{"dirs"} || {})->{$p} || {})->{"mode"} // "0755"
l!l
00
($$dev{'dirs'} || {})->{$p} || {}
l!l
00
$$dev{'dirs'} || {}
l!l
00
MC/DC0%0/1
(($$dev{"dirs"} || {})->{$p} || {})->{"mode"} // "0755"
$$dev{'dirs'}
Truth table0%0/2
A
A= $$dev{'dirs'}
Aresult
11
00
635 7 return undef;
636 }
637  
638 42 ▶sub _test_cmd {
Subroutine _test_cmd: called CC=7 SCAR=19.9
639 42 my ( $name, $dev, $av ) = @_;
640 42 my @a = @$av;
641 42 ▶ if ( $name eq '[' ) { return ( "bash: [: missing `]'", 0 ) unless @a && $a[-1] eq ']'; pop @a }
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq "[") 27 15 42
unless @a and $a[-1] eq "]" 0 27 27
Condition33%1/3
@a and $a[-1] eq "]"
!ll&&!rl&&r
0027
MC/DC0%0/2
@a and $a[-1] eq "]"
@a $a[-1] eq "]"
Truth table33%1/3
A and B
A= @aB= $a[-1] eq "]"
ABresult
0X0
100
111
642 42 ▶ my ( $st, $err ) = Langertha::Holmgang::Shell::test_expr( \@a, sub { _fileinfo( $dev, $_[0] ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
643 42 ▶ $SH->{code} = $st if $SH;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH 42 0 42
644 42 ▶ return ( $err // '', $st == 0 ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$st == 0 ? : 21 21 42
Condition100%2/2
$err // ""
l!l
141
MC/DC100%1/1
$err // ""
$err
Truth table100%2/2
A
A= $err
Aresult
11
00
645 }
646  
647 # Ausgabe eines Blocks durch den Rest hinter done/fi (| filter, > datei)
648 38 ▶sub _post {
Subroutine _post: called CC=20 SCAR=32.3
649 38 my ( $class, $dev, $post, $ctx, $out, $ok ) = @_;
650 38 ▶ return ( $out, $ok ) unless $post && $post->{raw} =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $post and $$post{"raw"} =~ /\S/ 30 8 38
Condition66%2/3
$post and $$post{"raw"} =~ /\S/
!ll&&!rl&&r
0308
MC/DC50%1/2
$post and $$post{"raw"} =~ /\S/
$post $$post{"raw"} =~ /\S/
Truth table66%2/3
A and B
A= $postB= $$post{"raw"} =~ /\S/
ABresult
0X0
100
111
651 8 ▶ return ( $out, $ok ) if $post->{raw} =~ /\A\s*<\s*<\(.*\)\s*\z/s; # done < <( … ): schon als Eingabe gelesen
Branch: 1 branch
BranchTrueFalseTotal
if $$post{"raw"} =~ /\A\s*<\s*<\(.*\)\s*\z/s 2 6 8
652 6 my $w = $class->_words_of( $dev, $post->{raw}, $ctx );
653 6 my @w; # ohne < datei (schon als Eingabe gelesen)
654 6 ▶ for ( my $i = 0; $i < @$w; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$w) 18 6 24
655 18 my $x = $w->[$i];
656 18 ▶ if ( ref $x && $x->{op} eq '<' ) { $i++; next }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x and $$x{"op"} eq "<") 1 17 18
Condition100%3/3
ref $x and $$x{"op"} eq "<"
!ll&&!rl&&r
1251
MC/DC100%2/2
ref $x and $$x{"op"} eq "<"
ref $x $$x{"op"} eq "<"
Truth table100%3/3
A and B
A= ref $xB= $$x{"op"} eq "<"
ABresult
0X0
100
111
657 17 push @w, $x;
658 }
659 6 ▶ return ( $out, $ok ) unless @w;
Branch: 1 branch
BranchTrueFalseTotal
unless @w 1 5 6
660 5 my $text = join "\n", grep { length } @$out;
661 5 ▶ if ( ref $w[0] && $w[0]{op} eq '|' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $w[0] and $w[0]{"op"} eq "|") 4 1 5
Condition66%2/3
ref $w[0] and $w[0]{"op"} eq "|"
!ll&&!rl&&r
014
MC/DC50%1/2
ref $w[0] and $w[0]{"op"} eq "|"
ref $w[0] $w[0]{"op"} eq "|"
Truth table66%2/3
A and B
A= ref $w[0]B= $w[0]{"op"} eq "|"
ABresult
0X0
100
111
662 4 shift @w;
663 4 ▶ my ( $o, $k ) = $class->_pipeline( $dev, \@w, $ctx, length $text ? "$text\n" : '' );
Branch: 1 branch
BranchTrueFalseTotal
length $text ? : 4 0 4
664 4 ▶ return ( [ defined $o && length $o ? $o : () ], $k );
Branch: 1 branch
BranchTrueFalseTotal
defined $o && length $o ? : 3 1 4
Condition66%2/3
defined $o and length $o
!ll&&!rl&&r
013
MC/DC50%1/2
defined $o and length $o
defined $o length $o
Truth table66%2/3
A and B
A= defined $oB= length $o
ABresult
0X0
100
111
665 }
666 1 ▶ if ( ref $w[0] && ( $w[0]{op} eq '>' || $w[0]{op} eq '>>' ) && defined $w[1] && !ref $w[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $w[0] and $w[0]{"op"} eq ">" || $w[0]{"op"} eq ">>" and defined $w[1] and not ref $w[1]) 1 0 1
Condition33%4/12
ref $w[0] and $w[0]{"op"} eq ">" || $w[0]{"op"} eq ">>" and defined $w[1] and not ref $w[1]
!ll&&!rl&&r
001
ref $w[0] and $w[0]{"op"} eq ">" || $w[0]{"op"} eq ">>" and defined $w[1]
!ll&&!rl&&r
001
ref $w[0] and $w[0]{"op"} eq ">" || $w[0]{"op"} eq ">>"
!ll&&!rl&&r
001
$w[0]{"op"} eq ">" or $w[0]{"op"} eq ">>"
l!l&&r!l&&!r
100
MC/DC0%0/5
ref $w[0] and $w[0]{"op"} eq ">" || $w[0]{"op"} eq ">>" and defined $w[1] and not ref $w[1]
ref $w[0] $w[0]{"op"} eq ">" $w[0]{"op"} eq ">>" defined $w[1] not ref $w[1]
Truth table12%1/8
A and B or C and D and not(E)
A= ref $w[0]B= $w[0]{"op"} eq ">"C= $w[0]{"op"} eq ">>"D= defined $w[1]E= not ref $w[1]
ABCDEresult
0XXXX0
100XX0
11X0X0
1010X0
11X100
101100
11X111
101111
667 1 ▶ my ( $e, $wok ) = _write_path( $dev, $w[1], length $text ? "$text\n" : '', $w[0]{op} eq '>>', $ctx );
Branch: 1 branch
BranchTrueFalseTotal
length $text ? : 1 0 1
668 1 ▶ return $wok ? ( [], $ok ) : ( [$e], 0 );
Branch: 1 branch
BranchTrueFalseTotal
$wok ? : 1 0 1
669 }
670 0 die "gap: $post->{raw}\n";
671 }
672  
673 # Eingabe eines Blocks aus done < datei, Heredoc oder Here-String
674 6 ▶sub _post_input {
Subroutine _post_input: called CC=15 SCAR=31.1
675 6 my ( $class, $dev, $post, $ctx ) = @_;
676 6 ▶ return undef unless $post;
Branch: 1 branch
BranchTrueFalseTotal
unless $post 0 6 6
677 6 my $in = $class->_doc_input( $dev, $post, $ctx );
678 6 ▶ return $in if defined $in;
Branch: 1 branch
BranchTrueFalseTotal
if defined $in 0 6 6
679 6 ▶ return undef unless $post->{raw} =~ /</;
Branch: 1 branch
BranchTrueFalseTotal
unless $$post{"raw"} =~ /</ 3 3 6
680 # done < <( befehl ): die Ausgabe des Befehls (in einer Kopie der Shell) als Eingabe
681 3 ▶ if ( $post->{raw} =~ /<\s*<\((.*)\)\s*\z/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$post{"raw"} =~ /<\s*<\((.*)\)\s*\z/s) 2 1 3
682 2 my $sub = { %$SH, vars => { %{ $SH->{vars} } }, ctl => undef };
683 2 my ($o) = $class->_run_inner( $dev, $1, $ctx, $sub );
684 2 ▶ return length( $o // '' ) ? "$o\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
length($o // '') ? : 2 0 2
Condition50%1/2
$o // ""
l!l
20
MC/DC0%0/1
$o // ""
$o
Truth table50%1/2
A
A= $o
Aresult
11
00
685 }
686 1 ▶ die "gap: <( )\n" if $post->{raw} =~ /<\s*<\(/;
Branch: 1 branch
BranchTrueFalseTotal
if $$post{"raw"} =~ /<\s*<\(/ 0 1 1
687 1 my $w = $class->_words_of( $dev, $post->{raw}, $ctx );
688 1 for my $i ( 0 .. $#$w ) {
689 1 ▶ next unless ref $w->[$i] && $w->[$i]{op} eq '<';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$w[$i] and $$w[$i]{"op"} eq "<" 0 1 1
Condition33%1/3
ref $$w[$i] and $$w[$i]{"op"} eq "<"
!ll&&!rl&&r
001
MC/DC0%0/2
ref $$w[$i] and $$w[$i]{"op"} eq "<"
ref $$w[$i] $$w[$i]{"op"} eq "<"
Truth table33%1/3
A and B
A= ref $$w[$i]B= $$w[$i]{"op"} eq "<"
ABresult
0X0
100
111
690 1 my $f = $w->[ $i + 1 ];
691 1 ▶ my $t = defined $f && !ref $f ? _file_text( $dev, _absp($f) ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $f && !ref($f) ? : 1 0 1
Condition33%1/3
defined $f and not ref $f
!ll&&!rl&&r
001
MC/DC0%0/2
defined $f and not ref $f
defined $f not ref $f
Truth table33%1/3
A and not(B)
A= defined $fB= not ref $f
ABresult
0X0
100
111
692 1 ▶ die "bash: " . ( $f // '' ) . ": No such file or directory\n" unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 1 1
Condition0%0/2
$f // ""
l!l
00
MC/DC0%0/1
$f // ""
$f
Truth table0%0/2
A
A= $f
Aresult
11
00
693 1 return $t;
694 }
695 0 return undef;
696 }
697  
698 8 ▶sub _exec_if {
Subroutine _exec_if: called CC=6 SCAR=18.4
699 8 my ( $class, $dev, $nd, $ctx ) = @_;
700 8 my ( $out, $ok ) = ( [], 1 );
701 8 my $done;
702 8 for my $arm ( @{ $nd->{arms} } ) {
703 9 my ( $co, $ck ) = do { local $SH->{in_cond} = 1; $class->_exec_nodes( $dev, $arm->[0], $ctx ) };
704 9 push @$out, @$co;
705 9 ▶ return ( join( "\n", @$out ), 0 ) if $SH->{ctl};
Branch: 1 branch
BranchTrueFalseTotal
if $$Langertha::Holmgang::Sim::Linux::SH{"ctl"} 0 9 9
706 9 ▶ next unless $ck;
Branch: 1 branch
BranchTrueFalseTotal
unless $ck 3 6 9
707 6 my ( $bo, $bk ) = $class->_exec_nodes( $dev, $arm->[1], $ctx );
708 6 push @$out, @$bo;
709 6 ( $ok, $done ) = ( $bk, 1 );
710 6 last;
711 }
712 0 ▶ if ( !$done && $nd->{else} ) { my ( $bo, $bk ) = $class->_exec_nodes( $dev, $nd->{else}, $ctx ); push @$out, @$bo; $ok = $bk }
Branch: 1 branch
BranchTrueFalseTotal
if (not $done and $$nd{"else"}) 0 8 8
Condition66%2/3
not $done and $$nd{"else"}
!ll&&!rl&&r
620
MC/DC0%0/2
not $done and $$nd{"else"}
not $done $$nd{"else"}
Truth table66%2/3
not(A) and B
A= not $doneB= $$nd{"else"}
ABresult
0X0
100
111
713 8 ( $out, $ok ) = $class->_post( $dev, $nd->{post}, $ctx, $out, $ok );
714 8 return ( join( "\n", @$out ), $ok );
715 }
716  
717 # Schleifenrumpf: break/continue (mit Ebenen) auswerten; wahr = weiter
718 1057 ▶sub _loop_ctl {
Subroutine _loop_ctl: called CC=5 SCAR=16.1
719 1057 ▶ my $c = $SH->{ctl} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $c = $$Langertha::Holmgang::Sim::Linux::SH{"ctl"} or return 1 7 1050 1057
720 7 ▶ return 0 if $c->[0] eq 'exit';
Branch: 1 branch
BranchTrueFalseTotal
if $$c[0] eq "exit" 0 7 7
721 7 ▶ if ( $c->[1] > 1 ) { $c->[1]--; return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($$c[1] > 1) 2 5 7
722 5 delete $SH->{ctl};
723 5 ▶ return $c->[0] eq 'continue' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$$c[0] eq 'continue' ? : 4 1 5
724 }
725  
726 14 ▶sub _exec_for {
Subroutine _exec_for: called CC=3 SCAR=11.0
727 14 my ( $class, $dev, $nd, $ctx ) = @_;
728 14 my $w = $class->_words_of( $dev, $nd->{words}, $ctx );
729 14 my @list = grep { !ref } @$w; # Muster schon von _words_of geglobbt
730 14 my ( @out, $ok ) = ();
731 14 $ok = 1;
732 14 local $SH->{loop} = 1;
733 14 for my $v (@list) {
734 40 $SH->{vars}{ $nd->{var} } = $v;
735 40 my ( $o, $k ) = $class->_exec_nodes( $dev, $nd->{body}, $ctx );
736 40 push @out, @$o;
737 40 $ok = $k;
738 40 ▶ last unless _loop_ctl();
Branch: 1 branch
BranchTrueFalseTotal
unless _loop_ctl() 3 37 40
739 }
740 14 my ( $po, $pk ) = $class->_post( $dev, $nd->{post}, $ctx, \@out, $ok );
741 14 return ( join( "\n", @$po ), $pk );
742 }
743  
744 9 ▶sub _exec_while {
Subroutine _exec_while: called CC=22 SCAR=31.4
745 9 my ( $class, $dev, $nd, $ctx ) = @_;
746 9 my $in;
747 9 ▶ if ( defined $nd->{input_cmd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$nd{"input_cmd"}) 3 6 9
748 3 my $sub = { %$SH, vars => { %{ $SH->{vars} } }, ctl => undef };
749 3 ($in) = $class->_run_inner( $dev, $nd->{input_cmd}, $ctx, $sub );
750 3 ▶ $in = length( $in // '' ) ? "$in\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
length($in // '') ? : 3 0 3
Condition50%1/2
$in // ""
l!l
30
MC/DC0%0/1
$in // ""
$in
Truth table50%1/2
A
A= $in
Aresult
11
00
751 }
752 9 ▶ $in //= $class->_post_input( $dev, $nd->{post}, $ctx );
Condition100%3/3
$in //= $class->_post_input($dev, $$nd{"post"}, $ctx)
l!l&&r!l&&!r
333
MC/DC100%2/2
$in //= $class->_post_input($dev, $$nd{"post"}, $ctx)
$in $class->_post_input($dev, $$nd{"post"}, $ctx)
Truth table100%3/3
A //= B
A= $inB= $class->_post_input($dev, $$nd{"post"}, $ctx)
ABresult
1X1
011
000
753 9 my $cond = $nd->{cond};
754 9 ▶ my $read = @$cond == 1 && $cond->[0]{type} eq 'cmd' && $cond->[0]{raw} =~ /\A(?:IFS=\S*\s+)?read\b/ ? $cond->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$cond == 1 && $$cond[0]{'type'} eq 'cmd' && $$cond[0]{'raw'} =~ /\A(?:IFS=\S*\s+)?read\b/ ? : 6 3 9
Condition50%3/6
@$cond == 1 and $$cond[0]{"type"} eq "cmd" and $$cond[0]{"raw"} =~ /\A(?:IFS=\S*\s+)?read\b/
!ll&&!rl&&r
036
@$cond == 1 and $$cond[0]{"type"} eq "cmd"
!ll&&!rl&&r
009
MC/DC33%1/3
@$cond == 1 and $$cond[0]{"type"} eq "cmd" and $$cond[0]{"raw"} =~ /\A(?:IFS=\S*\s+)?read\b/
@$cond == 1 $$cond[0]{"type"} eq "cmd" $$cond[0]{"raw"} =~ /\A(?:IFS=\S*\s+)?read\b/
Truth table50%2/4
A and B and C
A= @$cond == 1B= $$cond[0]{"type"} eq "cmd"C= $$cond[0]{"raw"} =~ /\A(?:IFS=\S*\s+)?read\b/
ABCresult
0XX0
10X0
1100
1111
755 9 ▶ die "gap: while\n" if defined $in && !$read;
Branch: 1 branch
BranchTrueFalseTotal
if defined $in and not $read 0 9 9
Condition66%2/3
defined $in and not $read
!ll&&!rl&&r
360
MC/DC0%0/2
defined $in and not $read
defined $in not $read
Truth table66%2/3
A and not(B)
A= defined $inB= not $read
ABresult
0X0
100
111
756 9 my ( @out, $ok ) = ();
757 9 $ok = 1;
758 9 local $SH->{loop} = 1;
759 9 ▶ my @lines = defined $in ? split( /\n/, $in ) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $in ? : 6 3 9
760 9 my $n = 0;
761 9 while (1) {
762 1026 ▶ die "gap: while (mehr als 1000 Durchlaeufe)\n" if ++$n > 1000;
Branch: 1 branch
BranchTrueFalseTotal
if ++$n > 1000 1 1025 1026
763 1025 my $go;
764 1025 ▶ if ($read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read) { } 18 1007 1025
765 18 ▶ last if $nd->{until} || !@lines;
Branch: 1 branch
BranchTrueFalseTotal
if $$nd{"until"} or not @lines 6 12 18
Condition66%2/3
$$nd{"until"} or not @lines
l!l&&r!l&&!r
0612
MC/DC50%1/2
$$nd{"until"} or not @lines
$$nd{"until"} not @lines
Truth table66%2/3
A or not(B)
A= $$nd{"until"}B= not @lines
ABresult
1X1
011
000
766 12 my $w = $class->_words_of( $dev, $read->{raw}, $ctx );
767 12 my @a = grep { !ref } @$w;
768 12 ▶ local $SHENV = { %{ $SHENV || {} } };
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::SHENV || {}
l!l
012
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::SHENV || {}
$Langertha::Holmgang::Sim::Linux::SHENV
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::SHENV
Aresult
11
00
769 12 ▶ while ( @a && $a[0] =~ /\A(IFS)=(.*)\z/s ) { $SHENV->{$1} = $2; shift @a }
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A(IFS)=(.*)\z/s) 6 12 18
Condition66%2/3
@a and $a[0] =~ /\A(IFS)=(.*)\z/s
!ll&&!rl&&r
0126
MC/DC50%1/2
@a and $a[0] =~ /\A(IFS)=(.*)\z/s
@a $a[0] =~ /\A(IFS)=(.*)\z/s
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A(IFS)=(.*)\z/s
ABresult
0X0
100
111
770 12 shift @a; # read
771 12 _read_into( \@a, shift @lines );
772 12 $go = 1;
773 }
774 else {
775 1007 my ( $co, $ck ) = do { local $SH->{in_cond} = 1; $class->_exec_nodes( $dev, $cond, $ctx ) };
776 1007 push @out, @$co;
777 1007 ▶ last if $SH->{ctl};
Branch: 1 branch
BranchTrueFalseTotal
if $$Langertha::Holmgang::Sim::Linux::SH{"ctl"} 0 1007 1007
778 1007 ▶ $go = $nd->{until} ? !$ck : $ck;
Branch: 1 branch
BranchTrueFalseTotal
$$nd{'until'} ? : 3 1004 1007
779 }
780 1019 ▶ last unless $go;
Branch: 1 branch
BranchTrueFalseTotal
unless $go 2 1017 1019
781 1017 my ( $o, $k ) = $class->_exec_nodes( $dev, $nd->{body}, $ctx );
782 1017 push @out, @$o;
783 1017 $ok = $k;
784 1017 ▶ last unless _loop_ctl();
Branch: 1 branch
BranchTrueFalseTotal
unless _loop_ctl() 0 1017 1017
785 }
786 8 my ( $po, $pk ) = $class->_post( $dev, $nd->{post}, $ctx, \@out, $ok );
787 8 return ( join( "\n", @$po ), $pk );
788 }
789  
790 3 ▶sub _exec_case {
Subroutine _exec_case: called CC=4 SCAR=13.9
791 3 my ( $class, $dev, $nd, $ctx ) = @_;
792 3 my $w = $class->_words_of( $dev, $nd->{word}, $ctx, 1 );
793 3 my $word = join ' ', grep { !ref } @$w;
794 3 for my $arm ( @{ $nd->{arms} } ) {
795 6 for my $p ( @{ $arm->{pats} } ) {
796 7 my $pw = $class->_words_of( $dev, $p, $ctx, 1 );
797 7 my $re = Langertha::Holmgang::Shell::glob_re( join( ' ', grep { !ref } @$pw ), 1 );
798 7 ▶ next unless $word =~ /\A$re\z/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $word =~ /\A$re\z/s 4 3 7
799 3 my ( $o, $k ) = $class->_exec_nodes( $dev, $arm->{body}, $ctx );
800 3 return ( join( "\n", @$o ), $k );
801 }
802 }
803 0 return ( '', 1 );
804 }
805  
806 4616 ▶sub _pipeline {
Subroutine _pipeline: called CC=66 SCAR=51.4
807 4616 my ( $class, $dev, $words, $ctx, $stdin ) = @_;
808 4616 my @stages = ([]);
809 4616 my ( $redir, $file );
810 4616 my @w = @$words;
811 4616 my $infile;
812 4616 ▶ while (@w) {
Branch: 1 branch
BranchTrueFalseTotal
if (@w) 12179 4615 16794
813 12179 my $t = shift @w;
814 12179 ▶ if ( ref $t && $t->{op} eq '|' ) { push @stages, []; next }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t and $$t{"op"} eq "|") 117 12062 12179
Condition100%3/3
ref $t and $$t{"op"} eq "|"
!ll&&!rl&&r
11869193117
MC/DC100%2/2
ref $t and $$t{"op"} eq "|"
ref $t $$t{"op"} eq "|"
Truth table100%3/3
A and B
A= ref $tB= $$t{"op"} eq "|"
ABresult
0X0
100
111
815 12062 ▶ if ( ref $t && $t->{op} eq '<' ) { # < datei: Eingabe des ersten Befehls
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t and $$t{"op"} eq "<") 5 12057 12062
Condition100%3/3
ref $t and $$t{"op"} eq "<"
!ll&&!rl&&r
118691885
MC/DC100%2/2
ref $t and $$t{"op"} eq "<"
ref $t $$t{"op"} eq "<"
Truth table100%3/3
A and B
A= ref $tB= $$t{"op"} eq "<"
ABresult
0X0
100
111
816 5 $infile = shift @w;
817 5 ▶ die "gap: <( )\n" if defined $infile && !ref $infile && $infile =~ /\A<\(/; # < <( … ): Prozessersetzung
Branch: 1 branch
BranchTrueFalseTotal
if defined $infile and not ref $infile and $infile =~ /\A<\(/ 1 4 5
Condition50%3/6
defined $infile and not ref $infile and $infile =~ /\A<\(/
!ll&&!rl&&r
041
defined $infile and not ref $infile
!ll&&!rl&&r
005
MC/DC33%1/3
defined $infile and not ref $infile and $infile =~ /\A<\(/
defined $infile not ref $infile $infile =~ /\A<\(/
Truth table50%2/4
A and not(B) and C
A= defined $infileB= not ref $infileC= $infile =~ /\A<\(/
ABCresult
0XX0
10X0
1100
1111
818 4 ▶ return ( 'bash: syntax error near unexpected token `newline\'', 0 ) unless defined $infile && !ref $infile;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $infile and not ref $infile 0 4 4
Condition33%1/3
defined $infile and not ref $infile
!ll&&!rl&&r
004
MC/DC0%0/2
defined $infile and not ref $infile
defined $infile not ref $infile
Truth table33%1/3
A and not(B)
A= defined $infileB= not ref $infile
ABresult
0X0
100
111
819 4 next;
820 }
821 12057 ▶ if ( ref $t && ( $t->{op} eq '>' || $t->{op} eq '>>' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t and $$t{"op"} eq ">" || $$t{"op"} eq ">>") 188 11869 12057
Condition66%4/6
ref $t and $$t{"op"} eq ">" || $$t{"op"} eq ">>"
!ll&&!rl&&r
118690188
$$t{"op"} eq ">" or $$t{"op"} eq ">>"
l!l&&r!l&&!r
160280
MC/DC33%1/3
ref $t and $$t{"op"} eq ">" || $$t{"op"} eq ">>"
ref $t $$t{"op"} eq ">" $$t{"op"} eq ">>"
Truth table75%3/4
A and B or C
A= ref $tB= $$t{"op"} eq ">"C= $$t{"op"} eq ">>"
ABCresult
0XX0
1000
11X1
1011
822 188 $redir = $t->{op};
823 188 $file = shift @w;
824 188 ▶ return ( 'bash: syntax error near unexpected token `newline\'', 0 ) unless defined $file && !ref $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file and not ref $file 0 188 188
Condition33%1/3
defined $file and not ref $file
!ll&&!rl&&r
00188
MC/DC0%0/2
defined $file and not ref $file
defined $file not ref $file
Truth table33%1/3
A and not(B)
A= defined $fileB= not ref $file
ABresult
0X0
100
111
825 188 next;
826 }
827 11869 ▶ return ( 'bash: syntax error near unexpected token `' . $t->{op} . "'", 0 ) if ref $t;
Branch: 1 branch
BranchTrueFalseTotal
if ref $t 0 11869 11869
828 11869 push @{ $stages[-1] }, $t;
829 }
830 4615 ▶ if ( $redir && @stages == 1 && !@{ $stages[0] } ) { # > datei: leeren bzw. anlegen
Branch: 1 branch
BranchTrueFalseTotal
if ($redir and @stages == 1 and not @{$stages[0];}) 0 4615 4615
Condition83%5/6
$redir and @stages == 1 and not @{$stages[0];}
!ll&&!rl&&r
44281870
$redir and @stages == 1
!ll&&!rl&&r
44271187
MC/DC0%0/3
$redir and @stages == 1 and not @{$stages[0];}
$redir @stages == 1 not @{$stages[0];}
Truth table75%3/4
A and B and not(C)
A= $redirB= @stages == 1C= not @{$stages[0];}
ABCresult
0XX0
10X0
1100
1111
831 0 my ( $e, $wok ) = _write_path( $dev, $file, '', $redir eq '>>', $ctx );
832 0 ▶ return ( $wok ? '' : $e, $wok );
Branch: 1 branch
BranchTrueFalseTotal
$wok ? : 0 0 0
833 }
834 # < datei: Eingabe des ersten Befehls (sonst Heredoc bzw. Pipe in den Block)
835 4615 my $in = $stdin;
836 # /dev/tcp/HOST/PORT oeffnet die bash als Verbindung — ohne Netz nicht nachgebildet: Luecke
837 4615 ▶ if ( defined $infile && $infile =~ m{\A/dev/(?:tcp|udp)/} ) { return _dev_tcp( $dev, $infile, '<' ) }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $infile and $infile =~ m[\A/dev/(?:tcp|udp)/]) 1 4614 4615
Condition100%3/3
defined $infile and $infile =~ m[\A/dev/(?:tcp|udp)/]
!ll&&!rl&&r
461131
MC/DC100%2/2
defined $infile and $infile =~ m[\A/dev/(?:tcp|udp)/]
defined $infile $infile =~ m[\A/dev/(?:tcp|udp)/]
Truth table100%3/3
A and B
A= defined $infileB= $infile =~ m[\A/dev/(?:tcp|udp)/]
ABresult
0X0
100
111
838 4614 ▶ if ( defined $infile && !$redir && @stages == 1 && !@{ $stages[0] } ) { # nur < datei: oeffnen und schliessen
Branch: 1 branch
BranchTrueFalseTotal
if (defined $infile and not $redir and @stages == 1 and not @{$stages[0];}) 0 4614 4614
Condition77%7/9
defined $infile and not $redir and @stages == 1 and not @{$stages[0];}
!ll&&!rl&&r
461220
defined $infile and not $redir and @stages == 1
!ll&&!rl&&r
461202
defined $infile and not $redir
!ll&&!rl&&r
461112
MC/DC0%0/4
defined $infile and not $redir and @stages == 1 and not @{$stages[0];}
defined $infile not $redir @stages == 1 not @{$stages[0];}
Truth table60%3/5
A and not(B) and C and not(D)
A= defined $infileB= not $redirC= @stages == 1D= not @{$stages[0];}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
839 0 ▶ return defined _file_text( $dev, _absp($infile) ) ? ( '', 1 ) : ( "bash: $infile: No such file or directory", 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined _file_text($dev, _absp($infile)) ? : 0 0 0
840 }
841 4614 ▶ if ( defined $infile ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $infile) 3 4611 4614
842 3 $in = _file_text( $dev, _absp($infile) );
843 3 ▶ return ( "bash: $infile: No such file or directory", 0 ) unless defined $in;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in 0 3 3
844 }
845 4614 ▶ return ( "bash: syntax error near unexpected token `|'", 0 ) if grep { !@$_ } @stages;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not @$_;} @stages 0 4614 4614
846 4614 ▶ delete $SH->{code} if $SH;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH 4614 0 4614
847 4614 my ( $out, $ok ) = $class->_command( $dev, $stages[0], $ctx, $in );
848 # ${PIPESTATUS[@]}: Status jeder Stufe
849 4614 ▶ my @ps = ( $ok ? 0 : ( $SH && $SH->{code} ) || 1 );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 4150 464 4614
Condition80%4/5
$Langertha::Holmgang::Sim::Linux::SH and $$Langertha::Holmgang::Sim::Linux::SH{"code"} or 1
l!l
41423
$Langertha::Holmgang::Sim::Linux::SH and $$Langertha::Holmgang::Sim::Linux::SH{"code"}
!ll&&!rl&&r
042341
MC/DC50%1/2
$Langertha::Holmgang::Sim::Linux::SH and $$Langertha::Holmgang::Sim::Linux::SH{"code"} or 1
$Langertha::Holmgang::Sim::Linux::SH $$Langertha::Holmgang::Sim::Linux::SH{"code"}
Truth table66%2/3
A and B
A= $Langertha::Holmgang::Sim::Linux::SHB= $$Langertha::Holmgang::Sim::Linux::SH{"code"}
ABresult
111
0X0
100
850 4614 ▶ $SH->{pipestatus} = \@ps if $SH;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH 4614 0 4614
851 4614 my @err; # Meldungen der bash selbst (stderr) gehen nicht in die Pipe
852 4614 for my $i ( 1 .. $#stages ) {
853 117 local $AS_USER = $AS_USER;
854 117 ▶ if ($ERRNULL) { # 2>/dev/null an der vorigen Stufe: ihre Meldungen nicht in die Pipe
Branch: 1 branch
BranchTrueFalseTotal
if ($Langertha::Holmgang::Sim::Linux::ERRNULL) 2 115 117
855 2 my ($pn) = map { s{.*/}{}r } _strip_sudo( @{ $stages[ $i - 1 ] } );
856 2 ▶ $out = _errnull_cut( $out, [$pn] ) if defined $pn && $ERRNULL->{$pn};
Branch: 1 branch
BranchTrueFalseTotal
if defined $pn and $$Langertha::Holmgang::Sim::Linux::ERRNULL{$pn} 2 0 2
Condition33%1/3
defined $pn and $$Langertha::Holmgang::Sim::Linux::ERRNULL{$pn}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $pn and $$Langertha::Holmgang::Sim::Linux::ERRNULL{$pn}
defined $pn $$Langertha::Holmgang::Sim::Linux::ERRNULL{$pn}
Truth table33%1/3
A and B
A= defined $pnB= $$Langertha::Holmgang::Sim::Linux::ERRNULL{$pn}
ABresult
0X0
100
111
857 }
858 117 ▶ if ( !$ok && defined $out && $out =~ /\Abash: [^\n]+: (?:command not found|No such file or directory)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok and defined $out and $out =~ /\Abash: [^\n]+: (?:command not found|No such file or directory)\z/) 0 117 117
Condition66%4/6
not $ok and defined $out and $out =~ /\Abash: [^\n]+: (?:command not found|No such file or directory)\z/
!ll&&!rl&&r
10980
not $ok and defined $out
!ll&&!rl&&r
10908
MC/DC0%0/3
not $ok and defined $out and $out =~ /\Abash: [^\n]+: (?:command not found|No such file or directory)\z/
not $ok defined $out $out =~ /\Abash: [^\n]+: (?:command not found|No such file or directory)\z/
Truth table50%2/4
not(A) and B and C
A= not $okB= defined $outC= $out =~ /\Abash: [^\n]+: (?:command not found|No such file or directory)\z/
ABCresult
0XX0
10X0
1100
1111
859 0 push @err, $out;
860 0 $out = '';
861 }
862 117 my $argv = [ _strip_sudo( @{ $stages[$i] } ) ];
863 117 ▶ if ( $argv->[0] eq 'tee' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$argv[0] eq "tee") 0 117 117
864 0 my $append = grep { $_ eq '-a' } @$argv;
865 0 my @f = grep { !/\A-/ } @{$argv}[ 1 .. $#$argv ];
866 0 for my $f (@f) {
867 0 ▶ my ( $e, $wok ) = _write_path( $dev, $f, ( $out // '' ) . "\n", $append, $ctx );
Condition0%0/2
$out // ""
l!l
00
MC/DC0%0/1
$out // ""
$out
Truth table0%0/2
A
A= $out
Aresult
11
00
868 0 ▶ return ( $e, 0 ) unless $wok;
Branch: 1 branch
BranchTrueFalseTotal
unless $wok 0 0 0
869 }
870 0 push @ps, 0;
871 0 next;
872 }
873 117 ▶ my ( $t, $k ) = Langertha::Holmgang::Shell::Filter::filter_output( $out // '', $argv );
Condition50%1/2
$out // ""
l!l
1170
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
874 117 ▶ if ( !defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 54 63 117
875 # hatte die vorige Stufe ein Zeilenende? (echo -n, printf ohne \n: nein) — fuer base64
876 54 my @prev = _strip_sudo( @{ $stages[ $i - 1 ] } );
877 54 ▶ local our $STDIN_NL = !( ( $prev[0] // '' ) eq 'echo' && grep( { /\A-[a-zA-Z]*n/ } @prev[ 1 .. $#prev ] )
Condition80%12/15
($prev[0] // '') eq 'echo' && grep({/\A-[a-zA-Z]*n/;} @prev[1 .. $#prev]) || ($prev[0] // '') eq 'printf' && !(($prev[1] // '') =~ /\\n\z/)
l!l&&r!l&&!r
1449
($prev[0] // "") eq "echo" and grep {/\A-[a-zA-Z]*n/;} @prev[1 .. $#prev]
!ll&&!rl&&r
37161
$prev[0] // ""
l!l
540
($prev[0] // "") eq "printf" and not +($prev[1] // "") =~ /\\n\z/
!ll&&!rl&&r
4184
$prev[0] // ""
l!l
530
$prev[1] // ""
l!l
120
MC/DC0%0/4
($prev[0] // '') eq 'echo' && grep({/\A-[a-zA-Z]*n/;} @prev[1 .. $#prev]) || ($prev[0] // '') eq 'printf' && !(($prev[1] // '') =~ /\\n\z/)
$prev[0] grep {/\A-[a-zA-Z]*n/;} @prev[1 .. $#prev] $prev[0] $prev[1]
Truth table14%1/7
A and B || C and not(D)
A= $prev[0]B= grep {/\A-[a-zA-Z]*n/;} @prev[1 .. $#prev]C= $prev[0]D= $prev[1]
ABCDresult
11XX1
0X101
10101
0X0X0
0X110
100X0
10110
878 || ( $prev[0] // '' ) eq 'printf' && ( $prev[1] // '' ) !~ /\\n\z/ );
879 54 ▶ delete $SH->{code} if $SH;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH 54 0 54
880 54 ( $t, $k ) = $class->_command( $dev, $argv, $ctx, $out );
881 }
882 117 ▶ push @ps, $k ? 0 : ( $SH && $SH->{code} ) || 1;
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 113 4 117
Condition40%2/5
$Langertha::Holmgang::Sim::Linux::SH and $$Langertha::Holmgang::Sim::Linux::SH{"code"} or 1
l!l
04
$Langertha::Holmgang::Sim::Linux::SH and $$Langertha::Holmgang::Sim::Linux::SH{"code"}
!ll&&!rl&&r
040
MC/DC0%0/2
$Langertha::Holmgang::Sim::Linux::SH and $$Langertha::Holmgang::Sim::Linux::SH{"code"} or 1
$Langertha::Holmgang::Sim::Linux::SH $$Langertha::Holmgang::Sim::Linux::SH{"code"}
Truth table33%1/3
A and B
A= $Langertha::Holmgang::Sim::Linux::SHB= $$Langertha::Holmgang::Sim::Linux::SH{"code"}
ABresult
111
0X0
100
883 117 ( $out, $ok ) = ( $t, $k );
884 }
885 4614 ▶ if ($redir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($redir) 188 4426 4614
886 188 ▶ my ( $e, $wok ) = _write_path( $dev, $file, defined $out && length $out ? "$out\n" : '', $redir eq '>>', $ctx );
Branch: 1 branch
BranchTrueFalseTotal
defined $out && length $out ? : 179 9 188
Condition66%2/3
defined $out and length $out
!ll&&!rl&&r
09179
MC/DC50%1/2
defined $out and length $out
defined $out length $out
Truth table66%2/3
A and B
A= defined $outB= length $out
ABresult
0X0
100
111
887 188 ▶ return ( $e, 0 ) unless $wok;
Branch: 1 branch
BranchTrueFalseTotal
unless $wok 9 179 188
888 179 return ( join( "\n", @err ), $ok );
889 }
890 4426 ▶ return ( join( "\n", @err, defined $out && length $out ? $out : () ), $ok ) if @err;
Branch: 2 branches
BranchTrueFalseTotal
if @err 0 4426 4426
defined $out && length $out ? : 0 0 0
Condition0%0/3
defined $out and length $out
!ll&&!rl&&r
000
MC/DC0%0/2
defined $out and length $out
defined $out length $out
Truth table0%0/3
A and B
A= defined $outB= length $out
ABresult
0X0
100
111
891 4426 return ( $out, $ok );
892 }
893  
894 # Shell-Muster (*, ?) gegen die Pfade im Zustand; ohne Treffer bleibt das Wort
895 39 ▶sub _glob {
Subroutine _glob: called CC=10 SCAR=25.8
896 39 my ( $dev, $w ) = @_;
897 0 ▶ if ( $w =~ m{\A(.+?)/+\z} ) { my @h = _glob( $dev, $1 ); return @h == 1 && $h[0] eq $1 ? $w : map {"$_/"} @h }
Branch: 2 branches
BranchTrueFalseTotal
if ($w =~ m[\A(.+?)/+\z]) 0 39 39
@h == 1 && $h[0] eq $1 ? : 0 0 0
Condition0%0/3
@h == 1 and $h[0] eq $1
!ll&&!rl&&r
000
MC/DC0%0/2
@h == 1 and $h[0] eq $1
@h == 1 $h[0] eq $1
Truth table0%0/3
A and B
A= @h == 1B= $h[0] eq $1
ABresult
0X0
100
111
898 39 ( my $re = quotemeta $w ) =~ s/\\\*/[^\/]*/g;
899 39 $re =~ s/\\\?/[^\/]/g;
900 # Zeichenklassen [0-9], [!a] bzw. [^a]
901 39 ▶ $re =~ s/\\\[((?:\\[!^])?)((?:(?!\\\]).)+)\\\]/'[' . ( length $1 ? '^' : '' ) . ( $2 =~ s{\\(.)}{$1}gr ) . ']'/ge;
Branch: 1 branch
BranchTrueFalseTotal
length $1 ? : 0 2 2
902 39 my %cand;
903 39 ▶ for my $p ( keys %{ $dev->{files} || {} } ) {
Condition50%1/2
$$dev{'files'} || {}
l!l
390
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
904 348 my @seg = split m{/}, $p;
905 348 $cand{ join '/', @seg[ 0 .. $_ ] } = 1 for 1 .. $#seg;
906 }
907 82 ▶ my $rx = do { no warnings; eval { qr/\A$re\z/ } } // return $w; # kein gueltiges Muster (sed-Ausdruck, JSON): das Wort bleibt
Subroutine BEGIN: called CC=1 SCAR=0.0
Condition50%1/2
do { no warnings; eval { do { qr/\A$re\z/ } } } // (return $w)
l!l
390
MC/DC0%0/1
do { no warnings; eval { do { qr/\A$re\z/ } } } // (return $w)
do { no warnings; eval { do { qr/\A$re\z/ } } }
Truth table50%1/2
A
A= do { no warnings; eval { do { qr/\A$re\z/ } } }
Aresult
11
00
908 39 my @hit = sort grep { $_ =~ $rx } keys %cand;
909 39 ▶ return @hit ? @hit : $w;
Branch: 1 branch
BranchTrueFalseTotal
@hit ? : 9 30 39
910 }
911  
912 # mkdir [-p] [-m MODUS] [-v] dir …: ohne -p muss der Elternordner da sein; als Benutzer
913 # braucht es Schreibrecht am Elternordner (s. _may_create); umask und setgid wirken.
914 20 ▶sub _mkdir {
Subroutine _mkdir: called CC=27 SCAR=35.1
915 20 my ( $dev, $av ) = @_;
916 20 my @a = @$av;
917 20 my ( $p, $mode, $v, @d );
918 20 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 34 20 54
919 34 my $x = shift @a;
920 34 ▶ if ( $x eq '-m' || $x eq '--mode' ) { $mode = shift @a }
Branch: 6 branches
BranchTrueFalseTotal
if ($x eq '-m' or $x eq '--mode') { } 2 32 34
elsif ($x =~ /\A--mode=(.+)\z/) { } 0 32 32
elsif ($x eq '--parents') { } 0 32 32
elsif ($x eq '--verbose') { } 0 32 32
elsif ($x =~ /\A-([pvm]+)\z/) { } 11 21 32
elsif ($x eq '--') { } 0 21 21
Condition66%2/3
$x eq "-m" or $x eq "--mode"
l!l&&r!l&&!r
2032
MC/DC50%1/2
$x eq "-m" or $x eq "--mode"
$x eq "-m" $x eq "--mode"
Truth table66%2/3
A or B
A= $x eq "-m"B= $x eq "--mode"
ABresult
1X1
011
000
921 0 elsif ( $x =~ /\A--mode=(.+)\z/ ) { $mode = $1 }
922 0 elsif ( $x eq '--parents' ) { $p = 1 }
923 0 elsif ( $x eq '--verbose' ) { $v = 1 }
924 11 ▶ elsif ( $x =~ /\A-([pvm]+)\z/ ) { my $f = $1; $p = 1 if $f =~ /p/; $v = 1 if $f =~ /v/; $mode = shift @a if $f =~ /m/ }
Branch: 3 branches
BranchTrueFalseTotal
if $f =~ /p/ 11 0 11
if $f =~ /v/ 0 11 11
if $f =~ /m/ 0 11 11
925 0 elsif ( $x eq '--' ) { push @d, @a; last }
926 21 else { push @d, $x }
927 }
928 20 ▶ return ( "mkdir: missing operand\nTry 'mkdir --help' for more information.", 0 ) unless @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 20 20
929 20 ▶ return ( "mkdir: invalid mode '$mode'", 0 ) if defined $mode && $mode !~ /\A[0-7]{1,4}\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mode and not $mode =~ /\A[0-7]{1,4}\z/ 0 20 20
Condition66%2/3
defined $mode and not $mode =~ /\A[0-7]{1,4}\z/
!ll&&!rl&&r
1820
MC/DC0%0/2
defined $mode and not $mode =~ /\A[0-7]{1,4}\z/
defined $mode not $mode =~ /\A[0-7]{1,4}\z/
Truth table66%2/3
A and not(B)
A= defined $modeB= not $mode =~ /\A[0-7]{1,4}\z/
ABresult
0X0
100
111
930 20 my ( @out, $ok ) = ();
931 20 $ok = 1;
932 20 for my $raw (@d) {
933 21 ( my $d = _absp($raw) ) =~ s{(?<=.)/+\z}{};
934 21 ▶ if ( _is_dir( $dev, $d ) || _file_entry( $dev, $d ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_dir($dev, $d) or _file_entry($dev, $d)) 5 16 21
Condition66%2/3
_is_dir($dev, $d) or _file_entry($dev, $d)
l!l&&r!l&&!r
5016
MC/DC50%1/2
_is_dir($dev, $d) or _file_entry($dev, $d)
_is_dir($dev, $d) _file_entry($dev, $d)
Truth table66%2/3
A or B
A= _is_dir($dev, $d)B= _file_entry($dev, $d)
ABresult
1X1
011
000
935 5 ▶ next if $p && _is_dir( $dev, $d );
Branch: 1 branch
BranchTrueFalseTotal
if $p and _is_dir($dev, $d) 3 2 5
Condition66%2/3
$p and _is_dir($dev, $d)
!ll&&!rl&&r
203
MC/DC50%1/2
$p and _is_dir($dev, $d)
$p _is_dir($dev, $d)
Truth table66%2/3
A and B
A= $pB= _is_dir($dev, $d)
ABresult
0X0
100
111
936 2 push @out, "mkdir: cannot create directory '$raw': File exists";
937 2 $ok = 0;
938 2 next;
939 }
940 16 my @seg = split m{/}, $d;
941 16 my @todo = grep { !_is_dir( $dev, $_ ) } map { join '/', @seg[ 0 .. $_ ] } 1 .. $#seg;
942 16 ▶ if ( @todo > 1 && !$p ) { push @out, "mkdir: cannot create directory '$raw': No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if (@todo > 1 and not $p) 1 15 16
Condition100%3/3
@todo > 1 and not $p
!ll&&!rl&&r
1321
MC/DC100%2/2
@todo > 1 and not $p
@todo > 1 not $p
Truth table100%3/3
A and not(B)
A= @todo > 1B= not $p
ABresult
0X0
100
111
943 15 for my $t (@todo) {
944 19 ▶ if ( my $err = _may_create( $dev, $t ) ) { push @out, "mkdir: cannot create directory '" . ( $t eq $d ? $raw : $t ) . "': $err"; $ok = 0; last }
Branch: 2 branches
BranchTrueFalseTotal
if (my $err = _may_create($dev, $t)) 1 18 19
$t eq $d ? : 1 0 1
945 18 ▶ $dev->{dirs}{$t} = _new_meta( $dev, $t, 1, $t eq $d ? $mode : undef );
Branch: 1 branch
BranchTrueFalseTotal
$t eq $d ? : 14 4 18
946 18 ▶ push @out, "mkdir: created directory '$t'" if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 0 18 18
947 }
948 }
949 20 return ( join( "\n", @out ), $ok );
950 }
951  
952 # Wer gerade anlegt: der Benutzer des Befehls (sudo -u), sonst der Shell (su)
953 1056 ▶sub _who { return $AS_USER // $LOGIN_USER // 'root' }
Subroutine _who: called CC=3 SCAR=11.0
Condition100%5/5
($Langertha::Holmgang::Sim::Linux::AS_USER // $Langertha::Holmgang::Sim::Linux::LOGIN_USER) // "root"
l!l
60996
$Langertha::Holmgang::Sim::Linux::AS_USER // $Langertha::Holmgang::Sim::Linux::LOGIN_USER
l!l&&r!l&&!r
528996
MC/DC100%2/2
($Langertha::Holmgang::Sim::Linux::AS_USER // $Langertha::Holmgang::Sim::Linux::LOGIN_USER) // "root"
$Langertha::Holmgang::Sim::Linux::AS_USER $Langertha::Holmgang::Sim::Linux::LOGIN_USER
Truth table100%3/3
A // B
A= $Langertha::Holmgang::Sim::Linux::AS_USERB= $Langertha::Holmgang::Sim::Linux::LOGIN_USER
ABresult
1X1
011
000
954  
955 # Verzeichnis-Eintrag mit Rechten (auch /tmp, /var/tmp: 1777; /home/<benutzer>: dem Benutzer)
956 263 ▶sub _dir_meta {
Subroutine _dir_meta: called CC=9 SCAR=25.5
957 263 my ( $dev, $d ) = @_;
958 263 ▶ return { mode => '0755', %{ $dev->{dirs}{$d} } } if ref( ( $dev->{dirs} || {} )->{$d} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref(($$dev{"dirs"} || {})->{$d}) eq "HASH" 59 204 263
Condition100%2/2
$$dev{'dirs'} || {}
l!l
105158
MC/DC100%1/1
$$dev{'dirs'} || {}
$$dev{'dirs'}
Truth table100%2/2
A
A= $$dev{'dirs'}
Aresult
11
00
959 204 ▶ return { mode => '1777' } if $d eq '/tmp' || $d eq '/var/tmp';
Branch: 1 branch
BranchTrueFalseTotal
if $d eq "/tmp" or $d eq "/var/tmp" 22 182 204
Condition66%2/3
$d eq "/tmp" or $d eq "/var/tmp"
l!l&&r!l&&!r
220182
MC/DC50%1/2
$d eq "/tmp" or $d eq "/var/tmp"
$d eq "/tmp" $d eq "/var/tmp"
Truth table66%2/3
A or B
A= $d eq "/tmp"B= $d eq "/var/tmp"
ABresult
1X1
011
000
960 182 ▶ if ( $d =~ m{\A/home/([^/]+)\z} && ( my $u = ( $dev->{users} || {} )->{$1} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d =~ m[\A/home/([^/]+)\z] and my $u = ($$dev{"users"} || {})->{$1}) 0 182 182
Condition20%1/5
$d =~ m[\A/home/([^/]+)\z] and my $u = ($$dev{"users"} || {})->{$1}
!ll&&!rl&&r
18200
$$dev{'users'} || {}
l!l
00
MC/DC0%0/2
$d =~ m[\A/home/([^/]+)\z] and my $u = ($$dev{"users"} || {})->{$1}
$d =~ m[\A/home/([^/]+)\z] $$dev{'users'}
Truth table33%1/3
A and B
A= $d =~ m[\A/home/([^/]+)\z]B= $$dev{'users'}
ABresult
0X0
100
111
961 0 ▶ return { owner => $1, group => ( $u->{groups} || [$1] )->[0], mode => '0755' };
Condition0%0/2
$$u{'groups'} || [$1]
l!l
00
MC/DC0%0/1
$$u{'groups'} || [$1]
$$u{'groups'}
Truth table0%0/2
A
A= $$u{'groups'}
Aresult
11
00
962 }
963 182 return { mode => '0755' };
964 }
965  
966 # Recht (4 r, 2 w, 1 x) eines Benutzers an einem Eintrag mit owner/group/mode
967 69 ▶sub _perm {
Subroutine _perm: called CC=13 SCAR=26.8
968 69 my ( $dev, $user, $e, $bit ) = @_;
969 69 ▶ return 1 if $user eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $user eq "root" 0 69 69
970 69 ▶ my $m = oct( $e->{mode} // '0644' );
Condition50%1/2
$$e{"mode"} // "0644"
l!l
690
MC/DC0%0/1
$$e{"mode"} // "0644"
$$e{"mode"}
Truth table50%1/2
A
A= $$e{"mode"}
Aresult
11
00
971 69 ▶ return ( ( $m >> 6 ) & $bit ) ? 1 : 0 if ( $e->{owner} // 'root' ) eq $user;
Branch: 2 branches
BranchTrueFalseTotal
if ($$e{"owner"} // "root") eq $user 2 67 69
$m >> 6 & $bit ? : 2 0 2
Condition100%2/2
$$e{"owner"} // "root"
l!l
3831
MC/DC100%1/1
$$e{"owner"} // "root"
$$e{"owner"}
Truth table100%2/2
A
A= $$e{"owner"}
Aresult
11
00
972 67 ▶ my @groups = @{ ( ( $dev->{users} || {} )->{$user} || {} )->{groups} || [] };
Condition50%3/6
(($$dev{'users'} || {})->{$user} || {})->{'groups'} || []
l!l
670
($$dev{'users'} || {})->{$user} || {}
l!l
670
$$dev{'users'} || {}
l!l
670
MC/DC0%0/1
(($$dev{'users'} || {})->{$user} || {})->{'groups'} || []
$$dev{'users'}
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
973 67 ▶ return ( ( $m >> 3 ) & $bit ) ? 1 : 0 if grep { $_ eq ( $e->{group} // 'root' ) } @groups;
Branch: 2 branches
BranchTrueFalseTotal
if grep {$_ eq ($$e{"group"} // "root");} @groups 17 50 67
$m >> 3 & $bit ? : 17 0 17
Condition100%2/2
$$e{"group"} // "root"
l!l
5338
MC/DC100%1/1
$$e{"group"} // "root"
$$e{"group"}
Truth table100%2/2
A
A= $$e{"group"}
Aresult
11
00
974 50 ▶ return ( $m & $bit ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$m & $bit ? : 35 15 50
975 }
976  
977 # Darf der aktuelle Benutzer $path anlegen bzw. beschreiben? undef oder die Meldung
978 385 ▶sub _may_create {
Subroutine _may_create: called CC=8 SCAR=20.9
979 385 my ( $dev, $path ) = @_;
980 385 my $user = _who();
981 385 ▶ return undef if $user eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $user eq "root" 373 12 385
982 12 ▶ return 'Permission denied' unless _traverse_ok( $dev, $path );
Branch: 1 branch
BranchTrueFalseTotal
unless _traverse_ok($dev, $path) 4 8 12
983 8 ▶ if ( my $e = _file_entry( $dev, $path ) ) { return _perm( $dev, $user, $e, 2 ) ? undef : 'Permission denied' }
Branch: 2 branches
BranchTrueFalseTotal
if (my $e = _file_entry($dev, $path)) 1 7 8
_perm($dev, $user, $e, 2) ? : 1 0 1
984 7 ( my $dir = $path ) =~ s{/[^/]+\z}{};
985 7 ▶ my $de = _dir_meta( $dev, length $dir ? $dir : '/' );
Branch: 1 branch
BranchTrueFalseTotal
length $dir ? : 7 0 7
986 7 ▶ return _perm( $dev, $user, $de, 2 ) && _perm( $dev, $user, $de, 1 ) ? undef : 'Permission denied';
Branch: 1 branch
BranchTrueFalseTotal
_perm($dev, $user, $de, 2) && _perm($dev, $user, $de, 1) ? : 3 4 7
Condition66%2/3
_perm($dev, $user, $de, 2) and _perm($dev, $user, $de, 1)
!ll&&!rl&&r
403
MC/DC50%1/2
_perm($dev, $user, $de, 2) and _perm($dev, $user, $de, 1)
_perm($dev, $user, $de, 2) _perm($dev, $user, $de, 1)
Truth table66%2/3
A and B
A= _perm($dev, $user, $de, 2)B= _perm($dev, $user, $de, 1)
ABresult
0X0
100
111
987 }
988  
989 # Darf der aktuelle Benutzer bis $path gehen (x an jedem Verzeichnis davor)? root immer
990 132 ▶sub _traverse_ok {
Subroutine _traverse_ok: called CC=4 SCAR=13.9
991 132 my ( $dev, $path ) = @_;
992 132 my $user = _who();
993 132 ▶ return 1 if $user eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $user eq "root" 107 25 132
994 25 my @seg = split m{/}, $path =~ s{(?<=.)/+\z}{}r;
995 25 for my $i ( 1 .. $#seg - 1 ) {
996 49 my $d = join '/', @seg[ 0 .. $i ];
997 49 ▶ return 0 unless _perm( $dev, $user, _dir_meta( $dev, $d ), 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless _perm($dev, $user, _dir_meta($dev, $d), 1) 10 39 49
998 }
999 15 return 1;
1000 }
1001  
1002 # Recht (4 r, 2 w, 1 x) des aktuellen Benutzers an einem Verzeichnis selbst
1003 115 ▶sub _dir_ok {
Subroutine _dir_ok: called CC=2 SCAR=6.9
1004 115 my ( $dev, $d, $bit ) = @_;
1005 115 my $user = _who();
1006 115 ▶ return $user eq 'root' ? 1 : _perm( $dev, $user, _dir_meta( $dev, $d ), $bit );
Branch: 1 branch
BranchTrueFalseTotal
$user eq 'root' ? : 107 8 115
1007 }
1008  
1009 # Darf der aktuelle Benutzer die Datei lesen (Weg und r)?
1010 104 ▶sub _read_ok {
Subroutine _read_ok: called CC=4 SCAR=14.0
1011 104 my ( $dev, $path ) = @_;
1012 104 my $user = _who();
1013 104 ▶ return 1 if $user eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $user eq "root" 101 3 104
1014 3 ▶ my $e = _file_entry( $dev, $path ) or return 1; # gibt es nicht: die Meldung dafuer kommt woanders
Branch: 1 branch
BranchTrueFalseTotal
my $e = _file_entry($dev, $path) or return 1 3 0 3
1015 3 ▶ return _traverse_ok( $dev, $path ) && _perm( $dev, $user, { mode => sprintf( '%o', _mode_of($e) ), owner => $e->{owner}, group => $e->{group} }, 4 );
Condition66%2/3
_traverse_ok($dev, $path) && _perm($dev, $user, {'mode', sprintf('%o', _mode_of($e)), 'owner', $$e{'owner'}, 'group', $$e{'group'}}, 4)
!ll&&!rl&&r
201
MC/DC50%1/2
_traverse_ok($dev, $path) && _perm($dev, $user, {'mode', sprintf('%o', _mode_of($e)), 'owner', $$e{'owner'}, 'group', $$e{'group'}}, 4)
_traverse_ok($dev, $path) _perm($dev, $user, {'mode', sprintf('%o', _mode_of($e)), 'owner', $$e{'owner'}, 'group', $$e{'group'}}, 4)
Truth table66%2/3
A && B
A= _traverse_ok($dev, $path)B= _perm($dev, $user, {'mode', sprintf('%o', _mode_of($e)), 'owner', $$e{'owner'}, 'group', $$e{'group'}}, 4)
ABresult
0X0
100
111
1016 }
1017  
1018 # Metadaten eines neuen Eintrags: Eigentuemer der aktuelle Benutzer, Gruppe seine erste
1019 # (im setgid-Verzeichnis die des Verzeichnisses, Verzeichnisse erben setgid), Rechte
1020 # 0666/0777 ohne umask. Als root mit umask 022 ohne setgid: wie bisher (Vorgaben).
1021 195 ▶sub _new_meta {
Subroutine _new_meta: called CC=20 SCAR=30.1
1022 195 my ( $dev, $path, $isdir, $mode ) = @_;
1023 195 my $user = _who();
1024 195 ( my $dir = $path ) =~ s{/[^/]+\z}{};
1025 195 ▶ my $pe = _dir_meta( $dev, length $dir ? $dir : '/' );
Branch: 1 branch
BranchTrueFalseTotal
length $dir ? : 194 1 195
1026 195 ▶ my $sgid = oct( $pe->{mode} // '0755' ) & 02000;
Condition50%1/2
$$pe{"mode"} // "0755"
l!l
1950
MC/DC0%0/1
$$pe{"mode"} // "0755"
$$pe{"mode"}
Truth table50%1/2
A
A= $$pe{"mode"}
Aresult
11
00
1027 195 ▶ my $umask = $SH && defined $SH->{umask} ? $SH->{umask} : 022;
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::SH && defined $$Langertha::Holmgang::Sim::Linux::SH{'umask'} ? : 3 192 195
Condition100%3/3
$Langertha::Holmgang::Sim::Linux::SH and defined $$Langertha::Holmgang::Sim::Linux::SH{"umask"}
!ll&&!rl&&r
471453
MC/DC100%2/2
$Langertha::Holmgang::Sim::Linux::SH and defined $$Langertha::Holmgang::Sim::Linux::SH{"umask"}
$Langertha::Holmgang::Sim::Linux::SH defined $$Langertha::Holmgang::Sim::Linux::SH{"umask"}
Truth table100%3/3
A and B
A= $Langertha::Holmgang::Sim::Linux::SHB= defined $$Langertha::Holmgang::Sim::Linux::SH{"umask"}
ABresult
0X0
100
111
1028 195 ▶ return $isdir ? {} : undef if $user eq 'root' && !$sgid && $umask == 022 && !defined $mode;
Branch: 2 branches
BranchTrueFalseTotal
if $user eq "root" and not $sgid and $umask == 18 and not defined $mode 187 8 195
$isdir ? : 14 173 187
Condition100%9/9
$user eq "root" and not $sgid and $umask == 18 and not defined $mode
!ll&&!rl&&r
62187
$user eq "root" and not $sgid and $umask == 18
!ll&&!rl&&r
42189
$user eq "root" and not $sgid
!ll&&!rl&&r
31191
MC/DC100%4/4
$user eq "root" and not $sgid and $umask == 18 and not defined $mode
$user eq "root" not $sgid $umask == 18 not defined $mode
Truth table100%5/5
A and not(B) and C and not(D)
A= $user eq "root"B= not $sgidC= $umask == 18D= not defined $mode
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1029 8 ▶ my $m = defined $mode ? oct($mode) : ( $isdir ? 0777 : 0666 ) & ~$umask;
Branch: 2 branches
BranchTrueFalseTotal
defined $mode ? : 2 6 8
$isdir ? : 2 4 6
1030 8 ▶ $m |= 02000 if $isdir && $sgid;
Branch: 1 branch
BranchTrueFalseTotal
if $isdir and $sgid 1 7 8
Condition100%3/3
$isdir and $sgid
!ll&&!rl&&r
431
MC/DC100%2/2
$isdir and $sgid
$isdir $sgid
Truth table100%3/3
A and B
A= $isdirB= $sgid
ABresult
0X0
100
111
1031 8 ▶ my $grp = $sgid ? $pe->{group} // 'root' : $user eq 'root' ? 'root' : ( ( ( $dev->{users} || {} )->{$user} || {} )->{groups} || [$user] )->[0];
Branch: 2 branches
BranchTrueFalseTotal
$sgid ? : 3 5 8
$user eq 'root' ? : 4 1 5
Condition50%4/8
$$pe{"group"} // "root"
l!l
30
(($$dev{'users'} || {})->{$user} || {})->{'groups'} || [$user]
l!l
10
($$dev{'users'} || {})->{$user} || {}
l!l
10
$$dev{'users'} || {}
l!l
10
MC/DC0%0/1
$$pe{"group"} // "root"
$$pe{"group"}
MC/DC0%0/1
(($$dev{'users'} || {})->{$user} || {})->{'groups'} || [$user]
$$dev{'users'}
Truth table50%1/2
A
A= $$pe{"group"}
Aresult
11
00
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
1032 8 return { owner => $user, group => $grp, mode => sprintf( '%04o', $m ) };
1033 }
1034  
1035 # umask [-S] [MODUS] (eingebaut, je Shell)
1036 7 ▶sub _umask {
Subroutine _umask: called CC=9 SCAR=22.0
1037 7 my @a = @_;
1038 7 ▶ my $sym = @a && $a[0] eq '-S' ? shift @a : undef;
Branch: 1 branch
BranchTrueFalseTotal
@a && $a[0] eq '-S' ? : 1 6 7
Condition100%3/3
@a and $a[0] eq "-S"
!ll&&!rl&&r
241
MC/DC100%2/2
@a and $a[0] eq "-S"
@a $a[0] eq "-S"
Truth table100%3/3
A and B
A= @aB= $a[0] eq "-S"
ABresult
0X0
100
111
1039 7 ▶ my $cur = defined $SH->{umask} ? $SH->{umask} : 022;
Branch: 1 branch
BranchTrueFalseTotal
defined $$Langertha::Holmgang::Sim::Linux::SH{'umask'} ? : 1 6 7
1040 7 ▶ if ( !@a ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@a) 3 4 7
1041 3 ▶ return ( sprintf( '%04o', $cur ), 1 ) unless $sym;
Branch: 1 branch
BranchTrueFalseTotal
unless $sym 2 1 3
1042 1 ▶ my @p = map { my $b = 7 & ~( $cur >> $_->[1] ); "$_->[0]=" . join '', map { $b & $_->[1] ? $_->[0] : () } [ r => 4 ], [ w => 2 ], [ x => 1 ] } [ u => 6 ], [ g => 3 ], [ o => 0 ];
Branch: 1 branch
BranchTrueFalseTotal
$b & $$_[1] ? : 7 2 9
1043 1 return ( join( ',', @p ), 1 );
1044 }
1045 4 ▶ die "gap: umask $a[0]\n" if $a[0] =~ /[ugoa=+-]/; # symbolisch: nicht nachgebildet
Branch: 1 branch
BranchTrueFalseTotal
if $a[0] =~ /[ugoa=+-]/ 0 4 4
1046 4 ▶ return ( "bash: umask: $a[0]: octal number out of range", 0 ) unless $a[0] =~ /\A[0-7]{1,4}\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $a[0] =~ /\A[0-7]{1,4}\z/ 1 3 4
1047 3 $SH->{umask} = oct( $a[0] ) & 0777;
1048 3 return ( '', 1 );
1049 }
1050  
1051 # Pfad relativ zum aktuellen Verzeichnis (cd)
1052 1286 ▶sub _absp {
Subroutine _absp: called CC=5 SCAR=16.1
1053 1286 my ($p) = @_;
1054 1286 ▶ return _dotdot($p) if $p =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ m[\A/] 845 441 1286
1055 441 ▶ my $c = $CWD_DIR // '/root';
Condition100%2/2
$Langertha::Holmgang::Sim::Linux::CWD_DIR // "/root"
l!l
40833
MC/DC100%1/1
$Langertha::Holmgang::Sim::Linux::CWD_DIR // "/root"
$Langertha::Holmgang::Sim::Linux::CWD_DIR
Truth table100%2/2
A
A= $Langertha::Holmgang::Sim::Linux::CWD_DIR
Aresult
11
00
1056 441 $p =~ s{\A\./}{};
1057 441 ▶ return _dotdot( $p eq '.' ? $c : $c eq '/' ? "/$p" : "$c/$p" );
Branch: 2 branches
BranchTrueFalseTotal
$p eq '.' ? : 6 435 441
$c eq '/' ? : 2 433 435
1058 }
1059  
1060 # . und .. in einem absoluten Pfad aufloesen (/srv/a/../b -> /srv/b); ein / am Ende bleibt
1061 1288 ▶sub _dotdot {
Subroutine _dotdot: called CC=8 SCAR=20.8
1062 1288 my ($p) = @_;
1063 1288 ▶ return $p unless $p =~ m{(?:\A|/)\.\.?(?:/|\z)};
Branch: 1 branch
BranchTrueFalseTotal
unless $p =~ m[(?:\A|/)\.\.?(?:/|\z)] 1278 10 1288
1064 10 ▶ my $end = $p =~ m{(?<=.)/\z} ? '/' : '';
Branch: 1 branch
BranchTrueFalseTotal
$p =~ m[(?<=.)/\z] ? : 4 6 10
1065 10 my @s;
1066 10 for my $x ( split m{/+}, $p ) {
1067 60 ▶ next if $x eq '' || $x eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "" or $x eq "." 12 48 60
Condition100%3/3
$x eq "" or $x eq "."
l!l&&r!l&&!r
10248
MC/DC100%2/2
$x eq "" or $x eq "."
$x eq "" $x eq "."
Truth table100%3/3
A or B
A= $x eq ""B= $x eq "."
ABresult
1X1
011
000
1068 48 ▶ if ( $x eq '..' ) { pop @s; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "..") 10 38 48
1069 38 push @s, $x;
1070 }
1071 10 ▶ return '/' . join( '/', @s ) . ( @s ? $end : '' );
Branch: 1 branch
BranchTrueFalseTotal
@s ? : 10 0 10
1072 }
1073  
1074 # cp wie GNU: ohne -p/-a gehoert die neue Datei root (Rechte der Quelle ohne umask 022),
1075 # eine vorhandene Zieldatei behaelt Eigentuemer und Rechte; -a/-p erhaelt alles;
1076 # Verzeichnisse nur mit -r/-R/-a.
1077 18 ▶sub _cp {
Subroutine _cp: called CC=32 SCAR=38.4
1078 18 my ( $dev, $av ) = @_;
1079 18 my ( %o, @a );
1080 18 for my $x (@$av) {
1081 0 ▶ if ( $x =~ /\A--(archive|preserve(?:=.*)?|recursive|no-clobber)\z/ ) { $o{ substr( $1, 0, 1 ) eq 'a' ? 'a' : substr( $1, 0, 1 ) eq 'p' ? 'p' : substr( $1, 0, 1 ) eq 'r' ? 'r' : 'n' } = 1 }
Branch: 6 branches
BranchTrueFalseTotal
if ($x =~ /\A--(archive|preserve(?:=.*)?|recursive|no-clobber)\z/) { } 0 43 43
elsif ($x =~ /\A--/) { } 0 43 43
elsif ($x =~ /\A-([a-zA-Z]+)\z/) { } 6 37 43
substr($1, 0, 1) eq 'a' ? : 0 0 0
substr($1, 0, 1) eq 'p' ? : 0 0 0
substr($1, 0, 1) eq 'r' ? : 0 0 0
1082 elsif ( $x =~ /\A--/ ) { }
1083 6 ▶ elsif ( $x =~ /\A-([a-zA-Z]+)\z/ ) { $o{ $_ eq 'R' ? 'r' : $_ } = 1 for split //, $1 }
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'R' ? : 0 6 6
1084 37 else { push @a, _absp($x) }
1085 }
1086 18 ▶ return ( 'cp: missing file operand', 0 ) unless @a >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @a >= 2 0 18 18
1087 18 my $to = pop @a;
1088 18 $to =~ s{(?<=.)/+\z}{};
1089 18 ▶ my $keep = $o{a} || $o{p};
Condition100%3/3
$o{'a'} || $o{'p'}
l!l&&r!l&&!r
2214
MC/DC100%2/2
$o{'a'} || $o{'p'}
$o{'a'} $o{'p'}
Truth table100%3/3
A || B
A= $o{'a'}B= $o{'p'}
ABresult
1X1
011
000
1090 18 ▶ my $rec = $o{a} || $o{r};
Condition100%3/3
$o{'a'} || $o{'r'}
l!l&&r!l&&!r
2214
MC/DC100%2/2
$o{'a'} || $o{'r'}
$o{'a'} $o{'r'}
Truth table100%3/3
A || B
A= $o{'a'}B= $o{'r'}
ABresult
1X1
011
000
1091 18 ▶ return ( "cp: target '$to': Not a directory", 0 ) if @a > 1 && !_is_dir( $dev, $to );
Branch: 1 branch
BranchTrueFalseTotal
if @a > 1 and not _is_dir($dev, $to) 0 18 18
Condition66%2/3
@a > 1 and not _is_dir($dev, $to)
!ll&&!rl&&r
1710
MC/DC0%0/2
@a > 1 and not _is_dir($dev, $to)
@a > 1 not _is_dir($dev, $to)
Truth table66%2/3
A and not(B)
A= @a > 1B= not _is_dir($dev, $to)
ABresult
0X0
100
111
1092 18 _part('Backup');
1093 18 ▶ my $put = sub {
Subroutine __ANON__: called CC=9 SCAR=23.0
1094 18 my ( $src, $dst ) = @_;
1095 18 ▶ return if $o{n} && _file_entry( $dev, $dst );
Branch: 1 branch
BranchTrueFalseTotal
if $o{"n"} and _file_entry($dev, $dst) 0 18 18
Condition33%1/3
$o{"n"} and _file_entry($dev, $dst)
!ll&&!rl&&r
1800
MC/DC0%0/2
$o{"n"} and _file_entry($dev, $dst)
$o{"n"} _file_entry($dev, $dst)
Truth table33%1/3
A and B
A= $o{"n"}B= _file_entry($dev, $dst)
ABresult
0X0
100
111
1096 18 my $new = Langertha::Holmgang::Sim::Linux::Backup::copy_entry( $dev->{files}{$src}, $keep );
1097 18 ▶ my $old = ref $dev->{files}{$dst} eq 'HASH' ? $dev->{files}{$dst} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'}{$dst} eq 'HASH' ? : 2 16 18
1098 18 ▶ if ( $old && !$keep ) { $new->{$_} = $old->{$_} for grep { defined $old->{$_} } qw( owner group mode ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($old and not $keep) 2 16 18
Condition66%2/3
$old and not $keep
!ll&&!rl&&r
1602
MC/DC50%1/2
$old and not $keep
$old not $keep
Truth table66%2/3
A and not(B)
A= $oldB= not $keep
ABresult
0X0
100
111
1099 18 ▶ $new->{open_by} = $old->{open_by} if $old && $old->{open_by};
Branch: 1 branch
BranchTrueFalseTotal
if $old and $$old{"open_by"} 0 18 18
Condition66%2/3
$old and $$old{"open_by"}
!ll&&!rl&&r
1620
MC/DC0%0/2
$old and $$old{"open_by"}
$old $$old{"open_by"}
Truth table66%2/3
A and B
A= $oldB= $$old{"open_by"}
ABresult
0X0
100
111
1100 18 $dev->{files}{$dst} = $new;
1101 18 };
1102 18 for my $from (@a) {
1103 19 $from =~ s{(?<=.)/+\z}{};
1104 19 ( my $base = $from ) =~ s{.*/}{};
1105 19 ▶ if ( _file_entry( $dev, $from ) ) { $put->( $from, _is_dir( $dev, $to ) ? "$to/$base" : $to ); next }
Branch: 2 branches
BranchTrueFalseTotal
if (_file_entry($dev, $from)) 13 6 19
_is_dir($dev, $to) ? : 4 9 13
1106 6 ▶ return ( "cp: cannot stat '$from': No such file or directory", 0 ) unless _is_dir( $dev, $from );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_dir($dev, $from) 1 5 6
1107 5 ▶ return ( "cp: -r not specified; omitting directory '$from'", 0 ) unless $rec;
Branch: 1 branch
BranchTrueFalseTotal
unless $rec 2 3 5
1108 3 ▶ my $root = _is_dir( $dev, $to ) ? ( $to eq '/' ? '' : $to ) . "/$base" : $to;
Branch: 2 branches
BranchTrueFalseTotal
_is_dir($dev, $to) ? : 2 1 3
$to eq '/' ? : 0 2 2
1109 3 $put->( $_, $root . substr( $_, length $from ) ) for _under( $dev, $from );
1110 3 ▶ for my $d ( sort grep { $_ eq $from || index( $_, "$from/" ) == 0 } keys %{ $dev->{dirs} || {} } ) {
Condition80%4/5
$_ eq $from || index($_, "$from/") == 0
l!l&&r!l&&!r
2011
$$dev{'dirs'} || {}
l!l
21
MC/DC50%1/2
$_ eq $from || index($_, "$from/") == 0
$_ eq $from index($_, "$from/") == 0
MC/DC100%1/1
$$dev{'dirs'} || {}
$$dev{'dirs'}
Truth table66%2/3
A || B
A= $_ eq $fromB= index($_, "$from/") == 0
ABresult
1X1
011
000
Truth table100%2/2
A
A= $$dev{'dirs'}
Aresult
11
00
1111 2 my $e = $dev->{dirs}{$d};
1112 2 ▶ $dev->{dirs}{ $root . substr( $d, length $from ) } = $keep && ref $e eq 'HASH' ? {%$e} : ref $e eq 'HASH' && defined $e->{mode} ? { mode => $e->{mode} } : {};
Branch: 2 branches
BranchTrueFalseTotal
$keep && ref $e eq 'HASH' ? : 1 1 2
ref $e eq 'HASH' && defined $$e{'mode'} ? : 1 0 1
Condition50%3/6
$keep and ref $e eq "HASH"
!ll&&!rl&&r
101
ref $e eq "HASH" and defined $$e{"mode"}
!ll&&!rl&&r
001
MC/DC50%1/2
$keep and ref $e eq "HASH"
$keep ref $e eq "HASH"
MC/DC0%0/2
ref $e eq "HASH" and defined $$e{"mode"}
ref $e eq "HASH" defined $$e{"mode"}
Truth table66%2/3
A and B
A= $keepB= ref $e eq "HASH"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= ref $e eq "HASH"B= defined $$e{"mode"}
ABresult
0X0
100
111
1113 }
1114 3 ▶ $dev->{dirs}{$root} //= {} unless _is_dir( $dev, $root );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_dir($dev, $root) 0 3 3
Condition0%0/2
$$dev{"dirs"}{$root} //= {}
l!l
00
MC/DC0%0/1
$$dev{"dirs"}{$root} //= {}
$$dev{"dirs"}{$root}
Truth table0%0/2
A
A= $$dev{"dirs"}{$root}
Aresult
11
00
1115 }
1116 15 return ( '', 1 );
1117 }
1118  
1119 # Ziel einer Kopie/Verschiebung: in ein vorhandenes Verzeichnis hinein, sonst der Name selbst
1120 0 ▶sub _dest {
Subroutine _dest: not called CC=3 SCAR=24.8
1121 0 my ( $dev, $from, $to ) = @_;
1122 0 ( my $base = $from ) =~ s{/+\z}{};
1123 0 $base =~ s{.*/}{};
1124 0 $to =~ s{(?<=.)/+\z}{};
1125 0 ▶ return _is_dir( $dev, $to ) ? ( $to eq '/' ? "/$base" : "$to/$base" ) : $to;
Branch: 2 branches
BranchTrueFalseTotal
_is_dir($dev, $to) ? : 0 0 0
$to eq '/' ? : 0 0 0
1126 }
1127  
1128 # Verzeichnis samt Inhalt kopieren/verschieben (cp -r/-a, mv)
1129 1 ▶sub _tree {
Subroutine _tree: called CC=10 SCAR=25.5
1130 1 my ( $dev, $from, $to, $how ) = @_;
1131 1 $from =~ s{(?<=.)/+\z}{};
1132 1 ▶ my $who = $Langertha::Holmgang::Sim::Linux::AS_USER // 'root';
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
01
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
$Langertha::Holmgang::Sim::Linux::AS_USER
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::AS_USER
Aresult
11
00
1133 4 ▶ my $own = sub {
Subroutine __ANON__: called CC=3 SCAR=18.1
1134 4 my $e = shift;
1135 4 ▶ return $e if $how ne 'copy';
Branch: 1 branch
BranchTrueFalseTotal
if $how ne "copy" 4 0 4
1136 0 my %n = %$e;
1137 0 delete @n{qw( owner group open_by )};
1138 0 ▶ @n{qw( owner group )} = ( $who, $who ) if $who ne 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $who ne "root" 0 0 0
1139 0 return \%n;
1140 1 };
1141 1 ▶ my $dirs = $dev->{dirs} ||= {};
Condition50%1/2
$$dev{"dirs"} ||= {}
l!l
10
MC/DC0%0/1
$$dev{"dirs"} ||= {}
$$dev{"dirs"}
Truth table50%1/2
A
A= $$dev{"dirs"}
Aresult
11
00
1142 1 ▶ for my $d ( sort grep { $_ eq $from || index( $_, "$from/" ) == 0 } keys %$dirs ) {
Condition100%3/3
$_ eq $from || index($_, "$from/") == 0
l!l&&r!l&&!r
125
MC/DC100%2/2
$_ eq $from || index($_, "$from/") == 0
$_ eq $from index($_, "$from/") == 0
Truth table100%3/3
A || B
A= $_ eq $fromB= index($_, "$from/") == 0
ABresult
1X1
011
000
1143 3 my $n = $to . substr( $d, length $from );
1144 3 $dirs->{$n} = $own->( { %{ $dirs->{$d} } } );
1145 3 ▶ delete $dirs->{$d} if $how eq 'move';
Branch: 1 branch
BranchTrueFalseTotal
if $how eq "move" 3 0 3
1146 }
1147 1 ▶ $dirs->{$to} //= {};
Condition50%1/2
$$dirs{$to} //= {}
l!l
10
MC/DC0%0/1
$$dirs{$to} //= {}
$$dirs{$to}
Truth table50%1/2
A
A= $$dirs{$to}
Aresult
11
00
1148 1 for my $f ( _under( $dev, $from ) ) {
1149 1 my $n = $to . substr( $f, length $from );
1150 1 my $e = $dev->{files}{$f};
1151 1 ▶ $dev->{files}{$n} = ref $e ? $own->( { %$e } ) : $e;
Branch: 1 branch
BranchTrueFalseTotal
ref $e ? : 1 0 1
1152 1 ▶ delete $dev->{files}{$f} if $how eq 'move';
Branch: 1 branch
BranchTrueFalseTotal
if $how eq "move" 1 0 1
1153 }
1154 1 return ( '', 1 );
1155 }
1156  
1157 # namei -l pfad: jeder Teil des Pfads mit Rechten und Besitzern (wie util-linux)
1158 1 ▶sub _namei {
Subroutine _namei: called CC=22 SCAR=31.5
1159 1 my ( $dev, $av ) = @_;
1160 1 ▶ my @p = grep { !/\A-/ } @$av or return ( 'namei: no pathname specified', 0 );
Branch: 1 branch
BranchTrueFalseTotal
my(@p) = grep({not /\A-/;} @$av) or return "namei: no pathname specified", 0 1 0 1
1161 1 my @out;
1162 1 for my $path (@p) {
1163 1 push @out, "f: $path";
1164 1 my @parts = grep {length} split m{/}, $path;
1165 1 my $cur = '';
1166 1 for my $i ( -1 .. $#parts ) {
1167 5 ▶ my $name = $i < 0 ? '/' : $parts[$i];
Branch: 1 branch
BranchTrueFalseTotal
$i < 0 ? : 1 4 5
1168 5 ▶ $cur = $i < 0 ? '' : "$cur/$parts[$i]";
Branch: 1 branch
BranchTrueFalseTotal
$i < 0 ? : 1 4 5
1169 5 ▶ my $p = $cur eq '' ? '/' : $cur;
Branch: 1 branch
BranchTrueFalseTotal
$cur eq '' ? : 1 4 5
1170 5 my $e = _file_entry( $dev, $p );
1171 5 ▶ my $dir = !$e && ( $p eq '/' || _is_dir( $dev, $p ) );
Condition66%4/6
!$e && ($p eq '/' || _is_dir($dev, $p))
!ll&&!rl&&r
104
$p eq "/" or _is_dir($dev, $p)
l!l&&r!l&&!r
130
MC/DC33%1/3
!$e && ($p eq '/' || _is_dir($dev, $p))
!$e $p eq "/" _is_dir($dev, $p)
Truth table75%3/4
not(A) && B or C
A= !$eB= $p eq "/"C= _is_dir($dev, $p)
ABCresult
0XX0
1000
11X1
1011
1172 5 ▶ return ( join( "\n", @out, " $name - No such file or directory" ), 0 ) unless $e || $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $e or $dir 0 5 5
Condition66%2/3
$e or $dir
l!l&&r!l&&!r
140
MC/DC0%0/2
$e or $dir
$e $dir
Truth table66%2/3
A or B
A= $eB= $dir
ABresult
1X1
011
000
1173 5 ▶ my $x = $e // { mode => '0755', %{ ( $dev->{dirs} || {} )->{$p} || {} } };
Condition83%5/6
$e // {"mode", "0755", %{($$dev{"dirs"} || {})->{$p} or {};}}
l!l
14
($$dev{'dirs'} || {})->{$p} || {}
l!l
22
$$dev{'dirs'} || {}
l!l
40
MC/DC100%1/1
$e // {"mode", "0755", %{($$dev{"dirs"} || {})->{$p} or {};}}
$e
MC/DC0%0/1
($$dev{'dirs'} || {})->{$p} || {}
$$dev{'dirs'}
Truth table100%2/2
A
A= $e
Aresult
11
00
Truth table50%1/2
A
A= $$dev{'dirs'}
Aresult
11
00
1174 5 ▶ my $m = oct( $x->{mode} // ( $dir ? '0755' : '0644' ) );
Branch: 1 branch
BranchTrueFalseTotal
$dir ? : 0 0 0
Condition50%1/2
$$x{"mode"} // ($dir ? "0755" : "0644")
l!l
50
MC/DC0%0/1
$$x{"mode"} // ($dir ? "0755" : "0644")
$$x{"mode"}
Truth table50%1/2
A
A= $$x{"mode"}
Aresult
11
00
1175 5 ▶ my $s = ( $dir ? 'd' : '-' ) . join '', map { my $b = ( $m >> ( 3 * $_ ) ) & 7; ( $b & 4 ? 'r' : '-' ) . ( $b & 2 ? 'w' : '-' ) . ( $b & 1 ? 'x' : '-' ) } 2, 1, 0;
Branch: 4 branches
BranchTrueFalseTotal
$dir ? : 4 1 5
$b & 4 ? : 11 4 15
$b & 2 ? : 6 9 15
$b & 1 ? : 10 5 15
1176 5 ▶ push @out, sprintf( '%s %-8s %-8s %s', $s, $x->{owner} // 'root', $x->{group} // 'root', $name );
Condition100%4/4
$$x{"owner"} // "root"
l!l
32
$$x{"group"} // "root"
l!l
32
MC/DC100%1/1
$$x{"owner"} // "root"
$$x{"owner"}
MC/DC100%1/1
$$x{"group"} // "root"
$$x{"group"}
Truth table100%2/2
A
A= $$x{"owner"}
Aresult
11
00
Truth table100%2/2
A
A= $$x{"group"}
Aresult
11
00
1177 }
1178 }
1179 1 return ( join( "\n", @out ), 1 );
1180 }
1181  
1182 20 ▶sub _mv {
Subroutine _mv: called CC=14 SCAR=26.8
1183 20 my ( $dev, $av ) = @_;
1184 20 my @a = map { _absp($_) } grep { !/\A-/ } @$av;
1185 20 ▶ return ( 'mv: missing file operand', 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 20 20
1186 20 ▶ return ( "mv: missing destination file operand after '$a[0]'", 0 ) if @a == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @a == 1 0 20 20
1187 20 ▶ return _mv_many( $dev, @a ) if @a > 2 || !_file_entry( $dev, $a[0] ) && _is_dir( $dev, $a[0] );
Branch: 1 branch
BranchTrueFalseTotal
if @a > 2 or not _file_entry($dev, $a[0]) and _is_dir($dev, $a[0]) 8 12 20
Condition83%5/6
@a > 2 or not _file_entry($dev, $a[0]) and _is_dir($dev, $a[0])
l!l&&r!l&&!r
4412
not _file_entry($dev, $a[0]) and _is_dir($dev, $a[0])
!ll&&!rl&&r
1204
MC/DC66%2/3
@a > 2 or not _file_entry($dev, $a[0]) and _is_dir($dev, $a[0])
@a > 2 not _file_entry($dev, $a[0]) _is_dir($dev, $a[0])
Truth table75%3/4
A or not(B) and C
A= @a > 2B= not _file_entry($dev, $a[0])C= _is_dir($dev, $a[0])
ABCresult
1XX1
0111
00X0
0100
1188 12 my ( $from, $to ) = @a;
1189 12 my $as_dir = $to =~ m{.(?:/+)\z};
1190 12 $to =~ s{(?<=.)/+\z}{}; # mv datei dir/
1191 12 ▶ _file_entry( $dev, $from ) or return ( "mv: cannot stat '$from': No such file or directory", 0 );
Branch: 1 branch
BranchTrueFalseTotal
_file_entry($dev, $from) or return "mv: cannot stat '${from}': No such file or directory", 0 12 0 12
1192 12 ▶ return ( "mv: cannot move '$from' to '$to/': Not a directory", 0 ) if $as_dir && !_is_dir( $dev, $to ); # Ziel mit / muss ein Verzeichnis sein
Branch: 1 branch
BranchTrueFalseTotal
if $as_dir and not _is_dir($dev, $to) 1 11 12
Condition100%3/3
$as_dir and not _is_dir($dev, $to)
!ll&&!rl&&r
921
MC/DC100%2/2
$as_dir and not _is_dir($dev, $to)
$as_dir not _is_dir($dev, $to)
Truth table100%3/3
A and not(B)
A= $as_dirB= not _is_dir($dev, $to)
ABresult
0X0
100
111
1193 11 ( my $base = $from ) =~ s{.*/}{};
1194 11 ▶ my $no_dir = grep { /\A-\w*T/ || $_ eq '--no-target-directory' } @$av;
Condition66%2/3
/\A-\w*T/ || $_ eq '--no-target-directory'
l!l&&r!l&&!r
1022
MC/DC50%1/2
/\A-\w*T/ || $_ eq '--no-target-directory'
/\A-\w*T/ $_ eq '--no-target-directory'
Truth table66%2/3
A || B
A= /\A-\w*T/B= $_ eq '--no-target-directory'
ABresult
1X1
011
000
1195 11 ▶ if ( !$no_dir && _is_dir( $dev, $to ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $no_dir and _is_dir($dev, $to)) 7 4 11
Condition100%3/3
not $no_dir and _is_dir($dev, $to)
!ll&&!rl&&r
137
MC/DC100%2/2
not $no_dir and _is_dir($dev, $to)
not $no_dir _is_dir($dev, $to)
Truth table100%3/3
not(A) and B
A= not $no_dirB= _is_dir($dev, $to)
ABresult
0X0
100
111
1196 7 my $e = $dev->{files}{$to};
1197 7 ▶ $to = ( ref $e eq 'HASH' && defined $e->{link} ? _link_target( $to, $e->{link} ) : $to ) . "/$base";
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' && defined $$e{'link'} ? : 0 7 7
Condition33%1/3
ref $e eq "HASH" and defined $$e{"link"}
!ll&&!rl&&r
700
MC/DC0%0/2
ref $e eq "HASH" and defined $$e{"link"}
ref $e eq "HASH" defined $$e{"link"}
Truth table33%1/3
A and B
A= ref $e eq "HASH"B= defined $$e{"link"}
ABresult
0X0
100
111
1198 }
1199 11 my @keep = _parents_of( $dev, $from );
1200 11 $dev->{files}{$to} = delete $dev->{files}{$from};
1201 11 _keep_dirs( $dev, @keep );
1202 11 return ( '', 1 );
1203 }
1204  
1205 # mv QUELLE… VERZEICHNIS (auch Verzeichnisse als Quelle): Fehler je Quelle, die uebrigen laufen
1206 8 ▶sub _mv_many {
Subroutine _mv_many: called CC=23 SCAR=34.7
1207 8 my ( $dev, @a ) = @_;
1208 8 my $to = pop @a;
1209 8 $to =~ s{(?<=.)/+\z}{};
1210 8 ▶ if ( !_is_dir( $dev, $to ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_is_dir($dev, $to)) 5 3 8
1211 5 ▶ return ( "mv: target '$to': Not a directory", 0 ) if @a > 1 && _file_entry( $dev, $to );
Branch: 1 branch
BranchTrueFalseTotal
if @a > 1 and _file_entry($dev, $to) 0 5 5
Condition66%2/3
@a > 1 and _file_entry($dev, $to)
!ll&&!rl&&r
320
MC/DC0%0/2
@a > 1 and _file_entry($dev, $to)
@a > 1 _file_entry($dev, $to)
Truth table66%2/3
A and B
A= @a > 1B= _file_entry($dev, $to)
ABresult
0X0
100
111
1212 5 ▶ return ( "mv: target '$to': No such file or directory", 0 ) if @a > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @a > 1 2 3 5
1213 }
1214 6 my ( @out, $ok ) = ();
1215 6 $ok = 1;
1216 6 for my $from (@a) {
1217 8 $from =~ s{(?<=.)/+\z}{};
1218 8 ( my $base = $from ) =~ s{.*/}{};
1219 8 ▶ if ( _file_entry( $dev, $from ) ) { my ( $o, $k ) = _mv( $dev, [ $from, $to ] ); push @out, $o if length $o; $ok &&= $k; next }
Branch: 2 branches
BranchTrueFalseTotal
if (_file_entry($dev, $from)) 4 4 8
if length $o 0 4 4
Condition33%1/3
$ok &&= $k
!ll&&!rl&&r
004
MC/DC0%0/2
$ok &&= $k
$ok $k
Truth table33%1/3
A &&= B
A= $okB= $k
ABresult
0X0
100
111
1220 0 ▶ if ( !_is_dir( $dev, $from ) ) { push @out, "mv: cannot stat '$from': No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (_is_dir($dev, $from)) 0 4 4
1221 4 ▶ my $dst = _is_dir( $dev, $to ) ? ( $to eq '/' ? '' : $to ) . "/$base" : $to;
Branch: 2 branches
BranchTrueFalseTotal
_is_dir($dev, $to) ? : 1 3 4
$to eq '/' ? : 0 1 1
1222 0 ▶ if ( $dst eq $from || index( $dst, "$from/" ) == 0 ) { push @out, "mv: cannot move '$from' to a subdirectory of itself, '$dst'"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($dst eq $from or index($dst, "$from/") == 0) 0 4 4
Condition33%1/3
$dst eq $from or index($dst, "$from/") == 0
l!l&&r!l&&!r
004
MC/DC0%0/2
$dst eq $from or index($dst, "$from/") == 0
$dst eq $from index($dst, "$from/") == 0
Truth table33%1/3
A or B
A= $dst eq $fromB= index($dst, "$from/") == 0
ABresult
1X1
011
000
1223 4 ( my $up = $dst ) =~ s{/[^/]+\z}{};
1224 4 ▶ if ( length $up && !_is_dir( $dev, $up ) ) { push @out, "mv: cannot move '$from' to '$dst': No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if (length $up and not _is_dir($dev, $up)) 1 3 4
Condition66%2/3
length $up and not _is_dir($dev, $up)
!ll&&!rl&&r
031
MC/DC50%1/2
length $up and not _is_dir($dev, $up)
length $up not _is_dir($dev, $up)
Truth table66%2/3
A and not(B)
A= length $upB= not _is_dir($dev, $up)
ABresult
0X0
100
111
1225 3 my @keep = _parents_of( $dev, $from );
1226 3 $dev->{files}{ $dst . substr( $_, length $from ) } = delete $dev->{files}{$_} for _under( $dev, $from );
1227 3 for my $k (qw( dirs _dirs )) {
1228 6 ▶ for my $d ( grep { $_ eq $from || index( $_, "$from/" ) == 0 } keys %{ $dev->{$k} || {} } ) { $dev->{$k}{ $dst . substr( $d, length $from ) } = delete $dev->{$k}{$d} }
Condition80%4/5
$_ eq $from || index($_, "$from/") == 0
l!l&&r!l&&!r
109
$$dev{$k} || {}
l!l
33
MC/DC50%1/2
$_ eq $from || index($_, "$from/") == 0
$_ eq $from index($_, "$from/") == 0
MC/DC100%1/1
$$dev{$k} || {}
$$dev{$k}
Truth table66%2/3
A || B
A= $_ eq $fromB= index($_, "$from/") == 0
ABresult
1X1
011
000
Truth table100%2/2
A
A= $$dev{$k}
Aresult
11
00
1229 }
1230 3 ▶ $dev->{dirs}{$dst} //= {} unless _is_dir( $dev, $dst );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_dir($dev, $dst) 0 3 3
Condition0%0/2
$$dev{"dirs"}{$dst} //= {}
l!l
00
MC/DC0%0/1
$$dev{"dirs"}{$dst} //= {}
$$dev{"dirs"}{$dst}
Truth table0%0/2
A
A= $$dev{"dirs"}{$dst}
Aresult
11
00
1231 3 _keep_dirs( $dev, @keep );
1232 }
1233 6 return ( join( "\n", @out ), $ok );
1234 }
1235  
1236 # Elternverzeichnisse eines Pfads, die es gibt — vor dem Loeschen gemerkt, damit sie danach
1237 # bleiben (_keep_dirs; im Zustand unter _dirs, eine Laufzeitspur)
1238 36 ▶sub _parents_of {
Subroutine _parents_of: called CC=2 SCAR=7.2
1239 36 my ( $dev, $p ) = @_;
1240 36 my @seg = split m{/}, $p;
1241 36 ▶ return grep { length && _is_dir( $dev, $_ ) } map { join '/', @seg[ 0 .. $_ ] } 1 .. $#seg - 1;
Condition33%1/3
length $_ && _is_dir($dev, $_)
!ll&&!rl&&r
0072
MC/DC0%0/2
length $_ && _is_dir($dev, $_)
length $_ _is_dir($dev, $_)
Truth table33%1/3
A && B
A= length $_B= _is_dir($dev, $_)
ABresult
0X0
100
111
1242 }
1243  
1244 36 ▶sub _keep_dirs {
Subroutine _keep_dirs: called CC=2 SCAR=6.9
1245 36 my ( $dev, @d ) = @_;
1246 36 $dev->{_dirs}{$_} = 1 for grep { !_is_dir( $dev, $_ ) } @d;
1247 36 return;
1248 }
1249  
1250 82 our $STDIN_NL = 1;
1251  
1252 4872 ▶sub _strip_sudo {
Subroutine _strip_sudo: called CC=34 SCAR=41.4
1253 4872 my @a = @_;
1254 4872 ▶ while ( @a && $a[0] eq 'sudo' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] eq "sudo") 71 4867 4938
Condition66%2/3
@a and $a[0] eq "sudo"
!ll&&!rl&&r
0486771
MC/DC50%1/2
@a and $a[0] eq "sudo"
@a $a[0] eq "sudo"
Truth table66%2/3
A and B
A= @aB= $a[0] eq "sudo"
ABresult
0X0
100
111
1255 71 shift @a;
1256 71 ▶ my $invoker = $AS_USER // 'root';
Condition100%2/2
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
665
MC/DC100%1/1
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
$Langertha::Holmgang::Sim::Linux::AS_USER
Truth table100%2/2
A
A= $Langertha::Holmgang::Sim::Linux::AS_USER
Aresult
11
00
1257 71 my ( $list, $lu, $target, $nonint );
1258 71 ▶ while ( @a && $a[0] =~ /\A-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-/) 69 71 140
Condition100%3/3
@a and $a[0] =~ /\A-/
!ll&&!rl&&r
36869
MC/DC100%2/2
@a and $a[0] =~ /\A-/
@a $a[0] =~ /\A-/
Truth table100%3/3
A and B
A= @aB= $a[0] =~ /\A-/
ABresult
0X0
100
111
1259 69 my $o = shift @a;
1260 69 ▶ last if $o eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "--" 0 69 69
1261 69 ▶ if ( $o eq '-u' ) { $target = shift @a }
Branch: 7 branches
BranchTrueFalseTotal
if ($o eq '-u') { } 61 8 69
elsif ($o eq '-g') { } 0 8 8
elsif ($o =~ /\A--user=(.+)\z/) { } 0 8 8
elsif ($o eq '-U') { } 2 6 8
elsif ($o =~ /\A-l+\z/ or $o eq '--list') { } 3 3 6
elsif ($o eq '-n' or $o eq '--non-interactive') { } 3 0 3
elsif ($o =~ /\A-[nilsEHk]+\z/) { } 0 0 0
1262 0 elsif ( $o eq '-g' ) { shift @a }
1263 0 elsif ( $o =~ /\A--user=(.+)\z/ ) { $target = $1 }
1264 2 elsif ( $o eq '-U' ) { $lu = shift @a }
1265 3 ▶ elsif ( $o =~ /\A-l+\z/ || $o eq '--list' ) { $list = 1 }
Condition66%2/3
$o =~ /\A-l+\z/ or $o eq "--list"
l!l&&r!l&&!r
303
MC/DC50%1/2
$o =~ /\A-l+\z/ or $o eq "--list"
$o =~ /\A-l+\z/ $o eq "--list"
Truth table66%2/3
A or B
A= $o =~ /\A-l+\z/B= $o eq "--list"
ABresult
1X1
011
000
1266 3 ▶ elsif ( $o eq '-n' || $o eq '--non-interactive' ) { $nonint = 1 }
Condition33%1/3
$o eq "-n" or $o eq "--non-interactive"
l!l&&r!l&&!r
300
MC/DC0%0/2
$o eq "-n" or $o eq "--non-interactive"
$o eq "-n" $o eq "--non-interactive"
Truth table33%1/3
A or B
A= $o eq "-n"B= $o eq "--non-interactive"
ABresult
1X1
011
000
1267 0 ▶ elsif ( $o =~ /\A-[nilsEHk]+\z/ ) { $nonint = 1 if $o =~ /n/; $list = 1 if $o =~ /l/ }
Branch: 2 branches
BranchTrueFalseTotal
if $o =~ /n/ 0 0 0
if $o =~ /l/ 0 0 0
1268 }
1269 71 ▶ return ( 'sudo-list', $lu // $invoker ) if $list && !@a;
Branch: 1 branch
BranchTrueFalseTotal
if $list and not @a 3 68 71
Condition66%4/6
$list and not @a
!ll&&!rl&&r
6803
$lu // $invoker
l!l&&r!l&&!r
210
MC/DC50%1/2
$list and not @a
$list not @a
MC/DC0%0/2
$lu // $invoker
$lu $invoker
Truth table66%2/3
A and not(B)
A= $listB= not @a
ABresult
0X0
100
111
Truth table66%2/3
A // B
A= $luB= $invoker
ABresult
1X1
011
000
1270 # ein Benutzer ohne Root-Rechte: sudo prueft seine Regeln (wie sudo -n ohne Terminal)
1271 68 ▶ if ( $invoker ne 'root' && @a && $CTX && ref $CTX->{state} eq 'HASH' && defined $CTX->{host} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($invoker ne "root" and @a and $Langertha::Holmgang::Sim::Linux::CTX and ref $$Langertha::Holmgang::Sim::Linux::CTX{"state"} eq "HASH" and defined $$Langertha::Holmgang::Sim::Linux::CTX{"host"}) 5 63 68
Condition66%8/12
$invoker ne "root" and @a and $Langertha::Holmgang::Sim::Linux::CTX and ref $$Langertha::Holmgang::Sim::Linux::CTX{"state"} eq "HASH" and defined $$Langertha::Holmgang::Sim::Linux::CTX{"host"}
!ll&&!rl&&r
6305
$invoker ne "root" and @a and $Langertha::Holmgang::Sim::Linux::CTX and ref $$Langertha::Holmgang::Sim::Linux::CTX{"state"} eq "HASH"
!ll&&!rl&&r
6305
$invoker ne "root" and @a and $Langertha::Holmgang::Sim::Linux::CTX
!ll&&!rl&&r
6305
$invoker ne "root" and @a
!ll&&!rl&&r
6305
MC/DC20%1/5
$invoker ne "root" and @a and $Langertha::Holmgang::Sim::Linux::CTX and ref $$Langertha::Holmgang::Sim::Linux::CTX{"state"} eq "HASH" and defined $$Langertha::Holmgang::Sim::Linux::CTX{"host"}
$invoker ne "root" @a $Langertha::Holmgang::Sim::Linux::CTX ref $$Langertha::Holmgang::Sim::Linux::CTX{"state"} eq "HASH" defined $$Langertha::Holmgang::Sim::Linux::CTX{"host"}
Truth table33%2/6
A and B and C and D and E
A= $invoker ne "root"B= @aC= $Langertha::Holmgang::Sim::Linux::CTXD= ref $$Langertha::Holmgang::Sim::Linux::CTX{"state"} eq "HASH"E= defined $$Langertha::Holmgang::Sim::Linux::CTX{"host"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1272 5 my $dev = $CTX->{state}{ $CTX->{host} };
1273 5 ▶ if ( ref $dev eq 'HASH' && defined _file_text( $dev, '/etc/sudoers' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dev eq "HASH" and defined _file_text($dev, "/etc/sudoers")) 5 0 5
Condition33%1/3
ref $dev eq "HASH" and defined _file_text($dev, "/etc/sudoers")
!ll&&!rl&&r
005
MC/DC0%0/2
ref $dev eq "HASH" and defined _file_text($dev, "/etc/sudoers")
ref $dev eq "HASH" defined _file_text($dev, "/etc/sudoers")
Truth table33%1/3
A and B
A= ref $dev eq "HASH"B= defined _file_text($dev, "/etc/sudoers")
ABresult
0X0
100
111
1274 5 ▶ my $path = $a[0] =~ m{/} ? $a[0] : do { my ( $p, $k ) = _which( 'which', $dev, [ $a[0] ] ); $k ? $p : undef };
Branch: 2 branches
BranchTrueFalseTotal
$a[0] =~ m[/] ? : 4 1 5
$k ? : 1 0 1
1275 my $why = _acc()->can('sudo_check')->( $dev, $invoker, $target // 'root', $path // $a[0], defined $path,
1276 5 ▶ [ @a[ 1 .. $#a ] ], $nonint, $CTX->{host} );
Condition40%2/5
$target // "root"
l!l
05
$path // $a[0]
l!l&&r!l&&!r
500
MC/DC0%0/1
$target // "root"
$target
MC/DC0%0/2
$path // $a[0]
$path $a[0]
Truth table50%1/2
A
A= $target
Aresult
11
00
Truth table33%1/3
A // B
A= $pathB= $a[0]
ABresult
1X1
011
000
1277 5 ▶ return ( 'sudo-deny', $why ) if defined $why;
Branch: 1 branch
BranchTrueFalseTotal
if defined $why 2 3 5
1278 }
1279 }
1280 66 ▶ $AS_USER = $target // 'root';
Condition100%2/2
$target // "root"
l!l
615
MC/DC100%1/1
$target // "root"
$target
Truth table100%2/2
A
A= $target
Aresult
11
00
1281 }
1282 4867 return @a;
1283 }
1284  
1285 # Verzeichnisse, die "ls /" auf jedem Debian zeigt (dazu, was im Zustand liegt)
1286 82 our @ROOT_DIRS = qw( bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var );
1287  
1288 # Auf dem simulierten Debian 12 (minimal, nftables) nicht installiert: hier ist
1289 # "command not found" die Wahrheit.
1290 82 our %NOT_INSTALLED = map { $_ => 1 } qw( iptables ip6tables iptables-save iptables-restore iptables-nft
1291 iptables-legacy ebtables arptables ifconfig netstat route arp brctl tcpdump traceroute dig nslookup host
1292 mtr nmap telnet nc netcat ncat curl ufw firewall-cmd vtysh );
1293  
1294 # Echte Befehle eines Debian 12, die der Simulator nicht nachbildet: neutrale
1295 # Antwort, Aufruf als Luecke der Simulation (sim_gap) vermerkt.
1296 82 our %REAL = map { $_ => 1 } qw( xargs column less more vi vim nano editor top htop watch ps kill pkill
1297 pgrep uptime date w who last bridge tc ethtool systemd-resolve networkctl
1298 hostnamectl apt apt-get mount umount lsblk env od sleep timeout
1299 setfacl getfacl apachectl php mysql mariadb modprobe lsmod tracepath arping ss-ng ip6 nstat routel
1300 dhclient ifup ifdown wg-quick-save journalctl-x getent ping6 scp sftp rsync tar gzip
1301 zcat sha256sum md5sum realpath basename dirname seq yes tput clear
1302 python3 python node npm npx perl pip pip3 cpanm carton gunicorn uvicorn promtool amtool mysqladmin mysqldump
1303 openssl flock logger );
1304 82 our %INTERACTIVE = map { $_ => 1 } qw( less more vi vim nano editor top htop watch );
1305  
1306 # Befehle mit Dateiargumenten (fuer relative Pfade nach cd); f: nur die Datei hinter -f
1307 82 our %FILEARGS = ( ( map { $_ => 1 } qw( cat ls stat rm cp mv chmod chown chgrp touch mkdir find du sed grep egrep head tail wc sort uniq tee ln truncate file diff readlink realpath md5sum sha256sum gzip gunzip zcat ) ),
1308 kubectl => 'f', helm => 'f' );
1309  
1310 # Filter, die auch eine Datei lesen (head -n 3 /etc/x)
1311 82 our %FILTER = map { $_ => 1 } qw( head tail wc sort uniq cut awk tr fold );
1312  
1313 82 our $DATE_TZ; # TZ=… vor einem Befehl (wirkt auf date)
1314 82 our $BIN_MEMO; # innerhalb eines ls: { bin|sbin => [ namen ] } (_bin_names)
1315 82 our $LS_TIME; # innerhalb eines ls: --time-style (full-iso, long-iso, iso)
1316  
1317 # Wo die Programme auf dem simulierten Debian 12 liegen (usrmerge): /usr/sbin, sonst /usr/bin.
1318 82 our %SBIN = map { $_ => 1 } qw( ip nft sysctl sshd usermod userdel useradd groupadd deluser visudo reboot shutdown
1319 poweroff halt logrotate nginx dhclient modprobe lsmod ifup ifdown ethtool tc bridge conntrack runuser arping
1320 chpasswd iptables ip6tables ss-ng mariadbd mysqld redis-server
1321 wg-quick e2fsck resize2fs tune2fs swapon swapoff mkswap mdadm sfdisk sgdisk xfs_growfs
1322 rndc postconf postfix postmap postalias newaliases postqueue postsuper );
1323 82 our %BUILTIN = map { $_ => 1 } qw( echo printf true false : cd export type command test [ pwd umask );
1324  
1325 my %CMD = (
1326 23 ▶ which => sub { _which( 'which', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1327 1 ▶ whereis => sub { _which( 'whereis', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1328 2 ▶ type => sub { _which( 'type', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1329 2 ▶ command => sub { _which( 'command', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1330 15 ▶ test => sub { _test_cmd( 'test', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1331 27 ▶ '[' => sub { _test_cmd( '[', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1332 ip => \&_ip,
1333 wg => \&_wg,
1334 'wg-quick' => \&_wgquick,
1335 nft => \&_nft,
1336 sysctl => \&_sysctl,
1337 cat => \&_cat,
1338 ls => \&_ls,
1339 grep => \&_grep_file,
1340 egrep => \&_grep_file,
1341 sed => \&_sed,
1342 echo => \&_echo,
1343 printf => \&_printf,
1344 systemctl => \&_systemctl,
1345 service => \&_service,
1346 nmcli => \&_nmcli,
1347 ping => \&_ping,
1348 2 ▶ hostname => sub { ( $_[2]{host}, 1 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1349 0 ▶ uname => sub { ( "Linux $_[2]{host} 6.1.0-26-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.112-1 x86_64 GNU/Linux", 1 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1350 0 ▶ whoami => sub { ( _who(), 1 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1351 3 ▶ pwd => sub { ( $CWD_DIR // '/root', 1 ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::CWD_DIR // "/root"
l!l
03
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::CWD_DIR // "/root"
$Langertha::Holmgang::Sim::Linux::CWD_DIR
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::CWD_DIR
Aresult
11
00
1352 1014 ▶ true => sub { ( '', 1 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1353 0 ▶ free => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1354 0 my $h = grep { /\A-[a-z]*h/ } @{ $_[1] };
1355 0 ▶ return ( $h ? " total used free shared buff/cache available\nMem: 7.8Gi 1.9Gi 3.1Gi 24Mi 2.8Gi 5.6Gi\nSwap: 975Mi 0B 975Mi"
Branch: 1 branch
BranchTrueFalseTotal
$h ? : 0 0 0
1356 : " total used free shared buff/cache available\nMem: 7951 1946 3174 24 2867 5741\nSwap: 975 0 975", 1 );
1357 },
1358 1 ▶ sleep => sub { ( '', 1 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1359 date => \&_date,
1360 0 ▶ lsmod => sub { # die fuer Netzwerk und Firewall uebliche Auswahl
Subroutine __ANON__: not called CC=3 SCAR=24.8
1361 0 my ($dev) = @_;
1362 0 my @m = ( [ 'nf_tables', 307200, 1, '' ], [ 'nf_conntrack', 188416, 2, 'nf_nat,nft_ct' ], [ 'nf_nat', 57344, 1, 'nft_chain_nat' ],
1363 [ 'nft_ct', 24576, 1, '' ], [ 'nft_chain_nat', 16384, 1, '' ], [ 'nfnetlink', 20480, 2, 'nf_tables' ] );
1364 0 ▶ push @m, [ 'wireguard', 110592, 0, '' ], [ 'udp_tunnel', 28672, 1, 'wireguard' ] if %{ $dev->{wg} || {} };
Branch: 1 branch
BranchTrueFalseTotal
if %{$$dev{"wg"} or {};} 0 0 0
Condition0%0/2
$$dev{'wg'} || {}
l!l
00
MC/DC0%0/1
$$dev{'wg'} || {}
$$dev{'wg'}
Truth table0%0/2
A
A= $$dev{'wg'}
Aresult
11
00
1365 0 return ( join( "\n", sprintf( '%-24s %8s %s', 'Module', 'Size', 'Used by' ), map { sprintf( '%-24s %8d %d %s', @$_ ) } @m ), 1 );
1366 },
1367 ps => \&_ps,
1368 base64 => \&_base64,
1369 od => \&_od,
1370 flock => \&_flock,
1371 nc => \&_nc,
1372 netcat => \&_nc,
1373 ncat => \&_nc,
1374 curl => \&_curl,
1375 env => \&_env,
1376 last => \&_last,
1377 uptime => \&_uptime,
1378 lastlog => \&_lastlog,
1379 pgrep => \&_pgrep,
1380 7 ▶ false => sub { ( '', 0 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1381 journalctl => \&_journalctl,
1382 'systemd-analyze' => \&_systemd_analyze,
1383 timedatectl => \&_timedatectl,
1384 file => \&_file_cmd,
1385 dpkg => \&_dpkg,
1386 16 ▶ logrotate => sub { _part('Logrotate'); Langertha::Holmgang::Sim::Linux::Logrotate::run(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1387 bash => \&_shell_c,
1388 sh => \&_shell_c,
1389 df => \&_df,
1390 du => \&_du,
1391 stat => \&_stat,
1392 chmod => \&_chmod,
1393 chown => \&_chown,
1394 0 ▶ chgrp => sub { _chown( @_[ 0 .. 3 ], 1 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1395 rm => \&_rm,
1396 truncate => \&_truncate,
1397 touch => \&_touch,
1398 find => \&_find,
1399 lsof => \&_lsof,
1400 id => \&_id,
1401 groups => \&_groups_cmd,
1402 usermod => \&_usermod,
1403 namei => \&_namei,
1404 5 ▶ useradd => sub { _useradd( 'useradd', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1405 3 ▶ groupadd => sub { _groupadd( 'groupadd', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1406 3 ▶ adduser => sub { _useradd( 'adduser', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1407 1 ▶ addgroup => sub { _groupadd( 'addgroup', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1408 install => \&_install,
1409 gpasswd => \&_gpasswd,
1410 2 ▶ passwd => sub { _acc()->can('passwd')->(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1411 3 ▶ chage => sub { _acc()->can('chage')->(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1412 2 ▶ deluser => sub { _acc()->can('deluser')->(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1413 1 ▶ userdel => sub { _acc()->can('userdel')->(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1414 3 ▶ visudo => sub { _acc()->can('visudo')->(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1415 3 ▶ 'sudo-list' => sub { _acc()->can('sudo_list')->( $_[0], $_[1][0], $_[2]{host} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1416 2 ▶ 'sudo-deny' => sub { ( $_[1][0], 0 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1417 crontab => \&_crontab,
1418 getfacl => \&_getfacl,
1419 2 ▶ 'redis-server' => sub { _redis_cmd( 'server', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1420 pkill => \&_pkill,
1421 kill => \&_kill,
1422 sshd => \&_sshd,
1423 xargs => \&_xargs,
1424 file => \&_file_cmd,
1425 who => \&_who_cmd,
1426 printenv => \&_env,
1427 dpkg => \&_dpkg,
1428 'dpkg-query' => \&_dpkg,
1429 3 ▶ 'ssh-keygen' => sub {
Subroutine __ANON__: called CC=3 SCAR=18.7
1430 3 my ( $o, $k ) = _keygen( $_[0], $_[1], $_[2]{host} );
1431 3 ▶ return ( $o, $k ) if defined $o;
Branch: 1 branch
BranchTrueFalseTotal
if defined $o 3 0 3
1432 0 ( $o, $k ) = _sshd_sim()->can('ssh_keygen')->( $_[0], $_[1], $_[2]{host} );
1433 0 ▶ return ( $o, $k ) if defined $o;
Branch: 1 branch
BranchTrueFalseTotal
if defined $o 0 0 0
1434 0 push @GAPS, join( ' ', 'ssh-keygen', @{ $_[1] } );
1435 0 return ( '', 0 );
1436 },
1437 getent => \&_getent,
1438 resolvectl => \&_resolvectl,
1439 ln => \&_ln,
1440 readlink => \&_readlink,
1441 diff => \&_diff,
1442 ssh => \&_ssh,
1443 nginx => \&_nginx,
1444 wget => \&_wget,
1445 cmp => \&_cmp,
1446 mount => \&_mount_cmd,
1447 mkdir => \&_mkdir,
1448 cp => \&_cp,
1449 mv => \&_mv,
1450 1001 ▶ ':' => sub { ( '', 1 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1451 0 ▶ dmesg => sub { ( '', 1 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1452 conntrack => \&_conntrack,
1453 reboot => \&_reboot,
1454 shutdown => \&_reboot,
1455 poweroff => \&_reboot,
1456 halt => \&_reboot,
1457 ss => \&_ss,
1458 psql => \&_psql,
1459 kubectl => \&_kubectl,
1460 'redis-cli' => \&_redis_cli,
1461 5 ▶ promtool => sub { _mon( 'promtool', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1462 15 ▶ amtool => sub { _mon( 'amtool', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1463 53 ▶ mysql => sub { _mysql_client( 'mysql', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1464 0 ▶ mariadb => sub { _mysql_client( 'mariadb', @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1465 5 ▶ mysqladmin => sub { _mysql_client( 'mysqladmin', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1466 0 ▶ 'mariadb-admin' => sub { _mysql_client( 'mariadb-admin', @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1467 helm => \&_helm,
1468 git => \&_git,
1469 docker => \&_docker,
1470 0 ▶ openssl => sub { return _openssl(@_) if $_[0]{kubernetes}; push @GAPS, join( ' ', 'openssl', @{ $_[1] } ); return ( '', 0 ) },
Subroutine __ANON__: called CC=2 SCAR=11.6
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"kubernetes"} 3 0 3
1471 0 ▶ gunzip => sub { _gzip( 'gunzip', @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1472 1 ▶ zcat => sub { _gzip( 'zcat', @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1473 0 ▶ seq => sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
1474 0 my @n = grep {/\A-?\d+\z/} @{ $_[1] };
1475 0 ▶ return ( 'seq: missing operand', 0 ) unless @n;
Branch: 1 branch
BranchTrueFalseTotal
unless @n 0 0 0
1476 0 ▶ my ( $f, $s, $l ) = @n == 1 ? ( 1, 1, $n[0] ) : @n == 2 ? ( $n[0], 1, $n[1] ) : @n[ 0 .. 2 ];
Branch: 2 branches
BranchTrueFalseTotal
@n == 1 ? : 0 0 0
@n == 2 ? : 0 0 0
1477 0 ▶ return ( '', 1 ) unless $s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s 0 0 0
1478 0 my @o;
1479 0 ▶ for ( my $i = $f; $s > 0 ? $i <= $l : $i >= $l; $i += $s ) { push @o, $i; last if @o > 10000 }
Branch: 3 branches
BranchTrueFalseTotal
if ($s > 0 ? $i <= $l : $i >= $l) 0 0 0
$s > 0 ? : 0 0 0
if @o > 10000 0 0 0
1480 0 return ( join( "\n", @o ), 1 );
1481 },
1482 3 ▶ 'forgejo-runner' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1483 3 my ( $dev, $av, $ctx ) = @_;
1484 3 _part('Git');
1485 3 local @Langertha::Holmgang::Sim::Linux::Git::GAPS;
1486 3 my ( $o, $ok ) = Langertha::Holmgang::Sim::Linux::Git::runner( $dev, $av, $ctx, $CWD_DIR, $AS_USER );
1487 3 push @GAPS, @Langertha::Holmgang::Sim::Linux::Git::GAPS;
1488 3 return ( $o, $ok );
1489 },
1490 0 ▶ pg_lsclusters => sub { _pg()->can('pg_lsclusters')->(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1491 pg_ctlcluster => \&_pg_ctlcluster,
1492 su => \&_su,
1493 runuser => \&_su,
1494 # BIND und Postfix: nur, wo installiert
1495 rndc => _ext( 'Dns', 'rndc', ['bind'] ),
1496 'named-checkconf' => _ext( 'Dns', 'checkconf', ['bind'] ),
1497 'named-checkzone' => _ext( 'Dns', 'checkzone', ['bind'] ),
1498 dig => _ext( 'Dns', 'dig', [ 'bind', 'dnsutils' ] ),
1499 host => _ext( 'Dns', 'host', [ 'bind', 'dnsutils' ] ),
1500 postconf => _ext( 'Postfix', 'postconf', ['postfix'] ),
1501 postfix => _ext( 'Postfix', 'postfix', ['postfix'] ),
1502 postmap => _ext( 'Postfix', 'postmap', ['postfix'] ),
1503 postalias => _ext( 'Postfix', 'postmap', ['postfix'], prog => 'postalias' ),
1504 newaliases => _ext( 'Postfix', 'postmap', ['postfix'], prog => 'newaliases' ),
1505 postqueue => _ext( 'Postfix', 'postqueue', ['postfix'] ),
1506 mailq => _ext( 'Postfix', 'postqueue', ['postfix'], pre => ['-p'] ),
1507 postsuper => _ext( 'Postfix', 'postsuper', ['postfix'] ),
1508 postcat => _ext( 'Postfix', 'postcat', ['postfix'] ),
1509 # Sichern und Wiederherstellen; restic nur, wo installiert
1510 tar => _ext( 'Backup', 'tar', [] ),
1511 rsync => _ext( 'Backup', 'rsync', [] ),
1512 4 ▶ sha256sum => do { my $x = _ext( 'Backup', 'sha256sum', [] ); sub { ( grep { !/\A-/ } @{ $_[1] } ) ? $x->(@_) : _digest( 'sha256', @_ ) } }, # ohne Datei: stdin
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
grep({not /\A-/;} @{$_[1];}) ? : 2 2 4
1513 md5sum => \&_md5sum,
1514 2 ▶ basename => sub { # basename name [suffix] | -s suffix | -a name …
Subroutine __ANON__: called CC=11 SCAR=33.1
1515 2 my ( $d, $a ) = @_;
1516 2 my @a = @$a;
1517 2 my ( $suf, $multi );
1518 0 ▶ while ( @a && $a[0] =~ /\A-/ ) { my $x = shift @a; if ( $x eq '-s' ) { $suf = shift @a; $multi = 1 } elsif ( $x eq '-a' ) { $multi = 1 } }
Branch: 3 branches
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-/) 0 2 2
if ($x eq '-s') { } 0 0 0
elsif ($x eq '-a') { } 0 0 0
Condition33%1/3
@a and $a[0] =~ /\A-/
!ll&&!rl&&r
020
MC/DC0%0/2
@a and $a[0] =~ /\A-/
@a $a[0] =~ /\A-/
Truth table33%1/3
A and B
A= @aB= $a[0] =~ /\A-/
ABresult
0X0
100
111
1519 2 ▶ return ( 'basename: missing operand', 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 2 2
1520 2 ▶ ( $suf, @a ) = ( $a[1], $a[0] ) unless $multi;
Branch: 1 branch
BranchTrueFalseTotal
unless $multi 2 0 2
1521 2 ▶ return ( join( "\n", map { my $b = $_ =~ s{/+\z}{}r =~ s{.*/}{}r; $b = '/' if $b eq '' && /\A\//; $b =~ s/\Q$suf\E\z// if defined $suf && $b ne $suf; $b } @a ), 1 );
Branch: 2 branches
BranchTrueFalseTotal
if $b eq "" and m[\A/] 0 2 2
if defined $suf and $b ne $suf 2 0 2
Condition33%2/6
$b eq "" and m[\A/]
!ll&&!rl&&r
200
defined $suf and $b ne $suf
!ll&&!rl&&r
002
MC/DC0%0/2
$b eq "" and m[\A/]
$b eq "" m[\A/]
MC/DC0%0/2
defined $suf and $b ne $suf
defined $suf $b ne $suf
Truth table33%1/3
A and B
A= $b eq ""B= m[\A/]
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $sufB= $b ne $suf
ABresult
0X0
100
111
1522 },
1523 2 ▶ dirname => sub {
Subroutine __ANON__: called CC=4 SCAR=14.5
1524 2 my ( $d, $a ) = @_;
1525 2 ▶ my @n = grep { !/\A-/ } @$a or return ( 'dirname: missing operand', 0 );
Branch: 1 branch
BranchTrueFalseTotal
my(@n) = grep({not /\A-/;} @$a) or return "dirname: missing operand", 0 2 0 2
1526 2 ▶ return ( join( "\n", map { my $x = s{/+\z}{}r; $x =~ m{/} ? ( $x =~ s{/+[^/]*\z}{}r || '/' ) : '.' } @n ), 1 );
Branch: 1 branch
BranchTrueFalseTotal
$x =~ m[/] ? : 2 0 2
Condition50%1/2
$x =~ s[/+[^/]*\z][]r or "/"
l!l
20
MC/DC0%0/1
$x =~ s[/+[^/]*\z][]r or "/"
$x =~ s[/+[^/]*\z][]r
Truth table50%1/2
A
A= $x =~ s[/+[^/]*\z][]r
Aresult
11
00
1527 },
1528 gzip => do {
1529 82 my $file = _ext( 'Backup', 'gzip', [] );
1530 2 ▶ sub { my @x = @_; return _gzip( 'gzip', @x ) if !grep( { !/\A-/ } @{ $x[1] } ) && grep( { /\A-[a-z]*d|\A--decompress\z/ } @{ $x[1] } ); return $file->(@x) };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if not grep({not /\A-/;} @{$x[1];}) and grep {/\A-[a-z]*d|\A--decompress\z/;} @{$x[1];} 1 1 2
Condition66%2/3
not grep({not /\A-/;} @{$x[1];}) and grep {/\A-[a-z]*d|\A--decompress\z/;} @{$x[1];}
!ll&&!rl&&r
101
MC/DC50%1/2
not grep({not /\A-/;} @{$x[1];}) and grep {/\A-[a-z]*d|\A--decompress\z/;} @{$x[1];}
not grep({not /\A-/;} @{$x[1];}) grep {/\A-[a-z]*d|\A--decompress\z/;} @{$x[1];}
Truth table66%2/3
not(A) and B
A= not grep({not /\A-/;} @{$x[1];})B= grep {/\A-[a-z]*d|\A--decompress\z/;} @{$x[1];}
ABresult
0X0
100
111
1531 },
1532 restic => _ext( 'Backup', 'restic', [ 'restic', 'restic_repos' ] ),
1533 cd => \&_cd,
1534 xargs => \&_xargs,
1535 10 ▶ timeout => sub { # timeout [-s SIG] DAUER befehl …: der Befehl laeuft (die Simulation wartet nie)
Subroutine __ANON__: called CC=9 SCAR=23.3
1536 10 my ( $d, $a, $c, $in ) = @_;
1537 10 my @w = @$a;
1538 10 ▶ shift @w while @w && $w[0] =~ /\A-/ && ( $w[0] !~ /\A-[sk]\z/ || shift @w );
Branch: 1 branch
BranchTrueFalseTotal
@w and $w[0] =~ /\A-/ and !($w[0] =~ /\A-[sk]\z/) || shift @w and do { shift @w } 2 10 12
Condition55%5/9
@w and $w[0] =~ /\A-/ and !($w[0] =~ /\A-[sk]\z/) || shift @w
!ll&&!rl&&r
1002
@w and $w[0] =~ /\A-/
!ll&&!rl&&r
0102
not $w[0] =~ /\A-[sk]\z/ or shift @w
l!l&&r!l&&!r
020
MC/DC25%1/4
@w and $w[0] =~ /\A-/ and !($w[0] =~ /\A-[sk]\z/) || shift @w
@w $w[0] =~ /\A-/ not $w[0] =~ /\A-[sk]\z/ shift @w
Truth table40%2/5
A and B and not(C) or D
A= @wB= $w[0] =~ /\A-/C= not $w[0] =~ /\A-[sk]\z/D= shift @w
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1539 10 my $dur = shift @w;
1540 10 ▶ return ( "timeout: invalid time interval '" . ( $dur // '' ) . "'", 0 ) unless defined $dur && $dur =~ /\A\d+(?:\.\d+)?[smhd]?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dur and $dur =~ /\A\d+(?:\.\d+)?[smhd]?\z/ 1 9 10
Condition60%3/5
defined $dur and $dur =~ /\A\d+(?:\.\d+)?[smhd]?\z/
!ll&&!rl&&r
019
$dur // ""
l!l
10
MC/DC50%1/2
defined $dur and $dur =~ /\A\d+(?:\.\d+)?[smhd]?\z/
defined $dur $dur =~ /\A\d+(?:\.\d+)?[smhd]?\z/
MC/DC0%0/1
$dur // ""
$dur
Truth table66%2/3
A and B
A= defined $durB= $dur =~ /\A\d+(?:\.\d+)?[smhd]?\z/
ABresult
0X0
100
111
Truth table50%1/2
A
A= $dur
Aresult
11
00
1541 9 ▶ return ( 'timeout: missing operand', 0 ) unless @w;
Branch: 1 branch
BranchTrueFalseTotal
unless @w 0 9 9
1542 9 local $IN_TIMEOUT = 1; # eine haengende Verbindung endet mit 124 statt einer Meldung
1543 9 return __PACKAGE__->_command( $d, \@w, $c, $in );
1544 },
1545 # Platten und Dateisysteme: nur mit storage im Zustand,
1546 # sonst wie bisher eine Luecke der Simulation
1547 3116 ▶ ( map { $_->[0] => _ext( 'Storage', $_->[1], ['storage'], prog => $_->[0], gap => 1, ( $_->[0] eq 'mount' ? ( else => \&_mount_cmd ) : $_->[0] eq 'lsblk' ? ( else => \&_lsblk_basic ) : $_->[0] eq 'free' ? ( else => \&_free_mem ) : () ) ) }
Branch: 3 branches
BranchTrueFalseTotal
$$_[0] eq 'mount' ? : 82 3034 3116
$$_[0] eq 'lsblk' ? : 82 2952 3034
$$_[0] eq 'free' ? : 82 2870 2952
1548 [ lsblk => 'lsblk' ], [ blkid => 'blkid' ], [ findmnt => 'findmnt' ], [ mount => 'mount' ], [ umount => 'umount' ],
1549 902 ( map { [ $_ => 'lvm' ] } qw( pvs vgs lvs pvdisplay vgdisplay lvdisplay pvcreate vgextend lvcreate lvextend lvresize ) ),
1550 [ resize2fs => 'resize2fs' ], [ xfs_growfs => 'xfs_growfs' ],
1551 328 ( map { [ $_ => 'mkfs' ] } qw( mkfs mkfs.ext4 mkfs.ext3 mkfs.xfs ) ), [ tune2fs => 'tune2fs' ],
1552 246 ( map { [ $_ => 'fsck' ] } qw( e2fsck fsck fsck.ext4 ) ),
1553 492 ( map { [ $_ => 'swap' ] } qw( mkswap swapon swapoff fallocate dd free ) ),
1554 82 ( map { [ $_ => 'part' ] } qw( sfdisk sgdisk growpart partprobe fdisk ) ), [ mdadm => 'mdadm' ] ),
1555 );
1556  
1557 # Ein Shell-Skript in einer neuen Shell (Argumente $1 …); Variablen, if, for, while, case
1558 # wie bash (Sim::Shell); Funktionen und Subshells bleiben eine Luecke der Simulation.
1559 7 ▶sub _script {
Subroutine _script: called CC=1 SCAR=0.0
1560 7 my ( $dev, $text, $ctx, $what, $arg0, @args ) = @_;
1561 7 return _run_shell( $dev, $text, $ctx, arg0 => $arg0, args => \@args );
1562 }
1563  
1564 # who: die eigene Sitzung (ssh_login des Geraets)
1565 1 ▶sub _who_cmd {
Subroutine _who_cmd: called CC=4 SCAR=15.2
1566 1 my ($dev) = @_;
1567 1 ▶ my $l = $dev->{ssh_login} || {};
Condition50%1/2
$$dev{'ssh_login'} || {}
l!l
10
MC/DC0%0/1
$$dev{'ssh_login'} || {}
$$dev{'ssh_login'}
Truth table50%1/2
A
A= $$dev{'ssh_login'}
Aresult
11
00
1568 1 ▶ return ( sprintf( '%-8s pts/0 2026-10-21 11:52 (%s)', $l->{user} // 'root', $l->{from} // '10.1.0.50' ), 1 );
Condition50%2/4
$$l{"user"} // "root"
l!l
10
$$l{"from"} // "10.1.0.50"
l!l
10
MC/DC0%0/1
$$l{"user"} // "root"
$$l{"user"}
MC/DC0%0/1
$$l{"from"} // "10.1.0.50"
$$l{"from"}
Truth table50%1/2
A
A= $$l{"user"}
Aresult
11
00
Truth table50%1/2
A
A= $$l{"from"}
Aresult
11
00
1569 }
1570  
1571 190 ▶sub _ssh_access { return _part('SshAccess') }
Subroutine _ssh_access: called CC=1 SCAR=0.0
1572  
1573 # ssh [-o …] [-p port] [-l user] [user@]host [befehl] — nur auf das Geraet selbst nachgebildet:
1574 # Anmeldung gegen die geladene sshd-Konfiguration, ohne Schluessel (root hat keinen fuer andere Konten)
1575 3 ▶sub _ssh_client {
Subroutine _ssh_client: called CC=22 SCAR=39.1
1576 3 my ( $dev, $av, $ctx ) = @_;
1577 3 my @a = @$av;
1578 3 my ( $port, $user, $target );
1579 3 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 7 0 7
1580 7 my $x = shift @a;
1581 7 ▶ if ( $x =~ /\A-[oiFlpJcmbeEDLRW]\z/ ) { my $v = shift @a; $port = $v if $x eq '-p'; $user = $v if $x eq '-l' }
Branch: 6 branches
BranchTrueFalseTotal
if ($x =~ /\A-[oiFlpJcmbeEDLRW]\z/) { } 4 3 7
elsif ($x =~ /\A-o(.+)\z/) { } 0 3 3
elsif ($x =~ /\A-p(\d+)\z/) { } 0 3 3
elsif ($x =~ /\A-[46AaCfGgKkMNnqsTtVvXxYy]+\z/) { } 0 3 3
if $x eq "-p" 1 3 4
if $x eq "-l" 0 4 4
1582 elsif ( $x =~ /\A-o(.+)\z/ ) { }
1583 0 elsif ( $x =~ /\A-p(\d+)\z/ ) { $port = $1 }
1584 0 ▶ elsif ( $x =~ /\A-[46AaCfGgKkMNnqsTtVvXxYy]+\z/ ) { return ( 'OpenSSH_9.2p1 Debian-2+deb12u3, OpenSSL 3.0.15 3 Sep 2024', 1 ) if $x =~ /V/ }
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /V/ 0 0 0
1585 3 else { $target = $x; last }
1586 }
1587 3 ▶ return ( 'usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface] [-b bind_address] destination [command [argument ...]]', 0 ) unless defined $target;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target 0 3 3
1588 3 my ( $u, $h ) = $target =~ /\A(?:([^@]+)@)?(.+)\z/;
1589 3 ▶ $user //= $u // ( $LOGIN_USER // 'root' );
Condition33%2/6
$user //= $u // ($Langertha::Holmgang::Sim::Linux::LOGIN_USER // "root")
l!l
03
$u // ($Langertha::Holmgang::Sim::Linux::LOGIN_USER // "root")
l!l
30
$Langertha::Holmgang::Sim::Linux::LOGIN_USER // "root"
l!l
00
MC/DC0%0/1
$user //= $u // ($Langertha::Holmgang::Sim::Linux::LOGIN_USER // "root")
$user
Truth table50%1/2
A
A= $user
Aresult
11
00
1590 3 ▶ my $me = $ctx->{host} // '';
Condition50%1/2
$$ctx{"host"} // ""
l!l
30
MC/DC0%0/1
$$ctx{"host"} // ""
$$ctx{"host"}
Truth table50%1/2
A
A= $$ctx{"host"}
Aresult
11
00
1591 3 my %own = map { $_ => 1 } _own_addrs($dev), 'localhost', $me;
1592 3 ▶ if ( !$own{$h} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($own{$h}) 0 3 3
1593 0 ▶ return ( "ssh: Could not resolve hostname $h: Name or service not known", 0 ) unless $h =~ /\A[\d.]+\z|:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $h =~ /\A[\d.]+\z|:/ 0 0 0
1594 0 push @GAPS, join( ' ', 'ssh', @$av );
1595 0 ▶ return ( "ssh: connect to host $h port " . ( $port // 22 ) . ': Connection timed out', 0 );
Condition0%0/2
$port // 22
l!l
00
MC/DC0%0/1
$port // 22
$port
Truth table0%0/2
A
A= $port
Aresult
11
00
1596 }
1597 3 ▶ my $from = $h =~ /:/ ? '::1' : $h =~ /\A[\d.]+\z/ && $h ne '127.0.0.1' ? $h : '127.0.0.1';
Branch: 2 branches
BranchTrueFalseTotal
$h =~ /:/ ? : 0 3 3
$h =~ /\A[\d.]+\z/ && $h ne '127.0.0.1' ? : 1 2 3
Condition66%2/3
$h =~ /\A[\d.]+\z/ and $h ne "127.0.0.1"
!ll&&!rl&&r
201
MC/DC50%1/2
$h =~ /\A[\d.]+\z/ and $h ne "127.0.0.1"
$h =~ /\A[\d.]+\z/ $h ne "127.0.0.1"
Truth table66%2/3
A and B
A= $h =~ /\A[\d.]+\z/B= $h ne "127.0.0.1"
ABresult
0X0
100
111
1598 3 ▶ my ( $ok, $msg ) = _ssh_access()->can('check')->( $dev, { user => $user, from => $from, port => $port // 22, key => '' }, $h );
Condition100%2/2
$port // 22
l!l
12
MC/DC100%1/1
$port // 22
$port
Truth table100%2/2
A
A= $port
Aresult
11
00
1599 3 ▶ return ( $msg, 0 ) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 3 0 3
1600 0 return ( "$user\@$h: Permission denied (publickey).", 0 );
1601 }
1602  
1603 # ssh-keygen: -l -f datei (je Schluessel eine Zeile, auch authorized_keys), -t … -f pfad (Paar), -y -f privat
1604 3 ▶sub _keygen {
Subroutine _keygen: called CC=33 SCAR=39.7
1605 3 my ( $dev, $av, $host ) = @_;
1606 3 my ( %o, $file, $type, $comment );
1607 3 my @a = @$av;
1608 3 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 8 3 11
1609 8 my $x = shift @a;
1610 8 ▶ if ( $x eq '-f' ) { $file = shift @a }
Branch: 5 branches
BranchTrueFalseTotal
if ($x eq '-f') { } 2 6 8
elsif ($x eq '-t') { } 1 5 6
elsif ($x eq '-C') { } 1 4 5
elsif ($x =~ /\A-[NEbZ]\z/) { } 1 3 4
elsif ($x =~ /\A-([lyqvf]+)\z/) { } 3 0 3
1611 1 elsif ( $x eq '-t' ) { $type = shift @a }
1612 1 elsif ( $x eq '-C' ) { $comment = shift @a }
1613 1 elsif ( $x =~ /\A-[NEbZ]\z/ ) { shift @a }
1614 3 ▶ elsif ( $x =~ /\A-([lyqvf]+)\z/ ) { $o{$_} = 1 for split //, $1; $file = shift @a if $x =~ /f\z/ }
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /f\z/ 1 2 3
1615 0 else { return undef }
1616 }
1617 3 ▶ my $files = $dev->{files} //= {};
Condition50%1/2
$$dev{"files"} //= {}
l!l
30
MC/DC0%0/1
$$dev{"files"} //= {}
$$dev{"files"}
Truth table50%1/2
A
A= $$dev{"files"}
Aresult
11
00
1618 3 ▶ if ( $o{l} && defined $file && !( $file =~ m{/ssh_host_\w+_key(?:\.pub)?\z} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"l"} and defined $file and not $file =~ m[/ssh_host_\w+_key(?:\.pub)?\z]) 1 2 3
Condition66%4/6
$o{"l"} and defined $file and not $file =~ m[/ssh_host_\w+_key(?:\.pub)?\z]
!ll&&!rl&&r
201
$o{"l"} and defined $file
!ll&&!rl&&r
201
MC/DC33%1/3
$o{"l"} and defined $file and not $file =~ m[/ssh_host_\w+_key(?:\.pub)?\z]
$o{"l"} defined $file not $file =~ m[/ssh_host_\w+_key(?:\.pub)?\z]
Truth table50%2/4
A and B and not(C)
A= $o{"l"}B= defined $fileC= not $file =~ m[/ssh_host_\w+_key(?:\.pub)?\z]
ABCresult
0XX0
10X0
1100
1111
1619 1 ▶ my $t = _file_text( $dev, $file ) // return ( "ssh-keygen: $file: No such file or directory", 0 );
Condition50%1/2
_file_text($dev, $file) // (return "ssh-keygen: ${file}: No such file or directory", 0)
l!l
10
MC/DC0%0/1
_file_text($dev, $file) // (return "ssh-keygen: ${file}: No such file or directory", 0)
_file_text($dev, $file)
Truth table50%1/2
A
A= _file_text($dev, $file)
Aresult
11
00
1620 1 my @l;
1621 1 for my $line ( split /\n/, $t ) {
1622 1 ▶ next if $line =~ /\A\s*(?:#|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A\s*(?:#|\z)/ 0 1 1
1623 1 ▶ my ( $opts, $kt, $blob ) = _ssh_access()->can('_key_parts')->($line) or next;
Branch: 1 branch
BranchTrueFalseTotal
() = _ssh_access()->can("_key_parts")->($line) or next 1 0 1
1624 1 my ($cm) = $line =~ /\Q$blob\E\s+(.*?)\s*\z/;
1625 1 ▶ my $ty = uc( ( $kt =~ /ssh-(\w+)/ )[0] // 'KEY' );
Condition50%1/2
($kt =~ /ssh-(\w+)/)[0] // "KEY"
l!l
10
MC/DC0%0/1
($kt =~ /ssh-(\w+)/)[0] // "KEY"
($kt =~ /ssh-(\w+)/)[0]
Truth table50%1/2
A
A= ($kt =~ /ssh-(\w+)/)[0]
Aresult
11
00
1626 1 ▶ push @l, ( $ty eq 'RSA' ? 3072 : 256 ) . ' SHA256:' . substr( $blob, 12, 43 ) . ' ' . ( $cm // 'no comment' ) . " ($ty)";
Branch: 1 branch
BranchTrueFalseTotal
$ty eq 'RSA' ? : 0 1 1
Condition50%1/2
$cm // "no comment"
l!l
10
MC/DC0%0/1
$cm // "no comment"
$cm
Truth table50%1/2
A
A= $cm
Aresult
11
00
1627 }
1628 1 ▶ return ( "$file is not a public key file.", 0 ) unless @l;
Branch: 1 branch
BranchTrueFalseTotal
unless @l 0 1 1
1629 1 return ( join( "\n", @l ), 1 );
1630 }
1631 2 ▶ if ( defined $type && defined $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type and defined $file) 1 1 2
Condition66%2/3
defined $type and defined $file
!ll&&!rl&&r
101
MC/DC50%1/2
defined $type and defined $file
defined $type defined $file
Truth table66%2/3
A and B
A= defined $typeB= defined $file
ABresult
0X0
100
111
1632 1 ▶ return ( "unknown key type $type", 0 ) unless $type =~ /\A(?:ed25519|rsa|ecdsa)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /\A(?:ed25519|rsa|ecdsa)\z/ 0 1 1
1633 1 ▶ my $n = unpack( '%32C*', $file . ( $comment // '' ) );
Condition50%1/2
$comment // ""
l!l
10
MC/DC0%0/1
$comment // ""
$comment
Truth table50%1/2
A
A= $comment
Aresult
11
00
1634 1 my $blob = 'AAAAC3NzaC1lZDI1NTE5AAAAI' . substr( join( '', map { ( 'A' .. 'Z', 'a' .. 'z', 0 .. 9 )[ ( $n * 7 + $_ * 13 ) % 62 ] } 1 .. 43 ), 0, 43 ) . '=';
1635 1 ▶ my $who = $comment // 'root@' . ( $host // 'localhost' );
Condition25%1/4
$comment // 'root@' . ($host // "localhost")
l!l
10
$host // "localhost"
l!l
00
MC/DC0%0/1
$comment // 'root@' . ($host // "localhost")
$comment
MC/DC0%0/1
$host // "localhost"
$host
Truth table50%1/2
A
A= $comment
Aresult
11
00
Truth table0%0/2
A
A= $host
Aresult
11
00
1636 1 $files->{$file} = { content => "-----BEGIN OPENSSH PRIVATE KEY-----\n(simuliert: $blob)\n-----END OPENSSH PRIVATE KEY-----\n", mode => '0600' };
1637 1 $files->{"$file.pub"} = { content => "ssh-$type $blob $who\n", mode => '0644' };
1638 1 ▶ return ( $o{q} ? '' : "Generating public/private $type key pair.\nYour identification has been saved in $file\nYour public key has been saved in $file.pub", 1 );
Branch: 1 branch
BranchTrueFalseTotal
$o{'q'} ? : 1 0 1
1639 }
1640 1 ▶ if ( $o{y} && defined $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"y"} and defined $file) 1 0 1
Condition33%1/3
$o{"y"} and defined $file
!ll&&!rl&&r
001
MC/DC0%0/2
$o{"y"} and defined $file
$o{"y"} defined $file
Truth table33%1/3
A and B
A= $o{"y"}B= defined $file
ABresult
0X0
100
111
1641 1 ▶ my $t = _file_text( $dev, $file ) // return ( "Load key \"$file\": No such file or directory", 0 );
Condition50%1/2
_file_text($dev, $file) // (return qq[Load key "$file": No such file or directory], 0)
l!l
10
MC/DC0%0/1
_file_text($dev, $file) // (return qq[Load key "$file": No such file or directory], 0)
_file_text($dev, $file)
Truth table50%1/2
A
A= _file_text($dev, $file)
Aresult
11
00
1642 0 ▶ my ($blob) = $t =~ /\(simuliert: (\S+)\)/ or do { push @GAPS, join( ' ', 'ssh-keygen', @$av ); return ( '', 0 ) };
Branch: 1 branch
BranchTrueFalseTotal
my($blob) = $t =~ /\(simuliert: (\S+)\)/ or do { push @Langertha::Holmgang::Sim::Linux::GAPS, join(" ", "ssh-keygen", @$av); return "", 0 } 1 0 1
1643 1 ▶ my $pub = _file_text( $dev, "$file.pub" ) // "ssh-ed25519 $blob";
Condition50%1/2
_file_text($dev, "$file.pub") // "ssh-ed25519 $blob"
l!l
10
MC/DC0%0/1
_file_text($dev, "$file.pub") // "ssh-ed25519 $blob"
_file_text($dev, "$file.pub")
Truth table50%1/2
A
A= _file_text($dev, "$file.pub")
Aresult
11
00
1644 1 return ( ( split /\n/, $pub )[0], 1 );
1645 }
1646 0 return undef;
1647 }
1648  
1649 # xargs [-r] [-n N] [-I X] befehl …: Woerter der Eingabe als Argumente
1650 5 ▶sub _xargs {
Subroutine _xargs: called CC=23 SCAR=37.0
1651 5 my ( $dev, $av, $ctx, $stdin ) = @_;
1652 5 my @a = @$av;
1653 5 my ( $r, $n, $rep );
1654 5 ▶ while ( @a && $a[0] =~ /\A-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-/) 2 5 7
Condition66%2/3
@a and $a[0] =~ /\A-/
!ll&&!rl&&r
052
MC/DC50%1/2
@a and $a[0] =~ /\A-/
@a $a[0] =~ /\A-/
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A-/
ABresult
0X0
100
111
1655 2 my $x = shift @a;
1656 2 ▶ if ( $x =~ /\A-r|--no-run-if-empty\z/ ) { $r = 1 }
Branch: 5 branches
BranchTrueFalseTotal
if ($x =~ /\A-r|--no-run-if-empty\z/) { } 1 1 2
elsif ($x eq '-n') { } 0 1 1
elsif ($x =~ /\A-n(\d+)\z/) { } 0 1 1
elsif ($x eq '-I') { } 0 1 1
elsif ($x =~ /\A-I(.+)\z/) { } 1 0 1
1657 0 elsif ( $x eq '-n' ) { $n = shift @a }
1658 0 elsif ( $x =~ /\A-n(\d+)\z/ ) { $n = $1 }
1659 0 elsif ( $x eq '-I' ) { $rep = shift @a }
1660 1 elsif ( $x =~ /\A-I(.+)\z/ ) { $rep = $1 }
1661 }
1662 5 ▶ @a = ('echo') unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 5 5
1663 5 ▶ my @w = defined $rep ? grep {length} split /\n/, $stdin // '' : split ' ', $stdin // '';
Branch: 1 branch
BranchTrueFalseTotal
defined $rep ? : 1 4 5
Condition50%2/4
$stdin // ""
l!l
10
$stdin // ""
l!l
40
MC/DC0%0/1
$stdin // ""
$stdin
MC/DC0%0/1
$stdin // ""
$stdin
Truth table50%1/2
A
A= $stdin
Aresult
11
00
Truth table50%1/2
A
A= $stdin
Aresult
11
00
1664 5 ▶ return ( '', 1 ) if !@w && ( $r || defined $rep );
Branch: 1 branch
BranchTrueFalseTotal
if not @w and $r || defined $rep 1 4 5
Condition50%3/6
not @w and $r || defined $rep
!ll&&!rl&&r
401
$r or defined $rep
l!l&&r!l&&!r
100
MC/DC33%1/3
not @w and $r || defined $rep
not @w $r defined $rep
Truth table50%2/4
not(A) and B or C
A= not @wB= $rC= defined $rep
ABCresult
0XX0
1000
11X1
1011
1665 0 ▶ my @sets = defined $rep ? map { [$_] } @w : $n ? do { my @s; push @s, [ splice @w, 0, $n ] while @w; @s } : ( [@w] );
Branch: 3 branches
BranchTrueFalseTotal
defined $rep ? : 1 3 4
$n ? : 0 3 3
@w and do { push @s, [splice(@w, 0, $n)] } 0 0 0
1666 4 my ( @o, $ok );
1667 4 $ok = 1;
1668 4 for my $s (@sets) {
1669 5 ▶ my @argv = defined $rep ? map { s/\Q$rep\E/$s->[0]/gr } @a : ( @a, @$s );
Branch: 1 branch
BranchTrueFalseTotal
defined $rep ? : 2 3 5
1670 5 my ( $out, $k ) = __PACKAGE__->_command( $dev, \@argv, $ctx, undef );
1671 5 ▶ push @o, $out if defined $out && length $out;
Branch: 1 branch
BranchTrueFalseTotal
if defined $out and length $out 5 0 5
Condition33%1/3
defined $out and length $out
!ll&&!rl&&r
005
MC/DC0%0/2
defined $out and length $out
defined $out length $out
Truth table33%1/3
A and B
A= defined $outB= length $out
ABresult
0X0
100
111
1672 5 ▶ $ok = 0 unless $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $k 0 5 5
1673 }
1674 4 return ( join( "\n", @o ), $ok );
1675 }
1676  
1677 112 ▶sub _cd {
Subroutine _cd: called CC=6 SCAR=18.3
1678 112 my ( $dev, $av ) = @_;
1679 112 my ($arg) = grep { !/\A-/ } @$av;
1680 112 ▶ my $d = !defined $arg || $arg eq '~' ? '/root' : _absp( $arg =~ s{\A~/}{/root/}r );
Branch: 1 branch
BranchTrueFalseTotal
!defined($arg) || $arg eq '~' ? : 0 112 112
Condition33%1/3
not defined $arg or $arg eq "~"
l!l&&r!l&&!r
00112
MC/DC0%0/2
not defined $arg or $arg eq "~"
not defined $arg $arg eq "~"
Truth table33%1/3
not(A) or B
A= not defined $argB= $arg eq "~"
ABresult
1X1
011
000
1681 112 $d =~ s{(?<=.)/+\z}{};
1682 112 ▶ return ( "bash: cd: $arg: No such file or directory", 0 ) unless _is_dir( $dev, $d );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_dir($dev, $d) 2 110 112
1683 110 ▶ return ( "bash: cd: $arg: Permission denied", 0 ) unless _traverse_ok( $dev, $d ) && _dir_ok( $dev, $d, 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless _traverse_ok($dev, $d) and _dir_ok($dev, $d, 1) 1 109 110
Condition66%2/3
_traverse_ok($dev, $d) and _dir_ok($dev, $d, 1)
!ll&&!rl&&r
10109
MC/DC50%1/2
_traverse_ok($dev, $d) and _dir_ok($dev, $d, 1)
_traverse_ok($dev, $d) _dir_ok($dev, $d, 1)
Truth table66%2/3
A and B
A= _traverse_ok($dev, $d)B= _dir_ok($dev, $d, 1)
ABresult
0X0
100
111
1684 109 $CWD_DIR = $d;
1685 109 return ( '', 1 );
1686 }
1687  
1688 # Befehl eines Zusatz-Simulators (Sim::<Modul>::<fn>( $dev, \@argv, $ctx, $stdin|$prog ));
1689 # ohne das Paket (Schluessel im Zustand des Geraets) wie Debian: nicht installiert.
1690 4674 ▶sub _ext {
Subroutine _ext: called CC=2 SCAR=7.3
1691 4674 my ( $mod, $fn, $need, %o ) = @_;
1692 4674 my $sub;
1693 142 ▶ $sub = sub {
Subroutine __ANON__: called CC=12 SCAR=27.8
1694 142 my ( $dev, $av, $ctx, $stdin ) = @_;
1695 142 ▶ unless ( !@$need || grep { $dev->{$_} } @$need ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (not @$need or grep {$$dev{$_};} @$need) 12 130 142
Condition100%3/3
not @$need or grep {$$dev{$_};} @$need
l!l&&r!l&&!r
2510512
MC/DC100%2/2
not @$need or grep {$$dev{$_};} @$need
not @$need grep {$$dev{$_};} @$need
Truth table100%3/3
not(A) or B
A= not @$needB= grep {$$dev{$_};} @$need
ABresult
1X1
011
000
1696 12 ▶ return $o{else}->(@_) if $o{else}; # ohne Paket: was der Grundsimulator kann
Branch: 1 branch
BranchTrueFalseTotal
if $o{"else"} 10 2 12
1697 0 ▶ if ( $o{gap} ) { push @GAPS, join( ' ', $o{prog} // $fn, @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"gap"}) 0 2 2
Condition0%0/3
$o{"prog"} // $fn
l!l&&r!l&&!r
000
MC/DC0%0/2
$o{"prog"} // $fn
$o{"prog"} $fn
Truth table0%0/3
A // B
A= $o{"prog"}B= $fn
ABresult
1X1
011
000
1698 2 ▶ return ( 'bash: ' . ( $o{name} // $o{prog} // ( $o{pre} ? 'mailq' : $fn =~ s/\Acheck/named-check/r ) ) . ': command not found', 0 );
Branch: 1 branch
BranchTrueFalseTotal
$o{'pre'} ? : 0 2 2
Condition33%2/6
($o{"name"} // $o{"prog"}) // ($o{"pre"} ? "mailq" : $fn =~ s/\Acheck/named-check/r)
l!l&&r!l&&!r
020
$o{"name"} // $o{"prog"}
l!l&&r!l&&!r
002
MC/DC0%0/3
($o{"name"} // $o{"prog"}) // ($o{"pre"} ? "mailq" : $fn =~ s/\Acheck/named-check/r)
$o{"name"} $o{"prog"} ($o{"pre"} ? "mailq" : $fn =~ s/\Acheck/named-check/r)
Truth table25%1/4
A // B // C
A= $o{"name"}B= $o{"prog"}C= ($o{"pre"} ? "mailq" : $fn =~ s/\Acheck/named-check/r)
ABCresult
1XX1
01X1
0011
0000
1699 }
1700 130 my $class = _part($mod);
1701 130 ▶ return $class->can($fn)->( $dev, [ @{ $o{pre} || [] }, @$av ], { %{ $ctx || {} }, stdin => $stdin }, $o{prog} // $stdin );
Condition85%6/7
$o{'pre'} || []
l!l
2128
$ctx || {}
l!l
1300
$o{"prog"} // $stdin
l!l&&r!l&&!r
42187
MC/DC100%1/1
$o{'pre'} || []
$o{'pre'}
MC/DC0%0/1
$ctx || {}
$ctx
MC/DC100%2/2
$o{"prog"} // $stdin
$o{"prog"} $stdin
Truth table100%2/2
A
A= $o{'pre'}
Aresult
11
00
Truth table50%1/2
A
A= $ctx
Aresult
11
00
Truth table100%3/3
A // B
A= $o{"prog"}B= $stdin
ABresult
1X1
011
000
1702 4674 };
1703 4674 ▶ $EXT_NEED{$sub} = $o{gap} ? [] : $need;
Branch: 1 branch
BranchTrueFalseTotal
$o{'gap'} ? : 3116 1558 4674
1704 4674 return $sub;
1705 }
1706  
1707 76 ▶sub _pg { return _part('Postgres') }
Subroutine _pg: called CC=1 SCAR=0.0
1708 57 ▶sub _redis { return _part('Redis') }
Subroutine _redis: called CC=1 SCAR=0.0
1709 70 ▶sub _maria { return _part('MariaDB') }
Subroutine _maria: called CC=1 SCAR=0.0
1710  
1711  
1712 86 ▶sub prepare {
Subroutine prepare: called CC=18 SCAR=29.2
Pod documented
1713 86 my ( $class, $dev, $ctx ) = @_;
1714 86 local @MISSING; # a missing part dies here: the case does not load
1715 86 ▶ _redis()->can('_running')->($dev) if $dev->{redis};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"redis"} 2 84 86
1716 85 ▶ _maria()->can('_vars')->($dev) if $dev->{mariadb};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"mariadb"} 1 84 85
1717 85 for ( [ bind => 'Dns' ], [ postfix => 'Postfix' ], [ storage => 'Storage' ] ) {
1718 255 my ( $key, $mod ) = @$_;
1719 255 ▶ next unless $dev->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{$key} 238 17 255
1720 17 my $c = _part($mod);
1721 17 $c->can('prepare')->( $dev, $ctx );
1722 }
1723 # Dienste mit mehreren Dateien laufen mit dem, was beim Start in den Dateien stand
1724 85 ▶ for my $n ( sort keys %{ $dev->{services} || {} } ) {
Condition100%2/2
$$dev{'services'} || {}
l!l
2758
MC/DC100%1/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table100%2/2
A
A= $$dev{'services'}
Aresult
11
00
1725 35 my $svc = $dev->{services}{$n};
1726 35 ▶ $svc->{unit_loaded} = _unit_text( $dev, $n, $svc ) if ( $svc->{unit_loaded} // '' ) eq 'current';
Branch: 1 branch
BranchTrueFalseTotal
if ($$svc{"unit_loaded"} // "") eq "current" 1 34 35
Condition100%2/2
$$svc{"unit_loaded"} // ""
l!l
233
MC/DC100%1/1
$$svc{"unit_loaded"} // ""
$$svc{"unit_loaded"}
Truth table100%2/2
A
A= $$svc{"unit_loaded"}
Aresult
11
00
1727 35 ▶ if ( $svc->{active} && !$svc->{_started} && defined( my $t = $svc->{unit_loaded} // _unit_text( $dev, $n, $svc ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$svc{"active"} and not $$svc{"_started"} and defined(my $t = $$svc{"unit_loaded"} // _unit_text($dev, $n, $svc))) 16 19 35
Condition66%6/9
$$svc{"active"} and not $$svc{"_started"} and defined(my $t = $$svc{"unit_loaded"} // _unit_text($dev, $n, $svc))
!ll&&!rl&&r
01916
$$svc{"active"} and not $$svc{"_started"}
!ll&&!rl&&r
0035
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
l!l&&r!l&&!r
21419
MC/DC50%2/4
$$svc{"active"} and not $$svc{"_started"} and defined(my $t = $$svc{"unit_loaded"} // _unit_text($dev, $n, $svc))
$$svc{"active"} not $$svc{"_started"} $$svc{"unit_loaded"} _unit_text($dev, $n, $svc)
Truth table60%3/5
A and not(B) and C // D
A= $$svc{"active"}B= not $$svc{"_started"}C= $$svc{"unit_loaded"}D= _unit_text($dev, $n, $svc)
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1728 16 $svc->{_started} = _unit_props($t);
1729 }
1730 35 ▶ next unless ref $svc->{config} eq 'ARRAY' && !defined $svc->{running} && $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$svc{"config"} eq "ARRAY" and not defined $$svc{"running"} and $$svc{"active"} 27 8 35
Condition66%4/6
ref $$svc{"config"} eq "ARRAY" and not defined $$svc{"running"} and $$svc{"active"}
!ll&&!rl&&r
2708
ref $$svc{"config"} eq "ARRAY" and not defined $$svc{"running"}
!ll&&!rl&&r
2708
MC/DC33%1/3
ref $$svc{"config"} eq "ARRAY" and not defined $$svc{"running"} and $$svc{"active"}
ref $$svc{"config"} eq "ARRAY" not defined $$svc{"running"} $$svc{"active"}
Truth table50%2/4
A and not(B) and C
A= ref $$svc{"config"} eq "ARRAY"B= not defined $$svc{"running"}C= $$svc{"active"}
ABCresult
0XX0
10X0
1100
1111
1731 8 my ( undef, $extra ) = _config_check( $dev, $svc );
1732 8 ▶ $svc->{running} = { ( map { my $t = _file_text( $dev, $_ ); defined $t ? ( $_ => $t ) : () } @{ $svc->{config} } ), %{ $extra || {} } };
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 15 0 15
Condition50%1/2
$extra || {}
l!l
80
MC/DC0%0/1
$extra || {}
$extra
Truth table50%1/2
A
A= $extra
Aresult
11
00
1733 }
1734 85 return;
1735 }
1736  
1737 # redis-cli gegen den Redis des Geraets (redis); ohne Redis nicht installiert
1738 61 ▶sub _redis_cli {
Subroutine _redis_cli: called CC=11 SCAR=24.4
1739 61 my ( $dev, $av, $ctx, $stdin ) = @_;
1740 # ohne den Redis-Zustand (redis): Redis nur aus dem Dienst (Sim::RedisService)
1741 61 ▶ return _redis_cmd( 'cli', $dev, $av, $ctx ) unless $dev->{redis};
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{"redis"} 12 49 61
1742 # -h <Adresse eines anderen Geraets>: dessen Redis antwortet
1743 49 my $target = $dev;
1744 49 for my $i ( 0 .. $#$av - 1 ) {
1745 73 ▶ next unless $av->[$i] eq '-h';
Branch: 1 branch
BranchTrueFalseTotal
unless $$av[$i] eq "-h" 71 2 73
1746 2 my $h = $av->[ $i + 1 ];
1747 0 ▶ last if $h =~ /\A(?:127\.|localhost\z)/ || grep { $_ eq $h } _own_addrs($dev);
Branch: 1 branch
BranchTrueFalseTotal
if $h =~ /\A(?:127\.|localhost\z)/ or grep {$_ eq $h;} _own_addrs($dev) 0 2 2
Condition33%1/3
$h =~ /\A(?:127\.|localhost\z)/ or grep {$_ eq $h;} _own_addrs($dev)
l!l&&r!l&&!r
002
MC/DC0%0/2
$h =~ /\A(?:127\.|localhost\z)/ or grep {$_ eq $h;} _own_addrs($dev)
$h =~ /\A(?:127\.|localhost\z)/ grep {$_ eq $h;} _own_addrs($dev)
Truth table33%1/3
A or B
A= $h =~ /\A(?:127\.|localhost\z)/B= grep {$_ eq $h;} _own_addrs($dev)
ABresult
1X1
011
000
1748 2 ▶ my ($other) = grep { ref $_ eq 'HASH' && grep { $_ eq $h } _own_addrs($_) } values %{ $CTX ? $CTX->{state} : {} };
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 2 0 2
Condition66%2/3
ref $_ eq 'HASH' && grep({$_ eq $h;} _own_addrs($_))
!ll&&!rl&&r
021
MC/DC50%1/2
ref $_ eq 'HASH' && grep({$_ eq $h;} _own_addrs($_))
ref $_ eq 'HASH' grep({$_ eq $h;} _own_addrs($_))
Truth table66%2/3
A && B
A= ref $_ eq 'HASH'B= grep({$_ eq $h;} _own_addrs($_))
ABresult
0X0
100
111
1749 2 ▶ $target = $other if $other;
Branch: 1 branch
BranchTrueFalseTotal
if $other 1 1 2
1750 2 ▶ return ( "Could not connect to Redis at $h:6379: Connection refused", 1 ) unless $other && $other->{redis};
Branch: 1 branch
BranchTrueFalseTotal
unless $other and $$other{"redis"} 1 1 2
Condition66%2/3
$other and $$other{"redis"}
!ll&&!rl&&r
101
MC/DC50%1/2
$other and $$other{"redis"}
$other $$other{"redis"}
Truth table66%2/3
A and B
A= $otherB= $$other{"redis"}
ABresult
0X0
100
111
1751 1 last;
1752 }
1753 48 my $m = _redis();
1754 82 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1755 47 local @{"${m}::GAPS"};
1756 47 my ( $o, $ok ) = $m->can('redis_cli')->( $target, $av, $ctx, $stdin );
1757 47 push @GAPS, @{"${m}::GAPS"};
1758 47 return ( $o, $ok );
1759 }
1760  
1761 # promtool/amtool (Sim::Monitoring)
1762 20 ▶sub _mon {
Subroutine _mon: called CC=1 SCAR=0.0
1763 20 my ( $prog, $dev, $av, $ctx ) = @_;
1764 20 _part('Monitoring');
1765 20 my $m = 'Langertha::Holmgang::Sim::Linux::Monitoring';
1766 82 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1767 20 local @{"${m}::GAPS"};
1768 20 my ( $o, $ok ) = $m->can($prog)->( $dev, $av );
1769 20 push @GAPS, @{"${m}::GAPS"};
1770 20 return ( $o, $ok );
1771 }
1772  
1773 # mysql/mariadb/mysqladmin gegen den MariaDB-Server des Geraets (mariadb)
1774 58 ▶sub _mysql_client {
Subroutine _mysql_client: called CC=5 SCAR=16.7
1775 58 my ( $prog, $dev, $av, $ctx, $stdin ) = @_;
1776 0 ▶ if ( !$dev->{mariadb} ) { push @GAPS, join( ' ', $prog, @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($$dev{"mariadb"}) 0 58 58
1777 58 my $m = _maria();
1778 82 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1779 58 local @{"${m}::GAPS"};
1780 58 ▶ my ( $o, $ok ) = $prog =~ /admin/
Branch: 1 branch
BranchTrueFalseTotal
$prog =~ /admin/ ? : 5 53 58
Condition50%2/4
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
05
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
053
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
$Langertha::Holmgang::Sim::Linux::AS_USER
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
$Langertha::Holmgang::Sim::Linux::AS_USER
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::AS_USER
Aresult
11
00
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::AS_USER
Aresult
11
00
1781 ? $m->can('mysqladmin')->( $dev, $av, $ctx, $AS_USER // 'root' )
1782 : $m->can('client')->( $dev, $av, $ctx, $stdin, $AS_USER // 'root', $prog );
1783 58 push @GAPS, @{"${m}::GAPS"};
1784 58 return ( $o, $ok );
1785 }
1786  
1787 # Datenbankdienste: Konfigurationsfehler verhindern den Start (Journalzeilen) oder undef
1788 77 ▶sub _app_conf_error {
Subroutine _app_conf_error: called CC=13 SCAR=26.1
1789 77 my ( $dev, $n ) = @_;
1790 77 ▶ my $svc = ( $dev->{services} || {} )->{$n} || {};
Condition50%2/4
($$dev{'services'} || {})->{$n} || {}
l!l
770
$$dev{'services'} || {}
l!l
770
MC/DC0%0/1
($$dev{'services'} || {})->{$n} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
1791 77 ▶ if ( $svc->{config_check} ) { my ($e) = _config_check( $dev, $svc ); return $e if @$e }
Branch: 2 branches
BranchTrueFalseTotal
if ($$svc{"config_check"}) 11 66 77
if @$e 1 10 11
1792 76 my ( $lines, $exe );
1793 76 ▶ if ( $dev->{redis} && $n eq ( $dev->{redis}{service} // 'redis-server' ) ) { $lines = _redis()->can('conf_error')->($dev); $exe = 'redis-server' }
Branch: 2 branches
BranchTrueFalseTotal
if ($$dev{'redis'} and $n eq ($$dev{'redis'}{'service'} // 'redis-server')) { } 3 73 76
elsif ($$dev{'mariadb'} and $n eq ($$dev{'mariadb'}{'service'} // 'mariadb')) { } 5 136 141
Condition60%3/5
$$dev{"redis"} and $n eq ($$dev{"redis"}{"service"} // "redis-server")
!ll&&!rl&&r
7303
$$dev{"redis"}{"service"} // "redis-server"
l!l
30
MC/DC50%1/2
$$dev{"redis"} and $n eq ($$dev{"redis"}{"service"} // "redis-server")
$$dev{"redis"} $n eq ($$dev{"redis"}{"service"} // "redis-server")
MC/DC0%0/1
$$dev{"redis"}{"service"} // "redis-server"
$$dev{"redis"}{"service"}
Truth table66%2/3
A and B
A= $$dev{"redis"}B= $n eq ($$dev{"redis"}{"service"} // "redis-server")
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$dev{"redis"}{"service"}
Aresult
11
00
1794 5 ▶ elsif ( $dev->{mariadb} && $n eq ( $dev->{mariadb}{service} // 'mariadb' ) ) { $lines = _maria()->can('conf_error')->($dev); $exe = 'mariadbd' }
Condition60%3/5
$$dev{"mariadb"} and $n eq ($$dev{"mariadb"}{"service"} // "mariadb")
!ll&&!rl&&r
6805
$$dev{"mariadb"}{"service"} // "mariadb"
l!l
50
MC/DC50%1/2
$$dev{"mariadb"} and $n eq ($$dev{"mariadb"}{"service"} // "mariadb")
$$dev{"mariadb"} $n eq ($$dev{"mariadb"}{"service"} // "mariadb")
MC/DC0%0/1
$$dev{"mariadb"}{"service"} // "mariadb"
$$dev{"mariadb"}{"service"}
Truth table66%2/3
A and B
A= $$dev{"mariadb"}B= $n eq ($$dev{"mariadb"}{"service"} // "mariadb")
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$dev{"mariadb"}{"service"}
Aresult
11
00
1795 76 ▶ return undef unless $lines;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines 73 3 76
1796 3 ▶ return [ map { "$exe\[" . ( 50000 + ( $dev->{_tick} // 0 ) ) . "]: $_" } @$lines ];
Condition100%2/2
$$dev{"_tick"} // 0
l!l
36
MC/DC100%1/1
$$dev{"_tick"} // 0
$$dev{"_tick"}
Truth table100%2/2
A
A= $$dev{"_tick"}
Aresult
11
00
1797 }
1798  
1799 # Pruefung der Konfiguration eines Dienstes (config_check: prometheus|alertmanager):
1800 # ( [ Journalzeilen bei Fehler ], { nachgeladene Datei => Text } )
1801 33 ▶sub _config_check {
Subroutine _config_check: called CC=5 SCAR=16.8
1802 33 my ( $dev, $svc ) = @_;
1803 33 ▶ my $kind = $svc->{config_check} or return ( [], {} );
Branch: 1 branch
BranchTrueFalseTotal
my $kind = $$svc{"config_check"} or return [], {} 33 0 33
1804 33 _part('Monitoring');
1805 33 my ( $err, $extra ) = Langertha::Holmgang::Sim::Linux::Monitoring::service_check( $dev, $svc, $kind );
1806 33 ▶ my $pid = 50000 + ( $dev->{_tick} // 0 );
Condition100%2/2
$$dev{"_tick"} // 0
l!l
1122
MC/DC100%1/1
$$dev{"_tick"} // 0
$$dev{"_tick"}
Truth table100%2/2
A
A= $$dev{"_tick"}
Aresult
11
00
1807 33 ▶ return ( [ map { ( $svc->{exec} // $kind ) . "[$pid]: $_" } @$err ], $extra || {} );
Condition40%2/5
$$svc{"exec"} // $kind
l!l&&r!l&&!r
200
$extra || {}
l!l
330
MC/DC0%0/2
$$svc{"exec"} // $kind
$$svc{"exec"} $kind
MC/DC0%0/1
$extra || {}
$extra
Truth table33%1/3
A // B
A= $$svc{"exec"}B= $kind
ABresult
1X1
011
000
Truth table50%1/2
A
A= $extra
Aresult
11
00
1808 }
1809  
1810 # Datenbankdienste: Wirkung von Start, Neustart, Stopp
1811 73 ▶sub _app_event {
Subroutine _app_event: called CC=8 SCAR=21.7
1812 73 my ( $dev, $n, $verb ) = @_;
1813 73 ▶ if ( $dev->{redis} && $n eq ( $dev->{redis}{service} // 'redis-server' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"redis"} and $n eq ($$dev{"redis"}{"service"} // "redis-server")) 3 70 73
Condition60%3/5
$$dev{"redis"} and $n eq ($$dev{"redis"}{"service"} // "redis-server")
!ll&&!rl&&r
7003
$$dev{"redis"}{"service"} // "redis-server"
l!l
30
MC/DC50%1/2
$$dev{"redis"} and $n eq ($$dev{"redis"}{"service"} // "redis-server")
$$dev{"redis"} $n eq ($$dev{"redis"}{"service"} // "redis-server")
MC/DC0%0/1
$$dev{"redis"}{"service"} // "redis-server"
$$dev{"redis"}{"service"}
Truth table66%2/3
A and B
A= $$dev{"redis"}B= $n eq ($$dev{"redis"}{"service"} // "redis-server")
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$dev{"redis"}{"service"}
Aresult
11
00
1814 3 ▶ _redis()->can('service_event')->( $dev, $verb, $CTX ? $CTX->{state} : {} );
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 3 0 3
1815 }
1816 73 ▶ if ( $dev->{mariadb} && $n eq ( $dev->{mariadb}{service} // 'mariadb' ) ) { _maria()->can('service_event')->( $dev, $verb ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"mariadb"} and $n eq ($$dev{"mariadb"}{"service"} // "mariadb")) 5 68 73
Condition60%3/5
$$dev{"mariadb"} and $n eq ($$dev{"mariadb"}{"service"} // "mariadb")
!ll&&!rl&&r
6805
$$dev{"mariadb"}{"service"} // "mariadb"
l!l
50
MC/DC50%1/2
$$dev{"mariadb"} and $n eq ($$dev{"mariadb"}{"service"} // "mariadb")
$$dev{"mariadb"} $n eq ($$dev{"mariadb"}{"service"} // "mariadb")
MC/DC0%0/1
$$dev{"mariadb"}{"service"} // "mariadb"
$$dev{"mariadb"}{"service"}
Truth table66%2/3
A and B
A= $$dev{"mariadb"}B= $n eq ($$dev{"mariadb"}{"service"} // "mariadb")
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$dev{"mariadb"}{"service"}
Aresult
11
00
1817 73 return;
1818 }
1819  
1820 23 ▶sub _acc { return _part('Accounts') }
Subroutine _acc: called CC=1 SCAR=0.0
1821 204 ▶sub _sshd_sim { return _part('Sshd') }
Subroutine _sshd_sim: called CC=1 SCAR=0.0
1822  
1823 10 ▶sub _sshd {
Subroutine _sshd: called CC=19 SCAR=31.9
1824 10 my ( $dev, $av ) = @_;
1825 10 ▶ return ( "sshd: no hostkeys available -- exiting.", 0 ) unless _sshd_sim()->can('active')->($dev);
Branch: 1 branch
BranchTrueFalseTotal
unless _sshd_sim()->can("active")->($dev) 0 10 10
1826 # sshd -T -C user=…,addr=…[,host=…,laddr=…,lport=…]: Match-Abschnitte fuer diese Verbindung
1827 10 my @a = @$av;
1828 10 my ($ci) = map { $a[ $_ + 1 ] } grep { $a[$_] eq '-C' } 0 .. $#a - 1;
1829 10 my ( $out, $ok ) = _sshd_sim()->can('sshd')->( $dev, $av );
1830 10 ▶ return ( $out, $ok ) unless $ok && defined $ci && grep { /\A-[a-zA-Z]*T/ } @a;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok and defined $ci and grep {/\A-[a-zA-Z]*T/;} @a 8 2 10
Condition83%5/6
$ok and defined $ci and grep {/\A-[a-zA-Z]*T/;} @a
!ll&&!rl&&r
802
$ok and defined $ci
!ll&&!rl&&r
352
MC/DC66%2/3
$ok and defined $ci and grep {/\A-[a-zA-Z]*T/;} @a
$ok defined $ci grep {/\A-[a-zA-Z]*T/;} @a
Truth table75%3/4
A and B and C
A= $okB= defined $ciC= grep {/\A-[a-zA-Z]*T/;} @a
ABCresult
0XX0
10X0
1100
1111
1831 2 ▶ my %c = map { /\A(\w+)=(.*)\z/ ? ( lc $1 => $2 ) : () } split /,/, $ci;
Branch: 1 branch
BranchTrueFalseTotal
/\A(\w+)=(.*)\z/ ? : 4 0 4
1832 2 ▶ return ( "sshd: Invalid test mode specification $ci", 0 ) unless defined $c{user} || defined $c{addr};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c{"user"} or defined $c{"addr"} 0 2 2
Condition33%1/3
defined $c{"user"} or defined $c{"addr"}
l!l&&r!l&&!r
200
MC/DC0%0/2
defined $c{"user"} or defined $c{"addr"}
defined $c{"user"} defined $c{"addr"}
Truth table33%1/3
A or B
A= defined $c{"user"}B= defined $c{"addr"}
ABresult
1X1
011
000
1833 2 ▶ my $u = ( $dev->{users} || {} )->{ $c{user} // '' } || {};
Condition50%3/6
($$dev{'users'} || {})->{$c{'user'} // ''} || {}
l!l
20
$$dev{'users'} || {}
l!l
20
$c{"user"} // ""
l!l
20
MC/DC0%0/1
($$dev{'users'} || {})->{$c{'user'} // ''} || {}
$$dev{'users'}
MC/DC0%0/1
$c{"user"} // ""
$c{"user"}
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
Truth table50%1/2
A
A= $c{"user"}
Aresult
11
00
1834 my $over = _ssh_access()->can('match_overrides')->( $dev,
1835 2 ▶ { user => $c{user} // '', from => $c{addr}, groups => [ @{ $u->{groups} || [] } ], port => $c{lport} // 22 }, 1 );
Condition50%3/6
$c{"user"} // ""
l!l
20
$$u{'groups'} || []
l!l
20
$c{"lport"} // 22
l!l
02
MC/DC0%0/1
$c{"user"} // ""
$c{"user"}
MC/DC0%0/1
$$u{'groups'} || []
$$u{'groups'}
MC/DC0%0/1
$c{"lport"} // 22
$c{"lport"}
Truth table50%1/2
A
A= $c{"user"}
Aresult
11
00
Truth table50%1/2
A
A= $$u{'groups'}
Aresult
11
00
Truth table50%1/2
A
A= $c{"lport"}
Aresult
11
00
1836 2 ▶ return ( $out, 1 ) unless %$over;
Branch: 1 branch
BranchTrueFalseTotal
unless %$over 1 1 2
1837 1 ▶ my @l = grep { my ($k) = /\A(\S+)/; !exists $over->{ $k // '' } } split /\n/, $out;
Condition50%1/2
$k // ""
l!l
390
MC/DC0%0/1
$k // ""
$k
Truth table50%1/2
A
A= $k
Aresult
11
00
1838 1 for my $k ( sort keys %$over ) {
1839 1 my $v = $over->{$k};
1840 1 ▶ push @l, map {"$k $_"} ref $v ? @$v : ( $k =~ /\A(?:passwordauthentication|pubkeyauthentication|permitrootlogin|strictmodes)\z/ ? lc $v : $v );
Branch: 2 branches
BranchTrueFalseTotal
ref $v ? : 0 1 1
$k =~ /\A(?:passwordauthentication|pubkeyauthentication|permitrootlogin|strictmodes)\z/ ? : 1 0 1
1841 }
1842 1 return ( join( "\n", @l ), 1 );
1843 }
1844  
1845 67 ▶sub _psql {
Subroutine _psql: called CC=2 SCAR=6.9
1846 67 my ( $dev, $av, $ctx ) = @_;
1847 67 my $pg = _pg();
1848 82 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1849 67 local @{"${pg}::GAPS"};
1850 67 ▶ my ( $o, $ok ) = $pg->can('psql')->( $dev, $av, $ctx, $AS_USER // 'root' );
Condition100%2/2
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
589
MC/DC100%1/1
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
$Langertha::Holmgang::Sim::Linux::AS_USER
Truth table100%2/2
A
A= $Langertha::Holmgang::Sim::Linux::AS_USER
Aresult
11
00
1851 67 push @GAPS, @{"${pg}::GAPS"};
1852 67 return ( $o, $ok );
1853 }
1854  
1855 # kubectl gegen den Cluster im Zustand des Geraets (kubernetes)
1856 133 ▶sub _kubectl {
Subroutine _kubectl: called CC=1 SCAR=0.0
1857 133 my ( $dev, $av, $ctx, $stdin ) = @_;
1858 133 _part('Kubernetes');
1859 133 local @Langertha::Holmgang::Sim::Linux::Kubernetes::GAPS;
1860 133 my ( $o, $ok ) = Langertha::Holmgang::Sim::Linux::Kubernetes::kubectl( $dev, $av, $ctx, $stdin );
1861 133 push @GAPS, @Langertha::Holmgang::Sim::Linux::Kubernetes::GAPS;
1862 133 return ( $o, $ok );
1863 }
1864  
1865 # openssl x509 (Pseudo-PEM der Simulation), s_client ueber den Ingress eines simulierten Clusters
1866 3 ▶sub _openssl {
Subroutine _openssl: called CC=15 SCAR=29.8
1867 3 my ( $dev, $av, $ctx, $stdin ) = @_;
1868 3 my @a = @$av;
1869 3 ▶ my $verb = shift(@a) // '';
Condition50%1/2
shift @a // ""
l!l
30
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
1870 3 _part('Kubernetes');
1871 3 ▶ if ( $verb eq 'x509' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "x509") 2 1 3
1872 2 my $in;
1873 2 ▶ for my $i ( 0 .. $#a ) { $in = $a[ $i + 1 ] if $a[$i] eq '-in' }
Branch: 1 branch
BranchTrueFalseTotal
if $a[$i] eq "-in" 0 5 5
1874 2 ▶ my $pem = defined $in ? _file_text( $dev, $in ) : $stdin;
Branch: 1 branch
BranchTrueFalseTotal
defined $in ? : 0 2 2
1875 2 ▶ return ( "Could not open file or uri for loading certificate from $in", 0 ) unless defined $pem;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pem 0 2 2
1876 2 return Langertha::Holmgang::Sim::Linux::Kubernetes::x509( $pem, \@a );
1877 }
1878 1 ▶ if ( $verb eq 's_client' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "s_client") 1 0 1
1879 1 my ( $conn, $sni );
1880 1 ▶ for my $i ( 0 .. $#a ) { $conn = $a[ $i + 1 ] if $a[$i] eq '-connect'; $sni = $a[ $i + 1 ] if $a[$i] eq '-servername' }
Branch: 2 branches
BranchTrueFalseTotal
if $a[$i] eq "-connect" 1 3 4
if $a[$i] eq "-servername" 1 3 4
1881 1 ▶ my ($h) = ( $conn // '' ) =~ /\A([^:]+)/;
Condition50%1/2
$conn // ""
l!l
10
MC/DC0%0/1
$conn // ""
$conn
Truth table50%1/2
A
A= $conn
Aresult
11
00
1882 1 ▶ return ( "s_client: -connect requires an argument", 0 ) unless defined $h;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h 0 1 1
1883 1 ▶ return ( "4087F6B7A57F0000:error:8000006F:system library:BIO_connect:Connection refused", 0 ) unless $dev->{kubernetes};
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{"kubernetes"} 0 1 1
1884 1 return Langertha::Holmgang::Sim::Linux::Kubernetes::tls_probe( $dev->{kubernetes}, $h, $sni );
1885 }
1886 0 ▶ return ( 'OpenSSL 3.0.15 3 Sep 2024 (Library: OpenSSL 3.0.15 3 Sep 2024)', 1 ) if $verb eq 'version';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "version" 0 0 0
1887 0 push @GAPS, "openssl $verb";
1888 0 return ( '', 0 );
1889 }
1890  
1891 # docker (nur, wo es einen Socket gibt): Zugriff wie echt ueber Rechte am Socket
1892 2 ▶sub _docker {
Subroutine _docker: called CC=20 SCAR=36.6
1893 2 my ( $dev, $av ) = @_;
1894 2 my $sock = '/var/run/docker.sock';
1895 2 ▶ return ( 'bash: docker: command not found', 0 ) unless _file_entry( $dev, $sock );
Branch: 1 branch
BranchTrueFalseTotal
unless _file_entry($dev, $sock) 0 2 2
1896 2 ▶ my $user = $AS_USER // 'root';
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
02
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
$Langertha::Holmgang::Sim::Linux::AS_USER
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::AS_USER
Aresult
11
00
1897 2 my ($verb) = grep { !/\A-/ } @$av;
1898 2 ▶ $verb //= '';
Condition50%1/2
$verb //= ""
l!l
20
MC/DC0%0/1
$verb //= ""
$verb
Truth table50%1/2
A
A= $verb
Aresult
11
00
1899 0 ▶ return ( "Docker version 26.1.5+dfsg1, build a72d7cd", 1 ) if $verb eq '' && grep { $_ eq '--version' || $_ eq '-v' } @$av;
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "" and grep {$_ eq "--version" or $_ eq "-v";} @$av 0 2 2
Condition16%1/6
$verb eq "" and grep {$_ eq "--version" or $_ eq "-v";} @$av
!ll&&!rl&&r
200
$_ eq '--version' || $_ eq '-v'
l!l&&r!l&&!r
000
MC/DC0%0/2
$verb eq "" and grep {$_ eq "--version" or $_ eq "-v";} @$av
$verb eq "" grep {$_ eq "--version" or $_ eq "-v";} @$av
MC/DC0%0/2
$_ eq '--version' || $_ eq '-v'
$_ eq '--version' $_ eq '-v'
Truth table33%1/3
A and B
A= $verb eq ""B= grep {$_ eq "--version" or $_ eq "-v";} @$av
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= $_ eq '--version'B= $_ eq '-v'
ABresult
1X1
011
000
1900 2 ▶ return ( "permission denied while trying to connect to the Docker daemon socket at unix://$sock: Get \"http://%2Fvar%2Frun%2Fdocker.sock/v1.45/$verb\": dial unix $sock: connect: permission denied", 0 )
Branch: 1 branch
BranchTrueFalseTotal
unless _can($dev, $user, $sock, "w") 0 2 2
1901 unless _can( $dev, $user, $sock, 'w' );
1902 2 ▶ return ( 'Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?', 0 ) unless ( ( $dev->{services} || {} )->{docker} || {} )->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless (($$dev{"services"} || {})->{"docker"} || {})->{"active"} 0 2 2
Condition50%2/4
($$dev{'services'} || {})->{'docker'} || {}
l!l
20
$$dev{'services'} || {}
l!l
20
MC/DC0%0/1
($$dev{'services'} || {})->{'docker'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
1903 2 ▶ return ( 'CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES', 1 ) if $verb eq 'ps';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "ps" 0 2 2
1904 2 ▶ return ( 'REPOSITORY TAG IMAGE ID CREATED SIZE', 1 ) if $verb eq 'images';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "images" 0 2 2
1905 2 ▶ return ( "Client: Docker Engine - Community\n Version: 26.1.5\n\nServer:\n Containers: 0\n Images: 0\n Server Version: 26.1.5\n Storage Driver: overlay2\n Cgroup Driver: systemd", 1 ) if $verb eq 'info';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "info" 0 2 2
1906 2 ▶ return ( "Client:\n Version: 26.1.5\n API version: 1.45\n\nServer:\n Engine:\n Version: 26.1.5\n API version: 1.45 (minimum version 1.24)", 1 ) if $verb eq 'version';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "version" 0 2 2
1907 2 my @p = grep { !/\A-/ } @$av;
1908 2 ▶ if ( $verb eq 'pull' && @p >= 2 ) { # Registry erreichbar: Bild laedt
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "pull" and @p >= 2) 1 1 2
Condition66%2/3
$verb eq "pull" and @p >= 2
!ll&&!rl&&r
101
MC/DC50%1/2
$verb eq "pull" and @p >= 2
$verb eq "pull" @p >= 2
Truth table66%2/3
A and B
A= $verb eq "pull"B= @p >= 2
ABresult
0X0
100
111
1909 1 ( my $img = $p[1] ) =~ s/\A(?![\w.-]+\.[\w-]+\/)/docker.io\/library\//;
1910 1 ▶ $img .= ':latest' unless $p[1] =~ /:[\w.-]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $p[1] =~ /:[\w.-]+\z/ 0 1 1
1911 1 ( my $tag = $img ) =~ s/.*://;
1912 1 return ( "$tag: Pulling from " . ( $img =~ s/:[^:]+\z//r =~ s{\Adocker\.io/}{}r ) . "\nDigest: sha256:3f1b2c0e5d6a7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e\nStatus: Downloaded newer image for $img\n$img", 1 );
1913 }
1914 1 ▶ if ( $verb eq 'run' && grep { $_ eq 'hello-world' } @p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "run" and grep {$_ eq "hello-world";} @p) 1 0 1
Condition33%1/3
$verb eq "run" and grep {$_ eq "hello-world";} @p
!ll&&!rl&&r
001
MC/DC0%0/2
$verb eq "run" and grep {$_ eq "hello-world";} @p
$verb eq "run" grep {$_ eq "hello-world";} @p
Truth table33%1/3
A and B
A= $verb eq "run"B= grep {$_ eq "hello-world";} @p
ABresult
0X0
100
111
1915 1 return ( "Unable to find image 'hello-world:latest' locally\nlatest: Pulling from library/hello-world\nStatus: Downloaded newer image for hello-world:latest\n\nHello from Docker!\nThis message shows that your installation appears to be working correctly.", 1 );
1916 }
1917 0 push @GAPS, "docker @$av";
1918 0 return ( '', 0 );
1919 }
1920  
1921 # git auf den Arbeitskopien des Geraets (git.repos), Server ueber den Zustand
1922 75 ▶sub _git {
Subroutine _git: called CC=1 SCAR=0.0
1923 75 my ( $dev, $av, $ctx ) = @_;
1924 75 _part('Git');
1925 75 local @Langertha::Holmgang::Sim::Linux::Git::GAPS;
1926 75 my ( $o, $ok ) = Langertha::Holmgang::Sim::Linux::Git::git( $dev, $av, $ctx, $CWD_DIR );
1927 75 push @GAPS, @Langertha::Holmgang::Sim::Linux::Git::GAPS;
1928 75 return ( $o, $ok );
1929 }
1930  
1931 # helm gegen den Cluster im Zustand des Geraets (kubernetes.helm)
1932 31 ▶sub _helm {
Subroutine _helm: called CC=1 SCAR=0.0
1933 31 my ( $dev, $av, $ctx ) = @_;
1934 31 _part('Helm');
1935 31 local @Langertha::Holmgang::Sim::Linux::Helm::GAPS;
1936 31 my ( $o, $ok ) = Langertha::Holmgang::Sim::Linux::Helm::helm( $dev, $av, $ctx );
1937 30 push @GAPS, @Langertha::Holmgang::Sim::Linux::Helm::GAPS;
1938 30 return ( $o, $ok );
1939 }
1940  
1941 # pg_ctlcluster 15 main reload -> systemctl reload postgresql@15-main
1942 1 ▶sub _pg_ctlcluster {
Subroutine _pg_ctlcluster: called CC=7 SCAR=22.4
1943 1 my ( $dev, $av, $ctx ) = @_;
1944 1 my @a = grep { !/\A-/ } @$av;
1945 1 ▶ return ( 'Usage: /usr/bin/pg_ctlcluster <version> <cluster> <action> [-- <pg_ctl options>]', 0 ) unless @a >= 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @a >= 3 0 1 1
1946 1 my ( $ver, $name, $verb ) = @a;
1947 1 my $pg = $dev->{postgres};
1948 1 ▶ return ( "Error: specified cluster $ver/$name does not exist", 0 ) unless $pg && ( $pg->{cluster} // '' ) eq "$ver/$name";
Branch: 1 branch
BranchTrueFalseTotal
unless $pg and ($$pg{"cluster"} // "") eq "$ver/$name" 0 1 1
Condition40%2/5
$pg and ($$pg{"cluster"} // "") eq "$ver/$name"
!ll&&!rl&&r
001
$$pg{"cluster"} // ""
l!l
10
MC/DC0%0/2
$pg and ($$pg{"cluster"} // "") eq "$ver/$name"
$pg $$pg{"cluster"}
Truth table33%1/3
A and B
A= $pgB= $$pg{"cluster"}
ABresult
0X0
100
111
1949 1 ▶ return _systemctl( $dev, [ $verb eq 'status' ? 'status' : $verb, $pg->{service} ], $ctx )
Branch: 2 branches
BranchTrueFalseTotal
if $verb =~ /\A(?:start|stop|restart|reload|status)\z/ 1 0 1
$verb eq 'status' ? : 0 1 1
1950 if $verb =~ /\A(?:start|stop|restart|reload|status)\z/;
1951 0 return ( "Error: Invalid action $verb", 0 );
1952 }
1953  
1954 # su [-|-l] benutzer -c 'befehl' / runuser -u benutzer -- befehl
1955  
1956  
1957 27 ▶sub _su {
Subroutine _su: called CC=27 SCAR=37.4
1958 27 my ( $dev, $av, $ctx ) = @_;
1959 27 my @a = @$av;
1960 27 my ( $user, $cmd );
1961 27 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 81 27 108
1962 81 my $x = shift @a;
1963 81 ▶ if ( $x eq '-' || $x eq '-l' || $x eq '--login' ) { next }
Branch: 6 branches
BranchTrueFalseTotal
if ($x eq '-' or $x eq '-l' or $x eq '--login') { } 25 56 81
elsif ($x eq '-c' or $x eq '--command') { } 27 29 56
elsif ($x eq '-u') { } 0 29 29
elsif ($x eq '--') { } 0 29 29
elsif ($x eq '-s') { } 2 27 29
elsif (not defined $user) { } 27 0 27
Condition66%4/6
$x eq "-" or $x eq "-l" or $x eq "--login"
l!l&&r!l&&!r
25056
$x eq "-" or $x eq "-l"
l!l&&r!l&&!r
25056
MC/DC33%1/3
$x eq "-" or $x eq "-l" or $x eq "--login"
$x eq "-" $x eq "-l" $x eq "--login"
Truth table50%2/4
A or B or C
A= $x eq "-"B= $x eq "-l"C= $x eq "--login"
ABCresult
1XX1
01X1
0011
0000
1964 27 ▶ elsif ( $x eq '-c' || $x eq '--command' ) { $cmd = shift @a }
Condition66%2/3
$x eq "-c" or $x eq "--command"
l!l&&r!l&&!r
27029
MC/DC50%1/2
$x eq "-c" or $x eq "--command"
$x eq "-c" $x eq "--command"
Truth table66%2/3
A or B
A= $x eq "-c"B= $x eq "--command"
ABresult
1X1
011
000
1965 0 elsif ( $x eq '-u' ) { $user = shift @a }
1966 0 ▶ elsif ( $x eq '--' ) { $cmd = join ' ', map { /[\s'"]/ ? "'$_'" : $_ } @a; last }
Branch: 1 branch
BranchTrueFalseTotal
/[\s'"]/ ? : 0 0 0
1967 2 elsif ( $x eq '-s' ) { shift @a }
1968 27 elsif ( !defined $user ) { $user = $x }
1969 }
1970 27 ▶ $user //= 'root';
Condition50%1/2
$user //= "root"
l!l
270
MC/DC0%0/1
$user //= "root"
$user
Truth table50%1/2
A
A= $user
Aresult
11
00
1971 return ( "su: user $user does not exist or the user entry does not contain all the required fields", 0 )
1972 27 ▶ unless $user eq 'root' || $user eq 'postgres' || ( $dev->{users} || {} )->{$user};
Branch: 1 branch
BranchTrueFalseTotal
unless $user eq "root" or $user eq "postgres" or ($$dev{"users"} || {})->{$user} 1 26 27
Condition75%6/8
$user eq "root" or $user eq "postgres" or ($$dev{"users"} || {})->{$user}
l!l&&r!l&&!r
1251
$user eq "root" or $user eq "postgres"
l!l&&r!l&&!r
0126
$$dev{'users'} || {}
l!l
260
MC/DC0%0/3
$user eq "root" or $user eq "postgres" or ($$dev{"users"} || {})->{$user}
$user eq "root" $user eq "postgres" $$dev{'users'}
Truth table50%2/4
A or B or C
A= $user eq "root"B= $user eq "postgres"C= $$dev{'users'}
ABCresult
1XX1
01X1
0011
0000
1973 # su ohne -s startet die Shell des Kontos: nologin/false lehnen ab (runuser -u nicht)
1974 26 ▶ my $ushell = ( ( $dev->{users} || {} )->{$user} || {} )->{shell} // '';
Condition66%4/6
(($$dev{"users"} || {})->{$user} || {})->{"shell"} // ""
l!l
1313
($$dev{'users'} || {})->{$user} || {}
l!l
260
$$dev{'users'} || {}
l!l
260
MC/DC0%0/1
(($$dev{"users"} || {})->{$user} || {})->{"shell"} // ""
$$dev{'users'}
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
1975 26 ▶ if ( !grep( { $_ eq '-s' || $_ eq '--shell' || $_ eq '-u' } @$av ) && $ushell =~ m{/(?:nologin|false)\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not grep({$_ eq "-s" or $_ eq "--shell" or $_ eq "-u";} @$av) and $ushell =~ m[/(?:nologin|false)\z]) 1 25 26
Condition77%7/9
not grep({$_ eq "-s" or $_ eq "--shell" or $_ eq "-u";} @$av) and $ushell =~ m[/(?:nologin|false)\z]
!ll&&!rl&&r
2231
$_ eq '-s' || $_ eq '--shell' || $_ eq '-u'
l!l&&r!l&&!r
20104
$_ eq "-s" or $_ eq "--shell"
l!l&&r!l&&!r
20104
MC/DC100%2/2
not grep({$_ eq "-s" or $_ eq "--shell" or $_ eq "-u";} @$av) and $ushell =~ m[/(?:nologin|false)\z]
not grep({$_ eq "-s" or $_ eq "--shell" or $_ eq "-u";} @$av) $ushell =~ m[/(?:nologin|false)\z]
MC/DC33%1/3
$_ eq '-s' || $_ eq '--shell' || $_ eq '-u'
$_ eq "-s" $_ eq "--shell" $_ eq '-u'
Truth table100%3/3
not(A) and B
A= not grep({$_ eq "-s" or $_ eq "--shell" or $_ eq "-u";} @$av)B= $ushell =~ m[/(?:nologin|false)\z]
ABresult
0X0
100
111
Truth table50%2/4
A or B || C
A= $_ eq "-s"B= $_ eq "--shell"C= $_ eq '-u'
ABCresult
1XX1
01X1
0011
0000
1976 1 ▶ return ( $ushell =~ /nologin/ ? 'This account is currently not available.' : '', 0 );
Branch: 1 branch
BranchTrueFalseTotal
$ushell =~ /nologin/ ? : 1 0 1
1977 }
1978 0 ▶ if ( !defined $cmd ) { push @GAPS, 'su (interaktiv)'; return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cmd) 0 25 25
1979 25 local $LOGIN_USER = $user;
1980 25 my ( $o, $ok, $gap ) = __PACKAGE__->_run_inner( $dev, $cmd, $ctx );
1981 25 ▶ push @GAPS, $gap if defined $gap;
Branch: 1 branch
BranchTrueFalseTotal
if defined $gap 0 25 25
1982 25 return ( $o, $ok );
1983 }
1984  
1985 4699 ▶sub _command {
Subroutine _command: called CC=176 SCAR=65.1
1986 4699 my ( $class, $dev, $argv, $ctx, $stdin ) = @_;
1987 4699 local $AS_USER = $LOGIN_USER;
1988 4699 my @a = _strip_sudo(@$argv);
1989 4699 ▶ return ( '', 1 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 4699 4699
1990 4699 my $cmd = shift @a;
1991 # NAME=wert befehl …: Umgebung nur fuer diesen Befehl
1992 4699 ▶ local $SHENV = { %{ $SHENV || {} } };
Condition100%2/2
$Langertha::Holmgang::Sim::Linux::SHENV || {}
l!l
1234576
MC/DC100%1/1
$Langertha::Holmgang::Sim::Linux::SHENV || {}
$Langertha::Holmgang::Sim::Linux::SHENV
Truth table100%2/2
A
A= $Langertha::Holmgang::Sim::Linux::SHENV
Aresult
11
00
1993 4699 my %env;
1994 4699 ▶ while ( $cmd =~ /\A([A-Za-z_]\w*)=(.*)\z/s && @a ) { $SHENV->{$1} = $env{$1} = $2; $cmd = shift @a }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /\A([A-Za-z_]\w*)=(.*)\z/s and @a) 3 4699 4702
Condition66%2/3
$cmd =~ /\A([A-Za-z_]\w*)=(.*)\z/s and @a
!ll&&!rl&&r
469903
MC/DC50%1/2
$cmd =~ /\A([A-Za-z_]\w*)=(.*)\z/s and @a
$cmd =~ /\A([A-Za-z_]\w*)=(.*)\z/s @a
Truth table66%2/3
A and B
A= $cmd =~ /\A([A-Za-z_]\w*)=(.*)\z/sB= @a
ABresult
0X0
100
111
1995 # TZ=… wirkt auf date
1996 4699 ▶ local $DATE_TZ = exists $env{TZ} ? ( $env{TZ} =~ s/\A://r ) : $DATE_TZ;
Branch: 1 branch
BranchTrueFalseTotal
exists $env{'TZ'} ? : 1 4698 4699
1997 # nach cd: relative Pfade (die es gibt oder die ein Muster sind) gelten im aktuellen Verzeichnis
1998 4699 ▶ if ( defined $CWD_DIR && $cmd !~ /\A(?:cd|tar|rsync|restic|echo|printf|basename|dirname|expr|test|\[|wc|ls|ln)\z/ ) { # diese loesen selbst relativ auf bzw. geben nur Text aus
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Langertha::Holmgang::Sim::Linux::CWD_DIR and not $cmd =~ /\A(?:cd|tar|rsync|restic|echo|printf|basename|dirname|expr|test|\[|wc|ls|ln)\z/) 108 4591 4699
Condition100%3/3
defined $Langertha::Holmgang::Sim::Linux::CWD_DIR and not $cmd =~ /\A(?:cd|tar|rsync|restic|echo|printf|basename|dirname|expr|test|\[|wc|ls|ln)\z/
!ll&&!rl&&r
455536108
MC/DC100%2/2
defined $Langertha::Holmgang::Sim::Linux::CWD_DIR and not $cmd =~ /\A(?:cd|tar|rsync|restic|echo|printf|basename|dirname|expr|test|\[|wc|ls|ln)\z/
defined $Langertha::Holmgang::Sim::Linux::CWD_DIR not $cmd =~ /\A(?:cd|tar|rsync|restic|echo|printf|basename|dirname|expr|test|\[|wc|ls|ln)\z/
Truth table100%3/3
A and not(B)
A= defined $Langertha::Holmgang::Sim::Linux::CWD_DIRB= not $cmd =~ /\A(?:cd|tar|rsync|restic|echo|printf|basename|dirname|expr|test|\[|wc|ls|ln)\z/
ABresult
0X0
100
111
1999 @a = map {
2000 108 my $x = $_;
2001 294 ▶ $x !~ m{\A[-/]} && $x =~ m{\A[\w.@+][\w./@+*?\[\]!-]*\z}
Branch: 1 branch
BranchTrueFalseTotal
!($x =~ m[\A[-/]]) && $x =~ m(\A[\w.\@+][\w./\@+*?\[\]!-]*\z) && (_file_entry($dev, _absp($x)) || _is_dir($dev, _absp($x))) ? : 15 279 294
Condition100%9/9
not $x =~ m[\A[-/]] and $x =~ m(\A[\w.\@+][\w./\@+*?\[\]!-]*\z) and _file_entry($dev, _absp($x)) || _is_dir($dev, _absp($x))
!ll&&!rl&&r
10917015
not $x =~ m[\A[-/]] and $x =~ m(\A[\w.\@+][\w./\@+*?\[\]!-]*\z)
!ll&&!rl&&r
9415185
_file_entry($dev, _absp($x)) or _is_dir($dev, _absp($x))
l!l&&r!l&&!r
132170
MC/DC100%4/4
not $x =~ m[\A[-/]] and $x =~ m(\A[\w.\@+][\w./\@+*?\[\]!-]*\z) and _file_entry($dev, _absp($x)) || _is_dir($dev, _absp($x))
not $x =~ m[\A[-/]] $x =~ m(\A[\w.\@+][\w./\@+*?\[\]!-]*\z) _file_entry($dev, _absp($x)) _is_dir($dev, _absp($x))
Truth table100%5/5
not(A) and B and C or D
A= not $x =~ m[\A[-/]]B= $x =~ m(\A[\w.\@+][\w./\@+*?\[\]!-]*\z)C= _file_entry($dev, _absp($x))D= _is_dir($dev, _absp($x))
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2002 && ( _file_entry( $dev, _absp($x) ) || _is_dir( $dev, _absp($x) ) ) ? _absp($x) : $x
2003 } @a;
2004 }
2005 4699 ▶ if ( $cmd =~ /\A[A-Za-z_]\w*=/ ) { # Zuweisung ohne Befehl: Shell-Variablen sind nicht nachgebildet
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /\A[A-Za-z_]\w*=/) 0 4699 4699
2006 0 push @GAPS, join( ' ', $cmd, @a );
2007 0 return ( '', 0 );
2008 }
2009 # Skripte: bash|sh -c '…', bash|sh datei, ./datei bzw. /pfad/datei (ausfuehrbar)
2010 4699 ( my $sh = $cmd ) =~ s{\A/(?:usr/)?bin/}{};
2011 4699 ▶ local $LOGIN_USER = defined $AS_USER && ( $sh eq 'bash' || $sh eq 'sh' || $cmd =~ m{/} ) ? $AS_USER : $LOGIN_USER;
Branch: 1 branch
BranchTrueFalseTotal
defined $Langertha::Holmgang::Sim::Linux::AS_USER && ($sh eq 'bash' || $sh eq 'sh' || $cmd =~ m[/]) ? : 3 4696 4699
Condition66%6/9
defined $Langertha::Holmgang::Sim::Linux::AS_USER and $sh eq "bash" || $sh eq "sh" || $cmd =~ m[/]
!ll&&!rl&&r
4606903
$sh eq "bash" or $sh eq "sh" or $cmd =~ m[/]
l!l&&r!l&&!r
0390
$sh eq "bash" or $sh eq "sh"
l!l&&r!l&&!r
0093
MC/DC50%2/4
defined $Langertha::Holmgang::Sim::Linux::AS_USER and $sh eq "bash" || $sh eq "sh" || $cmd =~ m[/]
defined $Langertha::Holmgang::Sim::Linux::AS_USER $sh eq "bash" $sh eq "sh" $cmd =~ m[/]
Truth table60%3/5
A and B or C or D
A= defined $Langertha::Holmgang::Sim::Linux::AS_USERB= $sh eq "bash"C= $sh eq "sh"D= $cmd =~ m[/]
ABCDresult
0XXX0
10000
11XX1
101X1
10011
2012 4699 ▶ if ( $sh eq 'bash' || $sh eq 'sh' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sh eq "bash" or $sh eq "sh") 21 4678 4699
Condition66%2/3
$sh eq "bash" or $sh eq "sh"
l!l&&r!l&&!r
2104678
MC/DC50%1/2
$sh eq "bash" or $sh eq "sh"
$sh eq "bash" $sh eq "sh"
Truth table66%2/3
A or B
A= $sh eq "bash"B= $sh eq "sh"
ABresult
1X1
011
000
2013 21 my $e;
2014 my $noexec;
2015 21 ▶ while ( @a && $a[0] =~ /\A-([euxon]+)\z/ ) { my $f = $1; $e = 1 if $f =~ /e/; $noexec = 1 if $f =~ /n/; shift @a; shift @a if $f =~ /o/ }
Branch: 4 branches
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-([euxon]+)\z/) 2 21 23
if $f =~ /e/ 0 2 2
if $f =~ /n/ 2 0 2
if $f =~ /o/ 0 2 2
Condition66%2/3
@a and $a[0] =~ /\A-([euxon]+)\z/
!ll&&!rl&&r
0212
MC/DC50%1/2
@a and $a[0] =~ /\A-([euxon]+)\z/
@a $a[0] =~ /\A-([euxon]+)\z/
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A-([euxon]+)\z/
ABresult
0X0
100
111
2016 21 ▶ if ($noexec) { # bash -n: nur lesen und zerlegen
Branch: 1 branch
BranchTrueFalseTotal
if ($noexec) 2 19 21
2017 2 ▶ my $t = @a && $a[0] eq '-c' ? $a[1] : @a ? _file_text( $dev, _absp( $a[0] ) ) : $stdin;
Branch: 2 branches
BranchTrueFalseTotal
@a && $a[0] eq '-c' ? : 0 2 2
@a ? : 2 0 2
Condition33%1/3
@a and $a[0] eq "-c"
!ll&&!rl&&r
020
MC/DC0%0/2
@a and $a[0] eq "-c"
@a $a[0] eq "-c"
Truth table33%1/3
A and B
A= @aB= $a[0] eq "-c"
ABresult
0X0
100
111
2018 2 ▶ return ( "$sh: $a[0]: No such file or directory", 0 ) if @a && $a[0] ne '-c' && !defined $t;
Branch: 1 branch
BranchTrueFalseTotal
if @a and $a[0] ne "-c" and not defined $t 0 2 2
Condition33%2/6
@a and $a[0] ne "-c" and not defined $t
!ll&&!rl&&r
020
@a and $a[0] ne "-c"
!ll&&!rl&&r
002
MC/DC0%0/3
@a and $a[0] ne "-c" and not defined $t
@a $a[0] ne "-c" not defined $t
Truth table25%1/4
A and B and not(C)
A= @aB= $a[0] ne "-c"C= not defined $t
ABCresult
0XX0
10X0
1100
1111
2019 2 ▶ my @it = eval { Langertha::Holmgang::Shell::split_items( $t // '' ) };
Condition50%1/2
$t // ""
l!l
20
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
Aresult
11
00
2020 2 my $err = $@;
2021 2 ▶ my $nodes = $err ? undef : Langertha::Holmgang::Shell::parse( \@it );
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 0 2 2
2022 2 ▶ $err ||= ref $nodes ? '' : $nodes;
Branch: 1 branch
BranchTrueFalseTotal
ref $nodes ? : 1 1 2
Condition66%2/3
$err ||= ref $nodes ? "" : $nodes
l!l&&r!l&&!r
011
MC/DC50%1/2
$err ||= ref $nodes ? "" : $nodes
$err ref $nodes ? "" : $nodes
Truth table66%2/3
A ||= B
A= $errB= ref $nodes ? "" : $nodes
ABresult
1X1
011
000
2023 2 $err =~ s/\s+\z//;
2024 2 ▶ return ( length $err ? ( @a && $a[0] ne '-c' ? "$a[0]: " : '' ) . $err : '', length $err ? 0 : 1 );
Branch: 3 branches
BranchTrueFalseTotal
length $err ? : 1 1 2
@a && $a[0] ne '-c' ? : 1 0 1
length $err ? : 1 1 2
Condition33%1/3
@a and $a[0] ne "-c"
!ll&&!rl&&r
001
MC/DC0%0/2
@a and $a[0] ne "-c"
@a $a[0] ne "-c"
Truth table33%1/3
A and B
A= @aB= $a[0] ne "-c"
ABresult
0X0
100
111
2025 }
2026 19 ▶ if ( @a && $a[0] eq '-c' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] eq "-c") 18 1 19
Condition66%2/3
@a and $a[0] eq "-c"
!ll&&!rl&&r
0118
MC/DC50%1/2
@a and $a[0] eq "-c"
@a $a[0] eq "-c"
Truth table66%2/3
A and B
A= @aB= $a[0] eq "-c"
ABresult
0X0
100
111
2027 18 my ( undef, $text, $arg0, @args ) = @a;
2028 18 ▶ return _run_shell( $dev, $text // q{}, $ctx, arg0 => $arg0 // $sh, args => \@args, errexit => $e );
Condition60%3/5
$text // ""
l!l
180
$arg0 // $sh
l!l&&r!l&&!r
1170
MC/DC0%0/1
$text // ""
$text
MC/DC0%0/2
$arg0 // $sh
$arg0 $sh
Truth table50%1/2
A
A= $text
Aresult
11
00
Truth table66%2/3
A // B
A= $arg0B= $sh
ABresult
1X1
011
000
2029 }
2030 1 ▶ my $t = @a ? _file_text( $dev, _absp( $a[0] ) ) : $stdin;
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 1 0 1
2031 1 ▶ return ( "$sh: $a[0]: No such file or directory", 0 ) if @a && !defined $t;
Branch: 1 branch
BranchTrueFalseTotal
if @a and not defined $t 0 1 1
Condition33%1/3
@a and not defined $t
!ll&&!rl&&r
010
MC/DC0%0/2
@a and not defined $t
@a not defined $t
Truth table33%1/3
A and not(B)
A= @aB= not defined $t
ABresult
0X0
100
111
2032 1 ▶ return _run_shell( $dev, $t // q{}, $ctx, arg0 => $a[0] // $sh, args => [ @a[ 1 .. $#a ] ], errexit => $e );
Condition40%2/5
$t // ""
l!l
10
$a[0] // $sh
l!l&&r!l&&!r
100
MC/DC0%0/1
$t // ""
$t
MC/DC0%0/2
$a[0] // $sh
$a[0] $sh
Truth table50%1/2
A
A= $t
Aresult
11
00
Truth table33%1/3
A // B
A= $a[0]B= $sh
ABresult
1X1
011
000
2033 }
2034 # curl/wget gegen die HTTP-API eines Forgejo-Servers: auf dem Server selbst (localhost:3000 bzw. der
2035 # eigene Name), von anderen Geraeten ueber den oeffentlichen Namen (ROOT_URL, hinter dem Proxy)
2036 4678 ▶ my $fsrv = $cmd =~ /\A(?:curl|wget)\z/ && !$dev->{pod} ? _forgejo_for( $dev, \@a ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$cmd =~ /\A(?:curl|wget)\z/ && !$$dev{'pod'} ? : 60 4618 4678
Condition100%3/3
$cmd =~ /\A(?:curl|wget)\z/ and not $$dev{"pod"}
!ll&&!rl&&r
4617160
MC/DC100%2/2
$cmd =~ /\A(?:curl|wget)\z/ and not $$dev{"pod"}
$cmd =~ /\A(?:curl|wget)\z/ not $$dev{"pod"}
Truth table100%3/3
A and not(B)
A= $cmd =~ /\A(?:curl|wget)\z/B= not $$dev{"pod"}
ABresult
0X0
100
111
2037 4678 ▶ if ($fsrv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fsrv) 6 4672 4678
2038 6 my $self = $fsrv == $dev;
2039 6 _part('Git');
2040 6 my ($url) = grep {m{\Ahttps?://}} @a;
2041 6 ▶ return ( $cmd eq 'curl' ? 'curl: (3) URL using bad/illegal format or missing URL' : 'wget: missing URL', 0 ) unless $url;
Branch: 2 branches
BranchTrueFalseTotal
unless $url 0 6 6
$cmd eq 'curl' ? : 0 0 0
2042 6 my ( $h, $port, $path ) = $url =~ m{\Ahttps?://([^/:]+)(?::(\d+))?(/[^\s]*)?\z};
2043 6 ▶ ( my $root = $fsrv->{forgejo}{root_url} // '' ) =~ s{\Ahttps?://([^/:]+).*}{$1}s;
Condition50%1/2
$$fsrv{"forgejo"}{"root_url"} // ""
l!l
60
MC/DC0%0/1
$$fsrv{"forgejo"}{"root_url"} // ""
$$fsrv{"forgejo"}{"root_url"}
Truth table50%1/2
A
A= $$fsrv{"forgejo"}{"root_url"}
Aresult
11
00
2044 6 ▶ unless ( $self && ( $h =~ /\A(?:127\.0\.0\.1|localhost)\z/ && ( $port // 80 ) == 3000 ) || $h eq $root ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self and ($h =~ /\A(?:127\.0\.0\.1|localhost)\z/ and ($port // 80) == 3000) or $h eq $root) 2 4 6
Condition63%7/11
$self and ($h =~ /\A(?:127\.0\.0\.1|localhost)\z/ and ($port // 80) == 3000) or $h eq $root
l!l&&r!l&&!r
222
$self and ($h =~ /\A(?:127\.0\.0\.1|localhost)\z/ and ($port // 80) == 3000)
!ll&&!rl&&r
402
$h =~ /\A(?:127\.0\.0\.1|localhost)\z/ and ($port // 80) == 3000
!ll&&!rl&&r
002
$port // 80
l!l
20
MC/DC50%2/4
$self and ($h =~ /\A(?:127\.0\.0\.1|localhost)\z/ and ($port // 80) == 3000) or $h eq $root
$self $h =~ /\A(?:127\.0\.0\.1|localhost)\z/ $port $h eq $root
Truth table42%3/7
A and B and C or D
A= $selfB= $h =~ /\A(?:127\.0\.0\.1|localhost)\z/C= $portD= $h eq $root
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
2045 2 ▶ my $hf = ( $dev->{files} || {} )->{'/etc/hosts'} // '';
Condition50%2/4
($$dev{"files"} || {})->{"/etc/hosts"} // ""
l!l
02
$$dev{'files'} || {}
l!l
20
MC/DC0%0/1
($$dev{"files"} || {})->{"/etc/hosts"} // ""
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
2046 2 ▶ $hf = $hf->{content} // '' if ref $hf eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $hf eq "HASH" 0 2 2
Condition0%0/2
$$hf{"content"} // ""
l!l
00
MC/DC0%0/1
$$hf{"content"} // ""
$$hf{"content"}
Truth table0%0/2
A
A= $$hf{"content"}
Aresult
11
00
2047 2 ▶ return ( $cmd eq 'curl' ? "curl: (6) Could not resolve host: $h" : "wget: unable to resolve host address '$h'", 0 )
Branch: 2 branches
BranchTrueFalseTotal
unless $h =~ /\A[\d.]+\z|\Alocalhost\z/ or $hf =~ /^\s*[\d.:a-f]+\s+(?:\S+\s+)*\Q$h\E(?:\s|$)/m 1 1 2
$cmd eq 'curl' ? : 1 0 1
Condition66%2/3
$h =~ /\A[\d.]+\z|\Alocalhost\z/ or $hf =~ /^\s*[\d.:a-f]+\s+(?:\S+\s+)*\Q$h\E(?:\s|$)/m
l!l&&r!l&&!r
101
MC/DC50%1/2
$h =~ /\A[\d.]+\z|\Alocalhost\z/ or $hf =~ /^\s*[\d.:a-f]+\s+(?:\S+\s+)*\Q$h\E(?:\s|$)/m
$h =~ /\A[\d.]+\z|\Alocalhost\z/ $hf =~ /^\s*[\d.:a-f]+\s+(?:\S+\s+)*\Q$h\E(?:\s|$)/m
Truth table66%2/3
A or B
A= $h =~ /\A[\d.]+\z|\Alocalhost\z/B= $hf =~ /^\s*[\d.:a-f]+\s+(?:\S+\s+)*\Q$h\E(?:\s|$)/m
ABresult
1X1
011
000
2048 unless $h =~ /\A[\d.]+\z|\Alocalhost\z/ || $hf =~ /^\s*[\d.:a-f]+\s+(?:\S+\s+)*\Q$h\E(?:\s|$)/m;
2049 1 ▶ return ( $cmd eq 'curl' ? "curl: (7) Failed to connect to $h port " . ( $port // ( $url =~ /\Ahttps/ ? 443 : 80 ) ) . " after 0 ms: Couldn't connect to server" : "wget: can't connect to remote host ($h): Connection refused", 0 );
Branch: 2 branches
BranchTrueFalseTotal
$cmd eq 'curl' ? : 1 0 1
$url =~ /\Ahttps/ ? : 0 0 0
Condition50%1/2
$port // ($url =~ /\Ahttps/ ? 443 : 80)
l!l
10
MC/DC0%0/1
$port // ($url =~ /\Ahttps/ ? 443 : 80)
$port
Truth table50%1/2
A
A= $port
Aresult
11
00
2050 }
2051 4 $dev = $fsrv;
2052 4 my $method = 'GET';
2053 4 ▶ for my $i ( 0 .. $#a ) { $method = uc $a[ $i + 1 ] if $a[$i] eq '-X' && defined $a[ $i + 1 ]; $method = 'POST' if $a[$i] =~ /\A(?:-d|--data(?:-raw|-binary)?)\z/ && $method eq 'GET' }
Branch: 2 branches
BranchTrueFalseTotal
if $a[$i] eq "-X" and defined $a[$i + 1] 0 10 10
if $a[$i] =~ /\A(?:-d|--data(?:-raw|-binary)?)\z/ and $method eq "GET" 0 10 10
Condition33%2/6
$a[$i] eq "-X" and defined $a[$i + 1]
!ll&&!rl&&r
1000
$a[$i] =~ /\A(?:-d|--data(?:-raw|-binary)?)\z/ and $method eq "GET"
!ll&&!rl&&r
1000
MC/DC0%0/2
$a[$i] eq "-X" and defined $a[$i + 1]
$a[$i] eq "-X" defined $a[$i + 1]
MC/DC0%0/2
$a[$i] =~ /\A(?:-d|--data(?:-raw|-binary)?)\z/ and $method eq "GET"
$a[$i] =~ /\A(?:-d|--data(?:-raw|-binary)?)\z/ $method eq "GET"
Truth table33%1/3
A and B
A= $a[$i] eq "-X"B= defined $a[$i + 1]
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $a[$i] =~ /\A(?:-d|--data(?:-raw|-binary)?)\z/B= $method eq "GET"
ABresult
0X0
100
111
2054 4 ▶ my ( $st, $body ) = Langertha::Holmgang::Sim::Linux::Git::api( $dev, $method, $path // '/' );
Condition50%1/2
$path // "/"
l!l
40
MC/DC0%0/1
$path // "/"
$path
Truth table50%1/2
A
A= $path
Aresult
11
00
2055 4 my $fail = grep { /\A-[a-zA-Z]*f[a-zA-Z]*\z|\A--fail\z/ } @a;
2056 4 ▶ if ( $cmd eq 'wget' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "wget") 1 3 4
2057 1 my $quiet = grep { /\A-[a-zA-Z]*q/ } @a;
2058 1 ▶ my $hdr = ( grep { /\A-[a-zA-Z]*S\z|\A--server-response\z/ } @a ) ? " HTTP/1.1 $st " . ( $st == 200 ? 'OK' : $st == 401 ? 'Unauthorized' : $st == 404 ? 'Not Found' : 'Error' ) . "\n Content-Type: application/json;charset=utf-8\n" : '';
Branch: 4 branches
BranchTrueFalseTotal
grep({/\A-[a-zA-Z]*S\z|\A--server-response\z/;} @a) ? : 0 1 1
$st == 200 ? : 0 0 0
$st == 401 ? : 0 0 0
$st == 404 ? : 0 0 0
2059 0 my ($of) = map { $a[ $_ + 1 ] } grep { $a[$_] =~ /\A-[a-zA-Z]*O\z/ } 0 .. $#a;
2060 1 ▶ ($of) = map {/\A-[a-zA-Z]*O(.+)\z|\A--output-document=(.+)\z/ ? $1 // $2 : ()} @a unless defined $of;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $of 1 0 1
/\A-[a-zA-Z]*O(.+)\z|\A--output-document=(.+)\z/ ? : 1 1 2
Condition33%1/3
$1 // $2
l!l&&r!l&&!r
100
MC/DC0%0/2
$1 // $2
$1 $2
Truth table33%1/3
A // B
A= $1B= $2
ABresult
1X1
011
000
2061 1 ▶ my $show = defined $of && $of eq '-' && !grep { $_ eq '--spider' } @a;
Condition33%2/6
defined $of && $of eq '-' && !grep({$_ eq '--spider';} @a)
!ll&&!rl&&r
001
defined $of and $of eq "-"
!ll&&!rl&&r
001
MC/DC0%0/3
defined $of && $of eq '-' && !grep({$_ eq '--spider';} @a)
defined $of $of eq "-" !grep({$_ eq '--spider';} @a)
Truth table25%1/4
A and B && not(C)
A= defined $ofB= $of eq "-"C= !grep({$_ eq '--spider';} @a)
ABCresult
0XX0
10X0
1100
1111
2062 1 ▶ return ( $hdr . ( $quiet ? '' : "--2026-10-20 12:00:00-- $url\n" ) . "wget: server returned error: HTTP/1.1 $st " . ( $st == 401 ? 'Unauthorized' : $st == 404 ? 'Not Found' : 'Error' ), 0 ) if $st != 200;
Branch: 4 branches
BranchTrueFalseTotal
if $st != 200 0 1 1
$quiet ? : 0 0 0
$st == 401 ? : 0 0 0
$st == 404 ? : 0 0 0
2063 1 ▶ return ( $hdr . ( $show ? $body : $quiet ? '' : "--2026-10-20 12:00:00-- $url\nHTTP request sent, awaiting response... 200 OK\nSaving to: '" . ( $of // 'index.html' ) . "'" ), 1 );
Branch: 2 branches
BranchTrueFalseTotal
$show ? : 1 0 1
$quiet ? : 0 0 0
Condition0%0/2
$of // "index.html"
l!l
00
MC/DC0%0/1
$of // "index.html"
$of
Truth table0%0/2
A
A= $of
Aresult
11
00
2064 }
2065 3 ▶ return ( "curl: (22) The requested URL returned error: $st", 0 ) if $fail && $st >= 400;
Branch: 1 branch
BranchTrueFalseTotal
if $fail and $st >= 400 0 3 3
Condition33%1/3
$fail and $st >= 400
!ll&&!rl&&r
300
MC/DC0%0/2
$fail and $st >= 400
$fail $st >= 400
Truth table33%1/3
A and B
A= $failB= $st >= 400
ABresult
0X0
100
111
2066 3 ▶ my ($w) = map { $a[ $_ + 1 ] } grep { $a[$_] eq '-w' || $a[$_] eq '--write-out' } 0 .. $#a;
Condition66%2/3
$a[$_] eq '-w' || $a[$_] eq '--write-out'
l!l&&r!l&&!r
107
MC/DC50%1/2
$a[$_] eq '-w' || $a[$_] eq '--write-out'
$a[$_] eq '-w' $a[$_] eq '--write-out'
Truth table66%2/3
A || B
A= $a[$_] eq '-w'B= $a[$_] eq '--write-out'
ABresult
1X1
011
000
2067 3 ▶ my $out = ( grep { $_ eq '-I' || $_ eq '--head' } @a ) ? "HTTP/1.1 $st\nContent-Type: application/json;charset=utf-8" : $body;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq '-I' or $_ eq '--head';} @a) ? : 0 3 3
Condition33%1/3
$_ eq '-I' || $_ eq '--head'
l!l&&r!l&&!r
008
MC/DC0%0/2
$_ eq '-I' || $_ eq '--head'
$_ eq '-I' $_ eq '--head'
Truth table33%1/3
A || B
A= $_ eq '-I'B= $_ eq '--head'
ABresult
1X1
011
000
2068 3 ▶ $out = '' if grep { $_ eq '-o' } @a;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "-o";} @a 0 3 3
2069 3 ▶ $out .= ( $w // '' ) =~ s/%\{http_code\}/$st/gr =~ s/\\n/\n/gr if defined $w;
Branch: 1 branch
BranchTrueFalseTotal
if defined $w 1 2 3
Condition50%1/2
$w // ""
l!l
10
MC/DC0%0/1
$w // ""
$w
Truth table50%1/2
A
A= $w
Aresult
11
00
2070 3 return ( $out, 1 );
2071 }
2072 # im Pod (kubectl exec): Netzwerkzeuge ueber den Cluster, Umgebung des Containers
2073 4672 ▶ if ( my $pod = $dev->{pod} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pod = $$dev{"pod"}) 7 4665 4672
2074 7 _part('Kubernetes');
2075 7 my $K = 'Langertha::Holmgang::Sim::Linux::Kubernetes';
2076 7 ▶ if ( $cmd =~ /\A(?:curl|wget)\z/ || $cmd eq 'openssl' && ( $a[0] // '' ) eq 's_client' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /\A(?:curl|wget)\z/ or $cmd eq "openssl" and ($a[0] // "") eq "s_client") 2 5 7
Condition75%6/8
$cmd =~ /\A(?:curl|wget)\z/ or $cmd eq "openssl" and ($a[0] // "") eq "s_client"
l!l&&r!l&&!r
115
$cmd eq "openssl" and ($a[0] // "") eq "s_client"
!ll&&!rl&&r
501
$a[0] // ""
l!l
10
MC/DC66%2/3
$cmd =~ /\A(?:curl|wget)\z/ or $cmd eq "openssl" and ($a[0] // "") eq "s_client"
$cmd =~ /\A(?:curl|wget)\z/ $cmd eq "openssl" $a[0]
Truth table75%3/4
A or B and C
A= $cmd =~ /\A(?:curl|wget)\z/B= $cmd eq "openssl"C= $a[0]
ABCresult
1XX1
0111
00X0
0100
2077 2 my ($src) = grep { $_->{name} eq $pod->{name} } $K->can('_pods')->( $dev->{kubernetes}, $pod->{ns} );
2078 2 ▶ return ( "bash: $cmd: command not found", 0 ) unless $src;
Branch: 1 branch
BranchTrueFalseTotal
unless $src 0 2 2
2079 2 local @Langertha::Holmgang::Sim::Linux::Kubernetes::GAPS;
2080 2 my @r = $K->can('pod_tool')->( $dev->{kubernetes}, $pod->{ns}, $src, [ $cmd, @a ] );
2081 2 push @GAPS, @Langertha::Holmgang::Sim::Linux::Kubernetes::GAPS;
2082 2 return @r;
2083 }
2084 5 ▶ if ( $cmd eq 'env' || $cmd eq 'printenv' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "env" or $cmd eq "printenv") 0 5 5
Condition33%1/3
$cmd eq "env" or $cmd eq "printenv"
l!l&&r!l&&!r
005
MC/DC0%0/2
$cmd eq "env" or $cmd eq "printenv"
$cmd eq "env" $cmd eq "printenv"
Truth table33%1/3
A or B
A= $cmd eq "env"B= $cmd eq "printenv"
ABresult
1X1
011
000
2085 0 ▶ my %e = ( PATH => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', HOSTNAME => $dev->{hostname}, HOME => '/root', %{ $dev->{env} || {} },
Condition0%0/2
$$dev{'env'} || {}
l!l
00
MC/DC0%0/1
$$dev{'env'} || {}
$$dev{'env'}
Truth table0%0/2
A
A= $$dev{'env'}
Aresult
11
00
2086 KUBERNETES_SERVICE_HOST => '10.43.0.1', KUBERNETES_SERVICE_PORT => '443' );
2087 0 ▶ return @a ? ( join( "\n", map { $e{$_} // () } @a ), ( grep { exists $e{$_} } @a ) ? 1 : 0 ) : ( join( "\n", map {"$_=$e{$_}"} sort keys %e ), 1 );
Branch: 2 branches
BranchTrueFalseTotal
@a ? : 0 0 0
grep({exists $e{$_};} @a) ? : 0 0 0
Condition0%0/3
$e{$_} // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$e{$_} // ()
$e{$_} ()
Truth table0%0/3
A // B
A= $e{$_}B= ()
ABresult
1X1
011
000
2088 }
2089 }
2090 # (nur Shell-Skripte mit Inhalt; ein anderes Programm bleibt eine Luecke), auch ueber PATH
2091 4670 my $web_cmd = _web_cmd( $dev, $cmd );
2092 4670 ▶ my $prog_path = $cmd =~ m{\A\.?/} ? _absp($cmd) : !$web_cmd && !$CMD{$cmd} && !$FILTER{$cmd} && !$REAL{$cmd} ? _prog_file( $dev, $cmd ) : undef;
Branch: 2 branches
BranchTrueFalseTotal
$cmd =~ m[\A\.?/] ? : 13 4657 4670
!($web_cmd || $CMD{$cmd} || $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} || $Langertha::Holmgang::Sim::Linux::REAL{$cmd}) ? : 5 4652 4657
Condition100%9/9
$web_cmd || $CMD{$cmd} || $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} || $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
l!l&&r!l&&!r
464665
$web_cmd or $CMD{$cmd} or $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}
l!l&&r!l&&!r
46153111
$web_cmd or $CMD{$cmd}
l!l&&r!l&&!r
120449542
MC/DC100%4/4
$web_cmd || $CMD{$cmd} || $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} || $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
$web_cmd $CMD{$cmd} $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
Truth table100%5/5
A or B or C || D
A= $web_cmdB= $CMD{$cmd}C= $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}D= $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
2093 4670 ▶ if ( defined $prog_path && _shell_script( $dev, $prog_path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prog_path and _shell_script($dev, $prog_path)) 4 4666 4670
Condition100%3/3
defined $prog_path and _shell_script($dev, $prog_path)
!ll&&!rl&&r
465794
MC/DC100%2/2
defined $prog_path and _shell_script($dev, $prog_path)
defined $prog_path _shell_script($dev, $prog_path)
Truth table100%3/3
A and B
A= defined $prog_pathB= _shell_script($dev, $prog_path)
ABresult
0X0
100
111
2094 4 ▶ return ( "bash: $cmd: Permission denied", 0 ) unless _mode_of( _file_entry( $dev, $prog_path ) ) & 0111;
Branch: 1 branch
BranchTrueFalseTotal
unless _mode_of(_file_entry($dev, $prog_path)) & 73 0 4 4
2095 4 return _script( $dev, _file_text( $dev, $prog_path ), $ctx, join( ' ', $cmd, @a ), $cmd, @a );
2096 }
2097 4666 ▶ if ( $cmd =~ m{/} && !$CMD{$cmd} ) { # anderes Programm mit Pfad (kein Shell-Skript)
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ m[/] and not $CMD{$cmd}) 9 4657 4666
Condition66%2/3
$cmd =~ m[/] and not $CMD{$cmd}
!ll&&!rl&&r
465709
MC/DC50%1/2
$cmd =~ m[/] and not $CMD{$cmd}
$cmd =~ m[/] not $CMD{$cmd}
Truth table66%2/3
A and not(B)
A= $cmd =~ m[/]B= not $CMD{$cmd}
ABresult
0X0
100
111
2098 9 ( my $abs = $cmd ) =~ s{\A/(s?bin)/}{/usr/$1/};
2099 9 my ( $n ) = $abs =~ m{\A/usr/s?bin/([^/]+)\z};
2100 9 ▶ my ( $p, $k ) = defined $n ? _which( 'which', $dev, [$n] ) : ( '', 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 6 3 9
2101 9 ▶ if ( defined $n && $k && $p eq $abs && !_file_entry( $dev, $cmd ) ) { $cmd = $n }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n and $k and $p eq $abs and not _file_entry($dev, $cmd)) { } 5 4 9
Condition77%7/9
defined $n and $k and $p eq $abs and not _file_entry($dev, $cmd)
!ll&&!rl&&r
405
defined $n and $k and $p eq $abs
!ll&&!rl&&r
315
defined $n and $k
!ll&&!rl&&r
306
MC/DC50%2/4
defined $n and $k and $p eq $abs and not _file_entry($dev, $cmd)
defined $n $k $p eq $abs not _file_entry($dev, $cmd)
Truth table60%3/5
A and B and C and not(D)
A= defined $nB= $kC= $p eq $absD= not _file_entry($dev, $cmd)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2102 else {
2103 4 ▶ my $e = _file_entry( $dev, _absp($cmd) ) or return ( "bash: $cmd: No such file or directory", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $e = _file_entry($dev, _absp($cmd)) or return "bash: ${cmd}: No such file or directory", 0 2 2 4
2104 2 ▶ return ( "bash: $cmd: Permission denied", 0 ) unless _mode_of($e) & 0111;
Branch: 1 branch
BranchTrueFalseTotal
unless _mode_of($e) & 73 0 2 2
2105 2 push @GAPS, join( ' ', $cmd, @a ); # Skript/Programm aus dem Zustand: nicht nachgebildet
2106 2 return ( '', 0 );
2107 }
2108 }
2109 4662 ▶ my $f = $web_cmd // $CMD{$cmd};
Condition100%3/3
$web_cmd // $CMD{$cmd}
l!l&&r!l&&!r
120450042
MC/DC100%2/2
$web_cmd // $CMD{$cmd}
$web_cmd $CMD{$cmd}
Truth table100%3/3
A // B
A= $web_cmdB= $CMD{$cmd}
ABresult
1X1
011
000
2110 4662 ▶ if ( !$f && !$FILTER{$cmd} && !$REAL{$cmd} && ( my $prog = _prog_file( $dev, $cmd ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $f || $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} || $Langertha::Holmgang::Sim::Linux::REAL{$cmd} and my $prog = _prog_file($dev, $cmd)) 0 4662 4662
Condition88%8/9
not $f || $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} || $Langertha::Holmgang::Sim::Linux::REAL{$cmd} and my $prog = _prog_file($dev, $cmd)
!ll&&!rl&&r
465750
$f || $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} || $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
l!l&&r!l&&!r
465165
$f or $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}
l!l&&r!l&&!r
46203111
MC/DC0%0/4
not $f || $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} || $Langertha::Holmgang::Sim::Linux::REAL{$cmd} and my $prog = _prog_file($dev, $cmd)
$f $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} $Langertha::Holmgang::Sim::Linux::REAL{$cmd} my $prog = _prog_file($dev, $cmd)
Truth table80%4/5
not(A or B || C) and D
A= $fB= $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}C= $Langertha::Holmgang::Sim::Linux::REAL{$cmd}D= my $prog = _prog_file($dev, $cmd)
ABCDresult
1XXX0
01XX0
001X0
00000
00011
2111 0 push @GAPS, join( ' ', $prog, @a ); # installiertes Programm ohne Nachbildung
2112 0 return ( '', 0 );
2113 }
2114 4662 ▶ if ( !$f && $FILTER{$cmd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $f and $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}) 31 4631 4662
Condition100%3/3
not $f and $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}
!ll&&!rl&&r
46201131
MC/DC100%2/2
not $f and $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}
not $f $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}
Truth table100%3/3
not(A) and B
A= not $fB= $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}
ABresult
0X0
100
111
2115 # Filter mit Datei-Argument: head -n 5 /etc/x, awk '{print $1}' datei, …
2116 # relative Dateinamen (ohne cd: unter /root) wie absolute
2117 31 my %shown;
2118 31 ▶ @a = map { !m{\A[-/]} && m{\A[\w.@+][\w./@+-]*\z} && defined _file_text( $dev, _absp($_) ) ? do { $shown{ _absp($_) } = $_; _absp($_) } : $_ } @a;
Branch: 1 branch
BranchTrueFalseTotal
!m[\A[-/]] && m[\A[\w.\@+][\w./\@+-]*\z] && defined _file_text($dev, _absp($_)) ? : 1 69 70
Condition100%6/6
not m[\A[-/]] and m[\A[\w.\@+][\w./\@+-]*\z] and defined _file_text($dev, _absp($_))
!ll&&!rl&&r
6091
not m[\A[-/]] and m[\A[\w.\@+][\w./\@+-]*\z]
!ll&&!rl&&r
58210
MC/DC100%3/3
not m[\A[-/]] and m[\A[\w.\@+][\w./\@+-]*\z] and defined _file_text($dev, _absp($_))
not m[\A[-/]] m[\A[\w.\@+][\w./\@+-]*\z] defined _file_text($dev, _absp($_))
Truth table100%4/4
not(A) and B and C
A= not m[\A[-/]]B= m[\A[\w.\@+][\w./\@+-]*\z]C= defined _file_text($dev, _absp($_))
ABCresult
0XX0
10X0
1100
1111
2119 31 ▶ my @files = grep { m{\A/} && defined _file_text( $dev, $_ ) } @a;
Condition100%3/3
m[\A/] && defined _file_text($dev, $_)
!ll&&!rl&&r
401020
MC/DC100%2/2
m[\A/] && defined _file_text($dev, $_)
m[\A/] defined _file_text($dev, $_)
Truth table100%3/3
A && B
A= m[\A/]B= defined _file_text($dev, $_)
ABresult
0X0
100
111
2120 # Dateiargumente, die es nicht gibt: Meldung wie coreutils/mawk (Status 1), kein stdin
2121 31 ▶ my %miss = map { $_ => 'No such file or directory' } grep { $_ ne '-' && !defined _file_text( $dev, _absp($_) ) && !_is_dir( $dev, _absp($_) ) } _filter_files( $cmd, @a );
Condition66%4/6
$_ ne '-' && !defined(_file_text($dev, _absp($_))) && !_is_dir($dev, _absp($_))
!ll&&!rl&&r
20010
$_ ne "-" and not defined _file_text($dev, _absp($_))
!ll&&!rl&&r
02010
MC/DC33%1/3
$_ ne '-' && !defined(_file_text($dev, _absp($_))) && !_is_dir($dev, _absp($_))
$_ ne "-" not defined _file_text($dev, _absp($_)) !_is_dir($dev, _absp($_))
Truth table50%2/4
A and not(B) && not(C)
A= $_ ne "-"B= not defined _file_text($dev, _absp($_))C= !_is_dir($dev, _absp($_))
ABCresult
0XX0
10X0
1100
1111
2122 # als Benutzer ohne Leserecht (Weg oder Datei): Permission denied
2123 31 ▶ for my $f (@files) { $miss{$f} = 'Permission denied' unless _read_ok( $dev, $f ) }
Branch: 1 branch
BranchTrueFalseTotal
unless _read_ok($dev, $f) 1 19 20
2124 31 my @rest = grep { my $x = $_; !grep { $_ eq $x } @files } grep { !$miss{$_} } @a;
2125 31 @files = grep { !$miss{$_} } @files;
2126 11 ▶ my $miss_text = sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
2127 11 my ($p) = @_;
2128 11 my $why = $miss{$p};
2129 11 ▶ $p = $shown{$p} // $p;
Condition33%1/3
$shown{$p} // $p
l!l&&r!l&&!r
0110
MC/DC0%0/2
$shown{$p} // $p
$shown{$p} $p
Truth table33%1/3
A // B
A= $shown{$p}B= $p
ABresult
1X1
011
000
2130 11 ▶ return $cmd eq 'head' || $cmd eq 'tail' ? "$cmd: cannot open '$p' for reading: $why"
Branch: 3 branches
BranchTrueFalseTotal
$cmd eq 'head' || $cmd eq 'tail' ? : 3 8 11
$cmd eq 'sort' ? : 1 7 8
$cmd eq 'awk' ? : 1 6 7
Condition100%3/3
$cmd eq "head" or $cmd eq "tail"
l!l&&r!l&&!r
218
MC/DC100%2/2
$cmd eq "head" or $cmd eq "tail"
$cmd eq "head" $cmd eq "tail"
Truth table100%3/3
A or B
A= $cmd eq "head"B= $cmd eq "tail"
ABresult
1X1
011
000
2131 : $cmd eq 'sort' ? "sort: cannot read: $p: $why"
2132 : $cmd eq 'awk' ? "awk: cannot open $p ($why)"
2133 : "$cmd: $p: $why";
2134 31 };
2135 31 ▶ if ( %miss && !( $cmd eq 'wc' && @files ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%miss and not $cmd eq "wc" && @files) 10 21 31
Condition100%6/6
%miss and not $cmd eq "wc" && @files
!ll&&!rl&&r
20110
$cmd eq 'wc' && @files
!ll&&!rl&&r
731
MC/DC100%3/3
%miss and not $cmd eq "wc" && @files
%miss $cmd eq 'wc' @files
Truth table100%4/4
A and not(B && C)
A= %missB= $cmd eq 'wc'C= @files
ABCresult
0XX0
1110
10X1
1101
2136 10 my @err = map { $miss_text->($_) } grep { $miss{$_} } @a;
2137 10 ▶ return ( join( "\n", @err ), 0 ) unless @files;
Branch: 1 branch
BranchTrueFalseTotal
unless @files 10 0 10
2138 0 my ($t) = Langertha::Holmgang::Shell::Filter::filter_output( join( '', map { _file_text( $dev, $_ ) } @files ), [ $cmd, @rest ] );
2139 0 ▶ defined $t or do { push @GAPS, join( ' ', $cmd, @a ); return ( '', 0 ) };
Branch: 1 branch
BranchTrueFalseTotal
defined $t or do { push @Langertha::Holmgang::Sim::Linux::GAPS, join(" ", $cmd, @a); return "", 0 } 0 0 0
2140 0 return ( join( "\n", grep {length} $t, @err ), 0 );
2141 }
2142 21 ▶ if ( $cmd eq 'wc' && @files ) { # je Datei mit Namen, bei mehreren eine Summe (wie GNU wc)
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "wc" and @files) 9 12 21
Condition100%3/3
$cmd eq "wc" and @files
!ll&&!rl&&r
1119
MC/DC100%2/2
$cmd eq "wc" and @files
$cmd eq "wc" @files
Truth table100%3/3
A and B
A= $cmd eq "wc"B= @files
ABresult
0X0
100
111
2143 9 my ( @rows, @sum );
2144 9 my %is_file = map { $_ => 1 } @files;
2145 9 ▶ for my $p ( grep { $is_file{$_} || $miss{$_} } @a ) { # in der Reihenfolge der Argumente
Condition100%3/3
$is_file{$_} || $miss{$_}
l!l&&r!l&&!r
1119
MC/DC100%2/2
$is_file{$_} || $miss{$_}
$is_file{$_} $miss{$_}
Truth table100%3/3
A || B
A= $is_file{$_}B= $miss{$_}
ABresult
1X1
011
000
2146 12 ▶ if ( $miss{$p} ) { push @rows, \( $miss_text->($p) ); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($miss{$p}) 1 11 12
2147 11 my ($t) = Langertha::Holmgang::Shell::Filter::filter_output( _file_text( $dev, $p ), [ 'wc', @rest ] );
2148 0 ▶ defined $t or do { push @GAPS, join( ' ', $cmd, @a ); return ( '', 0 ) };
Branch: 1 branch
BranchTrueFalseTotal
defined $t or do { push @Langertha::Holmgang::Sim::Linux::GAPS, join(" ", $cmd, @a); return "", 0 } 11 0 11
2149 11 my @n = split ' ', $t;
2150 11 $sum[$_] += $n[$_] for 0 .. $#n;
2151 11 ▶ push @rows, [ @n, $shown{$p} // $p ];
Condition66%2/3
$shown{$p} // $p
l!l&&r!l&&!r
1100
MC/DC0%0/2
$shown{$p} // $p
$shown{$p} $p
Truth table66%2/3
A // B
A= $shown{$p}B= $p
ABresult
1X1
011
000
2152 }
2153 9 my @num = grep { ref eq 'ARRAY' } @rows;
2154 9 ▶ push @rows, [ @sum, 'total' ] if @files + keys(%miss) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @files + keys(%miss) > 1 3 6 9
2155 9 ▶ my $w = @files > 1 || @{ $num[0] } > 2 ? length( ( sort { $b <=> $a } map { @$_[ 0 .. $#$_ - 1 ] } grep { ref eq 'ARRAY' } @rows )[0] ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
@files > 1 || @{$num[0];} > 2 ? : 2 7 9
Condition66%2/3
@files > 1 or @{$num[0];} > 2
l!l&&r!l&&!r
207
MC/DC50%1/2
@files > 1 or @{$num[0];} > 2
@files > 1 @{$num[0];} > 2
Truth table66%2/3
A or B
A= @files > 1B= @{$num[0];} > 2
ABresult
1X1
011
000
2156 9 ▶ return ( join( "\n", map { my $r = $_; ref $r eq 'SCALAR' ? $$r : join( ' ', ( map { sprintf '%*s', $w, $_ } @$r[ 0 .. $#$r - 1 ] ), $r->[-1] ) } @rows ),
Branch: 2 branches
BranchTrueFalseTotal
ref $r eq 'SCALAR' ? : 1 14 15
%miss ? : 1 8 9
2157 %miss ? 0 : 1 );
2158 }
2159 12 ▶ my $text = @files ? join( '', map { _file_text( $dev, $_ ) } @files ) : $stdin // '';
Branch: 1 branch
BranchTrueFalseTotal
@files ? : 8 4 12
Condition50%1/2
$stdin // ""
l!l
40
MC/DC0%0/1
$stdin // ""
$stdin
Truth table50%1/2
A
A= $stdin
Aresult
11
00
2160 12 my ( $t, $k ) = Langertha::Holmgang::Shell::Filter::filter_output( $text, [ $cmd, @rest ] );
2161 12 ▶ $t .= " $files[0]" if defined $t && $cmd eq 'wc' && @files == 1; # wc -c datei: "123 datei"
Branch: 1 branch
BranchTrueFalseTotal
if defined $t and $cmd eq "wc" and @files == 1 0 12 12
Condition83%5/6
defined $t and $cmd eq "wc" and @files == 1
!ll&&!rl&&r
1110
defined $t and $cmd eq "wc"
!ll&&!rl&&r
1101
MC/DC0%0/3
defined $t and $cmd eq "wc" and @files == 1
defined $t $cmd eq "wc" @files == 1
Truth table75%3/4
A and B and C
A= defined $tB= $cmd eq "wc"C= @files == 1
ABCresult
0XX0
10X0
1100
1111
2162 12 ▶ return ( $t, $k ) if defined $t;
Branch: 1 branch
BranchTrueFalseTotal
if defined $t 11 1 12
2163 1 push @GAPS, join( ' ', $cmd, @a );
2164 1 return ( '', 0 );
2165 }
2166 4631 ▶ if ( !$f ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($f) 11 4620 4631
2167 11 ▶ if ( $cmd =~ m{/} ) { # Programm mit Pfad: gibt es die Datei, laeuft es (Luecke), sonst wie bash
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ m[/]) 0 11 11
2168 0 ▶ return ( "bash: $cmd: No such file or directory", 0 ) unless _file_entry( $dev, $cmd );
Branch: 1 branch
BranchTrueFalseTotal
unless _file_entry($dev, $cmd) 0 0 0
2169 0 push @GAPS, join( ' ', $cmd, @a );
2170 0 return ( '', 0 );
2171 }
2172 11 ▶ return ( "bash: $cmd: command not found", 0 ) if $NOT_INSTALLED{$cmd} || !$REAL{$cmd};
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::NOT_INSTALLED{$cmd} or not $Langertha::Holmgang::Sim::Linux::REAL{$cmd} 5 6 11
Condition100%3/3
$Langertha::Holmgang::Sim::Linux::NOT_INSTALLED{$cmd} or not $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
l!l&&r!l&&!r
326
MC/DC100%2/2
$Langertha::Holmgang::Sim::Linux::NOT_INSTALLED{$cmd} or not $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
$Langertha::Holmgang::Sim::Linux::NOT_INSTALLED{$cmd} not $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
Truth table100%3/3
A or not(B)
A= $Langertha::Holmgang::Sim::Linux::NOT_INSTALLED{$cmd}B= not $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
ABresult
1X1
011
000
2173 # Echter Befehl ohne Simulation: neutrale Antwort, als Luecke vermerkt
2174 6 push @GAPS, join( ' ', $cmd, @a );
2175 6 ▶ return ( 'Error opening terminal: unknown.', 0 ) if $INTERACTIVE{$cmd};
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::INTERACTIVE{$cmd} 4 2 6
2176 2 return ( '', 0 );
2177 }
2178 4620 my ( $out, $ok ) = eval { $f->( $dev, \@a, $ctx, $stdin ) };
2179 4620 ▶ if ( my $e = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 9 4611 4620
2180 9 $e =~ s/\s+\z//;
2181 9 return ( $e, 0 );
2182 }
2183 4611 ▶ return ( $out // '', $ok );
Condition50%1/2
$out // ""
l!l
46110
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
2184 }
2185  
2186 # date: Uhr des Geraets (clock), sonst die Simulationszeit (_sim_now); -d ZEIT; Zone aus TZ=
2187 # (Vorgabe timezone des Geraets bzw. Europe/Berlin). -u zeigt UTC; -d liest auch dann Ortszeit.
2188 23 ▶sub _date {
Subroutine _date: called CC=29 SCAR=40.8
2189 23 my ( $dev, $av ) = @_;
2190 23 require POSIX;
2191 23 require Langertha::Holmgang::Sim::Linux::Calendar;
2192 23 my $C = 'Langertha::Holmgang::Sim::Linux::Calendar';
2193 23 ▶ my $tz = $DATE_TZ // ( $dev->{timezone} // 'Europe/Berlin' );
Condition75%3/4
$Langertha::Holmgang::Sim::Linux::DATE_TZ // ($$dev{"timezone"} // "Europe/Berlin")
l!l
122
$$dev{"timezone"} // "Europe/Berlin"
l!l
022
MC/DC100%1/1
$Langertha::Holmgang::Sim::Linux::DATE_TZ // ($$dev{"timezone"} // "Europe/Berlin")
$Langertha::Holmgang::Sim::Linux::DATE_TZ
Truth table100%2/2
A
A= $Langertha::Holmgang::Sim::Linux::DATE_TZ
Aresult
11
00
2194 23 my ( $utc, $fmt, $when ) = ( 0, '%a %b %e %H:%M:%S %Z %Y' );
2195 23 my @a = @$av;
2196 23 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 34 23 57
2197 34 my $x = shift @a;
2198 34 ▶ if ( $x eq '-u' || $x eq '--utc' || $x eq '--universal' ) { $utc = 1 }
Branch: 7 branches
BranchTrueFalseTotal
if ($x eq '-u' or $x eq '--utc' or $x eq '--universal') { } 4 30 34
elsif ($x =~ /\A\+(.*)\z/s) { } 17 13 30
elsif ($x eq '-d' or $x eq '--date') { } 13 0 13
elsif ($x =~ /\A(?:-d|--date=)(.+)\z/s) { } 0 0 0
elsif ($x eq '-I' or $x =~ /\A--iso-8601(?:=date)?\z/) { } 0 0 0
elsif ($x eq '-Iseconds' or $x eq '--iso-8601=seconds') { } 0 0 0
elsif ($x eq '-R' or $x eq '--rfc-email') { } 0 0 0
Condition66%4/6
$x eq "-u" or $x eq "--utc" or $x eq "--universal"
l!l&&r!l&&!r
4030
$x eq "-u" or $x eq "--utc"
l!l&&r!l&&!r
4030
MC/DC33%1/3
$x eq "-u" or $x eq "--utc" or $x eq "--universal"
$x eq "-u" $x eq "--utc" $x eq "--universal"
Truth table50%2/4
A or B or C
A= $x eq "-u"B= $x eq "--utc"C= $x eq "--universal"
ABCresult
1XX1
01X1
0011
0000
2199 17 elsif ( $x =~ /\A\+(.*)\z/s ) { $fmt = $1 }
2200 13 ▶ elsif ( $x eq '-d' || $x eq '--date' ) { $when = shift @a // '' }
Condition40%2/5
$x eq "-d" or $x eq "--date"
l!l&&r!l&&!r
1300
shift @a // ""
l!l
130
MC/DC0%0/2
$x eq "-d" or $x eq "--date"
$x eq "-d" $x eq "--date"
MC/DC0%0/1
shift @a // ""
shift @a
Truth table33%1/3
A or B
A= $x eq "-d"B= $x eq "--date"
ABresult
1X1
011
000
Truth table50%1/2
A
A= shift @a
Aresult
11
00
2201 0 elsif ( $x =~ /\A(?:-d|--date=)(.+)\z/s ) { $when = $1 }
2202 0 ▶ elsif ( $x eq '-I' || $x =~ /\A--iso-8601(?:=date)?\z/ ) { $fmt = '%Y-%m-%d' }
Condition0%0/3
$x eq "-I" or $x =~ /\A--iso-8601(?:=date)?\z/
l!l&&r!l&&!r
000
MC/DC0%0/2
$x eq "-I" or $x =~ /\A--iso-8601(?:=date)?\z/
$x eq "-I" $x =~ /\A--iso-8601(?:=date)?\z/
Truth table0%0/3
A or B
A= $x eq "-I"B= $x =~ /\A--iso-8601(?:=date)?\z/
ABresult
1X1
011
000
2203 0 ▶ elsif ( $x eq '-Iseconds' || $x eq '--iso-8601=seconds' ) { $fmt = '%Y-%m-%dT%H:%M:%S%:z' }
Condition0%0/3
$x eq "-Iseconds" or $x eq "--iso-8601=seconds"
l!l&&r!l&&!r
000
MC/DC0%0/2
$x eq "-Iseconds" or $x eq "--iso-8601=seconds"
$x eq "-Iseconds" $x eq "--iso-8601=seconds"
Truth table0%0/3
A or B
A= $x eq "-Iseconds"B= $x eq "--iso-8601=seconds"
ABresult
1X1
011
000
2204 0 ▶ elsif ( $x eq '-R' || $x eq '--rfc-email' ) { $fmt = '%a, %d %b %Y %H:%M:%S %z' }
Condition0%0/3
$x eq "-R" or $x eq "--rfc-email"
l!l&&r!l&&!r
000
MC/DC0%0/2
$x eq "-R" or $x eq "--rfc-email"
$x eq "-R" $x eq "--rfc-email"
Truth table0%0/3
A or B
A= $x eq "-R"B= $x eq "--rfc-email"
ABresult
1X1
011
000
2205 0 else { push @GAPS, join( ' ', 'date', @$av ); return ( '', 0 ) } # -s, -r …
2206 }
2207 23 ▶ my $now = defined $dev->{clock} ? do { _part('Monitoring'); Langertha::Holmgang::Sim::Linux::Monitoring::now_epoch($dev) } : _pki_now($dev) // ( %{ $dev->{wg} || {} } ? $Langertha::Holmgang::Sim::Linux::NOW : _sim_now() ); # WireGuard: Zeit der Handshakes
Branch: 2 branches
BranchTrueFalseTotal
defined $$dev{'clock'} ? : 3 20 23
%{$$dev{'wg'} or {};} ? : 2 15 17
Condition80%4/5
_pki_now($dev) // (%{$$dev{"wg"} or {};} ? $Langertha::Holmgang::Sim::Linux::NOW : _sim_now())
l!l&&r!l&&!r
3170
$$dev{'wg'} || {}
l!l
215
MC/DC0%0/2
_pki_now($dev) // (%{$$dev{"wg"} or {};} ? $Langertha::Holmgang::Sim::Linux::NOW : _sim_now())
_pki_now($dev) (%{$$dev{"wg"} or {};} ? $Langertha::Holmgang::Sim::Linux::NOW : _sim_now())
MC/DC100%1/1
$$dev{'wg'} || {}
$$dev{'wg'}
Truth table66%2/3
A // B
A= _pki_now($dev)B= (%{$$dev{"wg"} or {};} ? $Langertha::Holmgang::Sim::Linux::NOW : _sim_now())
ABresult
1X1
011
000
Truth table100%2/2
A
A= $$dev{'wg'}
Aresult
11
00
2208 23 ▶ my $zone = $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz} or return ( POSIX::strftime( '%a %b %e %H:%M:%S UTC %Y', gmtime $now ), 1 ); # unbekannte TZ: UTC wie glibc
Branch: 1 branch
BranchTrueFalseTotal
my $zone = $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz} or return POSIX::strftime("%a %b %e %H:%M:%S UTC %Y", gmtime $now), 1 23 0 23
2209 23 my $t = $now;
2210 23 ▶ if ( defined $when ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $when) 13 10 23
2211 13 $t = _date_parse( $when, $tz, $C, $now );
2212 13 ▶ return ( "date: invalid date \x{2018}$when\x{2019}", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 1 12 13
2213 }
2214 22 my ( $off, $abbr ) = ( 0, 'UTC' );
2215 22 ▶ if ( !$utc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($utc) 18 4 22
2216 18 $off = $C->can('offset')->( $t, $tz );
2217 18 ▶ $abbr = $zone->[1] && $off != $zone->[0] ? $zone->[3] : $zone->[2];
Branch: 1 branch
BranchTrueFalseTotal
$$zone[1] && $off != $$zone[0] ? : 15 3 18
Condition100%3/3
$$zone[1] and $off != $$zone[0]
!ll&&!rl&&r
1215
MC/DC100%2/2
$$zone[1] and $off != $$zone[0]
$$zone[1] $off != $$zone[0]
Truth table100%3/3
A and B
A= $$zone[1]B= $off != $$zone[0]
ABresult
0X0
100
111
2218 }
2219 22 ▶ my $hm = sprintf '%s%02d%02d', $off < 0 ? '-' : '+', abs($off) / 3600, ( abs($off) % 3600 ) / 60;
Branch: 1 branch
BranchTrueFalseTotal
$off < 0 ? : 0 22 22
2220 0 $fmt =~ s/%:z/ substr( $hm, 0, 3 ) . ':' . substr( $hm, 3 ) /ge;
2221 22 $fmt =~ s/%Z/$abbr/g;
2222 22 $fmt =~ s/%z/$hm/g;
2223 22 $fmt =~ s/%s/$t/g;
2224 22 return ( POSIX::strftime( $fmt, gmtime( $t + $off ) ), 1 );
2225 }
2226  
2227 # --- Dateien -----------------------------------------------------------------------
2228  
2229 2575 ▶sub _file_text {
Subroutine _file_text: called CC=32 SCAR=37.1
2230 2575 my ( $dev, $path ) = @_;
2231 2575 ▶ return '' if $path eq '/dev/null';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/dev/null" 2 2573 2575
2232 2573 ▶ return _file_text( $dev, _dotdot($path) ) if $path =~ m{\A/.*/\.\.?(?:/|\z)};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[\A/.*/\.\.?(?:/|\z)] 1 2572 2573
2233 2572 ▶ if ( !( ref $dev->{files} eq 'HASH' && exists $dev->{files}{$path} ) && defined( my $r = _via_link( $dev, $path ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and defined(my $r = _via_link($dev, $path))) 3 2569 2572
Condition100%6/6
not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and defined(my $r = _via_link($dev, $path))
!ll&&!rl&&r
16738963
ref $$dev{'files'} eq 'HASH' && exists $$dev{'files'}{$path}
!ll&&!rl&&r
188811673
MC/DC66%2/3
not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and defined(my $r = _via_link($dev, $path))
ref $$dev{'files'} eq 'HASH' exists $$dev{'files'}{$path} defined(my $r = _via_link($dev, $path))
Truth table80%4/5
not(A && B) and C
A= ref $$dev{'files'} eq 'HASH'B= exists $$dev{'files'}{$path}C= defined(my $r = _via_link($dev, $path))
ABCresult
11X0
0X00
1000
0X11
1011
2234 3 return _file_text( $dev, $r );
2235 }
2236 2569 ▶ if ( ref $dev->{files} eq 'HASH' && exists $dev->{files}{$path} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{$path}) 1673 896 2569
Condition100%3/3
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{$path}
!ll&&!rl&&r
188781673
MC/DC100%2/2
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{$path}
ref $$dev{"files"} eq "HASH" exists $$dev{"files"}{$path}
Truth table100%3/3
A and B
A= ref $$dev{"files"} eq "HASH"B= exists $$dev{"files"}{$path}
ABresult
0X0
100
111
2237 1673 my $e = $dev->{files}{$path};
2238 1673 ▶ return _with_append( $dev, $path, $e ) unless ref $e eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" 1521 152 1673
2239 152 ▶ if ( defined $e->{link} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$e{"link"}) 47 105 152
2240 47 my $t = $e->{link};
2241 47 ( my $dir = $path ) =~ s{/[^/]+\z}{};
2242 47 ▶ $t = "$dir/$t" unless $t =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ m[\A/] 5 42 47
2243 47 ▶ 1 while $t =~ s{/[^/]+/\.\./}{/};
Branch: 1 branch
BranchTrueFalseTotal
$t =~ s[/[^/]+/\.\./][/] and do { '???' } 5 47 52
2244 47 $t =~ s{/\./}{/}g;
2245 47 ▶ return _stub_resolv($dev) if $t =~ m{/run/systemd/resolve/stub-resolv\.conf\z} && $dev->{resolved};
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ m[/run/systemd/resolve/stub-resolv\.conf\z] and $$dev{"resolved"} 5 42 47
Condition66%2/3
$t =~ m[/run/systemd/resolve/stub-resolv\.conf\z] and $$dev{"resolved"}
!ll&&!rl&&r
4205
MC/DC50%1/2
$t =~ m[/run/systemd/resolve/stub-resolv\.conf\z] and $$dev{"resolved"}
$t =~ m[/run/systemd/resolve/stub-resolv\.conf\z] $$dev{"resolved"}
Truth table66%2/3
A and B
A= $t =~ m[/run/systemd/resolve/stub-resolv\.conf\z]B= $$dev{"resolved"}
ABresult
0X0
100
111
2246 42 ▶ return _file_text( $dev, $t ) unless ( $_[2] // 0 ) > 5;
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[2] // 0) > 5 42 0 42
Condition50%1/2
$_[2] // 0
l!l
042
MC/DC0%0/1
$_[2] // 0
$_[2]
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
2247 0 return undef;
2248 }
2249 105 ▶ return _with_append( $dev, $path, $e->{content} // '' );
Condition50%1/2
$$e{"content"} // ""
l!l
1050
MC/DC0%0/1
$$e{"content"} // ""
$$e{"content"}
Truth table50%1/2
A
A= $$e{"content"}
Aresult
11
00
2250 }
2251 896 ▶ if ( $path =~ m{\A/proc/sys/(.+)\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[\A/proc/sys/(.+)\z]) 6 890 896
2252 6 ( my $k = $1 ) =~ s{/}{.}g;
2253 6 ▶ return "$dev->{sysctl}{$k}\n" if ref $dev->{sysctl} eq 'HASH' && exists $dev->{sysctl}{$k};
Branch: 1 branch
BranchTrueFalseTotal
if ref $$dev{"sysctl"} eq "HASH" and exists $$dev{"sysctl"}{$k} 6 0 6
Condition33%1/3
ref $$dev{"sysctl"} eq "HASH" and exists $$dev{"sysctl"}{$k}
!ll&&!rl&&r
006
MC/DC0%0/2
ref $$dev{"sysctl"} eq "HASH" and exists $$dev{"sysctl"}{$k}
ref $$dev{"sysctl"} eq "HASH" exists $$dev{"sysctl"}{$k}
Truth table33%1/3
A and B
A= ref $$dev{"sysctl"} eq "HASH"B= exists $$dev{"sysctl"}{$k}
ABresult
0X0
100
111
2254 0 return undef;
2255 }
2256 890 ▶ if ( $path =~ m{\A/etc/wireguard/(wg\d+)\.conf\z} && ref $dev->{wg} eq 'HASH' && $dev->{wg}{$1} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[\A/etc/wireguard/(wg\d+)\.conf\z] and ref $$dev{"wg"} eq "HASH" and $$dev{"wg"}{$1}) 2 888 890
Condition83%5/6
$path =~ m[\A/etc/wireguard/(wg\d+)\.conf\z] and ref $$dev{"wg"} eq "HASH" and $$dev{"wg"}{$1}
!ll&&!rl&&r
88802
$path =~ m[\A/etc/wireguard/(wg\d+)\.conf\z] and ref $$dev{"wg"} eq "HASH"
!ll&&!rl&&r
88712
MC/DC66%2/3
$path =~ m[\A/etc/wireguard/(wg\d+)\.conf\z] and ref $$dev{"wg"} eq "HASH" and $$dev{"wg"}{$1}
$path =~ m[\A/etc/wireguard/(wg\d+)\.conf\z] ref $$dev{"wg"} eq "HASH" $$dev{"wg"}{$1}
Truth table75%3/4
A and B and C
A= $path =~ m[\A/etc/wireguard/(wg\d+)\.conf\z]B= ref $$dev{"wg"} eq "HASH"C= $$dev{"wg"}{$1}
ABCresult
0XX0
10X0
1100
1111
2257 2 return _wg_conf( $dev->{wg}{$1} );
2258 }
2259 888 ▶ return _nft_conf($dev) if $path eq '/etc/nftables.conf' && ref $dev->{nft} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/etc/nftables.conf" and ref $$dev{"nft"} eq "HASH" 4 884 888
Condition66%2/3
$path eq "/etc/nftables.conf" and ref $$dev{"nft"} eq "HASH"
!ll&&!rl&&r
88404
MC/DC50%1/2
$path eq "/etc/nftables.conf" and ref $$dev{"nft"} eq "HASH"
$path eq "/etc/nftables.conf" ref $$dev{"nft"} eq "HASH"
Truth table66%2/3
A and B
A= $path eq "/etc/nftables.conf"B= ref $$dev{"nft"} eq "HASH"
ABresult
0X0
100
111
2260 884 ▶ if ( $path eq '/proc/mdstat' && $dev->{storage} ) { _part('Storage'); return Langertha::Holmgang::Sim::Linux::Storage::mdstat($dev) . "\n" }
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/proc/mdstat" and $$dev{"storage"}) 1 883 884
Condition66%2/3
$path eq "/proc/mdstat" and $$dev{"storage"}
!ll&&!rl&&r
88301
MC/DC50%1/2
$path eq "/proc/mdstat" and $$dev{"storage"}
$path eq "/proc/mdstat" $$dev{"storage"}
Truth table66%2/3
A and B
A= $path eq "/proc/mdstat"B= $$dev{"storage"}
ABresult
0X0
100
111
2261 883 ▶ if ( $path eq '/proc/partitions' && $dev->{storage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/proc/partitions" and $$dev{"storage"}) 0 883 883
Condition33%1/3
$path eq "/proc/partitions" and $$dev{"storage"}
!ll&&!rl&&r
88300
MC/DC0%0/2
$path eq "/proc/partitions" and $$dev{"storage"}
$path eq "/proc/partitions" $$dev{"storage"}
Truth table33%1/3
A and B
A= $path eq "/proc/partitions"B= $$dev{"storage"}
ABresult
0X0
100
111
2262 0 ▶ my $d = $dev->{storage}{disks} || {};
Condition0%0/2
$$dev{'storage'}{'disks'} || {}
l!l
00
MC/DC0%0/1
$$dev{'storage'}{'disks'} || {}
$$dev{'storage'}{'disks'}
Truth table0%0/2
A
A= $$dev{'storage'}{'disks'}
Aresult
11
00
2263 0 my $i = 0;
2264 return join( '', "major minor #blocks name\n\n",
2265 0 map { sprintf "%5d %7d %10d %s\n", 254, $i++, int( _bytes( $d->{$_}{size} ) / 1024 ), s{\A/dev/}{}r } sort keys %$d );
2266 }
2267 883 ▶ if ( my $v = _git_virtual( $dev, $path ) ) { return $v->{text} if defined $v->{text} }
Branch: 2 branches
BranchTrueFalseTotal
if (my $v = _git_virtual($dev, $path)) 3 880 883
if defined $$v{"text"} 3 0 3
2268 880 return undef;
2269 }
2270  
2271 # .git einer Arbeitskopie bzw. Bare-Repo des Servers (aus dem Git-Zustand abgeleitet)
2272 26622 ▶sub _git_virtual {
Subroutine _git_virtual: called CC=4 SCAR=13.9
2273 26622 my ( $dev, $path ) = @_;
2274 26622 ▶ return undef unless ( $dev->{git} || $dev->{forgejo} ) && $path =~ m{\.git(?:/|\z)};
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{"git"} || $$dev{"forgejo"} and $path =~ m[\.git(?:/|\z)] 26609 13 26622
Condition100%6/6
$$dev{"git"} || $$dev{"forgejo"} and $path =~ m[\.git(?:/|\z)]
!ll&&!rl&&r
23633297613
$$dev{"git"} or $$dev{"forgejo"}
l!l&&r!l&&!r
2981823633
MC/DC100%3/3
$$dev{"git"} || $$dev{"forgejo"} and $path =~ m[\.git(?:/|\z)]
$$dev{"git"} $$dev{"forgejo"} $path =~ m[\.git(?:/|\z)]
Truth table80%4/5
A or B and C
A= $$dev{"git"}B= $$dev{"forgejo"}C= $path =~ m[\.git(?:/|\z)]
ABCresult
00X0
1X00
0100
1X11
0111
2275 13 _part('Git');
2276 13 return Langertha::Holmgang::Sim::Linux::Git::virtual( $dev, $path =~ s{/+\z}{}r );
2277 }
2278  
2279 # Stub-resolv.conf von systemd-resolved
2280 5 ▶sub _stub_resolv {
Subroutine _stub_resolv: called CC=4 SCAR=14.8
2281 5 my ($dev) = @_;
2282 5 my $r = $dev->{resolved};
2283 0 ▶ my @dom = grep { !/\A~/ } map { @{ $r->{links}{$_}{domains} || [] } } sort keys %{ $r->{links} || {} };
Condition50%2/4
$$r{'links'}{$_}{'domains'} || []
l!l
50
$$r{'links'} || {}
l!l
50
MC/DC0%0/1
$$r{'links'}{$_}{'domains'} || []
$$r{'links'}{$_}{'domains'}
MC/DC0%0/1
$$r{'links'} || {}
$$r{'links'}
Truth table50%1/2
A
A= $$r{'links'}{$_}{'domains'}
Aresult
11
00
Truth table50%1/2
A
A= $$r{'links'}
Aresult
11
00
2284 5 ▶ return "nameserver 127.0.0.53\noptions edns0 trust-ad\n" . ( @dom ? 'search ' . join( ' ', @dom ) . "\n" : '' );
Branch: 1 branch
BranchTrueFalseTotal
@dom ? : 0 5 5
2285 }
2286  
2287 360 ▶sub _write_path {
Subroutine _write_path: called CC=18 SCAR=32.0
2288 360 my ( $dev, $path, $text, $append, $ctx ) = @_;
2289 360 ▶ return ( '', 1 ) if $path eq '/dev/null';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/dev/null" 2 358 360
2290 # > /dev/tcp/HOST/PORT: Verbindung der bash, keine Datei — ohne Netz eine Luecke
2291 358 ▶ if ( $path =~ m{\A/dev/(?:tcp|udp)/} ) { return _dev_tcp( $dev, $path, '>' ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[\A/dev/(?:tcp|udp)/]) 8 350 358
2292 350 $path = _absp($path); # relativ (nach cd) und mit .. wie die Shell
2293 350 ▶ if ( $path =~ m{\A/proc/sys/(.+)\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[\A/proc/sys/(.+)\z]) 1 349 350
2294 1 ( my $k = $1 ) =~ s{/}{.}g;
2295 return ( "bash: $path: No such file or directory", 0 )
2296 1 ▶ unless ref $dev->{sysctl} eq 'HASH' && exists $dev->{sysctl}{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$dev{"sysctl"} eq "HASH" and exists $$dev{"sysctl"}{$k} 0 1 1
Condition33%1/3
ref $$dev{"sysctl"} eq "HASH" and exists $$dev{"sysctl"}{$k}
!ll&&!rl&&r
001
MC/DC0%0/2
ref $$dev{"sysctl"} eq "HASH" and exists $$dev{"sysctl"}{$k}
ref $$dev{"sysctl"} eq "HASH" exists $$dev{"sysctl"}{$k}
Truth table33%1/3
A and B
A= ref $$dev{"sysctl"} eq "HASH"B= exists $$dev{"sysctl"}{$k}
ABresult
0X0
100
111
2297 1 ( my $v = $text ) =~ s/\s+\z//;
2298 1 $dev->{sysctl}{$k} = $v;
2299 1 return ( '', 1 );
2300 }
2301 349 my ($dir) = $path =~ m{\A(.*)/[^/]+\z};
2302 349 ▶ return ( "bash: $path: No such file or directory", 0 ) unless $path =~ m{\A/} && defined $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ m[\A/] and defined $dir 0 349 349
Condition33%1/3
$path =~ m[\A/] and defined $dir
!ll&&!rl&&r
00349
MC/DC0%0/2
$path =~ m[\A/] and defined $dir
$path =~ m[\A/] defined $dir
Truth table33%1/3
A and B
A= $path =~ m[\A/]B= defined $dir
ABresult
0X0
100
111
2303 349 ▶ return ( "bash: $path: No such file or directory", 0 ) unless _is_dir( $dev, $dir ) || $dir =~ m{\A/(?:etc|root|tmp|var|srv|opt|home|run|usr)\b};
Branch: 1 branch
BranchTrueFalseTotal
unless _is_dir($dev, $dir) or $dir =~ m[\A/(?:etc|root|tmp|var|srv|opt|home|run|usr)\b] 0 349 349
Condition66%2/3
_is_dir($dev, $dir) or $dir =~ m[\A/(?:etc|root|tmp|var|srv|opt|home|run|usr)\b]
l!l&&r!l&&!r
34540
MC/DC0%0/2
_is_dir($dev, $dir) or $dir =~ m[\A/(?:etc|root|tmp|var|srv|opt|home|run|usr)\b]
_is_dir($dev, $dir) $dir =~ m[\A/(?:etc|root|tmp|var|srv|opt|home|run|usr)\b]
Truth table66%2/3
A or B
A= _is_dir($dev, $dir)B= $dir =~ m[\A/(?:etc|root|tmp|var|srv|opt|home|run|usr)\b]
ABresult
1X1
011
000
2304 349 my $e = _file_entry( $dev, $path );
2305 349 ▶ if ( my $err = _may_create( $dev, $path ) ) { return ( "bash: $path: $err", 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = _may_create($dev, $path)) 3 346 349
2306 346 ▶ if ( $e && defined $e->{link} ) { # Schreiben durch einen Verweis: Verweis wird zur Datei (vereinfacht)
Branch: 1 branch
BranchTrueFalseTotal
if ($e and defined $$e{"link"}) 0 346 346
Condition66%2/3
$e and defined $$e{"link"}
!ll&&!rl&&r
1651810
MC/DC0%0/2
$e and defined $$e{"link"}
$e defined $$e{"link"}
Truth table66%2/3
A and B
A= $eB= defined $$e{"link"}
ABresult
0X0
100
111
2307 0 $dev->{files}{$path} = $text;
2308 0 return ( '', 1 );
2309 }
2310 346 ▶ if ( !$e && !_is_dir( $dev, $path ) && ( my $meta = _new_meta( $dev, $path, 0 ) ) ) { # neue Datei eines Benutzers, umask, setgid
Branch: 1 branch
BranchTrueFalseTotal
if (not $e || _is_dir($dev, $path) and my $meta = _new_meta($dev, $path, 0)) 0 346 346
Condition66%4/6
not $e || _is_dir($dev, $path) and my $meta = _new_meta($dev, $path, 0)
!ll&&!rl&&r
1811650
$e || _is_dir($dev, $path)
l!l&&r!l&&!r
1810165
MC/DC0%0/3
not $e || _is_dir($dev, $path) and my $meta = _new_meta($dev, $path, 0)
$e _is_dir($dev, $path) my $meta = _new_meta($dev, $path, 0)
Truth table50%2/4
not(A || B) and C
A= $eB= _is_dir($dev, $path)C= my $meta = _new_meta($dev, $path, 0)
ABCresult
1XX0
01X0
0000
0011
2311 0 $dev->{files}{$path} = { content => $text, %$meta };
2312 0 return ( '', 1 );
2313 }
2314 346 my $old = _file_text( $dev, $path );
2315 346 ▶ _file_set( $dev, $path, $append ? ( $old // '' ) . $text : $text );
Branch: 1 branch
BranchTrueFalseTotal
$append ? : 26 320 346
Condition50%1/2
$old // ""
l!l
260
MC/DC0%0/1
$old // ""
$old
Truth table50%1/2
A
A= $old
Aresult
11
00
2316 346 return ( '', 1 );
2317 }
2318  
2319  
2320 163 ▶sub write {
Subroutine write: called CC=9 SCAR=22.0
Pod documented
2321 163 my ( $class, $dev, $path, $content, $ctx ) = @_;
2322 163 ▶ _ssh_access()->can('remember')->($dev) if ref $dev->{files} eq 'HASH' && exists $dev->{files}{'/etc/ssh/sshd_config'};
Branch: 1 branch
BranchTrueFalseTotal
if ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"} 1 162 163
Condition100%3/3
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"}
!ll&&!rl&&r
11611
MC/DC100%2/2
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"}
ref $$dev{"files"} eq "HASH" exists $$dev{"files"}{"/etc/ssh/sshd_config"}
Truth table100%3/3
A and B
A= ref $$dev{"files"} eq "HASH"B= exists $$dev{"files"}{"/etc/ssh/sshd_config"}
ABresult
0X0
100
111
2323 163 ▶ if ( my $cut = _locked_out( $dev, $ctx ) ) { return ( $cut =~ s/\Assh:/scp:/r, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $cut = _locked_out($dev, $ctx)) 1 162 163
2324 162 ▶ if ( $dev->{ssh_login} ) { my $no = _sshd_sim()->can('login_denied')->( $dev, $ctx->{host} ); return ( $no, 0 ) if defined $no }
Branch: 2 branches
BranchTrueFalseTotal
if ($$dev{"ssh_login"}) 1 161 162
if defined $no 1 0 1
2325 161 my $web = _web_world($ctx);
2326 161 ▶ Langertha::Holmgang::Sim::Linux::Http::before( $ctx->{state} ) if $web;
Branch: 1 branch
BranchTrueFalseTotal
if $web 21 140 161
2327 161 my ( $e, $ok ) = _write_path( $dev, $path, $content, 0, $ctx );
2328 161 ▶ Langertha::Holmgang::Sim::Linux::Http::after( $ctx->{state} ) if $web;
Branch: 1 branch
BranchTrueFalseTotal
if $web 21 140 161
2329 161 ▶ return ( $ok ? "geschrieben: $path (" . length($content) . ' Zeichen)' : $e, $ok );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 161 0 161
2330 }
2331  
2332 107 ▶sub _cat {
Subroutine _cat: called CC=20 SCAR=30.1
2333 107 my ( $dev, $av, $ctx, $stdin ) = @_;
2334 107 my @out;
2335 107 my $ok = 1;
2336 # ohne Datei: die Eingabe (aus einer Pipe), -A/-E zeigen das Zeilenende als $
2337 107 ▶ if ( !grep { !/\A-/ } @$av ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {not /\A-/;} @$av) 5 102 107
2338 5 ▶ my $t = ( $stdin // '' ) =~ s/\n\z//r;
Condition50%1/2
$stdin // ""
l!l
50
MC/DC0%0/1
$stdin // ""
$stdin
Truth table50%1/2
A
A= $stdin
Aresult
11
00
2339 0 ▶ $t =~ s/$/\$/mg if grep {/\A-\w*[AE]/} @$av;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/\A-\w*[AE]/;} @$av 0 5 5
2340 5 return ( $t, 1 );
2341 }
2342 102 for my $p ( grep { !/\A-/ } @$av ) {
2343 105 ▶ if ( $p =~ m{\A/proc/(\d+)/cmdline\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ m[\A/proc/(\d+)/cmdline\z]) 1 104 105
2344 1 my ($x) = grep { $_->{pid} == $1 } _procs($dev);
2345 1 ▶ push @out, $x ? join( "\0", split ' ', $x->{cmd} ) . "\0" : "cat: $p: No such file or directory";
Branch: 1 branch
BranchTrueFalseTotal
$x ? : 1 0 1
2346 1 ▶ $ok = 0 unless $x;
Branch: 1 branch
BranchTrueFalseTotal
unless $x 0 1 1
2347 1 next;
2348 }
2349 104 ▶ if ( $p =~ m{\A/proc/(\d+)/limits\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ m[\A/proc/(\d+)/limits\z]) 1 103 104
2350 1 my $t = _proc_limits( $dev, $1 );
2351 1 ▶ push @out, $t // "cat: $p: No such file or directory";
Condition50%1/2
$t // "cat: ${p}: No such file or directory"
l!l
10
MC/DC0%0/1
$t // "cat: ${p}: No such file or directory"
$t
Truth table50%1/2
A
A= $t
Aresult
11
00
2352 1 ▶ $ok = 0 unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 1 1
2353 1 next;
2354 }
2355 103 ▶ if ( _file_entry( $dev, $p ) && !_read_ok( $dev, $p ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_file_entry($dev, $p) and not _read_ok($dev, $p)) 1 102 103
Condition100%3/3
_file_entry($dev, $p) and not _read_ok($dev, $p)
!ll&&!rl&&r
20821
MC/DC100%2/2
_file_entry($dev, $p) and not _read_ok($dev, $p)
_file_entry($dev, $p) not _read_ok($dev, $p)
Truth table100%3/3
A and not(B)
A= _file_entry($dev, $p)B= not _read_ok($dev, $p)
ABresult
0X0
100
111
2356 1 push @out, "cat: $p: Permission denied";
2357 1 $ok = 0;
2358 1 next;
2359 }
2360 102 my $t = _file_text( $dev, $p );
2361 102 ▶ if ( !defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 11 91 102
2362 11 push @out, "cat: $p: No such file or directory";
2363 11 $ok = 0;
2364 11 next;
2365 }
2366 91 $t =~ s/\n\z//;
2367 91 push @out, $t;
2368 }
2369 # -A/-T zeigen Tabs als ^I, -A/-E Zeilenenden als $, -n nummeriert (ueber alle Dateien)
2370 102 ▶ my $f = join '', map { /\A-([AETvn]+)\z/ ? $1 : '' } @$av;
Branch: 1 branch
BranchTrueFalseTotal
/\A-([AETvn]+)\z/ ? : 2 105 107
2371 102 ▶ if ( $f =~ /[ATEn]/ && $ok ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /[ATEn]/ and $ok) 2 100 102
Condition66%2/3
$f =~ /[ATEn]/ and $ok
!ll&&!rl&&r
10002
MC/DC50%1/2
$f =~ /[ATEn]/ and $ok
$f =~ /[ATEn]/ $ok
Truth table66%2/3
A and B
A= $f =~ /[ATEn]/B= $ok
ABresult
0X0
100
111
2372 2 my @l = split /\n/, join( "\n", @out ), -1;
2373 2 ▶ @l = map { s/\t/^I/gr } @l if $f =~ /[AT]/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /[AT]/ 1 1 2
2374 2 ▶ @l = map {"$_\$"} @l if $f =~ /[AE]/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /[AE]/ 1 1 2
2375 2 my $i = 0;
2376 2 ▶ @l = map { sprintf '%6d %s', ++$i, $_ } @l if $f =~ /n/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /n/ 1 1 2
2377 2 return ( join( "\n", @l ), 1 );
2378 }
2379 100 return ( join( "\n", @out ), $ok );
2380 }
2381  
2382 37 ▶sub _grep_file {
Subroutine _grep_file: called CC=42 SCAR=39.3
2383 37 my ( $dev, $av, $ctx, $stdin ) = @_;
2384 37 my ( @opts, @plain, @pats );
2385 37 my @a = @$av;
2386 37 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 106 37 143
2387 106 my $x = shift @a;
2388 106 ▶ if ( $x =~ /\A-[a-zA-Z]*[ABCm]\z/ ) { push @opts, $x, shift(@a) // '' } # -A 3, -m 1
Branch: 3 branches
BranchTrueFalseTotal
if ($x =~ /\A-[a-zA-Z]*[ABCm]\z/) { } 1 105 106
elsif ($x eq '-e') { } 0 105 105
elsif ($x =~ /\A-/) { } 29 76 105
Condition50%1/2
shift @a // ""
l!l
10
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
2389 0 ▶ elsif ( $x eq '-e' ) { push @pats, '-e', shift(@a) // '' }
Condition0%0/2
shift @a // ""
l!l
00
MC/DC0%0/1
shift @a // ""
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
2390 29 elsif ( $x =~ /\A-/ ) { push @opts, $x }
2391 76 else { push @plain, $x }
2392 }
2393 37 ▶ my @pat = @pats ? @pats : ( shift @plain );
Branch: 1 branch
BranchTrueFalseTotal
@pats ? : 0 37 37
2394 37 ▶ return ( 'Usage: grep [OPTION]... PATTERNS [FILE]...', 0 ) unless defined $pat[-1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pat[-1] 0 37 37
2395 37 ▶ return Langertha::Holmgang::Shell::Filter::filter_output( $stdin // '', [ 'grep', @opts, @pat ] ) unless @plain;
Branch: 1 branch
BranchTrueFalseTotal
unless @plain 3 34 37
Condition50%1/2
$stdin // ""
l!l
30
MC/DC0%0/1
$stdin // ""
$stdin
Truth table50%1/2
A
A= $stdin
Aresult
11
00
2396 # Dateien (mit -r/-R auch Verzeichnisse); mehrere: Zeilen mit Dateinamen davor (wie GNU grep)
2397 34 ▶ my $flags = join '', map { /\A-([a-zA-Z]+)\z/ ? $1 : '' } @opts;
Branch: 1 branch
BranchTrueFalseTotal
/\A-([a-zA-Z]+)\z/ ? : 26 2 28
2398 34 ▶ my $rec = $flags =~ /[rR]/ || grep { $_ eq '--recursive' } @opts;
Condition66%2/3
$flags =~ /[rR]/ || grep({$_ eq '--recursive';} @opts)
l!l&&r!l&&!r
14020
MC/DC50%1/2
$flags =~ /[rR]/ || grep({$_ eq '--recursive';} @opts)
$flags =~ /[rR]/ grep({$_ eq '--recursive';} @opts)
Truth table66%2/3
A || B
A= $flags =~ /[rR]/B= grep({$_ eq '--recursive';} @opts)
ABresult
1X1
011
000
2399 34 my ( @files, @err );
2400 34 for my $p (@plain) {
2401 39 ▶ if ( defined _file_text( $dev, $p ) && !( $rec && _is_dir( $dev, $p ) ) ) { push @files, $p; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined _file_text($dev, $p) and not $rec && _is_dir($dev, $p)) 21 18 39
Condition66%4/6
defined _file_text($dev, $p) and not $rec && _is_dir($dev, $p)
!ll&&!rl&&r
18021
$rec && _is_dir($dev, $p)
!ll&&!rl&&r
2010
MC/DC33%1/3
defined _file_text($dev, $p) and not $rec && _is_dir($dev, $p)
defined _file_text($dev, $p) $rec _is_dir($dev, $p)
Truth table75%3/4
A and not(B && C)
A= defined _file_text($dev, $p)B= $recC= _is_dir($dev, $p)
ABCresult
0XX0
1110
10X1
1101
2402 18 ▶ if ( _is_dir( $dev, $p ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_dir($dev, $p)) 16 2 18
2403 16 ▶ if ($rec) { # -r folgt Verweisen unterwegs nicht (nur -R), wie GNU grep
Branch: 1 branch
BranchTrueFalseTotal
if ($rec) { } 12 4 16
2404 12 ( my $d = $p ) =~ s{(?<=.)/+\z}{};
2405 12 ▶ my $follow = $flags =~ /R/ || grep { $_ eq '--dereference-recursive' } @opts;
Condition66%2/3
$flags =~ /R/ || grep({$_ eq '--dereference-recursive';} @opts)
l!l&&r!l&&!r
1011
MC/DC50%1/2
$flags =~ /R/ || grep({$_ eq '--dereference-recursive';} @opts)
$flags =~ /R/ grep({$_ eq '--dereference-recursive';} @opts)
Truth table66%2/3
A || B
A= $flags =~ /R/B= grep({$_ eq '--dereference-recursive';} @opts)
ABresult
1X1
011
000
2406 12 ▶ push @files, grep { defined _file_text( $dev, $_ ) && ( $follow || !defined( ( _file_entry( $dev, $_ ) || {} )->{link} ) ) } _under( $dev, $d );
Condition75%6/8
defined _file_text($dev, $_) && ($follow || !defined((_file_entry($dev, $_) || {})->{'link'}))
!ll&&!rl&&r
0339
$follow or not defined((_file_entry($dev, $_) || {})->{"link"})
l!l&&r!l&&!r
3363
_file_entry($dev, $_) || {}
l!l
390
MC/DC33%1/3
defined _file_text($dev, $_) && ($follow || !defined((_file_entry($dev, $_) || {})->{'link'}))
defined _file_text($dev, $_) $follow _file_entry($dev, $_)
Truth table50%2/4
A && B or not(C)
A= defined _file_text($dev, $_)B= $followC= _file_entry($dev, $_)
ABCresult
0XX0
1010
11X1
1001
2407 }
2408 4 else { push @err, "grep: $p: Is a directory" }
2409 16 next;
2410 }
2411 2 ▶ push @err, "grep: $p: No such file or directory" unless $flags =~ /s/; # -s: Meldungen fehlender Dateien unterdrueckt
Branch: 1 branch
BranchTrueFalseTotal
unless $flags =~ /s/ 2 0 2
2412 }
2413 34 ▶ my @fo = grep { !/\A-[a-zA-Z]*[lLchHrRs][a-zA-Z]*\z/ || /[ABCm]\z/ } @opts;
Condition66%2/3
!/\A-[a-zA-Z]*[lLchHrRs][a-zA-Z]*\z/ || /[ABCm]\z/
l!l&&r!l&&!r
6022
MC/DC50%1/2
!/\A-[a-zA-Z]*[lLchHrRs][a-zA-Z]*\z/ || /[ABCm]\z/
!/\A-[a-zA-Z]*[lLchHrRs][a-zA-Z]*\z/ /[ABCm]\z/
Truth table66%2/3
not(A) || B
A= !/\A-[a-zA-Z]*[lLchHrRs][a-zA-Z]*\z/B= /[ABCm]\z/
ABresult
1X1
011
000
2414 34 push @fo, map {"-$_"} grep { $flags =~ /$_/ } qw( n i v w x o E F P );
2415 34 @fo = do { my %s; grep { !$s{$_}++ } @fo };
2416 34 ▶ my $names = ( @files > 1 || $rec && grep { _is_dir( $dev, $_ ) && !_file_entry( $dev, $_ ) } @plain ) && $flags !~ /h/ || $flags =~ /H/;
Condition66%10/15
(@files > 1 || $rec && grep({_is_dir($dev, $_) and not _file_entry($dev, $_);} @plain)) && !($flags =~ /h/) || $flags =~ /H/
l!l&&r!l&&!r
15019
@files > 1 || $rec && grep({_is_dir($dev, $_) and not _file_entry($dev, $_);} @plain) and not $flags =~ /h/
!ll&&!rl&&r
18115
@files > 1 or $rec and grep {_is_dir($dev, $_) and not _file_entry($dev, $_);} @plain
l!l&&r!l&&!r
16018
$rec and grep {_is_dir($dev, $_) and not _file_entry($dev, $_);} @plain
!ll&&!rl&&r
1620
_is_dir($dev, $_) && !_file_entry($dev, $_)
!ll&&!rl&&r
300
MC/DC40%2/5
(@files > 1 || $rec && grep({_is_dir($dev, $_) and not _file_entry($dev, $_);} @plain)) && !($flags =~ /h/) || $flags =~ /H/
@files > 1 $rec grep {_is_dir($dev, $_) and not _file_entry($dev, $_);} @plain not $flags =~ /h/ $flags =~ /H/
MC/DC0%0/2
_is_dir($dev, $_) && !_file_entry($dev, $_)
_is_dir($dev, $_) !_file_entry($dev, $_)
Truth table40%4/10
A or B and C and not(D) || E
A= @files > 1B= $recC= grep {_is_dir($dev, $_) and not _file_entry($dev, $_);} @plainD= not $flags =~ /h/E= $flags =~ /H/
ABCDEresult
1XX1X1
0111X1
00XX11
010X11
1XX011
011011
00XX00
010X00
1XX000
011000
Truth table33%1/3
A && not(B)
A= _is_dir($dev, $_)B= !_file_entry($dev, $_)
ABresult
0X0
100
111
2417 34 my ( @out, $any );
2418 34 for my $f (@files) {
2419 60 my ( $t, $k ) = Langertha::Holmgang::Shell::Filter::filter_output( _file_text( $dev, $f ), [ 'grep', @fo, @pat ] );
2420 60 ▶ $t //= '';
Condition50%1/2
$t //= ""
l!l
600
MC/DC0%0/1
$t //= ""
$t
Truth table50%1/2
A
A= $t
Aresult
11
00
2421 60 ▶ my @l = length $t ? split /\n/, $t : ();
Branch: 1 branch
BranchTrueFalseTotal
length $t ? : 34 26 60
2422 60 ▶ if ( $flags =~ /c/ ) { push @out, ( $names ? "$f:" : '' ) . scalar( grep { $_ ne '--' } @l ); $any = 1 if @l; next }
Branch: 3 branches
BranchTrueFalseTotal
if ($flags =~ /c/) 1 59 60
$names ? : 0 1 1
if @l 1 0 1
2423 59 ▶ next unless @l;
Branch: 1 branch
BranchTrueFalseTotal
unless @l 26 33 59
2424 33 $any = 1;
2425 33 ▶ if ( $flags =~ /l/ ) { push @out, $f; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($flags =~ /l/) 11 22 33
2426 22 ▶ push @out, map { $_ eq '--' ? $_ : $names ? "$f:$_" : $_ } @l;
Branch: 2 branches
BranchTrueFalseTotal
$_ eq '--' ? : 0 24 24
$names ? : 14 10 24
2427 }
2428 34 ▶ return ( join( "\n", @err, @out ), $any && !@err ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$any && !@err ? : 25 9 34
Condition66%2/3
$any and not @err
!ll&&!rl&&r
9025
MC/DC50%1/2
$any and not @err
$any not @err
Truth table66%2/3
A and not(B)
A= $anyB= not @err
ABresult
0X0
100
111
2429 }
2430  
2431 74 ▶sub _sed {
Subroutine _sed: called CC=25 SCAR=34.0
2432 74 my ( $dev, $av, $ctx, $stdin ) = @_;
2433 74 my @a = @$av;
2434 74 my ( $inplace, $quiet, $ere ) = ( 0, 0, 0 );
2435 74 my @expr;
2436 my @files;
2437 74 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 202 74 276
2438 202 my $x = shift @a;
2439 202 ▶ if ( $x =~ /\A-i/ ) { $inplace = 1 }
Branch: 6 branches
BranchTrueFalseTotal
if ($x =~ /\A-i/) { } 56 146 202
elsif ($x eq '-e') { } 2 144 146
elsif ($x =~ /\A-([nErs]+)\z/) { } 9 135 144
elsif ($x eq '--regexp-extended') { } 0 135 135
elsif ($x eq '--quiet' or $x eq '--silent') { } 0 135 135
elsif (not @expr) { } 73 62 135
2440 2 elsif ( $x eq '-e' ) { push @expr, shift @a }
2441 9 ▶ elsif ( $x =~ /\A-([nErs]+)\z/ ) { my $f = $1; $quiet = 1 if $f =~ /n/; $ere = 1 if $f =~ /[Er]/ }
Branch: 2 branches
BranchTrueFalseTotal
if $f =~ /n/ 6 3 9
if $f =~ /[Er]/ 3 6 9
2442 0 elsif ( $x eq '--regexp-extended' ) { $ere = 1 }
2443 0 ▶ elsif ( $x eq '--quiet' || $x eq '--silent' ) { $quiet = 1 }
Condition33%1/3
$x eq "--quiet" or $x eq "--silent"
l!l&&r!l&&!r
00135
MC/DC0%0/2
$x eq "--quiet" or $x eq "--silent"
$x eq "--quiet" $x eq "--silent"
Truth table33%1/3
A or B
A= $x eq "--quiet"B= $x eq "--silent"
ABresult
1X1
011
000
2444 73 elsif ( !@expr ) { push @expr, $x }
2445 62 else { push @files, $x }
2446 }
2447 74 ▶ return ( "Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...", 0 )
Branch: 1 branch
BranchTrueFalseTotal
unless @expr and @files || !$inplace && defined $stdin 0 74 74
Condition44%4/9
@expr and @files || !$inplace && defined $stdin
!ll&&!rl&&r
0074
@files or not $inplace and defined $stdin
l!l&&r!l&&!r
62120
not $inplace and defined $stdin
!ll&&!rl&&r
0012
MC/DC0%0/4
@expr and @files || !$inplace && defined $stdin
@expr @files not $inplace defined $stdin
Truth table40%2/5
A and B or not(C) and D
A= @exprB= @filesC= not $inplaceD= defined $stdin
ABCDresult
0XXX0
100X0
10100
11XX1
10111
2448 unless @expr && ( @files || !$inplace && defined $stdin );
2449 74 ▶ return ( 'sed: no input files', 0 ) if $inplace && !@files;
Branch: 1 branch
BranchTrueFalseTotal
if $inplace and not @files 0 74 74
Condition66%2/3
$inplace and not @files
!ll&&!rl&&r
18560
MC/DC0%0/2
$inplace and not @files
$inplace not @files
Truth table66%2/3
A and not(B)
A= $inplaceB= not @files
ABresult
0X0
100
111
2450 74 my @cmds;
2451 74 for my $e (@expr) {
2452 75 for my $part ( _sed_split($e) ) {
2453 82 my $c = _sed_cmd( $part, $ere );
2454 82 ▶ return ( $c, 0 ) unless ref $c;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c 0 82 82
2455 82 push @cmds, $c;
2456 }
2457 }
2458 74 my @out;
2459 74 ▶ for my $f ( @files ? @files : (undef) ) {
Branch: 1 branch
BranchTrueFalseTotal
@files ? : 62 12 74
2460 74 ▶ my $t = defined $f ? _file_text( $dev, $f ) : $stdin;
Branch: 1 branch
BranchTrueFalseTotal
defined $f ? : 62 12 74
2461 74 ▶ return ( "sed: can't read $f: No such file or directory", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 74 74
2462 74 my $r = _sed_apply( \@cmds, $t, $quiet );
2463 74 ▶ if ($inplace) { _file_set( $dev, $f, $r ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($inplace) { } 56 18 74
2464 18 else { push @out, $r }
2465 }
2466 74 return ( join( '', @out ) =~ s/\n\z//r, 1 );
2467 }
2468  
2469 # sed-Skript an ; und Zeilenende in Befehle zerlegen; Inhalt von /re/ und s/…/…/ bleibt ganz
2470 75 ▶sub _sed_split {
Subroutine _sed_split: called CC=21 SCAR=30.7
2471 75 my ($e) = @_;
2472 75 my ( @cmd, $delim, $left ) = ();
2473 75 my $cur = '';
2474 75 my @c = split //, $e;
2475 75 ▶ for ( my $i = 0; $i < @c; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @c) 1842 75 1917
2476 1842 my $x = $c[$i];
2477 1842 ▶ if ( defined $delim ) { # in /re/ bzw. s/…/…/: bis zum letzten Trennzeichen
Branch: 1 branch
BranchTrueFalseTotal
if (defined $delim) 1699 143 1842
2478 1699 $cur .= $x;
2479 1699 ▶ if ( $x eq '\\' && $i + 1 < @c ) { $cur .= $c[ ++$i ]; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "\\" and $i + 1 < @c) 38 1661 1699
Condition66%2/3
$x eq "\\" and $i + 1 < @c
!ll&&!rl&&r
1661038
MC/DC50%1/2
$x eq "\\" and $i + 1 < @c
$x eq "\\" $i + 1 < @c
Truth table66%2/3
A and B
A= $x eq "\\"B= $i + 1 < @c
ABresult
0X0
100
111
2480 1661 ▶ undef $delim if $x eq $delim && !--$left;
Branch: 1 branch
BranchTrueFalseTotal
if $x eq $delim and not --$left 74 1587 1661
Condition100%3/3
$x eq $delim and not --$left
!ll&&!rl&&r
15276074
MC/DC100%2/2
$x eq $delim and not --$left
$x eq $delim not --$left
Truth table100%3/3
A and not(B)
A= $x eq $delimB= not --$left
ABresult
0X0
100
111
2481 1661 next;
2482 }
2483 143 ▶ if ( $x eq ';' || $x eq "\n" ) { push @cmd, $cur if $cur =~ /\S/; $cur = ''; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($x eq ";" or $x eq "\n") 7 136 143
if $cur =~ /\S/ 7 0 7
Condition66%2/3
$x eq ";" or $x eq "\n"
l!l&&r!l&&!r
70136
MC/DC50%1/2
$x eq ";" or $x eq "\n"
$x eq ";" $x eq "\n"
Truth table66%2/3
A or B
A= $x eq ";"B= $x eq "\n"
ABresult
1X1
011
000
2484 136 ▶ if ( $x eq '/' ) { ( $delim, $left ) = ( '/', 1 ); $cur .= $x; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "/") 14 122 136
2485 122 my $at_cmd = $cur =~ m{\A\s*(?:(?:\d+|\$|/.*/)(?:,(?:\d+|\$|/.*/))?)?\s*!?\s*\z};
2486 # i/a/c an Befehlsstelle: der Text reicht bis zum Zeilenende (a\ + Zeilenumbruch: naechste Zeile)
2487 122 ▶ if ( $x =~ /\A[iac]\z/ && $at_cmd && ( $i + 1 >= @c || $c[ $i + 1 ] =~ /[\s\\]/ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /\A[iac]\z/ and $at_cmd and $i + 1 >= @c || $c[$i + 1] =~ /[\s\\]/) 7 115 122
Condition55%5/9
$x =~ /\A[iac]\z/ and $at_cmd and $i + 1 >= @c || $c[$i + 1] =~ /[\s\\]/
!ll&&!rl&&r
11507
$x =~ /\A[iac]\z/ and $at_cmd
!ll&&!rl&&r
11507
$i + 1 >= @c or $c[$i + 1] =~ /[\s\\]/
l!l&&r!l&&!r
070
MC/DC25%1/4
$x =~ /\A[iac]\z/ and $at_cmd and $i + 1 >= @c || $c[$i + 1] =~ /[\s\\]/
$x =~ /\A[iac]\z/ $at_cmd $i + 1 >= @c $c[$i + 1] =~ /[\s\\]/
Truth table40%2/5
A and B and C or D
A= $x =~ /\A[iac]\z/B= $at_cmdC= $i + 1 >= @cD= $c[$i + 1] =~ /[\s\\]/
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2488 7 my $all = join '', @c[ $i + 1 .. $#c ];
2489 7 my $rest = $all;
2490 7 ▶ $rest =~ s/\A\\\n// or $rest =~ s/\A\\?[ \t]*//;
Branch: 1 branch
BranchTrueFalseTotal
$rest =~ s/\A\\\n// or $rest =~ s/\A\\?[ \t]*// 1 6 7
2491 7 my ($text) = $rest =~ /\A([^\n]*)/;
2492 7 push @cmd, "$cur$x\x00$text";
2493 7 $cur = '';
2494 7 $i += length($all) - length($rest) + length($text);
2495 7 next;
2496 }
2497 # s an Befehlsstelle (nach hoechstens einer Adresse und !)
2498 115 ▶ if ( $x eq 's' && $i + 1 < @c && $at_cmd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "s" and $i + 1 < @c and $at_cmd) 60 55 115
Condition66%4/6
$x eq "s" and $i + 1 < @c and $at_cmd
!ll&&!rl&&r
55060
$x eq "s" and $i + 1 < @c
!ll&&!rl&&r
55060
MC/DC33%1/3
$x eq "s" and $i + 1 < @c and $at_cmd
$x eq "s" $i + 1 < @c $at_cmd
Truth table50%2/4
A and B and C
A= $x eq "s"B= $i + 1 < @cC= $at_cmd
ABCresult
0XX0
10X0
1100
1111
2499 60 ( $delim, $left ) = ( $c[ $i + 1 ], 2 );
2500 60 $cur .= $x . $c[ ++$i ];
2501 60 next;
2502 }
2503 55 $cur .= $x;
2504 }
2505 75 ▶ push @cmd, $cur if $cur =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $cur =~ /\S/ 68 7 75
2506 75 ▶ return map { /\x00/ ? s/\A\s+//r : s/\A\s+|\s+\z//gr } @cmd;
Branch: 1 branch
BranchTrueFalseTotal
/\x00/ ? : 7 75 82
2507 }
2508  
2509 # Ein sed-Befehl: [adresse[,adresse]][!] d | p | s/…/…/[gI]; Adresse N, $ oder /re/.
2510 82 ▶sub _sed_cmd {
Subroutine _sed_cmd: called CC=17 SCAR=28.7
2511 82 my ( $e, $ere ) = @_;
2512 82 my $bad = "sed: -e expression #1, char " . length($e) . ": unknown command: `" . substr( $e, 0, 1 ) . "'";
2513 82 my $addr = qr{\d+|\$|/(?:[^/\\]|\\.)*/};
2514 82 ▶ my ( $a1, $a2, $neg, $rest ) = $e =~ /\A\s*($addr)?(?:,($addr))?\s*(!?)\s*(.*)\z/s or return $bad;
Branch: 1 branch
BranchTrueFalseTotal
() = $e =~ /\A\s*($addr)?(?:,($addr))?\s*(!?)\s*(.*)\z/s or return $bad 82 0 82
2515 82 my %c = ( neg => $neg );
2516 82 for ( [ a1 => $a1 ], [ a2 => $a2 ] ) {
2517 164 my ( $k, $v ) = @$_;
2518 164 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 126 38 164
2519 38 ▶ if ( $v =~ m{\A/(.*)/\z}s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ m[\A/(.*)/\z]s) { } 14 24 38
2520 14 ▶ my $re = $ere ? $1 : _bre($1);
Branch: 1 branch
BranchTrueFalseTotal
$ere ? : 0 14 14
2521 14 ▶ $c{$k} = eval { qr/$re/ } or return "sed: -e expression #1: Invalid regular expression";
Branch: 1 branch
BranchTrueFalseTotal
$c{$k} = eval { do { qr/$re/ } } or return "sed: -e expression #1: Invalid regular expression" 14 0 14
2522 }
2523 24 else { $c{$k} = $v }
2524 }
2525 82 ▶ if ( $rest =~ /\A([dp])\s*\z/ ) { $c{op} = $1; return \%c }
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A([dp])\s*\z/) 15 67 82
2526 67 ▶ if ( $rest =~ /\A([iac])\x00(.*)\z/s ) { @c{qw( op text )} = ( $1, $2 ); return \%c }
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A([iac])\x00(.*)\z/s) 7 60 67
2527 60 ▶ my ( $d, $from, $to, $fl ) = $rest =~ /\As(.)(.*?)(?<!\\)\1(.*?)(?<!\\)\1([gI]*)\z/s or return $bad;
Branch: 1 branch
BranchTrueFalseTotal
() = $rest =~ /\As(.)(.*?)(?<!\\)\1(.*?)(?<!\\)\1([gI]*)\z/s or return $bad 60 0 60
2528 60 ▶ $from = $ere ? $from =~ s/\\(\Q$d\E)/\Q$1\E/gr : _bre( $from, $d ); # \<trenner>: der Trenner selbst
Branch: 1 branch
BranchTrueFalseTotal
$ere ? : 3 57 60
2529 60 $to =~ s/\\\Q$d\E/$d/g; # s/a\/b/c\/d/: Trenner im Ersatz entwertet
2530 60 ▶ if ( $from eq '' ) { # s//…/: das zuletzt benutzte Muster (hier: der Adresse)
Branch: 1 branch
BranchTrueFalseTotal
if ($from eq "") 1 59 60
2531 1 my ($last) = grep { ref } @c{qw( a2 a1 )};
2532 1 ▶ return "sed: -e expression #1, char 0: no previous regular expression" unless $last;
Branch: 1 branch
BranchTrueFalseTotal
unless $last 0 1 1
2533 1 ▶ @c{qw( op to global re )} = ( 's', $to, $fl =~ /g/ ? 1 : 0, $last );
Branch: 1 branch
BranchTrueFalseTotal
$fl =~ /g/ ? : 0 1 1
2534 1 return \%c;
2535 }
2536 59 ▶ $c{re} = eval { $fl =~ /I/ ? qr/$from/mi : qr/$from/m } or return "sed: -e expression #1: Invalid regular expression";
Branch: 2 branches
BranchTrueFalseTotal
$c{"re"} = eval { do { $fl =~ /I/ ? qr/$from/im : qr/$from/m } } or return "sed: -e expression #1: Invalid regular expression" 59 0 59
$fl =~ /I/ ? : 0 59 59
2537 59 ▶ @c{qw( op to global )} = ( 's', $to, $fl =~ /g/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$fl =~ /g/ ? : 1 58 59
2538 59 return \%c;
2539 }
2540  
2541 # GNU-BRE -> Perl: blanke ( ) { } | + ? sind Zeichen, mit Backslash Operatoren;
2542 # mit $delim (s|…|…|) ist \<trenner> der Trenner als Zeichen
2543 71 ▶sub _bre {
Subroutine _bre: called CC=11 SCAR=24.3
2544 71 my ( $re, $delim ) = @_;
2545 71 my $out = '';
2546 71 my @t = $re =~ /(\\.|.)/gs;
2547 71 for my $i ( 0 .. $#t ) {
2548 696 my $t = $t[$i];
2549 696 ▶ if ( defined $delim && $t eq "\\$delim" ) { $out .= quotemeta $delim }
Branch: 5 branches
BranchTrueFalseTotal
if (defined $delim and $t eq "\\$delim") { } 4 692 696
elsif ($t =~ /\A\\([(){}|+?])\z/) { } 7 685 692
elsif ($t =~ /\A[(){}|+?]\z/) { } 9 676 685
elsif ($t eq '$' and $i < $#t) { } 2 674 676
elsif ($t eq '^' and $i > 0 and $t[$i - 1] ne '[') { } 0 674 674
Condition100%3/3
defined $delim and $t eq "\\$delim"
!ll&&!rl&&r
916014
MC/DC100%2/2
defined $delim and $t eq "\\$delim"
defined $delim $t eq "\\$delim"
Truth table100%3/3
A and B
A= defined $delimB= $t eq "\\$delim"
ABresult
0X0
100
111
2550 7 elsif ( $t =~ /\A\\([(){}|+?])\z/ ) { $out .= $1 }
2551 9 elsif ( $t =~ /\A[(){}|+?]\z/ ) { $out .= "\\$t" }
2552 2 ▶ elsif ( $t eq '$' && $i < $#t ) { $out .= '\$' } # $ nur am Ende ein Anker
Condition100%3/3
$t eq "\$" and $i < $#t
!ll&&!rl&&r
658162
MC/DC100%2/2
$t eq "\$" and $i < $#t
$t eq "\$" $i < $#t
Truth table100%3/3
A and B
A= $t eq "\$"B= $i < $#t
ABresult
0X0
100
111
2553 0 ▶ elsif ( $t eq '^' && $i > 0 && $t[ $i - 1 ] ne '[' ) { $out .= '\^' } # ^ nur am Anfang
Condition50%3/6
$t eq "^" and $i > 0 and $t[$i - 1] ne "["
!ll&&!rl&&r
67400
$t eq "^" and $i > 0
!ll&&!rl&&r
654200
MC/DC0%0/3
$t eq "^" and $i > 0 and $t[$i - 1] ne "["
$t eq "^" $i > 0 $t[$i - 1] ne "["
Truth table50%2/4
A and B and C
A= $t eq "^"B= $i > 0C= $t[$i - 1] ne "["
ABCresult
0XX0
10X0
1100
1111
2554 674 else { $out .= $t }
2555 }
2556 71 return $out;
2557 }
2558  
2559 74 ▶sub _sed_apply {
Subroutine _sed_apply: called CC=31 SCAR=34.4
2560 74 my ( $cmds, $t, $quiet ) = @_;
2561 74 my $nl = $t =~ /\n\z/;
2562 74 my @lines = split /\n/, $t, -1;
2563 74 ▶ pop @lines if $nl;
Branch: 1 branch
BranchTrueFalseTotal
if $nl 62 12 74
2564 74 my @out;
2565 my %in; # offene Bereiche je Befehl
2566 # GNU: 0,/re/ — der Bereich ist von Anfang an offen und endet beim ersten Treffer
2567 74 ▶ $in{$_} = 1 for grep { my $c = $cmds->[$_]; defined $c->{a1} && !ref $c->{a1} && $c->{a1} eq '0' && ref $c->{a2} } 0 .. $#$cmds;
Condition88%8/9
defined $$c{'a1'} && !ref($$c{'a1'}) && $$c{'a1'} eq '0' && ref $$c{'a2'}
!ll&&!rl&&r
8002
defined $$c{"a1"} and not ref $$c{"a1"} and $$c{"a1"} eq 0
!ll&&!rl&&r
65152
defined $$c{"a1"} and not ref $$c{"a1"}
!ll&&!rl&&r
541117
MC/DC75%3/4
defined $$c{'a1'} && !ref($$c{'a1'}) && $$c{'a1'} eq '0' && ref $$c{'a2'}
defined $$c{"a1"} not ref $$c{"a1"} $$c{"a1"} eq 0 ref $$c{'a2'}
Truth table80%4/5
A and not(B) and C && D
A= defined $$c{"a1"}B= not ref $$c{"a1"}C= $$c{"a1"} eq 0D= ref $$c{'a2'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2568 157 ▶ my $hit = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
2569 157 my ( $a, $i, $line ) = @_;
2570 157 ▶ return ref $a ? $line =~ $a : $a eq '$' ? $i == @lines : $i == $a;
Branch: 2 branches
BranchTrueFalseTotal
ref $a ? : 86 71 157
$a eq '$' ? : 24 47 71
2571 74 };
2572 74 for my $i ( 1 .. @lines ) {
2573 423 my $ps = $lines[ $i - 1 ];
2574 423 my ( $deleted, @after );
2575 423 for my $n ( 0 .. $#$cmds ) {
2576 469 my $c = $cmds->[$n];
2577 469 my $m;
2578 469 ▶ if ( !defined $c->{a1} ) { $m = 1 }
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $$c{'a1'}) { } 312 157 469
elsif (not defined $$c{'a2'}) { } 119 38 157
elsif ($in{$n}) { } 9 29 38
elsif (&$hit($$c{'a1'}, $i, $ps)) { } 8 21 29
2579 119 elsif ( !defined $c->{a2} ) { $m = $hit->( $c->{a1}, $i, $ps ) }
2580 elsif ( $in{$n} ) {
2581 9 $m = 1;
2582 9 ▶ delete $in{$n} if $hit->( $c->{a2}, $i, $ps ) || !ref $c->{a2} && $c->{a2} ne '$' && $i >= $c->{a2};
Branch: 1 branch
BranchTrueFalseTotal
if &$hit($$c{"a2"}, $i, $ps) or not ref $$c{"a2"} and $$c{"a2"} ne "\$" and $i >= $$c{"a2"} 7 2 9
Condition55%5/9
&$hit($$c{"a2"}, $i, $ps) or not ref $$c{"a2"} and $$c{"a2"} ne "\$" and $i >= $$c{"a2"}
l!l&&r!l&&!r
702
not ref $$c{"a2"} and $$c{"a2"} ne "\$" and $i >= $$c{"a2"}
!ll&&!rl&&r
200
not ref $$c{"a2"} and $$c{"a2"} ne "\$"
!ll&&!rl&&r
110
MC/DC25%1/4
&$hit($$c{"a2"}, $i, $ps) or not ref $$c{"a2"} and $$c{"a2"} ne "\$" and $i >= $$c{"a2"}
&$hit($$c{"a2"}, $i, $ps) not ref $$c{"a2"} $$c{"a2"} ne "\$" $i >= $$c{"a2"}
Truth table60%3/5
A or not(B) and C and D
A= &$hit($$c{"a2"}, $i, $ps)B= not ref $$c{"a2"}C= $$c{"a2"} ne "\$"D= $i >= $$c{"a2"}
ABCDresult
1XXX1
01111
00XX0
010X0
01100
2583 }
2584 elsif ( $hit->( $c->{a1}, $i, $ps ) ) {
2585 8 $m = 1;
2586 8 ▶ $in{$n} = 1 unless !ref $c->{a2} && $c->{a2} ne '$' && $c->{a2} <= $i;
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $$c{"a2"} and $$c{"a2"} ne "\$" and $$c{"a2"} <= $i 7 1 8
Condition100%6/6
not ref $$c{"a2"} and $$c{"a2"} ne "\$" and $$c{"a2"} <= $i
!ll&&!rl&&r
521
not ref $$c{"a2"} and $$c{"a2"} ne "\$"
!ll&&!rl&&r
143
MC/DC100%3/3
not ref $$c{"a2"} and $$c{"a2"} ne "\$" and $$c{"a2"} <= $i
not ref $$c{"a2"} $$c{"a2"} ne "\$" $$c{"a2"} <= $i
Truth table100%4/4
not(A) and B and C
A= not ref $$c{"a2"}B= $$c{"a2"} ne "\$"C= $$c{"a2"} <= $i
ABCresult
0XX0
10X0
1100
1111
2587 }
2588 469 ▶ $m = !$m if $c->{neg};
Branch: 1 branch
BranchTrueFalseTotal
if $$c{"neg"} 3 466 469
2589 469 ▶ next unless $m;
Branch: 1 branch
BranchTrueFalseTotal
unless $m 122 347 469
2590 347 ▶ if ( $c->{op} eq 'd' ) { $deleted = 1; last }
Branch: 5 branches
BranchTrueFalseTotal
if ($$c{'op'} eq 'd') { } 12 335 347
elsif ($$c{'op'} eq 'p') { } 8 327 335
elsif ($$c{'op'} eq 'i') { } 2 325 327
elsif ($$c{'op'} eq 'a') { } 4 321 325
elsif ($$c{'op'} eq 'c') { } 1 320 321
2591 8 elsif ( $c->{op} eq 'p' ) { push @out, $ps }
2592 2 elsif ( $c->{op} eq 'i' ) { push @out, $c->{text} }
2593 4 elsif ( $c->{op} eq 'a' ) { push @after, $c->{text} }
2594 1 elsif ( $c->{op} eq 'c' ) { push @out, $c->{text}; $deleted = 1; last }
2595 else {
2596 320 my $re = $c->{re};
2597 320 ▶ if ( $c->{global} ) { $ps =~ s/$re/_expand($c->{to})/ge }
Branch: 1 branch
BranchTrueFalseTotal
if ($$c{'global'}) { } 1 319 320
2598 319 else { $ps =~ s/$re/_expand($c->{to})/e }
2599 }
2600 }
2601 423 ▶ push @out, $ps unless $deleted || $quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $deleted or $quiet 396 27 423
Condition100%3/3
$deleted or $quiet
l!l&&r!l&&!r
1314396
MC/DC100%2/2
$deleted or $quiet
$deleted $quiet
Truth table100%3/3
A or B
A= $deletedB= $quiet
ABresult
1X1
011
000
2602 423 push @out, @after;
2603 }
2604 74 ▶ return join( "\n", @out ) . ( @out && $nl ? "\n" : '' );
Branch: 1 branch
BranchTrueFalseTotal
@out && $nl ? : 62 12 74
Condition66%2/3
@out and $nl
!ll&&!rl&&r
01262
MC/DC50%1/2
@out and $nl
@out $nl
Truth table66%2/3
A and B
A= @outB= $nl
ABresult
0X0
100
111
2605 }
2606  
2607 # Ersatztext einer sed-Ersetzung: \1 .. \9 und & aus dem letzten Treffer.
2608 62 ▶sub _expand {
Subroutine _expand: called CC=7 SCAR=19.6
2609 62 my ($to) = @_;
2610 62 my $all = $&;
2611 62 my @c;
2612 {
2613 82 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2614 62 @c = map { ${$_} } 1 .. 9;
2615 }
2616 62 my $r = $to;
2617 62 ▶ $r =~ s/\\(\d)|(\\&)|(&)|\\([nt])|\\(.)/defined $1 ? ( $c[ $1 - 1 ] \/\/ '' ) : defined $2 ? '&' : defined $3 ? $all : defined $4 ? ( $4 eq 'n' ? "\n" : "\t" ) : $5/ges;
Branch: 5 branches
BranchTrueFalseTotal
defined $1 ? : 7 8 15
defined $2 ? : 0 8 8
defined $3 ? : 0 8 8
defined $4 ? : 6 2 8
$4 eq 'n' ? : 4 2 6
Condition50%1/2
$c[$1 - 1] // ""
l!l
70
MC/DC0%0/1
$c[$1 - 1] // ""
$c[$1 - 1]
Truth table50%1/2
A
A= $c[$1 - 1]
Aresult
11
00
2618 62 return $r;
2619 }
2620  
2621 313 ▶sub _echo {
Subroutine _echo: called CC=4 SCAR=13.9
2622 313 my ( $dev, $av ) = @_;
2623 313 my @a = @$av;
2624 313 my $n = 0;
2625 313 ▶ while ( @a && $a[0] =~ /\A-[neE]+\z/ ) { $n = 1 if $a[0] =~ /n/; shift @a }
Branch: 2 branches
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-[neE]+\z/) 1 313 314
if $a[0] =~ /n/ 1 0 1
Condition100%3/3
@a and $a[0] =~ /\A-[neE]+\z/
!ll&&!rl&&r
103031
MC/DC100%2/2
@a and $a[0] =~ /\A-[neE]+\z/
@a $a[0] =~ /\A-[neE]+\z/
Truth table100%3/3
A and B
A= @aB= $a[0] =~ /\A-[neE]+\z/
ABresult
0X0
100
111
2626 313 return ( join( ' ', @a ), 1 );
2627 }
2628  
2629 # Bytes, ueber die eine Pruefsumme rechnet: der Inhalt. Hat der Zustand keinen (Archiv
2630 # mit tar-Mitgliedern, nur eine Groesse), stehen die Daten des Eintrags ohne Eigentuemer,
2631 # Rechte und Zeiten dafuer -- fest, gleich fuer eine Kopie, verschieden fuer anderen Inhalt.
2632 # Nur eine leere Datei hat den Hash der leeren Eingabe.
2633 82 my %ENTRY_META = map { $_ => 1 } qw( owner group mode mtime atime ctime open_by uid gid );
2634 82 my $DIGEST_JSON = JSON::MaybeXS->new( canonical => 1, utf8 => 1 );
2635  
2636 12 ▶sub _digest_bytes {
Subroutine _digest_bytes: called CC=7 SCAR=21.8
2637 12 my ( $e, $text ) = @_;
2638 12 require Encode;
2639 12 ▶ return Encode::encode( 'UTF-8', $text ) if defined $text;
Branch: 1 branch
BranchTrueFalseTotal
if defined $text 7 5 12
2640 5 ▶ return '' unless ref $e eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" 0 5 5
2641 5 ▶ my %d = map { $_ => $e->{$_} } grep { !$ENTRY_META{$_} && !/\A_/ } keys %$e;
Condition33%1/3
$ENTRY_META{$_} || /\A_/
l!l&&r!l&&!r
0010
MC/DC0%0/2
$ENTRY_META{$_} || /\A_/
$ENTRY_META{$_} /\A_/
Truth table33%1/3
A || B
A= $ENTRY_META{$_}B= /\A_/
ABresult
1X1
011
000
2642 5 ▶ return '' if !grep { $_ ne 'size' } keys %d and ( $d{size} // 0 ) =~ /\A0*(?:[.,]0*)?[KMGTP]?i?B?\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if not grep({$_ ne "size";} keys %d) and ($d{"size"} // 0) =~ /\A0*(?:[.,]0*)?[KMGTP]?i?B?\z/i 0 5 5
Condition20%1/5
not grep({$_ ne "size";} keys %d) and ($d{"size"} // 0) =~ /\A0*(?:[.,]0*)?[KMGTP]?i?B?\z/i
!ll&&!rl&&r
500
$d{"size"} // 0
l!l
00
MC/DC0%0/2
not grep({$_ ne "size";} keys %d) and ($d{"size"} // 0) =~ /\A0*(?:[.,]0*)?[KMGTP]?i?B?\z/i
not grep({$_ ne "size";} keys %d) $d{"size"}
Truth table33%1/3
not(A) and B
A= not grep({$_ ne "size";} keys %d)B= $d{"size"}
ABresult
0X0
100
111
2643 5 return "holmgang-sim-entry\0" . $DIGEST_JSON->encode( \%d );
2644 }
2645  
2646 # md5sum datei … bzw. aus der Eingabe; ohne Inhalt im Zustand siehe _digest_bytes
2647 9 ▶sub _md5sum {
Subroutine _md5sum: called CC=10 SCAR=24.5
2648 9 my ( $dev, $av, $ctx, $stdin ) = @_;
2649 9 require Digest::MD5;
2650 9 require Encode;
2651 0 ▶ my $md5 = sub { Digest::MD5::md5_hex( Encode::encode( 'UTF-8', $_[0] ) ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
2652 9 my @f = grep { !/\A-/ } @$av;
2653 0 ▶ if ( grep { /\A-(?:c|-check)\z/ } @$av ) { push @GAPS, join( ' ', 'md5sum', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {/\A-(?:c|-check)\z/;} @$av) 0 9 9
2654 9 ▶ return ( $md5->( $stdin // '' ) . ' -', 1 ) unless @f;
Branch: 1 branch
BranchTrueFalseTotal
unless @f 0 9 9
Condition0%0/2
$stdin // ""
l!l
00
MC/DC0%0/1
$stdin // ""
$stdin
Truth table0%0/2
A
A= $stdin
Aresult
11
00
2655 9 my ( @l, $ok ) = ();
2656 9 $ok = 1;
2657 9 for my $p (@f) {
2658 10 my $e = _file_entry( $dev, _absp($p) );
2659 10 ▶ if ( !$e ) { push @l, "md5sum: $p: " . ( _is_dir( $dev, _absp($p) ) ? 'Is a directory' : 'No such file or directory' ); $ok = 0; next }
Branch: 2 branches
BranchTrueFalseTotal
unless ($e) 1 9 10
_is_dir($dev, _absp($p)) ? : 0 1 1
2660 9 ▶ my $t = defined $e->{content} || defined $e->{link} ? _file_text( $dev, _absp($p) ) // '' : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $$e{'content'} || defined $$e{'link'} ? : 7 2 9
Condition60%3/5
defined $$e{"content"} or defined $$e{"link"}
l!l&&r!l&&!r
702
_file_text($dev, _absp($p)) // ""
l!l
70
MC/DC50%1/2
defined $$e{"content"} or defined $$e{"link"}
defined $$e{"content"} defined $$e{"link"}
MC/DC0%0/1
_file_text($dev, _absp($p)) // ""
_file_text($dev, _absp($p))
Truth table66%2/3
A or B
A= defined $$e{"content"}B= defined $$e{"link"}
ABresult
1X1
011
000
Truth table50%1/2
A
A= _file_text($dev, _absp($p))
Aresult
11
00
2661 9 push @l, Digest::MD5::md5_hex( _digest_bytes( $e, $t ) ) . " $p";
2662 }
2663 9 return ( join( "\n", @l ), $ok );
2664 }
2665  
2666 # printf wie bash: Escapes, %s %b %c %d %i %o %u %x %X %e %f %g (Breite, Genauigkeit, *),
2667 # 'A als Zeichencode; mehr Argumente als Umwandlungen: das Format wiederholt sich.
2668 45 ▶sub _printf {
Subroutine _printf: called CC=29 SCAR=40.5
2669 45 my ( $dev, $av ) = @_;
2670 45 my @a = @$av;
2671 45 ▶ shift @a if @a && $a[0] eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if @a and $a[0] eq "--" 0 45 45
Condition33%1/3
@a and $a[0] eq "--"
!ll&&!rl&&r
0450
MC/DC0%0/2
@a and $a[0] eq "--"
@a $a[0] eq "--"
Truth table33%1/3
A and B
A= @aB= $a[0] eq "--"
ABresult
0X0
100
111
2672 0 ▶ if ( @a && $a[0] eq '-v' ) { push @GAPS, join( ' ', 'printf', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] eq "-v") 0 45 45
Condition33%1/3
@a and $a[0] eq "-v"
!ll&&!rl&&r
0450
MC/DC0%0/2
@a and $a[0] eq "-v"
@a $a[0] eq "-v"
Truth table33%1/3
A and B
A= @aB= $a[0] eq "-v"
ABresult
0X0
100
111
2673 45 my $fmt = shift @a;
2674 45 ▶ return ( 'printf: usage: printf [-v var] format [arguments]', 0 ) unless defined $fmt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fmt 0 45 45
2675 45 my %e = ( n => "\n", t => "\t", r => "\r", '\\' => '\\', a => "\a", b => "\b", f => "\f", v => "\x0b", '"' => '"', "'" => "'", e => "\e" );
2676 47 ▶ my $esc = sub {
Subroutine __ANON__: called CC=4 SCAR=14.9
2677 47 my ($s) = @_;
2678 47 ▶ $s =~ s/\\(?:0?([0-7]{1,3})|x([0-9a-fA-F]{1,2})|(.))/defined $1 ? chr( oct $1 ) : defined $2 ? chr( hex $2 ) : $e{$3} \/\/ "\\$3"/ges;
Branch: 2 branches
BranchTrueFalseTotal
defined $1 ? : 0 85 85
defined $2 ? : 0 85 85
Condition50%1/2
$e{$3} // "\\$3"
l!l
850
MC/DC0%0/1
$e{$3} // "\\$3"
$e{$3}
Truth table50%1/2
A
A= $e{$3}
Aresult
11
00
2679 47 return $s;
2680 45 };
2681 45 my ( @err, $ok ) = ();
2682 45 $ok = 1;
2683 4 ▶ my $num = sub {
Subroutine __ANON__: called CC=9 SCAR=23.6
2684 4 my ( $x, $float ) = @_;
2685 4 ▶ return 0 if !defined $x || $x eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $x or $x eq "" 0 4 4
Condition33%1/3
not defined $x or $x eq ""
l!l&&r!l&&!r
004
MC/DC0%0/2
not defined $x or $x eq ""
not defined $x $x eq ""
Truth table33%1/3
not(A) or B
A= not defined $xB= $x eq ""
ABresult
1X1
011
000
2686 4 ▶ return ord substr( $x, 1 ) if $x =~ /\A['"]./s;
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /\A['"]./s 1 3 4
2687 3 ▶ return 0 + $x if $float ? $x =~ /\A\s*[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?\s*\z/ : $x =~ /\A\s*[-+]?\d+\s*\z/;
Branch: 2 branches
BranchTrueFalseTotal
if $float ? $x =~ /\A\s*[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?\s*\z/ : $x =~ /\A\s*[-+]?\d+\s*\z/ 2 1 3
$float ? : 1 2 3
2688 1 ▶ return hex $x if !$float && $x =~ /\A0[xX][0-9a-fA-F]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if not $float and $x =~ /\A0[xX][0-9a-fA-F]+\z/ 0 1 1
Condition33%1/3
not $float and $x =~ /\A0[xX][0-9a-fA-F]+\z/
!ll&&!rl&&r
010
MC/DC0%0/2
not $float and $x =~ /\A0[xX][0-9a-fA-F]+\z/
not $float $x =~ /\A0[xX][0-9a-fA-F]+\z/
Truth table33%1/3
not(A) and B
A= not $floatB= $x =~ /\A0[xX][0-9a-fA-F]+\z/
ABresult
0X0
100
111
2689 1 push @err, "bash: printf: $x: invalid number";
2690 1 $ok = 0;
2691 1 ▶ return $x =~ /\A\s*([-+]?\d+(?:\.\d+)?)/ ? 0 + $1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$x =~ /\A\s*([-+]?\d+(?:\.\d+)?)/ ? : 0 1 1
2692 45 };
2693 45 my $out = '';
2694 45 my $conv = qr/%(%|([-+ #0]*)(\*|\d+)?(?:\.(\*|\d+))?([diouxXeEfFgGcsbq]))/;
2695 45 ▶ my $has = $fmt =~ $conv && $fmt =~ /%[^%]/;
Condition66%2/3
$fmt =~ /$conv/ && $fmt =~ /%[^%]/
!ll&&!rl&&r
4104
MC/DC50%1/2
$fmt =~ /$conv/ && $fmt =~ /%[^%]/
$fmt =~ /$conv/ $fmt =~ /%[^%]/
Truth table66%2/3
A && B
A= $fmt =~ /$conv/B= $fmt =~ /%[^%]/
ABresult
0X0
100
111
2696 45 while (1) {
2697 47 my $used = 0;
2698 47 my $piece = $esc->($fmt);
2699 47 $piece =~ s{$conv}{
2700 10 ▶ my ( $all, $fl, $w, $p, $c ) = ( $1, $2 // '', $3, $4, $5 );
Condition50%1/2
$2 // ""
l!l
100
MC/DC0%0/1
$2 // ""
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
2701 0 ▶ if ( $all eq '%' ) { '%' }
Branch: 1 branch
BranchTrueFalseTotal
if ($all eq '%') { } 0 10 10
2702 else {
2703 0 ▶ $w = do { $used++; shift(@a) // 0 } if defined $w && $w eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if defined $w and $w eq "*" 0 10 10
Condition40%2/5
defined $w and $w eq "*"
!ll&&!rl&&r
730
shift @a // 0
l!l
00
MC/DC0%0/2
defined $w and $w eq "*"
defined $w $w eq "*"
MC/DC0%0/1
shift @a // 0
shift @a
Truth table66%2/3
A and B
A= defined $wB= $w eq "*"
ABresult
0X0
100
111
Truth table0%0/2
A
A= shift @a
Aresult
11
00
2704 0 ▶ $p = do { $used++; shift(@a) // 0 } if defined $p && $p eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if defined $p and $p eq "*" 0 10 10
Condition40%2/5
defined $p and $p eq "*"
!ll&&!rl&&r
910
shift @a // 0
l!l
00
MC/DC0%0/2
defined $p and $p eq "*"
defined $p $p eq "*"
MC/DC0%0/1
shift @a // 0
shift @a
Truth table66%2/3
A and B
A= defined $pB= $p eq "*"
ABresult
0X0
100
111
Truth table0%0/2
A
A= shift @a
Aresult
11
00
2705 10 ▶ my $spec = '%' . $fl . ( $w // '' ) . ( defined $p ? ".$p" : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $p ? : 1 9 10
Condition100%2/2
$w // ""
l!l
37
MC/DC100%1/1
$w // ""
$w
Truth table100%2/2
A
A= $w
Aresult
11
00
2706 10 my $arg = shift @a;
2707 10 $used++;
2708 0 ▶ $c eq 'q' ? do { push @GAPS, join( ' ', 'printf', @$av ); '' }
Branch: 6 branches
BranchTrueFalseTotal
$c eq 'q' ? : 0 10 10
$c eq 's' ? : 5 5 10
$c eq 'b' ? : 0 5 5
$c eq 'c' ? : 1 4 5
$c =~ /[eEfFgG]/ ? : 1 3 4
$c eq 'i' ? : 0 3 3
Condition33%2/6
$arg // ""
l!l
50
$arg // ""
l!l
00
$arg // ""
l!l
10
MC/DC0%0/1
$arg // ""
$arg
MC/DC0%0/1
$arg // ""
$arg
MC/DC0%0/1
$arg // ""
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
Truth table0%0/2
A
A= $arg
Aresult
11
00
Truth table50%1/2
A
A= $arg
Aresult
11
00
2709 : $c eq 's' ? sprintf( "${spec}s", $arg // '' )
2710 : $c eq 'b' ? sprintf( "${spec}s", $esc->( $arg // '' ) )
2711 : $c eq 'c' ? sprintf( "${spec}s", substr( $arg // '', 0, 1 ) )
2712 : $c =~ /[eEfFgG]/ ? sprintf( "$spec$c", $num->( $arg, 1 ) )
2713 : sprintf( $spec . ( $c eq 'i' ? 'd' : $c ), int $num->($arg) );
2714 }
2715 }ge;
2716 47 $out .= $piece;
2717 47 ▶ last unless $has && $used && @a;
Branch: 1 branch
BranchTrueFalseTotal
unless $has and $used and @a 45 2 47
Condition83%5/6
$has and $used and @a
!ll&&!rl&&r
4142
$has and $used
!ll&&!rl&&r
4106
MC/DC66%2/3
$has and $used and @a
$has $used @a
Truth table75%3/4
A and B and C
A= $hasB= $usedC= @a
ABCresult
0XX0
10X0
1100
1111
2718 }
2719 45 $out =~ s/\n\z//;
2720 45 return ( join( "\n", grep { length } $out, @err ), $ok );
2721 }
2722  
2723 # --- ip --------------------------------------------------------------------------------
2724  
2725 82 ▶sub _abbrev {
Subroutine _abbrev: called CC=4 SCAR=14.3
2726 82 my ( $w, @full ) = @_;
2727 82 ▶ return undef unless defined $w;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $w 0 82 82
2728 82 ▶ for my $f (@full) { return $f if index( $f, $w ) == 0 }
Branch: 1 branch
BranchTrueFalseTotal
if index($f, $w) == 0 82 71 153
2729 0 return undef;
2730 }
2731  
2732 40 ▶sub _ip {
Subroutine _ip: called CC=28 SCAR=39.4
2733 40 my ( $dev, $av ) = @_;
2734 40 my @a = @$av;
2735 40 my %o;
2736 40 ▶ while ( @a && $a[0] =~ /\A-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-/) 4 40 44
Condition66%2/3
@a and $a[0] =~ /\A-/
!ll&&!rl&&r
0404
MC/DC50%1/2
@a and $a[0] =~ /\A-/
@a $a[0] =~ /\A-/
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A-/
ABresult
0X0
100
111
2737 4 my $x = shift @a;
2738 4 ▶ $o{4} = 1 if $x eq '-4';
Branch: 1 branch
BranchTrueFalseTotal
if $x eq -4 0 4 4
2739 4 ▶ $o{6} = 1 if $x eq '-6';
Branch: 1 branch
BranchTrueFalseTotal
if $x eq -6 1 3 4
2740 4 ▶ $o{br} = 1 if $x =~ /\A-br/;
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /\A-br/ 1 3 4
2741 4 ▶ $o{j} = 1 if $x eq '-j' || $x eq '-json' || $x eq '--json';
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "-j" or $x eq "-json" or $x eq "--json" 2 2 4
Condition66%4/6
$x eq "-j" or $x eq "-json" or $x eq "--json"
l!l&&r!l&&!r
202
$x eq "-j" or $x eq "-json"
l!l&&r!l&&!r
202
MC/DC33%1/3
$x eq "-j" or $x eq "-json" or $x eq "--json"
$x eq "-j" $x eq "-json" $x eq "--json"
Truth table50%2/4
A or B or C
A= $x eq "-j"B= $x eq "-json"C= $x eq "--json"
ABCresult
1XX1
01X1
0011
0000
2742 4 ▶ if ( $x eq '-c' || $x =~ /\A-col/ ) { }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "-c" or $x =~ /\A-col/) 0 4 4
Condition33%1/3
$x eq "-c" or $x =~ /\A-col/
l!l&&r!l&&!r
004
MC/DC0%0/2
$x eq "-c" or $x =~ /\A-col/
$x eq "-c" $x =~ /\A-col/
Truth table33%1/3
A or B
A= $x eq "-c"B= $x =~ /\A-col/
ABresult
1X1
011
000
2743 }
2744 40 my $obj = shift @a;
2745 40 ▶ return ( "Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }\nwhere OBJECT := { address | link | neigh | route | rule | … }", 0 ) unless defined $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj 0 40 40
2746 40 ▶ my $o = _abbrev( $obj, qw( route rule address link neighbour neigh ) )
Branch: 4 branches
BranchTrueFalseTotal
$obj eq 'r' ? : 0 0 0
$obj eq 'a' ? : 0 0 0
$obj eq 'l' ? : 0 0 0
$obj eq 'n' ? : 0 0 0
Condition50%1/2
_abbrev($obj, ("route", "rule", "address", "link", "neighbour", "neigh")) // ($obj eq "r" ? "route" : ($obj eq "a" ? "address" : ($obj eq "l" ? "link" : ($obj eq "n" ? "neigh" : undef))))
l!l
400
MC/DC0%0/1
_abbrev($obj, ("route", "rule", "address", "link", "neighbour", "neigh")) // ($obj eq "r" ? "route" : ($obj eq "a" ? "address" : ($obj eq "l" ? "link" : ($obj eq "n" ? "neigh" : undef))))
_abbrev($obj, ("route", "rule", "address", "link", "neighbour", "neigh"))
Truth table50%1/2
A
A= _abbrev($obj, ("route", "rule", "address", "link", "neighbour", "neigh"))
Aresult
11
00
2747 // ( $obj eq 'r' ? 'route' : $obj eq 'a' ? 'address' : $obj eq 'l' ? 'link' : $obj eq 'n' ? 'neigh' : undef );
2748 40 ▶ $o = 'address' if $obj eq 'addr';
Branch: 1 branch
BranchTrueFalseTotal
if $obj eq "addr" 2 38 40
2749 40 ▶ return ( qq{Object "$obj" is unknown, try "ip help".}, 0 ) unless $o;
Branch: 1 branch
BranchTrueFalseTotal
unless $o 0 40 40
2750 40 ▶ if ( $o{j} && ( !@a || $a[0] =~ /\A(?:show|list|ls)\z/ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"j"} and !@a || $a[0] =~ /\A(?:show|list|ls)\z/) 2 38 40
Condition66%4/6
$o{"j"} and !@a || $a[0] =~ /\A(?:show|list|ls)\z/
!ll&&!rl&&r
3802
not @a or $a[0] =~ /\A(?:show|list|ls)\z/
l!l&&r!l&&!r
110
MC/DC33%1/3
$o{"j"} and !@a || $a[0] =~ /\A(?:show|list|ls)\z/
$o{"j"} not @a $a[0] =~ /\A(?:show|list|ls)\z/
Truth table75%3/4
A and not(B) or C
A= $o{"j"}B= not @aC= $a[0] =~ /\A(?:show|list|ls)\z/
ABCresult
0XX0
1000
11X1
1011
2751 2 ▶ my $j = _ip_json( $dev, $o, @a ) // return ( 'Error: JSON fuer diese Ausgabe nicht vorhanden', 0 );
Condition50%1/2
_ip_json($dev, $o, @a) // (return "Error: JSON fuer diese Ausgabe nicht vorhanden", 0)
l!l
20
MC/DC0%0/1
_ip_json($dev, $o, @a) // (return "Error: JSON fuer diese Ausgabe nicht vorhanden", 0)
_ip_json($dev, $o, @a)
Truth table50%1/2
A
A= _ip_json($dev, $o, @a)
Aresult
11
00
2752 2 return ( $j, 1 );
2753 }
2754 38 ▶ return _ip_route( $dev, \@a, \%o ) if $o eq 'route';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "route" 30 8 38
2755 8 ▶ return _ip_rule( $dev, \@a ) if $o eq 'rule';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "rule" 2 6 8
2756 6 ▶ return _ip_addr( $dev, \@a, \%o ) if $o eq 'address';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "address" 2 4 6
2757 4 ▶ return _ip_link( $dev, \@a, \%o ) if $o eq 'link';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "link" 4 0 4
2758 0 ▶ return ( join( "\n", @{ $dev->{neigh} || [] } ), 1 );
Condition0%0/2
$$dev{'neigh'} || []
l!l
00
MC/DC0%0/1
$$dev{'neigh'} || []
$$dev{'neigh'}
Truth table0%0/2
A
A= $$dev{'neigh'}
Aresult
11
00
2759 }
2760  
2761 # ip -j: Routen, Adressen, Schnittstellen als JSON wie iproute2
2762 2 ▶sub _ip_json {
Subroutine _ip_json: called CC=22 SCAR=34.4
2763 2 my ( $dev, $o, @a ) = @_;
2764 2 ▶ shift @a if @a && $a[0] =~ /\A(?:show|list|ls)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if @a and $a[0] =~ /\A(?:show|list|ls)\z/ 1 1 2
Condition66%2/3
@a and $a[0] =~ /\A(?:show|list|ls)\z/
!ll&&!rl&&r
101
MC/DC50%1/2
@a and $a[0] =~ /\A(?:show|list|ls)\z/
@a $a[0] =~ /\A(?:show|list|ls)\z/
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A(?:show|list|ls)\z/
ABresult
0X0
100
111
2765 2 require JSON::MaybeXS;
2766 2 my $J = JSON::MaybeXS->new( canonical => 1, utf8 => 0 );
2767 2 ▶ if ( $o eq 'route' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "route") 1 1 2
2768 1 my $table = 'main';
2769 0 ▶ for my $i ( 0 .. $#a - 1 ) { $table = $a[ $i + 1 ] if $a[$i] eq 'table' }
Branch: 1 branch
BranchTrueFalseTotal
if $a[$i] eq "table" 0 0 0
2770 my @r = map {
2771 4 my $r = $_;
2772 4 ▶ +{ dst => $r->{dst}, ( map { defined $r->{$_} ? ( ( $_ eq 'via' ? 'gateway' : $_ eq 'src' ? 'prefsrc' : $_ ) => $r->{$_} ) : () }
Branch: 3 branches
BranchTrueFalseTotal
defined $$r{$_} ? : 14 10 24
$_ eq 'via' ? : 1 13 14
$_ eq 'src' ? : 3 10 13
2773 qw( via dev proto scope src metric ) ), flags => [] };
2774 1 ▶ } grep { $table eq 'all' || _table_of($_) eq $table } @{ $dev->{routes} || [] };
Condition40%2/5
$table eq 'all' || _table_of($_) eq $table
l!l&&r!l&&!r
040
$$dev{'routes'} || []
l!l
10
MC/DC0%0/2
$table eq 'all' || _table_of($_) eq $table
$table eq 'all' _table_of($_) eq $table
MC/DC0%0/1
$$dev{'routes'} || []
$$dev{'routes'}
Truth table33%1/3
A || B
A= $table eq 'all'B= _table_of($_) eq $table
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$dev{'routes'}
Aresult
11
00
2775 1 return $J->encode( \@r );
2776 }
2777 1 ▶ if ( $o eq 'address' || $o eq 'link' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "address" or $o eq "link") 1 0 1
Condition33%1/3
$o eq "address" or $o eq "link"
l!l&&r!l&&!r
100
MC/DC0%0/2
$o eq "address" or $o eq "link"
$o eq "address" $o eq "link"
Truth table33%1/3
A or B
A= $o eq "address"B= $o eq "link"
ABresult
1X1
011
000
2778 1 my $idx = 0;
2779 1 my @l;
2780 1 for my $n ( _ifaces($dev) ) {
2781 4 $idx++;
2782 4 my $i = _iface( $dev, $n );
2783 my %e = ( ifindex => $idx, ifname => $n, mtu => 0 + ( $i->{mtu} // 1500 ), operstate => $i->{state} // 'UP',
2784 4 ▶ flags => [ ( $i->{state} // 'UP' ) eq 'DOWN' ? qw( BROADCAST MULTICAST ) : qw( BROADCAST MULTICAST UP LOWER_UP ) ] );
Branch: 1 branch
BranchTrueFalseTotal
($$i{'state'} // 'UP') eq 'DOWN' ? : 0 4 4
Condition50%3/6
$$i{"mtu"} // 1500
l!l
40
$$i{"state"} // "UP"
l!l
40
$$i{"state"} // "UP"
l!l
40
MC/DC0%0/1
$$i{"mtu"} // 1500
$$i{"mtu"}
MC/DC0%0/1
$$i{"state"} // "UP"
$$i{"state"}
MC/DC0%0/1
$$i{"state"} // "UP"
$$i{"state"}
Truth table50%1/2
A
A= $$i{"mtu"}
Aresult
11
00
Truth table50%1/2
A
A= $$i{"state"}
Aresult
11
00
Truth table50%1/2
A
A= $$i{"state"}
Aresult
11
00
2785 4 ▶ if ( $o eq 'address' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "address") 4 0 4
2786 $e{addr_info} = [ map {
2787 4 my ( $ip, $len ) = split m{/};
2788 4 ▶ +{ family => /:/ ? 'inet6' : 'inet', local => $ip, prefixlen => 0 + ( $len // 32 ) };
Branch: 1 branch
BranchTrueFalseTotal
/:/ ? : 0 4 4
Condition50%1/2
$len // 32
l!l
40
MC/DC0%0/1
$len // 32
$len
Truth table50%1/2
A
A= $len
Aresult
11
00
2789 4 ▶ } @{ $i->{addr} || [] } ];
Condition50%1/2
$$i{'addr'} || []
l!l
40
MC/DC0%0/1
$$i{'addr'} || []
$$i{'addr'}
Truth table50%1/2
A
A= $$i{'addr'}
Aresult
11
00
2790 }
2791 4 push @l, \%e;
2792 }
2793 1 return $J->encode( \@l );
2794 }
2795 0 return undef;
2796 }
2797  
2798 # ss: Sockets aus dem Zustand (sockets: [ Zeilen ]) unter dem Kopf von ss
2799 143 ▶sub _own_addrs { my ($dev) = @_; return map { s{/\d+\z}{}r } map { @{ $_->{addr} || [] } } values %{ $dev->{interfaces} || {} } }
Subroutine _own_addrs: called CC=3 SCAR=11.0
Condition75%3/4
$$_{'addr'} || []
l!l
1040
$$dev{'interfaces'} || {}
l!l
10439
MC/DC0%0/1
$$_{'addr'} || []
$$_{'addr'}
MC/DC100%1/1
$$dev{'interfaces'} || {}
$$dev{'interfaces'}
Truth table50%1/2
A
A= $$_{'addr'}
Aresult
11
00
Truth table100%2/2
A
A= $$dev{'interfaces'}
Aresult
11
00
2800  
2801 24 ▶sub _ss {
Subroutine _ss: called CC=41 SCAR=42.0
2802 24 my ( $dev, $av ) = @_;
2803 24 my $head = sprintf( '%-6s %-7s %-6s %-6s %-25s %-25s %s', qw( Netid State Recv-Q Send-Q ), 'Local Address:Port', 'Peer Address:Port', 'Process' );
2804 24 ▶ my @l = @{ $dev->{sockets} || [] };
Condition50%1/2
$$dev{'sockets'} || []
l!l
024
MC/DC0%0/1
$$dev{'sockets'} || []
$$dev{'sockets'}
Truth table50%1/2
A
A= $$dev{'sockets'}
Aresult
11
00
2805 # Lauscher der Datenbankdienste aus ihren laufenden Werten
2806 24 ▶ my $svc = $dev->{services} || {};
Condition50%1/2
$$dev{'services'} || {}
l!l
240
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
2807 24 ▶ if ( $dev->{redis} && ( $svc->{ $dev->{redis}{service} // 'redis-server' } || {} )->{active} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"redis"} and ($$svc{$$dev{"redis"}{"service"} // "redis-server"} || {})->{"active"}) 1 23 24
Condition57%4/7
$$dev{"redis"} and ($$svc{$$dev{"redis"}{"service"} // "redis-server"} || {})->{"active"}
!ll&&!rl&&r
2301
$$svc{$$dev{'redis'}{'service'} // 'redis-server'} || {}
l!l
10
$$dev{"redis"}{"service"} // "redis-server"
l!l
10
MC/DC50%1/2
$$dev{"redis"} and ($$svc{$$dev{"redis"}{"service"} // "redis-server"} || {})->{"active"}
$$dev{"redis"} $$svc{$$dev{'redis'}{'service'} // 'redis-server'}
MC/DC0%0/1
$$dev{"redis"}{"service"} // "redis-server"
$$dev{"redis"}{"service"}
Truth table66%2/3
A and B
A= $$dev{"redis"}B= $$svc{$$dev{'redis'}{'service'} // 'redis-server'}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$dev{"redis"}{"service"}
Aresult
11
00
2808 1 my $run = _redis()->can('_running')->($dev);
2809 1 ▶ for my $a ( map { s/\A-//r } split /\s+/, $run->{bind} // '' ) {
Condition50%1/2
$$run{"bind"} // ""
l!l
10
MC/DC0%0/1
$$run{"bind"} // ""
$$run{"bind"}
Truth table50%1/2
A
A= $$run{"bind"}
Aresult
11
00
2810 2 ▶ push @l, sprintf( '%-6s %-7s %-6s %-6s %-25s %-25s %s', 'tcp', 'LISTEN', 0, 511, ( $a =~ /:/ ? "[$a]" : $a ) . ":$run->{port}", '0.0.0.0:*',
Branch: 1 branch
BranchTrueFalseTotal
$a =~ /:/ ? : 1 1 2
2811 'users:(("redis-server",pid=811,fd=6))' );
2812 }
2813 }
2814 24 ▶ if ( $dev->{mariadb} && ( $svc->{ $dev->{mariadb}{service} // 'mariadb' } || {} )->{active} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"mariadb"} and ($$svc{$$dev{"mariadb"}{"service"} // "mariadb"} || {})->{"active"}) 0 24 24
Condition14%1/7
$$dev{"mariadb"} and ($$svc{$$dev{"mariadb"}{"service"} // "mariadb"} || {})->{"active"}
!ll&&!rl&&r
2400
$$svc{$$dev{'mariadb'}{'service'} // 'mariadb'} || {}
l!l
00
$$dev{"mariadb"}{"service"} // "mariadb"
l!l
00
MC/DC0%0/2
$$dev{"mariadb"} and ($$svc{$$dev{"mariadb"}{"service"} // "mariadb"} || {})->{"active"}
$$dev{"mariadb"} $$svc{$$dev{'mariadb'}{'service'} // 'mariadb'}
MC/DC0%0/1
$$dev{"mariadb"}{"service"} // "mariadb"
$$dev{"mariadb"}{"service"}
Truth table33%1/3
A and B
A= $$dev{"mariadb"}B= $$svc{$$dev{'mariadb'}{'service'} // 'mariadb'}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $$dev{"mariadb"}{"service"}
Aresult
11
00
2815 0 my $v = _maria()->can('_vars')->($dev);
2816 0 ▶ push @l, map { sprintf( '%-6s %-7s %-6s %-6s %-25s %-25s %s', 'tcp', 'LISTEN', 0, 80, "$_:$v->{port}", '0.0.0.0:*', 'users:(("mariadbd",pid=911,fd=21))' ) }
Condition0%0/2
$$v{"bind_address"} // "127.0.0.1"
l!l
00
MC/DC0%0/1
$$v{"bind_address"} // "127.0.0.1"
$$v{"bind_address"}
Truth table0%0/2
A
A= $$v{"bind_address"}
Aresult
11
00
2817 0 split /\s*,\s*/, $v->{bind_address} // '127.0.0.1';
2818 }
2819 # laufende Dienste mit listen bzw. nginx: dort, wo ihre Konfiguration es sagt
2820 24 for my $n ( sort keys %$svc ) {
2821 45 my $s = $svc->{$n};
2822 45 ▶ next unless ref $s eq 'HASH' && $s->{active} && ( $s->{listen} || ( $s->{exec} // $n ) eq 'nginx' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $s eq "HASH" and $$s{"active"} and $$s{"listen"} || ($$s{"exec"} // $n) eq "nginx" 35 10 45
Condition83%10/12
ref $s eq "HASH" and $$s{"active"} and $$s{"listen"} || ($$s{"exec"} // $n) eq "nginx"
!ll&&!rl&&r
33210
ref $s eq "HASH" and $$s{"active"}
!ll&&!rl&&r
0342
$$s{"listen"} or ($$s{"exec"} // $n) eq "nginx"
l!l&&r!l&&!r
6432
$$s{"exec"} // $n
l!l&&r!l&&!r
3240
MC/DC20%1/5
ref $s eq "HASH" and $$s{"active"} and $$s{"listen"} || ($$s{"exec"} // $n) eq "nginx"
ref $s eq "HASH" $$s{"active"} $$s{"listen"} $$s{"exec"} $n
Truth table66%4/6
A and B and C or D // E
A= ref $s eq "HASH"B= $$s{"active"}C= $$s{"listen"}D= $$s{"exec"}E= $n
ABCDEresult
0XXXX0
10XXX0
110000
111XX1
1101X1
110011
2823 10 ▶ my @a = $s->{_listen} ? @{ $s->{_listen} } : _svc_listen( $dev, $n, $s );
Branch: 1 branch
BranchTrueFalseTotal
$$s{'_listen'} ? : 2 8 10
2824 10 my $pid = _main_pid( $dev, $n );
2825 10 ▶ my $comm = substr( ( split ' ', $s->{exec} // $n )[0] =~ s{.*/}{}r, 0, 15 );
Condition33%1/3
$$s{"exec"} // $n
l!l&&r!l&&!r
1000
MC/DC0%0/2
$$s{"exec"} // $n
$$s{"exec"} $n
Truth table33%1/3
A // B
A= $$s{"exec"}B= $n
ABresult
1X1
011
000
2826 10 my $fd = 5;
2827 10 for my $a (@a) {
2828 14 ▶ next if grep { /\s\Q$a\E\s/ } @l;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/\s\Q$a\E\s/;} @l 0 14 14
2829 14 ▶ push @l, sprintf( '%-6s %-7s %-6s %-6s %-25s %-25s %s', 'tcp', 'LISTEN', 0, $comm eq 'nginx' ? 511 : 4096, $a,
Branch: 2 branches
BranchTrueFalseTotal
$comm eq 'nginx' ? : 8 6 14
$a =~ /\A\[/ ? : 4 10 14
2830 $a =~ /\A\[/ ? '[::]:*' : '0.0.0.0:*', qq{users:(("$comm",pid=$pid,fd=} . $fd++ . '))' );
2831 }
2832 }
2833 24 ▶ my $ssh = ( $dev->{services} || {} )->{ssh};
Condition50%1/2
$$dev{'services'} || {}
l!l
240
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
2834 # sshd: Ports aus seiner Konfiguration (Sshd), ohne sshd_config im Zustand 22
2835 24 ▶ if ( $ssh && $ssh->{active} && !grep {/:22\s/} @l ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ssh and $$ssh{"active"} and not grep({/:22\s/;} @l)) 20 4 24
Condition66%4/6
$ssh and $$ssh{"active"} and not grep({/:22\s/;} @l)
!ll&&!rl&&r
4020
$ssh and $$ssh{"active"}
!ll&&!rl&&r
4020
MC/DC33%1/3
$ssh and $$ssh{"active"} and not grep({/:22\s/;} @l)
$ssh $$ssh{"active"} not grep({/:22\s/;} @l)
Truth table50%2/4
A and B and not(C)
A= $sshB= $$ssh{"active"}C= not grep({/:22\s/;} @l)
ABCresult
0XX0
10X0
1100
1111
2836 20 ▶ my $eff = %{ $ssh->{effective} || {} } ? $ssh->{effective}
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'} eq 'HASH' && exists $$dev{'files'}{'/etc/ssh/sshd_config'} ? : 1 18 19
Condition100%5/5
$$ssh{'effective'} || {}
l!l
218
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"}
!ll&&!rl&&r
1261
MC/DC100%1/1
$$ssh{'effective'} || {}
$$ssh{'effective'}
MC/DC100%2/2
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"}
ref $$dev{"files"} eq "HASH" exists $$dev{"files"}{"/etc/ssh/sshd_config"}
Truth table100%2/2
A
A= $$ssh{'effective'}
Aresult
11
00
Truth table100%3/3
A and B
A= ref $$dev{"files"} eq "HASH"B= exists $$dev{"files"}{"/etc/ssh/sshd_config"}
ABresult
0X0
100
111
2837 20 ▶ : ( ref $dev->{files} eq 'HASH' && exists $dev->{files}{'/etc/ssh/sshd_config'}
Branch: 1 branch
BranchTrueFalseTotal
%{$$ssh{'effective'} or {};} ? : 1 19 20
2838 ? _ssh_access()->can('config_for')->( $dev, { user => "\0", from => "\0", groups => [], port => 0 } ) : {} );
2839 20 ▶ my @ports = _sshd_sim()->can('active')->($dev) || $eff->{port} ? @{ $eff->{port} || [22] } : (22);
Branch: 1 branch
BranchTrueFalseTotal
_sshd_sim()->can('active')->($dev) || $$eff{'port'} ? : 2 18 20
Condition80%4/5
_sshd_sim()->can("active")->($dev) or $$eff{"port"}
l!l&&r!l&&!r
2018
$$eff{'port'} || [22]
l!l
11
MC/DC50%1/2
_sshd_sim()->can("active")->($dev) or $$eff{"port"}
_sshd_sim()->can("active")->($dev) $$eff{"port"}
MC/DC100%1/1
$$eff{'port'} || [22]
$$eff{'port'}
Truth table66%2/3
A or B
A= _sshd_sim()->can("active")->($dev)B= $$eff{"port"}
ABresult
1X1
011
000
Truth table100%2/2
A
A= $$eff{'port'}
Aresult
11
00
2840 20 my ($pr) = grep { $_->{unit} eq 'ssh' } _procs($dev);
2841 20 ▶ my $pid = $pr ? $pr->{pid} : 701;
Branch: 1 branch
BranchTrueFalseTotal
$pr ? : 20 0 20
2842 20 for my $p (@ports) {
2843 20 push @l, sprintf( '%-6s %-7s %-6s %-6s %-25s %-25s %s', 'tcp', 'LISTEN', 0, 128, "0.0.0.0:$p", '0.0.0.0:*', qq{users:(("sshd",pid=$pid,fd=3))} ),
2844 sprintf( '%-6s %-7s %-6s %-6s %-25s %-25s %s', 'tcp', 'LISTEN', 0, 128, "[::]:$p", '[::]:*', qq{users:(("sshd",pid=$pid,fd=4))} );
2845 }
2846 }
2847 0 ▶ if ( ref $dev->{docker} eq 'HASH' ) { _part('Docker'); push @l, Langertha::Holmgang::Sim::Linux::Docker::ss_lines($dev) }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$dev{"docker"} eq "HASH") 0 24 24
2848 24 return ( join( "\n", $head, @l ), 1 );
2849 }
2850  
2851 9 ▶sub _ifaces {
Subroutine _ifaces: called CC=2 SCAR=7.0
2852 9 my ($dev) = @_;
2853 9 ▶ my $i = $dev->{interfaces} || {};
Condition50%1/2
$$dev{'interfaces'} || {}
l!l
90
MC/DC0%0/1
$$dev{'interfaces'} || {}
$$dev{'interfaces'}
Truth table50%1/2
A
A= $$dev{'interfaces'}
Aresult
11
00
2854 9 return ( 'lo', grep { $_ ne 'lo' } sort keys %$i );
2855 }
2856  
2857 30 ▶sub _iface {
Subroutine _iface: called CC=3 SCAR=11.0
2858 30 my ( $dev, $n ) = @_;
2859 30 ▶ return { addr => ['127.0.0.1/8'], mtu => 65536, state => 'UNKNOWN' } if $n eq 'lo' && !$dev->{interfaces}{lo};
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "lo" and not $$dev{"interfaces"}{"lo"} 7 23 30
Condition66%2/3
$n eq "lo" and not $$dev{"interfaces"}{"lo"}
!ll&&!rl&&r
2307
MC/DC50%1/2
$n eq "lo" and not $$dev{"interfaces"}{"lo"}
$n eq "lo" not $$dev{"interfaces"}{"lo"}
Truth table66%2/3
A and not(B)
A= $n eq "lo"B= not $$dev{"interfaces"}{"lo"}
ABresult
0X0
100
111
2860 23 return $dev->{interfaces}{$n};
2861 }
2862  
2863 64 ▶sub _route_text {
Subroutine _route_text: called CC=13 SCAR=27.8
2864 64 my ( $r, $with_table ) = @_;
2865 64 ▶ my $s = $r->{type} && $r->{type} ne 'unicast' ? "$r->{type} $r->{dst}" : $r->{dst};
Branch: 1 branch
BranchTrueFalseTotal
$$r{'type'} && $$r{'type'} ne 'unicast' ? : 0 64 64
Condition33%1/3
$$r{"type"} and $$r{"type"} ne "unicast"
!ll&&!rl&&r
6400
MC/DC0%0/2
$$r{"type"} and $$r{"type"} ne "unicast"
$$r{"type"} $$r{"type"} ne "unicast"
Truth table33%1/3
A and B
A= $$r{"type"}B= $$r{"type"} ne "unicast"
ABresult
0X0
100
111
2866 64 ▶ $s .= " via $r->{via}" if defined $r->{via};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"via"} 18 46 64
2867 64 ▶ $s .= " dev $r->{dev}" if defined $r->{dev};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"dev"} 64 0 64
2868 64 ▶ $s .= " table $r->{table}" if $with_table && defined $r->{table} && $r->{table} ne 'main';
Branch: 1 branch
BranchTrueFalseTotal
if $with_table and defined $$r{"table"} and $$r{"table"} ne "main" 0 64 64
Condition33%2/6
$with_table and defined $$r{"table"} and $$r{"table"} ne "main"
!ll&&!rl&&r
6400
$with_table and defined $$r{"table"}
!ll&&!rl&&r
6400
MC/DC0%0/3
$with_table and defined $$r{"table"} and $$r{"table"} ne "main"
$with_table defined $$r{"table"} $$r{"table"} ne "main"
Truth table25%1/4
A and B and C
A= $with_tableB= defined $$r{"table"}C= $$r{"table"} ne "main"
ABCresult
0XX0
10X0
1100
1111
2869 64 ▶ $s .= " proto $r->{proto}" if defined $r->{proto};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"proto"} 46 18 64
2870 64 ▶ $s .= " scope $r->{scope}" if defined $r->{scope};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"scope"} 45 19 64
2871 64 ▶ $s .= " src $r->{src}" if defined $r->{src};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"src"} 45 19 64
2872 64 ▶ $s .= " metric $r->{metric}" if defined $r->{metric};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"metric"} 2 62 64
2873 64 ▶ $s .= " onlink" if $r->{onlink};
Branch: 1 branch
BranchTrueFalseTotal
if $$r{"onlink"} 0 64 64
2874 64 return $s;
2875 }
2876  
2877 132 ▶sub _table_of { my ($r) = @_; return defined $r->{table} ? "$r->{table}" : 'main' }
Subroutine _table_of: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $$r{'table'} ? : 5 127 132
2878  
2879 30 ▶sub _ip_route {
Subroutine _ip_route: called CC=98 SCAR=61.8
2880 30 my ( $dev, $av, $o ) = @_;
2881 30 my @a = @$av;
2882 30 ▶ my $sub = @a ? shift @a : 'show';
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 14 16 30
2883 30 ▶ my $cmd = _abbrev( $sub, qw( show list add delete replace change get flush append ) )
Branch: 1 branch
BranchTrueFalseTotal
$sub eq 'del' ? : 0 0 0
Condition50%1/2
_abbrev($sub, ("show", "list", "add", "delete", "replace", "change", "get", "flush", "append")) // ($sub eq "del" ? "delete" : undef)
l!l
300
MC/DC0%0/1
_abbrev($sub, ("show", "list", "add", "delete", "replace", "change", "get", "flush", "append")) // ($sub eq "del" ? "delete" : undef)
_abbrev($sub, ("show", "list", "add", "delete", "replace", "change", "get", "flush", "append"))
Truth table50%1/2
A
A= _abbrev($sub, ("show", "list", "add", "delete", "replace", "change", "get", "flush", "append"))
Aresult
11
00
2884 // ( $sub eq 'del' ? 'delete' : undef );
2885 30 ▶ if ( !$cmd ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmd) 0 30 30
2886 # ip route 10.0.0.0/8 ... = show mit Filter
2887 0 unshift @a, $sub;
2888 0 $cmd = 'show';
2889 }
2890 30 ▶ $cmd = 'show' if $cmd eq 'list';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "list" 0 30 30
2891 30 ▶ $dev->{routes} //= [];
Condition50%1/2
$$dev{"routes"} //= []
l!l
300
MC/DC0%0/1
$$dev{"routes"} //= []
$$dev{"routes"}
Truth table50%1/2
A
A= $$dev{"routes"}
Aresult
11
00
2892 30 ▶ if ( $cmd eq 'show' || $cmd eq 'flush' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "show" or $cmd eq "flush") 18 12 30
Condition66%2/3
$cmd eq "show" or $cmd eq "flush"
l!l&&r!l&&!r
18012
MC/DC50%1/2
$cmd eq "show" or $cmd eq "flush"
$cmd eq "show" $cmd eq "flush"
Truth table66%2/3
A or B
A= $cmd eq "show"B= $cmd eq "flush"
ABresult
1X1
011
000
2893 18 my %f = ( table => 'main' );
2894 18 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 2 18 20
2895 2 my $k = shift @a;
2896 2 ▶ if ( $k eq 'table' ) { $f{table} = shift @a }
Branch: 6 branches
BranchTrueFalseTotal
if ($k eq 'table') { } 1 1 2
elsif ($k eq 'dev') { } 0 1 1
elsif ($k eq 'proto') { } 0 1 1
elsif ($k eq 'via') { } 0 1 1
elsif ($k =~ m[\A(?:default|[\d.]+(?:/\d+)?)\z]) { } 1 0 1
elsif ($k eq 'exact' or $k eq 'root' or $k eq 'match') { } 0 0 0
2897 0 elsif ( $k eq 'dev' ) { $f{dev} = shift @a }
2898 0 elsif ( $k eq 'proto' ) { $f{proto} = shift @a }
2899 0 elsif ( $k eq 'via' ) { $f{via} = shift @a }
2900 1 elsif ( $k =~ /\A(?:default|[\d.]+(?:\/\d+)?)\z/ ) { $f{dst} = _canon_dst($k) }
2901 ▶ elsif ( $k eq 'exact' || $k eq 'root' || $k eq 'match' ) { }
Condition0%0/6
$k eq "exact" or $k eq "root" or $k eq "match"
l!l&&r!l&&!r
000
$k eq "exact" or $k eq "root"
l!l&&r!l&&!r
000
MC/DC0%0/3
$k eq "exact" or $k eq "root" or $k eq "match"
$k eq "exact" $k eq "root" $k eq "match"
Truth table0%0/4
A or B or C
A= $k eq "exact"B= $k eq "root"C= $k eq "match"
ABCresult
1XX1
01X1
0011
0000
2902 0 else { return ( qq{Error: either "to" is duplicate, or "$k" is a garbage.}, 0 ) }
2903 }
2904 18 my $all = $f{table} eq 'all';
2905 return ( 'Error: ipv4: FIB table does not exist.', 0 )
2906 18 ▶ if !$all && $f{table} !~ /\A(?:main|local|default)\z/ && !grep { _table_of($_) eq $f{table} } @{ $dev->{routes} };
Branch: 1 branch
BranchTrueFalseTotal
unless $all or $f{"table"} =~ /\A(?:main|local|default)\z/ or grep {_table_of($_) eq $f{"table"};} @{$$dev{"routes"};} 0 18 18
Condition66%4/6
$all or $f{"table"} =~ /\A(?:main|local|default)\z/ or grep {_table_of($_) eq $f{"table"};} @{$$dev{"routes"};}
l!l&&r!l&&!r
1710
$all or $f{"table"} =~ /\A(?:main|local|default)\z/
l!l&&r!l&&!r
0171
MC/DC0%0/3
$all or $f{"table"} =~ /\A(?:main|local|default)\z/ or grep {_table_of($_) eq $f{"table"};} @{$$dev{"routes"};}
$all $f{"table"} =~ /\A(?:main|local|default)\z/ grep {_table_of($_) eq $f{"table"};} @{$$dev{"routes"};}
Truth table50%2/4
A or B or C
A= $allB= $f{"table"} =~ /\A(?:main|local|default)\z/C= grep {_table_of($_) eq $f{"table"};} @{$$dev{"routes"};}
ABCresult
1XX1
01X1
0011
0000
2907 my @hit = grep {
2908 77 my $r = $_;
2909 ( $all || _table_of($r) eq $f{table} )
2910 && ( !defined $f{dev} || ( $r->{dev} // '' ) eq $f{dev} )
2911 && ( !defined $f{proto} || ( $r->{proto} // 'boot' ) eq $f{proto} )
2912 && ( !defined $f{via} || ( $r->{via} // '' ) eq $f{via} )
2913 && ( !defined $f{dst} || $r->{dst} eq $f{dst} )
2914 18 ▶ } @{ $dev->{routes} };
Condition51%17/33
($all || _table_of($r) eq $f{'table'}) && (!defined($f{'dev'}) || ($$r{'dev'} // '') eq $f{'dev'}) && (!defined($f{'proto'}) || ($$r{'proto'} // 'boot') eq $f{'proto'}) && (!defined($f{'via'}) || ($$r{'via'} // '') eq $f{'via'}) && (!defined($f{'dst'}) || $$r{'dst'} eq $f{'dst'})
!ll&&!rl&&r
4469
$all || _table_of($r) eq $f{"table"} and !defined($f{"dev"}) || ($$r{"dev"} // "") eq $f{"dev"} and !defined($f{"proto"}) || ($$r{"proto"} // "boot") eq $f{"proto"} and !defined($f{"via"}) || ($$r{"via"} // "") eq $f{"via"}
!ll&&!rl&&r
4073
$all || _table_of($r) eq $f{"table"} and !defined($f{"dev"}) || ($$r{"dev"} // "") eq $f{"dev"} and !defined($f{"proto"}) || ($$r{"proto"} // "boot") eq $f{"proto"}
!ll&&!rl&&r
4073
$all || _table_of($r) eq $f{"table"} and !defined($f{"dev"}) || ($$r{"dev"} // "") eq $f{"dev"}
!ll&&!rl&&r
4073
$all or _table_of($r) eq $f{"table"}
l!l&&r!l&&!r
0734
not defined $f{"dev"} or ($$r{"dev"} // "") eq $f{"dev"}
l!l&&r!l&&!r
7300
$$r{"dev"} // ""
l!l
00
not defined $f{"proto"} or ($$r{"proto"} // "boot") eq $f{"proto"}
l!l&&r!l&&!r
7300
$$r{"proto"} // "boot"
l!l
00
not defined $f{"via"} or ($$r{"via"} // "") eq $f{"via"}
l!l&&r!l&&!r
7300
$$r{"via"} // ""
l!l
00
not defined $f{"dst"} or $$r{"dst"} eq $f{"dst"}
l!l&&r!l&&!r
6814
MC/DC30%3/10
($all || _table_of($r) eq $f{'table'}) && (!defined($f{'dev'}) || ($$r{'dev'} // '') eq $f{'dev'}) && (!defined($f{'proto'}) || ($$r{'proto'} // 'boot') eq $f{'proto'}) && (!defined($f{'via'}) || ($$r{'via'} // '') eq $f{'via'}) && (!defined($f{'dst'}) || $$r{'dst'} eq $f{'dst'})
$all _table_of($r) eq $f{"table"} not defined $f{"dev"} $$r{"dev"} not defined $f{"proto"} $$r{"proto"} not defined $f{"via"} $$r{"via"} not defined $f{"dst"} $$r{"dst"} eq $f{"dst"}
Truth table6%4/63
A or B and not(C) or D and not(E) or F and not(G) or H && not(I) or J
A= $allB= _table_of($r) eq $f{"table"}C= not defined $f{"dev"}D= $$r{"dev"}E= not defined $f{"proto"}F= $$r{"proto"}G= not defined $f{"via"}H= $$r{"via"}I= not defined $f{"dst"}J= $$r{"dst"} eq $f{"dst"}
ABCDEFGHIJresult
00XXXXXXXX0
1X00XXXXXX0
0100XXXXXX0
1X1X00XXXX0
1X0100XXXX0
011X00XXXX0
010100XXXX0
1X1X1X00XX0
1X1X0100XX0
1X011X00XX0
1X010100XX0
011X1X00XX0
011X0100XX0
01011X00XX0
01010100XX0
1X1X1X1X000
1X1X1X01000
1X1X011X000
1X1X0101000
1X011X1X000
1X011X01000
1X01011X000
1X010101000
011X1X1X000
011X1X01000
011X011X000
011X0101000
01011X1X000
01011X01000
0101011X000
01010101000
1X1X1X1X1X1
1X1X1X1X011
1X1X1X011X1
1X1X1X01011
1X1X011X1X1
1X1X011X011
1X1X01011X1
1X1X0101011
1X011X1X1X1
1X011X1X011
1X011X011X1
1X011X01011
1X01011X1X1
1X01011X011
1X0101011X1
1X010101011
011X1X1X1X1
011X1X1X011
011X1X011X1
011X1X01011
011X011X1X1
011X011X011
011X01011X1
011X0101011
01011X1X1X1
01011X1X011
01011X011X1
01011X01011
0101011X1X1
0101011X011
010101011X1
01010101011
2915 18 ▶ if ( $cmd eq 'flush' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "flush") 0 18 18
2916 0 my %drop = map { $_ => 1 } @hit;
2917 0 @{ $dev->{routes} } = grep { !$drop{$_} } @{ $dev->{routes} };
2918 0 return ( '', 1 );
2919 }
2920 18 ▶ my $v6 = sub { $_[0]{dst} =~ /:/ || ( $_[0]{via} // '' ) =~ /:/ || ( $_[0]{family} // '' ) eq 'inet6' };
Subroutine __ANON__: called CC=5 SCAR=16.4
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"dst"} =~ /:/ or ($_[0]{"via"} // "") =~ /:/ or ($_[0]{"family"} // "") eq "inet6" 2 67 69
Condition71%5/7
$_[0]{"dst"} =~ /:/ or ($_[0]{"via"} // "") =~ /:/
l!l&&r!l&&!r
2067
$_[0]{"via"} // ""
l!l
1948
$_[0]{"family"} // ""
l!l
067
MC/DC50%1/2
$_[0]{"dst"} =~ /:/ or ($_[0]{"via"} // "") =~ /:/
$_[0]{"dst"} =~ /:/ $_[0]{"via"}
MC/DC0%0/1
$_[0]{"family"} // ""
$_[0]{"family"}
Truth table66%2/3
A or B
A= $_[0]{"dst"} =~ /:/B= $_[0]{"via"}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $_[0]{"family"}
Aresult
11
00
2921 18 ▶ @hit = $o->{6} ? grep { $v6->($_) } @hit : grep { !$v6->($_) } @hit;
Branch: 1 branch
BranchTrueFalseTotal
$$o{'6'} ? : 1 17 18
2922 18 return ( join( "\n", map { _route_text( $_, $all ) } @hit ), 1 );
2923 }
2924 12 ▶ if ( $cmd eq 'get' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "get") 3 9 12
2925 3 ▶ my $to = shift @a // return ( 'Usage: ip route get ADDRESS [ from ADDRESS iif STRING ] …', 0 );
Condition50%1/2
shift @a // (return "Usage: ip route get ADDRESS [ from ADDRESS iif STRING ] \x{2026}", 0)
l!l
30
MC/DC0%0/1
shift @a // (return "Usage: ip route get ADDRESS [ from ADDRESS iif STRING ] \x{2026}", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
2926 3 my %g;
2927 3 ▶ while (@a) { my $k = shift @a; $g{$k} = shift @a }
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 2 3 5
2928 3 ▶ return ( "Error: inet prefix is expected rather than \"$to\".", 0 ) unless defined _ip2n($to);
Branch: 1 branch
BranchTrueFalseTotal
unless defined _ip2n($to) 0 3 3
2929 3 my ( $r, $table ) = _lookup( $dev, $to, $g{from}, $g{iif} );
2930 3 ▶ return ( 'RTNETLINK answers: Network is unreachable', 0 ) unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 3 3
2931 3 ▶ my $src = $g{from} // _src_for( $dev, $r );
Condition66%2/3
$g{"from"} // _src_for($dev, $r)
l!l&&r!l&&!r
210
MC/DC0%0/2
$g{"from"} // _src_for($dev, $r)
$g{"from"} _src_for($dev, $r)
Truth table66%2/3
A // B
A= $g{"from"}B= _src_for($dev, $r)
ABresult
1X1
011
000
2932 3 my $s = $to;
2933 3 ▶ $s .= " from $g{from}" if defined $g{from};
Branch: 1 branch
BranchTrueFalseTotal
if defined $g{"from"} 2 1 3
2934 3 ▶ $s .= " via $r->{via}" if defined $r->{via};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"via"} 3 0 3
2935 3 ▶ $s .= " dev $r->{dev}" if defined $r->{dev};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"dev"} 3 0 3
2936 3 ▶ $s .= " table $table" if $table ne 'main';
Branch: 1 branch
BranchTrueFalseTotal
if $table ne "main" 1 2 3
2937 3 ▶ $s .= " src $src" if defined $src && !defined $g{from};
Branch: 1 branch
BranchTrueFalseTotal
if defined $src and not defined $g{"from"} 1 2 3
Condition66%2/3
defined $src and not defined $g{"from"}
!ll&&!rl&&r
021
MC/DC50%1/2
defined $src and not defined $g{"from"}
defined $src not defined $g{"from"}
Truth table66%2/3
A and not(B)
A= defined $srcB= not defined $g{"from"}
ABresult
0X0
100
111
2938 3 $s .= " uid 0";
2939 3 return ( "$s \n cache ", 1 );
2940 }
2941 # add/delete/replace/change/append
2942 9 ▶ my $dst = shift @a // return ( 'Error: either "to" is duplicate, or "" is a garbage.', 0 );
Condition50%1/2
shift @a // (return "Error: either \"to\" is duplicate, or \"\" is a garbage.", 0)
l!l
90
MC/DC0%0/1
shift @a // (return "Error: either \"to\" is duplicate, or \"\" is a garbage.", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
2943 9 ▶ $dst = shift @a if $dst eq 'to';
Branch: 1 branch
BranchTrueFalseTotal
if $dst eq "to" 0 9 9
2944 9 my %r;
2945 my $type;
2946 0 ▶ if ( $dst =~ /\A(?:unicast|blackhole|unreachable|prohibit)\z/ ) { $type = $dst; $dst = shift @a // '' }
Branch: 1 branch
BranchTrueFalseTotal
if ($dst =~ /\A(?:unicast|blackhole|unreachable|prohibit)\z/) 0 9 9
Condition0%0/2
shift @a // ""
l!l
00
MC/DC0%0/1
shift @a // ""
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
2947 9 ▶ my $c = _canon_dst($dst) // return ( qq{Error: any valid prefix is expected rather than "$dst".}, 0 );
Condition50%1/2
_canon_dst($dst) // (return qq[Error: any valid prefix is expected rather than "$dst".], 0)
l!l
90
MC/DC0%0/1
_canon_dst($dst) // (return qq[Error: any valid prefix is expected rather than "$dst".], 0)
_canon_dst($dst)
Truth table50%1/2
A
A= _canon_dst($dst)
Aresult
11
00
2948 9 $r{dst} = $c;
2949 9 ▶ $r{type} = $type if $type && $type ne 'unicast';
Branch: 1 branch
BranchTrueFalseTotal
if $type and $type ne "unicast" 0 9 9
Condition33%1/3
$type and $type ne "unicast"
!ll&&!rl&&r
900
MC/DC0%0/2
$type and $type ne "unicast"
$type $type ne "unicast"
Truth table33%1/3
A and B
A= $typeB= $type ne "unicast"
ABresult
0X0
100
111
2950 9 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 11 8 19
2951 11 my $k = shift @a;
2952 11 ▶ if ( $k =~ /\A(?:via|dev|metric|table|proto|scope|src|preference|pref)\z/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($k =~ /\A(?:via|dev|metric|table|proto|scope|src|preference|pref)\z/) { } 10 1 11
elsif ($k eq 'onlink') { } 0 1 1
2953 10 my $v = shift @a;
2954 10 ▶ return ( qq{Command line is not complete. Try option "help"}, 0 ) unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 10 10
2955 10 ▶ $k = 'metric' if $k eq 'preference' || $k eq 'pref';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "preference" or $k eq "pref" 0 10 10
Condition33%1/3
$k eq "preference" or $k eq "pref"
l!l&&r!l&&!r
0010
MC/DC0%0/2
$k eq "preference" or $k eq "pref"
$k eq "preference" $k eq "pref"
Truth table33%1/3
A or B
A= $k eq "preference"B= $k eq "pref"
ABresult
1X1
011
000
2956 10 $r{$k} = $v;
2957 }
2958 0 elsif ( $k eq 'onlink' ) { $r{onlink} = 1 }
2959 1 else { return ( qq{Error: either "to" is duplicate, or "$k" is a garbage.}, 0 ) }
2960 }
2961 return ( qq{Error: argument "$r{metric}" is wrong: "metric" value is invalid}, 0 )
2962 8 ▶ if defined $r{metric} && $r{metric} !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $r{"metric"} and not $r{"metric"} =~ /\A\d+\z/ 0 8 8
Condition66%2/3
defined $r{"metric"} and not $r{"metric"} =~ /\A\d+\z/
!ll&&!rl&&r
530
MC/DC0%0/2
defined $r{"metric"} and not $r{"metric"} =~ /\A\d+\z/
defined $r{"metric"} not $r{"metric"} =~ /\A\d+\z/
Truth table66%2/3
A and not(B)
A= defined $r{"metric"}B= not $r{"metric"} =~ /\A\d+\z/
ABresult
0X0
100
111
2963 8 ▶ if ( defined $r{dev} && !_iface( $dev, $r{dev} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $r{"dev"} and not _iface($dev, $r{"dev"})) 1 7 8
Condition66%2/3
defined $r{"dev"} and not _iface($dev, $r{"dev"})
!ll&&!rl&&r
701
MC/DC50%1/2
defined $r{"dev"} and not _iface($dev, $r{"dev"})
defined $r{"dev"} not _iface($dev, $r{"dev"})
Truth table66%2/3
A and not(B)
A= defined $r{"dev"}B= not _iface($dev, $r{"dev"})
ABresult
0X0
100
111
2964 1 return ( qq{Cannot find device "$r{dev}"}, 0 );
2965 }
2966 7 ▶ if ( defined $r{via} && $cmd ne 'delete' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $r{"via"} and $cmd ne "delete") 5 2 7
Condition66%2/3
defined $r{"via"} and $cmd ne "delete"
!ll&&!rl&&r
205
MC/DC50%1/2
defined $r{"via"} and $cmd ne "delete"
defined $r{"via"} $cmd ne "delete"
Truth table66%2/3
A and B
A= defined $r{"via"}B= $cmd ne "delete"
ABresult
0X0
100
111
2967 5 ▶ return ( qq{Error: inet address is expected rather than "$r{via}".}, 0 ) unless defined _ip2n( $r{via} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined _ip2n($r{"via"}) 0 5 5
2968 5 my $gwdev = _connected_dev( $dev, $r{via} );
2969 5 ▶ if ( !$r{onlink} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r{"onlink"}) 5 0 5
2970 5 ▶ return ( 'Error: Nexthop has invalid gateway.', 0 ) unless $gwdev;
Branch: 1 branch
BranchTrueFalseTotal
unless $gwdev 1 4 5
2971 4 ▶ return ( 'Error: Nexthop has invalid gateway.', 0 ) if defined $r{dev} && $r{dev} ne $gwdev;
Branch: 1 branch
BranchTrueFalseTotal
if defined $r{"dev"} and $r{"dev"} ne $gwdev 0 4 4
Condition33%1/3
defined $r{"dev"} and $r{"dev"} ne $gwdev
!ll&&!rl&&r
400
MC/DC0%0/2
defined $r{"dev"} and $r{"dev"} ne $gwdev
defined $r{"dev"} $r{"dev"} ne $gwdev
Truth table33%1/3
A and B
A= defined $r{"dev"}B= $r{"dev"} ne $gwdev
ABresult
0X0
100
111
2972 }
2973 4 ▶ $r{dev} //= $gwdev;
Condition33%1/3
$r{"dev"} //= $gwdev
l!l&&r!l&&!r
040
MC/DC0%0/2
$r{"dev"} //= $gwdev
$r{"dev"} $gwdev
Truth table33%1/3
A //= B
A= $r{"dev"}B= $gwdev
ABresult
1X1
011
000
2974 }
2975 6 ▶ if ( !defined $r{via} && !defined $r{dev} && $cmd ne 'delete' && !$r{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $r{"via"} || defined $r{"dev"} and $cmd ne "delete" and not $r{"type"}) 0 6 6
Condition55%5/9
not defined $r{"via"} || defined $r{"dev"} and $cmd ne "delete" and not $r{"type"}
!ll&&!rl&&r
600
not defined $r{"via"} || defined $r{"dev"} and $cmd ne "delete"
!ll&&!rl&&r
420
defined $r{'via'} || defined $r{'dev'}
l!l&&r!l&&!r
402
MC/DC0%0/4
not defined $r{"via"} || defined $r{"dev"} and $cmd ne "delete" and not $r{"type"}
defined $r{'via'} defined $r{'dev'} $cmd ne "delete" not $r{"type"}
Truth table40%2/5
not(A || B) and C and not(D)
A= defined $r{'via'}B= defined $r{'dev'}C= $cmd ne "delete"D= not $r{"type"}
ABCDresult
1XXX0
01XX0
000X0
00100
00111
2976 0 return ( 'Error: Device for nexthop is not up.', 0 );
2977 }
2978 6 ▶ $r{metric} = 0 + $r{metric} if defined $r{metric};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r{"metric"} 3 3 6
2979 6 ▶ delete $r{table} if defined $r{table} && $r{table} eq 'main';
Branch: 1 branch
BranchTrueFalseTotal
if defined $r{"table"} and $r{"table"} eq "main" 0 6 6
Condition66%2/3
defined $r{"table"} and $r{"table"} eq "main"
!ll&&!rl&&r
510
MC/DC0%0/2
defined $r{"table"} and $r{"table"} eq "main"
defined $r{"table"} $r{"table"} eq "main"
Truth table66%2/3
A and B
A= defined $r{"table"}B= $r{"table"} eq "main"
ABresult
0X0
100
111
2980 18 ▶ my $same = sub {
Subroutine __ANON__: called CC=5 SCAR=16.8
2981 18 my ($x) = @_;
2982 18 ▶ return $x->{dst} eq $r{dst} && _table_of($x) eq _table_of( \%r ) && ( $x->{metric} // 0 ) == ( $r{metric} // 0 );
Condition70%7/10
$$x{'dst'} eq $r{'dst'} && _table_of($x) eq _table_of(\%r) && ($$x{'metric'} // 0) == ($r{'metric'} // 0)
!ll&&!rl&&r
1602
$$x{"dst"} eq $r{"dst"} and _table_of($x) eq _table_of(\%r)
!ll&&!rl&&r
1512
$$x{"metric"} // 0
l!l
20
$r{"metric"} // 0
l!l
20
MC/DC66%2/3
$$x{'dst'} eq $r{'dst'} && _table_of($x) eq _table_of(\%r) && ($$x{'metric'} // 0) == ($r{'metric'} // 0)
$$x{"dst"} eq $r{"dst"} _table_of($x) eq _table_of(\%r) $$x{"metric"}
MC/DC0%0/1
$r{"metric"} // 0
$r{"metric"}
Truth table75%3/4
A and B && C
A= $$x{"dst"} eq $r{"dst"}B= _table_of($x) eq _table_of(\%r)C= $$x{"metric"}
ABCresult
0XX0
10X0
1100
1111
Truth table50%1/2
A
A= $r{"metric"}
Aresult
11
00
2983 6 };
2984 6 my @routes = @{ $dev->{routes} };
2985 6 ▶ if ( $cmd eq 'delete' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "delete") 2 4 6
2986 my ($i) = grep {
2987 2 my $x = $routes[$_];
2988 $x->{dst} eq $r{dst} && _table_of($x) eq _table_of( \%r )
2989 && ( !defined $r{via} || ( $x->{via} // '' ) eq $r{via} )
2990 && ( !defined $r{dev} || ( $x->{dev} // '' ) eq $r{dev} )
2991 && ( !defined $r{metric} || ( $x->{metric} // 0 ) == $r{metric} )
2992 9 ▶ } 0 .. $#routes;
Condition40%11/27
$$x{'dst'} eq $r{'dst'} && _table_of($x) eq _table_of(\%r) && (!defined($r{'via'}) || ($$x{'via'} // '') eq $r{'via'}) && (!defined($r{'dev'}) || ($$x{'dev'} // '') eq $r{'dev'}) && (!defined($r{'metric'}) || ($$x{'metric'} // 0) == $r{'metric'})
!ll&&!rl&&r
801
$$x{"dst"} eq $r{"dst"} and _table_of($x) eq _table_of(\%r) and !defined($r{"via"}) || ($$x{"via"} // "") eq $r{"via"} and !defined($r{"dev"}) || ($$x{"dev"} // "") eq $r{"dev"}
!ll&&!rl&&r
801
$$x{"dst"} eq $r{"dst"} and _table_of($x) eq _table_of(\%r) and !defined($r{"via"}) || ($$x{"via"} // "") eq $r{"via"}
!ll&&!rl&&r
801
$$x{"dst"} eq $r{"dst"} and _table_of($x) eq _table_of(\%r)
!ll&&!rl&&r
801
not defined $r{"via"} or ($$x{"via"} // "") eq $r{"via"}
l!l&&r!l&&!r
100
$$x{"via"} // ""
l!l
00
not defined $r{"dev"} or ($$x{"dev"} // "") eq $r{"dev"}
l!l&&r!l&&!r
100
$$x{"dev"} // ""
l!l
00
not defined $r{"metric"} or ($$x{"metric"} // 0) == $r{"metric"}
l!l&&r!l&&!r
100
$$x{"metric"} // 0
l!l
00
MC/DC12%1/8
$$x{'dst'} eq $r{'dst'} && _table_of($x) eq _table_of(\%r) && (!defined($r{'via'}) || ($$x{'via'} // '') eq $r{'via'}) && (!defined($r{'dev'}) || ($$x{'dev'} // '') eq $r{'dev'}) && (!defined($r{'metric'}) || ($$x{'metric'} // 0) == $r{'metric'})
$$x{"dst"} eq $r{"dst"} _table_of($x) eq _table_of(\%r) not defined $r{"via"} $$x{"via"} not defined $r{"dev"} $$x{"dev"} not defined $r{"metric"} $$x{"metric"}
Truth table11%2/17
A and B and not(C) or D and not(E) or F && not(G) or H
A= $$x{"dst"} eq $r{"dst"}B= _table_of($x) eq _table_of(\%r)C= not defined $r{"via"}D= $$x{"via"}E= not defined $r{"dev"}F= $$x{"dev"}G= not defined $r{"metric"}H= $$x{"metric"}
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
1100XXXX0
111X00XX0
110100XX0
111X1X000
111X01000
11011X000
110101000
111X1X1X1
111X1X011
111X011X1
111X01011
11011X1X1
11011X011
1101011X1
110101011
2993 2 ▶ return ( 'RTNETLINK answers: No such process', 0 ) unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 1 1 2
2994 1 splice @{ $dev->{routes} }, $i, 1;
2995 1 return ( '', 1 );
2996 }
2997 4 my ($i) = grep { $same->( $routes[$_] ) } 0 .. $#routes;
2998 4 ▶ if ( $cmd eq 'add' || $cmd eq 'append' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "add" or $cmd eq "append") 3 1 4
Condition66%2/3
$cmd eq "add" or $cmd eq "append"
l!l&&r!l&&!r
301
MC/DC50%1/2
$cmd eq "add" or $cmd eq "append"
$cmd eq "add" $cmd eq "append"
Truth table66%2/3
A or B
A= $cmd eq "add"B= $cmd eq "append"
ABresult
1X1
011
000
2999 3 ▶ return ( 'RTNETLINK answers: File exists', 0 ) if defined $i && $cmd eq 'add';
Branch: 1 branch
BranchTrueFalseTotal
if defined $i and $cmd eq "add" 1 2 3
Condition66%2/3
defined $i and $cmd eq "add"
!ll&&!rl&&r
201
MC/DC50%1/2
defined $i and $cmd eq "add"
defined $i $cmd eq "add"
Truth table66%2/3
A and B
A= defined $iB= $cmd eq "add"
ABresult
0X0
100
111
3000 2 push @{ $dev->{routes} }, \%r;
3001 2 return ( '', 1 );
3002 }
3003 1 ▶ if ( $cmd eq 'change' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "change") 0 1 1
3004 0 ▶ return ( 'RTNETLINK answers: No such file or directory', 0 ) unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 0 0
3005 0 $dev->{routes}[$i] = \%r;
3006 0 return ( '', 1 );
3007 }
3008 # replace
3009 1 ▶ if ( defined $i ) { $dev->{routes}[$i] = \%r }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) { } 1 0 1
3010 0 else { push @{ $dev->{routes} }, \%r }
3011 1 return ( '', 1 );
3012 }
3013  
3014 5 ▶sub _connected_dev {
Subroutine _connected_dev: called CC=17 SCAR=31.7
3015 5 my ( $dev, $ip ) = @_;
3016 5 for my $n ( _ifaces($dev) ) {
3017 15 ▶ my $i = _iface( $dev, $n ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $i = _iface($dev, $n) or next 15 0 15
3018 15 ▶ next if ( $i->{state} // 'UP' ) eq 'DOWN';
Branch: 1 branch
BranchTrueFalseTotal
if ($$i{"state"} // "UP") eq "DOWN" 0 15 15
Condition50%1/2
$$i{"state"} // "UP"
l!l
150
MC/DC0%0/1
$$i{"state"} // "UP"
$$i{"state"}
Truth table50%1/2
A
A= $$i{"state"}
Aresult
11
00
3019 15 ▶ for my $a ( @{ $i->{addr} || [] } ) {
Condition50%1/2
$$i{'addr'} || []
l!l
150
MC/DC0%0/1
$$i{'addr'} || []
$$i{'addr'}
Truth table50%1/2
A
A= $$i{'addr'}
Aresult
11
00
3020 15 ▶ return $n if _in( $ip, $a );
Branch: 1 branch
BranchTrueFalseTotal
if _in($ip, $a) 4 11 15
3021 }
3022 }
3023 # Kernel-Routen auf Schnittstellen (z. B. wg0 ohne Adresse im selben Netz)
3024 1 ▶ for my $r ( @{ $dev->{routes} || [] } ) {
Condition50%1/2
$$dev{'routes'} || []
l!l
10
MC/DC0%0/1
$$dev{'routes'} || []
$$dev{'routes'}
Truth table50%1/2
A
A= $$dev{'routes'}
Aresult
11
00
3025 return $r->{dev} if !defined $r->{via} && defined $r->{dev} && $r->{dst} ne 'default'
3026 4 ▶ && _table_of($r) eq 'main' && ( $r->{scope} // '' ) eq 'link' && _in( $ip, $r->{dst} );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $$r{"via"} and defined $$r{"dev"} and $$r{"dst"} ne "default" and _table_of($r) eq "main" and ($$r{"scope"} // "") eq "link" and _in($ip, $$r{"dst"}) 0 4 4
Condition64%11/17
not defined $$r{"via"} and defined $$r{"dev"} and $$r{"dst"} ne "default" and _table_of($r) eq "main" and ($$r{"scope"} // "") eq "link" and _in($ip, $$r{"dst"})
!ll&&!rl&&r
130
not defined $$r{"via"} and defined $$r{"dev"} and $$r{"dst"} ne "default" and _table_of($r) eq "main" and ($$r{"scope"} // "") eq "link"
!ll&&!rl&&r
103
not defined $$r{"via"} and defined $$r{"dev"} and $$r{"dst"} ne "default" and _table_of($r) eq "main"
!ll&&!rl&&r
103
not defined $$r{"via"} and defined $$r{"dev"} and $$r{"dst"} ne "default"
!ll&&!rl&&r
103
not defined $$r{"via"} and defined $$r{"dev"}
!ll&&!rl&&r
103
$$r{"scope"} // ""
l!l
30
MC/DC0%0/6
not defined $$r{"via"} and defined $$r{"dev"} and $$r{"dst"} ne "default" and _table_of($r) eq "main" and ($$r{"scope"} // "") eq "link" and _in($ip, $$r{"dst"})
not defined $$r{"via"} defined $$r{"dev"} $$r{"dst"} ne "default" _table_of($r) eq "main" $$r{"scope"} _in($ip, $$r{"dst"})
Truth table28%2/7
not(A) and B and C and D and E and F
A= not defined $$r{"via"}B= defined $$r{"dev"}C= $$r{"dst"} ne "default"D= _table_of($r) eq "main"E= $$r{"scope"}F= _in($ip, $$r{"dst"})
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
3027 }
3028 1 return undef;
3029 }
3030  
3031 1 ▶sub _src_for {
Subroutine _src_for: called CC=6 SCAR=19.6
3032 1 my ( $dev, $r ) = @_;
3033 1 ▶ return $r->{src} if defined $r->{src};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"src"} 0 1 1
3034 1 ▶ my $i = defined $r->{dev} ? _iface( $dev, $r->{dev} ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $$r{'dev'} ? : 1 0 1
3035 1 ▶ my ($first) = $i ? @{ $i->{addr} || [] } : ();
Branch: 1 branch
BranchTrueFalseTotal
$i ? : 1 0 1
Condition50%1/2
$$i{'addr'} || []
l!l
10
MC/DC0%0/1
$$i{'addr'} || []
$$i{'addr'}
Truth table50%1/2
A
A= $$i{'addr'}
Aresult
11
00
3036 1 ▶ return defined $first ? ( split m{/}, $first )[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $first ? : 1 0 1
3037 }
3038  
3039 22 ▶sub _best {
Subroutine _best: called CC=11 SCAR=26.2
3040 22 my ( $routes, $ip, $table ) = @_;
3041 22 my ( $best, $blen, $bm );
3042 22 for my $r (@$routes) {
3043 35 ▶ next unless _table_of($r) eq $table && $r->{dst} !~ /:/;
Branch: 1 branch
BranchTrueFalseTotal
unless _table_of($r) eq $table and not $$r{"dst"} =~ /:/ 5 30 35
Condition66%2/3
_table_of($r) eq $table and not $$r{"dst"} =~ /:/
!ll&&!rl&&r
5030
MC/DC50%1/2
_table_of($r) eq $table and not $$r{"dst"} =~ /:/
_table_of($r) eq $table not $$r{"dst"} =~ /:/
Truth table66%2/3
A and not(B)
A= _table_of($r) eq $tableB= not $$r{"dst"} =~ /:/
ABresult
0X0
100
111
3044 30 ▶ my ( $net, $len ) = _prefix( $r->{dst} ) or next;
Branch: 1 branch
BranchTrueFalseTotal
() = _prefix($$r{"dst"}) or next 30 0 30
3045 30 ▶ next unless _in( $ip, $r->{dst} );
Branch: 1 branch
BranchTrueFalseTotal
unless _in($ip, $$r{"dst"}) 6 24 30
3046 24 ▶ my $m = $r->{metric} // 0;
Condition100%2/2
$$r{"metric"} // 0
l!l
123
MC/DC100%1/1
$$r{"metric"} // 0
$$r{"metric"}
Truth table100%2/2
A
A= $$r{"metric"}
Aresult
11
00
3047 24 ▶ if ( !defined $best || $len > $blen || ( $len == $blen && $m < $bm ) ) { ( $best, $blen, $bm ) = ( $r, $len, $m ) }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $best or $len > $blen or $len == $blen and $m < $bm) 24 0 24
Condition33%3/9
not defined $best or $len > $blen or $len == $blen and $m < $bm
l!l&&r!l&&!r
2400
not defined $best or $len > $blen
l!l&&r!l&&!r
2220
$len == $blen and $m < $bm
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $best or $len > $blen or $len == $blen and $m < $bm
not defined $best $len > $blen $len == $blen $m < $bm
Truth table40%2/5
not(A) or B or C and D
A= not defined $bestB= $len > $blenC= $len == $blenD= $m < $bm
ABCDresult
1XXX1
01XX1
00111
000X0
00100
3048 }
3049 22 return $best;
3050 }
3051  
3052 22 ▶sub _lookup {
Subroutine _lookup: called CC=17 SCAR=34.2
3053 22 my ( $dev, $ip, $from, $iif ) = @_;
3054 22 my @rules = sort { $a->{priority} <=> $b->{priority} } _all_rules($dev);
3055 22 for my $ru (@rules) {
3056 45 ▶ next if defined $ru->{from} && $ru->{from} ne 'all' && !( defined $from && _in( $from, $ru->{from} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $$ru{"from"} and $$ru{"from"} ne "all" and not defined $from && _in($from, $$ru{"from"}) 1 44 45
Condition77%7/9
defined $$ru{"from"} and $$ru{"from"} ne "all" and not defined $from && _in($from, $$ru{"from"})
!ll&&!rl&&r
4311
defined $$ru{"from"} and $$ru{"from"} ne "all"
!ll&&!rl&&r
4302
defined $from && _in($from, $$ru{'from'})
!ll&&!rl&&r
011
MC/DC50%2/4
defined $$ru{"from"} and $$ru{"from"} ne "all" and not defined $from && _in($from, $$ru{"from"})
defined $$ru{"from"} $$ru{"from"} ne "all" defined $from _in($from, $$ru{'from'})
Truth table60%3/5
A and B and not(C && D)
A= defined $$ru{"from"}B= $$ru{"from"} ne "all"C= defined $fromD= _in($from, $$ru{'from'})
ABCDresult
0XXX0
10XX0
11110
110X1
11101
3057 44 ▶ next if defined $ru->{to} && $ru->{to} ne 'all' && !_in( $ip, $ru->{to} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $$ru{"to"} and $$ru{"to"} ne "all" and not _in($ip, $$ru{"to"}) 0 44 44
Condition33%2/6
defined $$ru{"to"} and $$ru{"to"} ne "all" and not _in($ip, $$ru{"to"})
!ll&&!rl&&r
4400
defined $$ru{"to"} and $$ru{"to"} ne "all"
!ll&&!rl&&r
4400
MC/DC0%0/3
defined $$ru{"to"} and $$ru{"to"} ne "all" and not _in($ip, $$ru{"to"})
defined $$ru{"to"} $$ru{"to"} ne "all" not _in($ip, $$ru{"to"})
Truth table25%1/4
A and B and not(C)
A= defined $$ru{"to"}B= $$ru{"to"} ne "all"C= not _in($ip, $$ru{"to"})
ABCresult
0XX0
10X0
1100
1111
3058 44 ▶ next if defined $ru->{iif} && !( defined $iif && $iif eq $ru->{iif} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $$ru{"iif"} and not defined $iif && $iif eq $$ru{"iif"} 0 44 44
Condition16%1/6
defined $$ru{"iif"} and not defined $iif && $iif eq $$ru{"iif"}
!ll&&!rl&&r
4400
defined $iif && $iif eq $$ru{'iif'}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $$ru{"iif"} and not defined $iif && $iif eq $$ru{"iif"}
defined $$ru{"iif"} defined $iif $iif eq $$ru{'iif'}
Truth table25%1/4
A and not(B && C)
A= defined $$ru{"iif"}B= defined $iifC= $iif eq $$ru{'iif'}
ABCresult
0XX0
1110
10X1
1101
3059 44 ▶ my $t = $ru->{table} // 'main';
Condition50%1/2
$$ru{"table"} // "main"
l!l
440
MC/DC0%0/1
$$ru{"table"} // "main"
$$ru{"table"}
Truth table50%1/2
A
A= $$ru{"table"}
Aresult
11
00
3060 44 ▶ next if $t eq 'local' || $t eq 'default';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "local" or $t eq "default" 22 22 44
Condition66%2/3
$t eq "local" or $t eq "default"
l!l&&r!l&&!r
22022
MC/DC50%1/2
$t eq "local" or $t eq "default"
$t eq "local" $t eq "default"
Truth table66%2/3
A or B
A= $t eq "local"B= $t eq "default"
ABresult
1X1
011
000
3061 22 ▶ my $r = _best( $dev->{routes} || [], $ip, $t );
Condition50%1/2
$$dev{'routes'} || []
l!l
220
MC/DC0%0/1
$$dev{'routes'} || []
$$dev{'routes'}
Truth table50%1/2
A
A= $$dev{'routes'}
Aresult
11
00
3062 22 ▶ return ( $r, $t ) if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 22 0 22
3063 }
3064 0 return ();
3065 }
3066  
3067 # --- ip rule -------------------------------------------------------------------------
3068  
3069 23 ▶sub _all_rules {
Subroutine _all_rules: called CC=2 SCAR=6.9
3070 23 my ($dev) = @_;
3071 23 ▶ return ( { priority => 0, table => 'local' }, @{ $dev->{rules} || [] },
Condition100%2/2
$$dev{'rules'} || []
l!l
320
MC/DC100%1/1
$$dev{'rules'} || []
$$dev{'rules'}
Truth table100%2/2
A
A= $$dev{'rules'}
Aresult
11
00
3072 { priority => 32766, table => 'main' }, { priority => 32767, table => 'default' } );
3073 }
3074  
3075 4 ▶sub _rule_text {
Subroutine _rule_text: called CC=7 SCAR=20.5
3076 4 my ($r) = @_;
3077 4 ▶ my $s = "$r->{priority}:\tfrom " . ( $r->{from} // 'all' );
Condition100%2/2
$$r{"from"} // "all"
l!l
13
MC/DC100%1/1
$$r{"from"} // "all"
$$r{"from"}
Truth table100%2/2
A
A= $$r{"from"}
Aresult
11
00
3078 4 ▶ $s .= " to $r->{to}" if defined $r->{to};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"to"} 0 4 4
3079 4 ▶ $s .= " fwmark $r->{fwmark}" if defined $r->{fwmark};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"fwmark"} 0 4 4
3080 4 ▶ $s .= " iif $r->{iif}" if defined $r->{iif};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"iif"} 0 4 4
3081 4 ▶ $s .= " oif $r->{oif}" if defined $r->{oif};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"oif"} 0 4 4
3082 4 ▶ $s .= ' lookup ' . ( $r->{table} // 'main' );
Condition50%1/2
$$r{"table"} // "main"
l!l
40
MC/DC0%0/1
$$r{"table"} // "main"
$$r{"table"}
Truth table50%1/2
A
A= $$r{"table"}
Aresult
11
00
3083 4 return $s;
3084 }
3085  
3086 2 ▶sub _ip_rule {
Subroutine _ip_rule: called CC=29 SCAR=45.2
3087 2 my ( $dev, $av ) = @_;
3088 2 my @a = @$av;
3089 2 ▶ my $sub = @a ? shift @a : 'show';
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 1 1 2
3090 2 ▶ my $cmd = _abbrev( $sub, qw( show list add delete flush ) ) // ( $sub eq 'del' ? 'delete' : undef )
Branch: 1 branch
BranchTrueFalseTotal
$sub eq 'del' ? : 0 0 0
Condition50%2/4
(_abbrev($sub, ("show", "list", "add", "delete", "flush")) // ($sub eq "del" ? "delete" : undef)) // (return qq[Command "$sub" is unknown, try "ip rule help".], 0)
l!l
20
_abbrev($sub, ("show", "list", "add", "delete", "flush")) // ($sub eq "del" ? "delete" : undef)
l!l
20
MC/DC0%0/1
(_abbrev($sub, ("show", "list", "add", "delete", "flush")) // ($sub eq "del" ? "delete" : undef)) // (return qq[Command "$sub" is unknown, try "ip rule help".], 0)
_abbrev($sub, ("show", "list", "add", "delete", "flush"))
Truth table50%1/2
A
A= _abbrev($sub, ("show", "list", "add", "delete", "flush"))
Aresult
11
00
3091 // return ( qq{Command "$sub" is unknown, try "ip rule help".}, 0 );
3092 2 ▶ if ( $cmd eq 'show' || $cmd eq 'list' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "show" or $cmd eq "list") 1 1 2
Condition66%2/3
$cmd eq "show" or $cmd eq "list"
l!l&&r!l&&!r
101
MC/DC50%1/2
$cmd eq "show" or $cmd eq "list"
$cmd eq "show" $cmd eq "list"
Truth table66%2/3
A or B
A= $cmd eq "show"B= $cmd eq "list"
ABresult
1X1
011
000
3093 1 return ( join( "\n", map { _rule_text($_) } sort { $a->{priority} <=> $b->{priority} } _all_rules($dev) ), 1 );
3094 }
3095 0 ▶ if ( $cmd eq 'flush' ) { $dev->{rules} = []; return ( '', 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "flush") 0 1 1
3096 1 my %r;
3097 1 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 3 1 4
3098 3 my $k = shift @a;
3099 3 my $v = shift @a;
3100 3 ▶ return ( qq{Command line is not complete. Try option "help"}, 0 ) unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 3 3
3101 3 ▶ if ( $k =~ /\A(?:priority|pref|preference|prio)\z/ ) { $r{priority} = $v }
Branch: 3 branches
BranchTrueFalseTotal
if ($k =~ /\A(?:priority|pref|preference|prio)\z/) { } 1 2 3
elsif ($k =~ /\A(?:lookup|table)\z/) { } 1 1 2
elsif ($k =~ /\A(?:from|to|iif|oif|fwmark)\z/) { } 1 0 1
3102 1 elsif ( $k =~ /\A(?:lookup|table)\z/ ) { $r{table} = $v }
3103 1 ▶ elsif ( $k =~ /\A(?:from|to|iif|oif|fwmark)\z/ ) { $r{$k} = $v eq 'all' ? undef : $v }
Branch: 1 branch
BranchTrueFalseTotal
$v eq 'all' ? : 0 1 1
3104 0 else { return ( qq{Error: argument "$k" is wrong: Failed to parse rule type}, 0 ) }
3105 }
3106 1 delete $r{$_} for grep { !defined $r{$_} } keys %r;
3107 1 for my $k (qw( from to )) {
3108 2 ▶ next unless defined $r{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r{$k} 1 1 2
3109 1 ▶ my $c = _canon_dst( $r{$k} ) // return ( qq{Error: inet prefix is expected rather than "$r{$k}".}, 0 );
Condition50%1/2
_canon_dst($r{$k}) // (return qq[Error: inet prefix is expected rather than "$r{$k}".], 0)
l!l
10
MC/DC0%0/1
_canon_dst($r{$k}) // (return qq[Error: inet prefix is expected rather than "$r{$k}".], 0)
_canon_dst($r{$k})
Truth table50%1/2
A
A= _canon_dst($r{$k})
Aresult
11
00
3110 1 $r{$k} = $c;
3111 }
3112 1 ▶ $dev->{rules} //= [];
Condition50%1/2
$$dev{"rules"} //= []
l!l
01
MC/DC0%0/1
$$dev{"rules"} //= []
$$dev{"rules"}
Truth table50%1/2
A
A= $$dev{"rules"}
Aresult
11
00
3113 1 ▶ if ( $cmd eq 'delete' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "delete") 0 1 1
3114 my ($i) = grep {
3115 0 my $x = $dev->{rules}[$_];
3116 0 ▶ !grep { ( $x->{$_} // '' ) ne ( $r{$_} // ( $_ eq 'priority' ? $x->{priority} : '' ) ) } qw( priority from to iif oif fwmark table )
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'priority' ? : 0 0 0
Condition0%0/5
$$x{$_} // ""
l!l
00
$r{$_} // ($_ eq "priority" ? $$x{"priority"} : "")
l!l&&r!l&&!r
000
MC/DC0%0/1
$$x{$_} // ""
$$x{$_}
MC/DC0%0/2
$r{$_} // ($_ eq "priority" ? $$x{"priority"} : "")
$r{$_} ($_ eq "priority" ? $$x{"priority"} : "")
Truth table0%0/2
A
A= $$x{$_}
Aresult
11
00
Truth table0%0/3
A // B
A= $r{$_}B= ($_ eq "priority" ? $$x{"priority"} : "")
ABresult
1X1
011
000
3117 0 } 0 .. $#{ $dev->{rules} };
3118 0 ▶ return ( 'RTNETLINK answers: No such file or directory', 0 ) unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 0 0
3119 0 splice @{ $dev->{rules} }, $i, 1;
3120 0 return ( '', 1 );
3121 }
3122 return ( 'Error: argument "' . $r{priority} . '" is wrong: preference value is invalid', 0 )
3123 1 ▶ if defined $r{priority} && $r{priority} !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $r{"priority"} and not $r{"priority"} =~ /\A\d+\z/ 0 1 1
Condition33%1/3
defined $r{"priority"} and not $r{"priority"} =~ /\A\d+\z/
!ll&&!rl&&r
010
MC/DC0%0/2
defined $r{"priority"} and not $r{"priority"} =~ /\A\d+\z/
defined $r{"priority"} not $r{"priority"} =~ /\A\d+\z/
Truth table33%1/3
A and not(B)
A= defined $r{"priority"}B= not $r{"priority"} =~ /\A\d+\z/
ABresult
0X0
100
111
3124 1 ▶ if ( !defined $r{priority} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $r{"priority"}) 0 1 1
3125 0 my ($low) = sort { $a <=> $b } map { $_->{priority} } @{ $dev->{rules} };
3126 0 ▶ $r{priority} = ( $low // 32766 ) - 1;
Condition0%0/2
$low // 32766
l!l
00
MC/DC0%0/1
$low // 32766
$low
Truth table0%0/2
A
A= $low
Aresult
11
00
3127 }
3128 1 $r{priority} = 0 + $r{priority};
3129 1 ▶ $r{table} //= 'main';
Condition50%1/2
$r{"table"} //= "main"
l!l
10
MC/DC0%0/1
$r{"table"} //= "main"
$r{"table"}
Truth table50%1/2
A
A= $r{"table"}
Aresult
11
00
3130 1 push @{ $dev->{rules} }, \%r;
3131 0 @{ $dev->{rules} } = sort { $a->{priority} <=> $b->{priority} } @{ $dev->{rules} };
3132 1 return ( '', 1 );
3133 }
3134  
3135 # --- ip addr / link --------------------------------------------------------------------
3136  
3137 2 ▶sub _ip_addr {
Subroutine _ip_addr: called CC=43 SCAR=53.0
3138 2 my ( $dev, $av, $o ) = @_;
3139 2 my @a = @$av;
3140 2 ▶ my $sub = @a ? shift @a : 'show';
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 2 0 2
3141 2 ▶ my $cmd = _abbrev( $sub, qw( show list add delete flush ) ) // ( $sub eq 'del' ? 'delete' : undef );
Branch: 1 branch
BranchTrueFalseTotal
$sub eq 'del' ? : 0 0 0
Condition50%1/2
_abbrev($sub, ("show", "list", "add", "delete", "flush")) // ($sub eq "del" ? "delete" : undef)
l!l
20
MC/DC0%0/1
_abbrev($sub, ("show", "list", "add", "delete", "flush")) // ($sub eq "del" ? "delete" : undef)
_abbrev($sub, ("show", "list", "add", "delete", "flush"))
Truth table50%1/2
A
A= _abbrev($sub, ("show", "list", "add", "delete", "flush"))
Aresult
11
00
3142 0 ▶ if ( !$cmd ) { unshift @a, $sub; $cmd = 'show' }
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmd) 0 2 2
3143 2 ▶ if ( $cmd eq 'show' || $cmd eq 'list' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "show" or $cmd eq "list") 1 1 2
Condition66%2/3
$cmd eq "show" or $cmd eq "list"
l!l&&r!l&&!r
101
MC/DC50%1/2
$cmd eq "show" or $cmd eq "list"
$cmd eq "show" $cmd eq "list"
Truth table66%2/3
A or B
A= $cmd eq "show"B= $cmd eq "list"
ABresult
1X1
011
000
3144 1 ▶ shift @a if @a && $a[0] eq 'dev';
Branch: 1 branch
BranchTrueFalseTotal
if @a and $a[0] eq "dev" 0 1 1
Condition33%1/3
@a and $a[0] eq "dev"
!ll&&!rl&&r
010
MC/DC0%0/2
@a and $a[0] eq "dev"
@a $a[0] eq "dev"
Truth table33%1/3
A and B
A= @aB= $a[0] eq "dev"
ABresult
0X0
100
111
3145 1 my $only = shift @a;
3146 1 ▶ return ( qq{Device "$only" does not exist.}, 0 ) if defined $only && !_iface( $dev, $only );
Branch: 1 branch
BranchTrueFalseTotal
if defined $only and not _iface($dev, $only) 0 1 1
Condition33%1/3
defined $only and not _iface($dev, $only)
!ll&&!rl&&r
010
MC/DC0%0/2
defined $only and not _iface($dev, $only)
defined $only not _iface($dev, $only)
Truth table33%1/3
A and not(B)
A= defined $onlyB= not _iface($dev, $only)
ABresult
0X0
100
111
3147 1 my @out;
3148 1 my $idx = 0;
3149 1 for my $n ( _ifaces($dev) ) {
3150 4 $idx++;
3151 4 ▶ next if defined $only && $n ne $only;
Branch: 1 branch
BranchTrueFalseTotal
if defined $only and $n ne $only 3 1 4
Condition66%2/3
defined $only and $n ne $only
!ll&&!rl&&r
013
MC/DC50%1/2
defined $only and $n ne $only
defined $only $n ne $only
Truth table66%2/3
A and B
A= defined $onlyB= $n ne $only
ABresult
0X0
100
111
3152 1 my $i = _iface( $dev, $n );
3153 1 ▶ my $st = $i->{state} // 'UP';
Condition50%1/2
$$i{"state"} // "UP"
l!l
10
MC/DC0%0/1
$$i{"state"} // "UP"
$$i{"state"}
Truth table50%1/2
A
A= $$i{"state"}
Aresult
11
00
3154 1 ▶ if ( $o->{br} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$o{"br"}) 0 1 1
3155 0 ▶ push @out, sprintf( '%-16s %-14s %s', $n, $st, join( ' ', @{ $i->{addr} || [] } ) );
Condition0%0/2
$$i{'addr'} || []
l!l
00
MC/DC0%0/1
$$i{'addr'} || []
$$i{'addr'}
Truth table0%0/2
A
A= $$i{'addr'}
Aresult
11
00
3156 0 next;
3157 }
3158 push @out, "$idx: $n: <" . ( $n eq 'lo' ? 'LOOPBACK,UP,LOWER_UP' : $st eq 'DOWN' ? 'BROADCAST,MULTICAST' : 'BROADCAST,MULTICAST,UP,LOWER_UP' )
3159 1 ▶ . "> mtu " . ( $i->{mtu} // 1500 ) . " qdisc noqueue state $st group default qlen 1000";
Branch: 2 branches
BranchTrueFalseTotal
$n eq 'lo' ? : 0 1 1
$st eq 'DOWN' ? : 0 1 1
Condition50%1/2
$$i{"mtu"} // 1500
l!l
10
MC/DC0%0/1
$$i{"mtu"} // 1500
$$i{"mtu"}
Truth table50%1/2
A
A= $$i{"mtu"}
Aresult
11
00
3160 1 ▶ push @out, " inet $_ scope " . ( $n eq 'lo' ? 'host' : 'global' ) . " $n" for $o->{6} ? () : grep { !/:/ } @{ $i->{addr} || [] };
Branch: 2 branches
BranchTrueFalseTotal
$$o{'6'} ? : 0 1 1
$n eq 'lo' ? : 0 2 2
Condition50%1/2
$$i{'addr'} || []
l!l
10
MC/DC0%0/1
$$i{'addr'} || []
$$i{'addr'}
Truth table50%1/2
A
A= $$i{'addr'}
Aresult
11
00
3161 1 ▶ push @out, " inet6 $_ scope global" for $o->{4} ? () : grep {/:/} @{ $i->{addr} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$$o{'4'} ? : 0 1 1
Condition50%1/2
$$i{'addr'} || []
l!l
10
MC/DC0%0/1
$$i{'addr'} || []
$$i{'addr'}
Truth table50%1/2
A
A= $$i{'addr'}
Aresult
11
00
3162 }
3163 1 return ( join( "\n", @out ), 1 );
3164 }
3165 1 ▶ my $addr = shift @a // return ( 'Command line is not complete. Try option "help"', 0 );
Condition50%1/2
shift @a // (return "Command line is not complete. Try option \"help\"", 0)
l!l
10
MC/DC0%0/1
shift @a // (return "Command line is not complete. Try option \"help\"", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3166 1 my %k;
3167 1 ▶ while (@a) { my $x = shift @a; $k{$x} = shift @a }
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 1 1 2
3168 1 ▶ my $ifn = $k{dev} // return ( 'Not enough information: "dev" argument is required.', 0 );
Condition50%1/2
$k{"dev"} // (return "Not enough information: \"dev\" argument is required.", 0)
l!l
10
MC/DC0%0/1
$k{"dev"} // (return "Not enough information: \"dev\" argument is required.", 0)
$k{"dev"}
Truth table50%1/2
A
A= $k{"dev"}
Aresult
11
00
3169 1 ▶ my $i = _iface( $dev, $ifn ) or return ( qq{Cannot find device "$ifn"}, 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $i = _iface($dev, $ifn) or return qq[Cannot find device "$ifn"], 0 1 0 1
3170 1 ▶ $addr .= '/32' if $addr !~ m{/} && $addr !~ /:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $addr =~ m[/] or $addr =~ /:/ 0 1 1
Condition33%1/3
$addr =~ m[/] or $addr =~ /:/
l!l&&r!l&&!r
100
MC/DC0%0/2
$addr =~ m[/] or $addr =~ /:/
$addr =~ m[/] $addr =~ /:/
Truth table33%1/3
A or B
A= $addr =~ m[/]B= $addr =~ /:/
ABresult
1X1
011
000
3171 1 ▶ my $list = $i->{addr} //= [];
Condition50%1/2
$$i{"addr"} //= []
l!l
10
MC/DC0%0/1
$$i{"addr"} //= []
$$i{"addr"}
Truth table50%1/2
A
A= $$i{"addr"}
Aresult
11
00
3172 1 ▶ if ( $cmd eq 'add' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "add") 1 0 1
3173 1 ▶ return ( 'RTNETLINK answers: File exists', 0 ) if grep { $_ eq $addr } @$list;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $addr;} @$list 0 1 1
3174 1 push @$list, $addr;
3175 1 ▶ if ( my ( $net, $len ) = _prefix($addr) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = _prefix($addr)) 1 0 1
3176 1 ▶ push @{ $dev->{routes} }, { dst => _n2ip($net) . "/$len", dev => $ifn, proto => 'kernel', scope => 'link',
Branch: 1 branch
BranchTrueFalseTotal
if $len < 32 1 0 1
3177 src => ( split m{/}, $addr )[0] } if $len < 32;
3178 }
3179 1 return ( '', 1 );
3180 }
3181 0 my $n = @$list;
3182 0 @$list = grep { $_ ne $addr } @$list;
3183 0 ▶ return ( 'RTNETLINK answers: Cannot assign requested address', 0 ) if @$list == $n;
Branch: 1 branch
BranchTrueFalseTotal
if @$list == $n 0 0 0
3184 0 my $src = ( split m{/}, $addr )[0];
3185 0 ▶ @{ $dev->{routes} } = grep { !( ( $_->{proto} // '' ) eq 'kernel' && ( $_->{src} // '' ) eq $src ) } @{ $dev->{routes} || [] };
Condition0%0/9
($$_{'proto'} // '') eq 'kernel' && ($$_{'src'} // '') eq $src
!ll&&!rl&&r
000
$$_{"proto"} // ""
l!l
00
$$_{"src"} // ""
l!l
00
$$dev{'routes'} || []
l!l
00
MC/DC0%0/2
($$_{'proto'} // '') eq 'kernel' && ($$_{'src'} // '') eq $src
$$_{"proto"} $$_{"src"}
MC/DC0%0/1
$$dev{'routes'} || []
$$dev{'routes'}
Truth table0%0/3
A && B
A= $$_{"proto"}B= $$_{"src"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $$dev{'routes'}
Aresult
11
00
3186 0 return ( '', 1 );
3187 }
3188  
3189 4 ▶sub _ip_link {
Subroutine _ip_link: called CC=38 SCAR=43.6
3190 4 my ( $dev, $av, $o ) = @_;
3191 4 my @a = @$av;
3192 4 ▶ my $sub = @a ? shift @a : 'show';
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 3 1 4
3193 4 ▶ my $cmd = _abbrev( $sub, qw( show list set add delete ) ) // ( $sub eq 'del' ? 'delete' : undef );
Branch: 1 branch
BranchTrueFalseTotal
$sub eq 'del' ? : 0 0 0
Condition50%1/2
_abbrev($sub, ("show", "list", "set", "add", "delete")) // ($sub eq "del" ? "delete" : undef)
l!l
40
MC/DC0%0/1
_abbrev($sub, ("show", "list", "set", "add", "delete")) // ($sub eq "del" ? "delete" : undef)
_abbrev($sub, ("show", "list", "set", "add", "delete"))
Truth table50%1/2
A
A= _abbrev($sub, ("show", "list", "set", "add", "delete"))
Aresult
11
00
3194 0 ▶ if ( !$cmd ) { unshift @a, $sub; $cmd = 'show' }
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmd) 0 4 4
3195 4 ▶ if ( $cmd eq 'show' || $cmd eq 'list' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "show" or $cmd eq "list") 2 2 4
Condition66%2/3
$cmd eq "show" or $cmd eq "list"
l!l&&r!l&&!r
202
MC/DC50%1/2
$cmd eq "show" or $cmd eq "list"
$cmd eq "show" $cmd eq "list"
Truth table66%2/3
A or B
A= $cmd eq "show"B= $cmd eq "list"
ABresult
1X1
011
000
3196 2 ▶ shift @a if @a && $a[0] eq 'dev';
Branch: 1 branch
BranchTrueFalseTotal
if @a and $a[0] eq "dev" 0 2 2
Condition66%2/3
@a and $a[0] eq "dev"
!ll&&!rl&&r
110
MC/DC0%0/2
@a and $a[0] eq "dev"
@a $a[0] eq "dev"
Truth table66%2/3
A and B
A= @aB= $a[0] eq "dev"
ABresult
0X0
100
111
3197 2 my $only = shift @a;
3198 2 ▶ return ( qq{Device "$only" does not exist.}, 0 ) if defined $only && !_iface( $dev, $only );
Branch: 1 branch
BranchTrueFalseTotal
if defined $only and not _iface($dev, $only) 0 2 2
Condition66%2/3
defined $only and not _iface($dev, $only)
!ll&&!rl&&r
110
MC/DC0%0/2
defined $only and not _iface($dev, $only)
defined $only not _iface($dev, $only)
Truth table66%2/3
A and not(B)
A= defined $onlyB= not _iface($dev, $only)
ABresult
0X0
100
111
3199 2 my @out;
3200 2 my $idx = 0;
3201 2 for my $n ( _ifaces($dev) ) {
3202 8 $idx++;
3203 8 ▶ next if defined $only && $n ne $only;
Branch: 1 branch
BranchTrueFalseTotal
if defined $only and $n ne $only 3 5 8
Condition100%3/3
defined $only and $n ne $only
!ll&&!rl&&r
413
MC/DC100%2/2
defined $only and $n ne $only
defined $only $n ne $only
Truth table100%3/3
A and B
A= defined $onlyB= $n ne $only
ABresult
0X0
100
111
3204 5 my $i = _iface( $dev, $n );
3205 5 ▶ my $st = $i->{state} // 'UP';
Condition50%1/2
$$i{"state"} // "UP"
l!l
50
MC/DC0%0/1
$$i{"state"} // "UP"
$$i{"state"}
Truth table50%1/2
A
A= $$i{"state"}
Aresult
11
00
3206 5 ▶ if ( $o->{br} ) { push @out, sprintf( '%-16s %-14s', $n, $st ); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($$o{"br"}) 4 1 5
3207 push @out, "$idx: $n: <" . ( $n eq 'lo' ? 'LOOPBACK,UP,LOWER_UP' : $st eq 'DOWN' ? 'BROADCAST,MULTICAST' : 'BROADCAST,MULTICAST,UP,LOWER_UP' )
3208 1 ▶ . "> mtu " . ( $i->{mtu} // 1500 ) . " qdisc noqueue state $st mode DEFAULT group default qlen 1000";
Branch: 2 branches
BranchTrueFalseTotal
$n eq 'lo' ? : 0 1 1
$st eq 'DOWN' ? : 0 1 1
Condition50%1/2
$$i{"mtu"} // 1500
l!l
10
MC/DC0%0/1
$$i{"mtu"} // 1500
$$i{"mtu"}
Truth table50%1/2
A
A= $$i{"mtu"}
Aresult
11
00
3209 push @out, $n eq 'lo' ? ' link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00'
3210 1 ▶ : $n =~ /\Awg|\Atun|ppp/ ? ' link/none ' : ' link/ether ' . ( $i->{mac} // '52:54:00:00:00:' . sprintf( '%02x', $idx ) ) . ' brd ff:ff:ff:ff:ff:ff';
Branch: 2 branches
BranchTrueFalseTotal
$n eq 'lo' ? : 0 1 1
$n =~ /\Awg|\Atun|ppp/ ? : 1 0 1
Condition0%0/2
$$i{"mac"} // '52:54:00:00:00:' . sprintf("%02x", $idx)
l!l
00
MC/DC0%0/1
$$i{"mac"} // '52:54:00:00:00:' . sprintf("%02x", $idx)
$$i{"mac"}
Truth table0%0/2
A
A= $$i{"mac"}
Aresult
11
00
3211 }
3212 2 return ( join( "\n", @out ), 1 );
3213 }
3214 2 ▶ return ( qq{Command "$cmd" is not supported here.}, 0 ) unless $cmd eq 'set';
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd eq "set" 0 2 2
3215 2 ▶ shift @a if @a && $a[0] eq 'dev';
Branch: 1 branch
BranchTrueFalseTotal
if @a and $a[0] eq "dev" 1 1 2
Condition66%2/3
@a and $a[0] eq "dev"
!ll&&!rl&&r
011
MC/DC50%1/2
@a and $a[0] eq "dev"
@a $a[0] eq "dev"
Truth table66%2/3
A and B
A= @aB= $a[0] eq "dev"
ABresult
0X0
100
111
3216 2 ▶ my $n = shift @a // return ( 'Not enough of information: "dev" argument is required.', 0 );
Condition50%1/2
shift @a // (return "Not enough of information: \"dev\" argument is required.", 0)
l!l
20
MC/DC0%0/1
shift @a // (return "Not enough of information: \"dev\" argument is required.", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3217 2 ▶ my $i = $dev->{interfaces}{$n} or return ( qq{Cannot find device "$n"}, 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $i = $$dev{"interfaces"}{$n} or return qq[Cannot find device "$n"], 0 2 0 2
3218 2 ▶ return ( 'Command line is not complete. Try option "help"', 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 2 2
3219 2 my %set;
3220 2 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 2 1 3
3221 2 my $k = shift @a;
3222 2 ▶ if ( $k eq 'mtu' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($k eq 'mtu') { } 2 0 2
elsif ($k eq 'up') { } 0 0 0
elsif ($k eq 'down') { } 0 0 0
3223 2 my $v = shift @a;
3224 2 ▶ return ( qq{Error: argument "} . ( $v // '' ) . qq{" is wrong: Invalid "mtu" value}, 0 ) unless defined $v && $v =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and $v =~ /\A\d+\z/ 1 1 2
Condition60%3/5
defined $v and $v =~ /\A\d+\z/
!ll&&!rl&&r
011
$v // ""
l!l
10
MC/DC50%1/2
defined $v and $v =~ /\A\d+\z/
defined $v $v =~ /\A\d+\z/
MC/DC0%0/1
$v // ""
$v
Truth table66%2/3
A and B
A= defined $vB= $v =~ /\A\d+\z/
ABresult
0X0
100
111
Truth table50%1/2
A
A= $v
Aresult
11
00
3225 1 ▶ return ( 'Error: mtu less than device minimum.', 0 ) if $v < 68;
Branch: 1 branch
BranchTrueFalseTotal
if $v < 68 0 1 1
3226 1 ▶ return ( 'Error: mtu greater than device maximum.', 0 ) if $v > 65535;
Branch: 1 branch
BranchTrueFalseTotal
if $v > 65535 0 1 1
3227 1 $set{mtu} = 0 + $v;
3228 }
3229 0 elsif ( $k eq 'up' ) { $set{state} = 'UP' }
3230 0 elsif ( $k eq 'down' ) { $set{state} = 'DOWN' }
3231 0 else { return ( qq{Error: either "dev" is duplicate, or "$k" is a garbage.}, 0 ) }
3232 }
3233 1 $i->{$_} = $set{$_} for keys %set;
3234 1 return ( '', 1 );
3235 }
3236  
3237 # --- WireGuard ---------------------------------------------------------------------
3238  
3239 4 ▶sub _wg_conf {
Subroutine _wg_conf: called CC=11 SCAR=25.2
3240 4 my ($w) = @_;
3241 4 my @l = ( '[Interface]' );
3242 4 ▶ push @l, "Address = $w->{address}" if defined $w->{address};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$w{"address"} 4 0 4
3243 4 ▶ push @l, "ListenPort = $w->{listen_port}" if defined $w->{listen_port};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$w{"listen_port"} 4 0 4
3244 4 ▶ push @l, 'PrivateKey = ' . ( $w->{private_key} // '(nicht angezeigt)' );
Condition50%1/2
$$w{"private_key"} // "(nicht angezeigt)"
l!l
04
MC/DC0%0/1
$$w{"private_key"} // "(nicht angezeigt)"
$$w{"private_key"}
Truth table50%1/2
A
A= $$w{"private_key"}
Aresult
11
00
3245 4 ▶ push @l, "MTU = $w->{mtu}" if defined $w->{mtu};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$w{"mtu"} 0 4 4
3246 4 ▶ for my $k ( sort keys %{ $w->{peers} || {} } ) {
Condition50%1/2
$$w{'peers'} || {}
l!l
40
MC/DC0%0/1
$$w{'peers'} || {}
$$w{'peers'}
Truth table50%1/2
A
A= $$w{'peers'}
Aresult
11
00
3247 5 my $p = $w->{peers}{$k};
3248 5 push @l, '', '[Peer]';
3249 5 ▶ push @l, "# $p->{name}" if defined $p->{name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"name"} 0 5 5
3250 5 push @l, "PublicKey = $k";
3251 5 ▶ push @l, "Endpoint = $p->{endpoint}" if defined $p->{endpoint};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"endpoint"} 3 2 5
3252 5 ▶ push @l, 'AllowedIPs = ' . join( ', ', @{ $p->{allowed_ips} || [] } );
Condition50%1/2
$$p{'allowed_ips'} || []
l!l
50
MC/DC0%0/1
$$p{'allowed_ips'} || []
$$p{'allowed_ips'}
Truth table50%1/2
A
A= $$p{'allowed_ips'}
Aresult
11
00
3253 5 ▶ push @l, "PersistentKeepalive = $p->{keepalive}" if defined $p->{keepalive};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"keepalive"} 0 5 5
3254 }
3255 4 return join( "\n", @l ) . "\n";
3256 }
3257  
3258 # wgN.conf lesen -> Zustand (ohne Address/MTU: die setzt wg-quick)
3259 9 ▶sub _wg_parse {
Subroutine _wg_parse: called CC=20 SCAR=30.8
3260 9 my ( $text, $old ) = @_;
3261 9 ▶ my %w = ( %{ $old || {} }, peers => {} );
Condition100%2/2
$old || {}
l!l
36
MC/DC100%1/1
$old || {}
$old
Truth table100%2/2
A
A= $old
Aresult
11
00
3262 9 my ( $sec, $peer, %pp );
3263 33 ▶ my $flush = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
3264 33 ▶ return unless $peer;
Branch: 1 branch
BranchTrueFalseTotal
unless $peer 18 15 33
3265 15 ▶ my $prev = ( $old->{peers} || {} )->{$peer} || {};
Condition100%4/4
($$old{'peers'} || {})->{$peer} || {}
l!l
411
$$old{'peers'} || {}
l!l
411
MC/DC100%1/1
($$old{'peers'} || {})->{$peer} || {}
$$old{'peers'}
Truth table100%2/2
A
A= $$old{'peers'}
Aresult
11
00
3266 15 $w{peers}{$peer} = { %$prev, allowed_ips => [], %pp };
3267 15 _wg_claim( \%w, $peer );
3268 15 ( $peer, %pp ) = ();
3269 9 };
3270 9 my $n = 0;
3271 9 for my $line ( split /\n/, $text ) {
3272 102 $n++;
3273 102 ( my $l = $line ) =~ s/#.*//;
3274 102 $l =~ s/\A\s+|\s+\z//g;
3275 102 ▶ next unless length $l;
Branch: 1 branch
BranchTrueFalseTotal
unless length $l 27 75 102
3276 75 ▶ if ( $l =~ /\A\[(Interface|Peer)\]\z/i ) { $flush->(); $sec = lc $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A\[(Interface|Peer)\]\z/i) 25 50 75
3277 # wie wg: aller Leerraum faellt weg ("Allowed IPs = a, b" ist AllowedIPs=a,b)
3278 50 ( my $flat = $l ) =~ s/\s+//g;
3279 50 ▶ my ( $k, $v ) = $flat =~ /\A(\w+)=(.*)\z/ or die "Line unrecognized: `$flat'\nConfiguration parsing error\n";
Branch: 1 branch
BranchTrueFalseTotal
() = $flat =~ /\A(\w+)=(.*)\z/ or die "Line unrecognized: `${flat}'\nConfiguration parsing error\n" 50 0 50
3280 50 $k = lc $k;
3281 50 ▶ if ( ( $sec // '' ) eq 'interface' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (($sec // '') eq 'interface') { } 17 33 50
elsif (($sec // '') eq 'peer') { } 33 0 33
Condition50%1/2
$sec // ""
l!l
500
MC/DC0%0/1
$sec // ""
$sec
Truth table50%1/2
A
A= $sec
Aresult
11
00
3282 17 ▶ $w{listen_port} = $v =~ /\A\d+\z/ ? 0 + $v : $v if $k eq 'listenport';
Branch: 2 branches
BranchTrueFalseTotal
if $k eq "listenport" 9 8 17
$v =~ /\A\d+\z/ ? : 9 0 9
3283 17 ▶ $w{address} = $v if $k eq 'address';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "address" 0 17 17
3284 17 ▶ $w{mtu} = 0 + $v if $k eq 'mtu';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "mtu" 0 17 17
3285 }
3286 ▶ elsif ( ( $sec // '' ) eq 'peer' ) {
Condition50%1/2
$sec // ""
l!l
330
MC/DC0%0/1
$sec // ""
$sec
Truth table50%1/2
A
A= $sec
Aresult
11
00
3287 33 ▶ if ( $k eq 'publickey' ) { $peer = $v }
Branch: 5 branches
BranchTrueFalseTotal
if ($k eq 'publickey') { } 16 17 33
elsif ($k eq 'allowedips') { } 15 2 17
elsif ($k eq 'endpoint') { } 1 1 2
elsif ($k eq 'persistentkeepalive') { } 0 1 1
elsif ($k ne 'presharedkey') { } 1 0 1
3288 15 elsif ( $k eq 'allowedips' ) { $pp{allowed_ips} = [ grep {length} split /\s*,\s*/, $v ] }
3289 1 elsif ( $k eq 'endpoint' ) { $pp{endpoint} = $v }
3290 0 ▶ elsif ( $k eq 'persistentkeepalive' ) { $pp{keepalive} = $v =~ /\A\d+\z/ ? 0 + $v : $v }
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /\A\d+\z/ ? : 0 0 0
3291 1 elsif ( $k ne 'presharedkey' ) { die "Line unrecognized: `$flat'\nConfiguration parsing error\n" }
3292 }
3293 0 else { die "Line unrecognized: `$flat'\nConfiguration parsing error\n" }
3294 }
3295 8 $flush->();
3296 8 return \%w;
3297 }
3298  
3299 # Eine AllowedIP gehoert in wg genau einem Peer: wer sie bekommt, nimmt sie den anderen.
3300 18 ▶sub _wg_claim {
Subroutine _wg_claim: called CC=6 SCAR=18.1
3301 18 my ( $w, $peer ) = @_;
3302 18 ▶ my %mine = map { $_ => 1 } @{ $w->{peers}{$peer}{allowed_ips} || [] };
Condition50%1/2
$$w{'peers'}{$peer}{'allowed_ips'} || []
l!l
180
MC/DC0%0/1
$$w{'peers'}{$peer}{'allowed_ips'} || []
$$w{'peers'}{$peer}{'allowed_ips'}
Truth table50%1/2
A
A= $$w{'peers'}{$peer}{'allowed_ips'}
Aresult
11
00
3303 18 ▶ for my $k ( grep { $_ ne $peer } keys %{ $w->{peers} || {} } ) {
Condition50%1/2
$$w{'peers'} || {}
l!l
180
MC/DC0%0/1
$$w{'peers'} || {}
$$w{'peers'}
Truth table50%1/2
A
A= $$w{'peers'}
Aresult
11
00
3304 11 ▶ my $l = $w->{peers}{$k}{allowed_ips} || [];
Condition50%1/2
$$w{'peers'}{$k}{'allowed_ips'} || []
l!l
110
MC/DC0%0/1
$$w{'peers'}{$k}{'allowed_ips'} || []
$$w{'peers'}{$k}{'allowed_ips'}
Truth table50%1/2
A
A= $$w{'peers'}{$k}{'allowed_ips'}
Aresult
11
00
3305 11 my @keep = grep { !$mine{$_} } @$l;
3306 11 ▶ $w->{peers}{$k}{allowed_ips} = \@keep if @keep != @$l;
Branch: 1 branch
BranchTrueFalseTotal
if @keep != @$l 2 9 11
3307 }
3308 18 return;
3309 }
3310  
3311 # [Interface] einer wgN.conf: was wg-quick daraus macht (Address, MTU, Table, Hooks, SaveConfig)
3312 10 ▶sub _wg_quick_conf {
Subroutine _wg_quick_conf: called CC=9 SCAR=22.0
3313 10 my ($text) = @_;
3314 10 my ( %c, $sec );
3315 10 for my $line ( split /\n/, $text ) {
3316 180 ( my $l = $line ) =~ s/#.*//;
3317 180 $l =~ s/\A\s+|\s+\z//g;
3318 180 ▶ next unless length $l;
Branch: 1 branch
BranchTrueFalseTotal
unless length $l 41 139 180
3319 139 ▶ if ( $l =~ /\A\[(\w+)\]\z/ ) { $sec = lc $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A\[(\w+)\]\z/) 32 107 139
3320 107 ▶ next unless ( $sec // '' ) eq 'interface';
Branch: 1 branch
BranchTrueFalseTotal
unless ($sec // "") eq "interface" 44 63 107
Condition50%1/2
$sec // ""
l!l
1070
MC/DC0%0/1
$sec // ""
$sec
Truth table50%1/2
A
A= $sec
Aresult
11
00
3321 63 ▶ my ( $k, $v ) = $l =~ /\A(\w+)\s*=\s*(.*)\z/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $l =~ /\A(\w+)\s*=\s*(.*)\z/ or next 63 0 63
3322 63 $k = lc $k;
3323 63 ▶ if ( $k =~ /\A(?:preup|postup|predown|postdown)\z/ ) { push @{ $c{$k} }, $v }
Branch: 2 branches
BranchTrueFalseTotal
if ($k =~ /\A(?:preup|postup|predown|postdown)\z/) { } 20 43 63
elsif ($k eq 'address') { } 10 33 43
3324 10 elsif ( $k eq 'address' ) { push @{ $c{address} }, grep {length} split /\s*,\s*/, $v }
3325 33 else { $c{$k} = $v }
3326 }
3327 10 return \%c;
3328 }
3329  
3330 # PreUp/PostUp: scheitert ein Befehl, bricht wg-quick up ab. PreDown/PostDown
3331 # ($soft): die Schnittstelle geht trotzdem herunter (wie der Stop der Unit).
3332 18 ▶sub _wg_hooks {
Subroutine _wg_hooks: called CC=5 SCAR=16.6
3333 18 my ( $dev, $n, $cmds, $soft ) = @_;
3334 18 ▶ for my $c ( @{ $cmds || [] } ) {
Condition100%2/2
$cmds || []
l!l
99
MC/DC100%1/1
$cmds || []
$cmds
Truth table100%2/2
A
A= $cmds
Aresult
11
00
3335 9 ( my $x = $c ) =~ s/%i/$n/g;
3336 9 my ( $o, $ok ) = __PACKAGE__->_run_inner( $dev, $x, $CTX );
3337 9 ▶ die "[#] $x\n$o\n" unless $ok || $soft;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok or $soft 0 9 9
Condition33%1/3
$ok or $soft
l!l&&r!l&&!r
900
MC/DC0%0/2
$ok or $soft
$ok $soft
Truth table33%1/3
A or B
A= $okB= $soft
ABresult
1X1
011
000
3338 }
3339 18 return;
3340 }
3341  
3342 # wg-quick up (von Hand: die Unit wg-quick@ behaelt ihren Stand): Schnittstelle mit Address/MTU, Peers aus der Datei, Routen zu den
3343 # AllowedIPs (ohne Table = off), PreUp/PostUp.
3344 8 ▶sub _wg_up {
Subroutine _wg_up: called CC=39 SCAR=49.2
3345 8 my ( $dev, $n ) = @_;
3346 8 my $file = "/etc/wireguard/$n.conf";
3347 8 ▶ die "wg-quick: `$n' already exists\n" if ( ( ( $dev->{interfaces} || {} )->{$n} || {} )->{state} // 'DOWN' ) ne 'DOWN';
Branch: 1 branch
BranchTrueFalseTotal
if ((($$dev{"interfaces"} || {})->{$n} || {})->{"state"} // "DOWN") ne "DOWN" 1 7 8
Condition83%5/6
(($$dev{"interfaces"} || {})->{$n} || {})->{"state"} // "DOWN"
l!l
26
($$dev{'interfaces'} || {})->{$n} || {}
l!l
26
$$dev{'interfaces'} || {}
l!l
80
MC/DC0%0/1
(($$dev{"interfaces"} || {})->{$n} || {})->{"state"} // "DOWN"
$$dev{'interfaces'}
Truth table50%1/2
A
A= $$dev{'interfaces'}
Aresult
11
00
3348 7 ▶ my $t = _file_text( $dev, $file ) // die "wg-quick: `$file' does not exist\n";
Condition50%1/2
_file_text($dev, $file) // die("wg-quick: `${file}' does not exist\n")
l!l
70
MC/DC0%0/1
_file_text($dev, $file) // die("wg-quick: `${file}' does not exist\n")
_file_text($dev, $file)
Truth table50%1/2
A
A= _file_text($dev, $file)
Aresult
11
00
3349 7 my $q = _wg_quick_conf($t);
3350 7 ( my $strip = $t ) =~ s/^\s*(Address|DNS|MTU|Table|PreUp|PostUp|PreDown|PostDown|SaveConfig)\s*=.*\n?//mgi;
3351 7 my $w = _wg_parse( $strip, $dev->{wg}{$n} );
3352 # ein UDP-Port gehoert genau einer laufenden WireGuard-Schnittstelle
3353 6 ▶ for my $o ( grep { $_ ne $n } sort keys %{ $dev->{wg} || {} } ) {
Condition50%1/2
$$dev{'wg'} || {}
l!l
60
MC/DC0%0/1
$$dev{'wg'} || {}
$$dev{'wg'}
Truth table50%1/2
A
A= $$dev{'wg'}
Aresult
11
00
3354 0 ▶ next unless defined $w->{listen_port} && defined $dev->{wg}{$o}{listen_port} && $dev->{wg}{$o}{listen_port} eq $w->{listen_port};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$w{"listen_port"} and defined $$dev{"wg"}{$o}{"listen_port"} and $$dev{"wg"}{$o}{"listen_port"} eq $$w{"listen_port"} 0 0 0
Condition0%0/6
defined $$w{"listen_port"} and defined $$dev{"wg"}{$o}{"listen_port"} and $$dev{"wg"}{$o}{"listen_port"} eq $$w{"listen_port"}
!ll&&!rl&&r
000
defined $$w{"listen_port"} and defined $$dev{"wg"}{$o}{"listen_port"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $$w{"listen_port"} and defined $$dev{"wg"}{$o}{"listen_port"} and $$dev{"wg"}{$o}{"listen_port"} eq $$w{"listen_port"}
defined $$w{"listen_port"} defined $$dev{"wg"}{$o}{"listen_port"} $$dev{"wg"}{$o}{"listen_port"} eq $$w{"listen_port"}
Truth table0%0/4
A and B and C
A= defined $$w{"listen_port"}B= defined $$dev{"wg"}{$o}{"listen_port"}C= $$dev{"wg"}{$o}{"listen_port"} eq $$w{"listen_port"}
ABCresult
0XX0
10X0
1100
1111
3355 0 ▶ next if ( ( ( $dev->{interfaces} || {} )->{$o} || {} )->{state} // 'DOWN' ) eq 'DOWN';
Branch: 1 branch
BranchTrueFalseTotal
if ((($$dev{"interfaces"} || {})->{$o} || {})->{"state"} // "DOWN") eq "DOWN" 0 0 0
Condition0%0/6
(($$dev{"interfaces"} || {})->{$o} || {})->{"state"} // "DOWN"
l!l
00
($$dev{'interfaces'} || {})->{$o} || {}
l!l
00
$$dev{'interfaces'} || {}
l!l
00
MC/DC0%0/1
(($$dev{"interfaces"} || {})->{$o} || {})->{"state"} // "DOWN"
$$dev{'interfaces'}
Truth table0%0/2
A
A= $$dev{'interfaces'}
Aresult
11
00
3356 0 die "[#] ip link add $n type wireguard\n[#] wg setconf $n /dev/fd/63\nUnable to modify interface: Address already in use\n[#] ip link delete dev $n\n";
3357 }
3358 6 _wg_hooks( $dev, $n, $q->{preup} );
3359 6 $dev->{wg}{$n} = $w;
3360 6 ▶ $w->{address} = join( ', ', @{ $q->{address} } ) if $q->{address};
Branch: 1 branch
BranchTrueFalseTotal
if $$q{"address"} 6 0 6
3361 6 ▶ my $if = $dev->{interfaces}{$n} //= {};
Condition100%2/2
$$dev{"interfaces"}{$n} //= {}
l!l
15
MC/DC100%1/1
$$dev{"interfaces"}{$n} //= {}
$$dev{"interfaces"}{$n}
Truth table100%2/2
A
A= $$dev{"interfaces"}{$n}
Aresult
11
00
3362 6 ▶ $if->{addr} = [ @{ $q->{address} || [] } ];
Condition50%1/2
$$q{'address'} || []
l!l
60
MC/DC0%0/1
$$q{'address'} || []
$$q{'address'}
Truth table50%1/2
A
A= $$q{'address'}
Aresult
11
00
3363 6 ▶ $if->{mtu} = defined $q->{mtu} ? 0 + $q->{mtu} : $if->{mtu} // 1420;
Branch: 1 branch
BranchTrueFalseTotal
defined $$q{'mtu'} ? : 6 0 6
Condition0%0/2
$$if{"mtu"} // 1420
l!l
00
MC/DC0%0/1
$$if{"mtu"} // 1420
$$if{"mtu"}
Truth table0%0/2
A
A= $$if{"mtu"}
Aresult
11
00
3364 6 $if->{state} = 'UP';
3365 6 ▶ my $routes = $dev->{routes} //= [];
Condition50%1/2
$$dev{"routes"} //= []
l!l
60
MC/DC0%0/1
$$dev{"routes"} //= []
$$dev{"routes"}
Truth table50%1/2
A
A= $$dev{"routes"}
Aresult
11
00
3366 6 ▶ for my $a ( grep { m{\A[\d.]+/\d+\z} } @{ $q->{address} || [] } ) {
Condition50%1/2
$$q{'address'} || []
l!l
60
MC/DC0%0/1
$$q{'address'} || []
$$q{'address'}
Truth table50%1/2
A
A= $$q{'address'}
Aresult
11
00
3367 6 my ( $ip, $len ) = split m{/}, $a;
3368 6 ▶ my $net = _n2ip( _ip2n($ip) & ( $len ? ( 0xffffffff << ( 32 - $len ) ) & 0xffffffff : 0 ) ) . "/$len";
Branch: 1 branch
BranchTrueFalseTotal
$len ? : 6 0 6
3369 push @$routes, { dst => $net, dev => $n, proto => 'kernel', scope => 'link', src => $ip }
3370 6 ▶ unless grep { ( $_->{dst} // '' ) eq $net && ( $_->{dev} // '' ) eq $n } @$routes;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {($$_{"dst"} // "") eq $net and ($$_{"dev"} // "") eq $n;} @$routes 6 0 6
Condition28%2/7
($$_{'dst'} // '') eq $net && ($$_{'dev'} // '') eq $n
!ll&&!rl&&r
600
$$_{"dst"} // ""
l!l
60
$$_{"dev"} // ""
l!l
00
MC/DC0%0/2
($$_{'dst'} // '') eq $net && ($$_{'dev'} // '') eq $n
$$_{"dst"} $$_{"dev"}
Truth table0%0/3
A && B
A= $$_{"dst"}B= $$_{"dev"}
ABresult
0X0
100
111
3371 }
3372 6 ▶ if ( lc( $q->{table} // '' ) ne 'off' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($$q{"table"} // "") ne "off") 6 0 6
Condition50%1/2
$$q{"table"} // ""
l!l
06
MC/DC0%0/1
$$q{"table"} // ""
$$q{"table"}
Truth table50%1/2
A
A= $$q{"table"}
Aresult
11
00
3373 6 ▶ for my $k ( sort keys %{ $w->{peers} || {} } ) {
Condition50%1/2
$$w{'peers'} || {}
l!l
60
MC/DC0%0/1
$$w{'peers'} || {}
$$w{'peers'}
Truth table50%1/2
A
A= $$w{'peers'}
Aresult
11
00
3374 13 ▶ for my $ip ( grep { m{\A[\d.]+/\d+\z} } @{ $w->{peers}{$k}{allowed_ips} || [] } ) {
Condition50%1/2
$$w{'peers'}{$k}{'allowed_ips'} || []
l!l
130
MC/DC0%0/1
$$w{'peers'}{$k}{'allowed_ips'} || []
$$w{'peers'}{$k}{'allowed_ips'}
Truth table50%1/2
A
A= $$w{'peers'}{$k}{'allowed_ips'}
Aresult
11
00
3375 0 ▶ if ( $ip =~ m{/0\z} ) { push @GAPS, "wg-quick up $n: AllowedIPs $ip (Routing ueber fwmark)"; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($ip =~ m[/0\z]) 0 18 18
3376 18 ▶ my $dst = $ip =~ m{/32\z} ? $ip : $ip;
Branch: 1 branch
BranchTrueFalseTotal
$ip =~ m[/32\z] ? : 12 6 18
3377 18 ▶ next if grep { _canon_dst( $_->{dst} // '' ) eq _canon_dst($dst) && !defined $_->{table} } @$routes;
Branch: 1 branch
BranchTrueFalseTotal
if grep {_canon_dst($$_{"dst"} // "") eq _canon_dst($dst) and not defined $$_{"table"};} @$routes 0 18 18
Condition40%2/5
_canon_dst($$_{'dst'} // '') eq _canon_dst($dst) && !defined($$_{'table'})
!ll&&!rl&&r
5400
$$_{"dst"} // ""
l!l
540
MC/DC0%0/2
_canon_dst($$_{'dst'} // '') eq _canon_dst($dst) && !defined($$_{'table'})
_canon_dst($$_{'dst'} // '') eq _canon_dst($dst) !defined($$_{'table'})
MC/DC0%0/1
$$_{"dst"} // ""
$$_{"dst"}
Truth table33%1/3
A && not(B)
A= _canon_dst($$_{'dst'} // '') eq _canon_dst($dst)B= !defined($$_{'table'})
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$_{"dst"}
Aresult
11
00
3378 18 push @$routes, { dst => $dst, dev => $n, scope => 'link' };
3379 }
3380 }
3381 }
3382 6 _wg_hooks( $dev, $n, $q->{postup} );
3383 6 return "[#] ip link add $n type wireguard\n[#] wg setconf $n /dev/fd/63\n[#] ip link set mtu $if->{mtu} up dev $n";
3384 }
3385  
3386 # wg-quick down (zaehlt interfaces.wgN.downs): SaveConfig = true schreibt erst die laufende Konfiguration in die
3387 # Datei (Interface-Abschnitt bleibt, Peers aus dem laufenden Zustand); Routen weg,
3388 # PreDown/PostDown.
3389 3 ▶sub _wg_down {
Subroutine _wg_down: called CC=16 SCAR=30.8
3390 3 my ( $dev, $n ) = @_;
3391 3 my $file = "/etc/wireguard/$n.conf";
3392 die "wg-quick: `$n' is not a WireGuard interface\n"
3393 3 ▶ unless $dev->{wg}{$n} && ( ( ( $dev->{interfaces} || {} )->{$n} || {} )->{state} // 'UP' ) ne 'DOWN';
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{"wg"}{$n} and ((($$dev{"interfaces"} || {})->{$n} || {})->{"state"} // "UP") ne "DOWN" 0 3 3
Condition44%4/9
$$dev{"wg"}{$n} and ((($$dev{"interfaces"} || {})->{$n} || {})->{"state"} // "UP") ne "DOWN"
!ll&&!rl&&r
003
(($$dev{"interfaces"} || {})->{$n} || {})->{"state"} // "UP"
l!l
30
($$dev{'interfaces'} || {})->{$n} || {}
l!l
30
$$dev{'interfaces'} || {}
l!l
30
MC/DC0%0/2
$$dev{"wg"}{$n} and ((($$dev{"interfaces"} || {})->{$n} || {})->{"state"} // "UP") ne "DOWN"
$$dev{"wg"}{$n} $$dev{'interfaces'}
Truth table33%1/3
A and B
A= $$dev{"wg"}{$n}B= $$dev{'interfaces'}
ABresult
0X0
100
111
3394 3 my $t = _file_text( $dev, $file );
3395 3 ▶ my $q = defined $t ? _wg_quick_conf($t) : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 3 0 3
3396 3 _wg_hooks( $dev, $n, $q->{predown}, 1 );
3397 3 ▶ if ( defined $t && ( $q->{saveconfig} // '' ) =~ /\A(?:true|yes|1)\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t and ($$q{"saveconfig"} // "") =~ /\A(?:true|yes|1)\z/i) 1 2 3
Condition80%4/5
defined $t and ($$q{"saveconfig"} // "") =~ /\A(?:true|yes|1)\z/i
!ll&&!rl&&r
021
$$q{"saveconfig"} // ""
l!l
12
MC/DC50%1/2
defined $t and ($$q{"saveconfig"} // "") =~ /\A(?:true|yes|1)\z/i
defined $t $$q{"saveconfig"}
Truth table66%2/3
A and B
A= defined $tB= $$q{"saveconfig"}
ABresult
0X0
100
111
3398 1 my ($head) = $t =~ /\A(.*?)(?=^\s*\[Peer\])/ms;
3399 1 ▶ $head //= $t;
Condition33%1/3
$head //= $t
l!l&&r!l&&!r
100
MC/DC0%0/2
$head //= $t
$head $t
Truth table33%1/3
A //= B
A= $headB= $t
ABresult
1X1
011
000
3400 1 $head =~ s/\n*\z/\n/;
3401 1 my ($peers) = _wg_conf( $dev->{wg}{$n} ) =~ /(^\[Peer\].*)\z/ms;
3402 1 ▶ _file_set( $dev, $file, $head . ( defined $peers ? "\n$peers" : '' ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $peers ? : 1 0 1
3403 }
3404 3 ▶ $dev->{routes} = [ grep { ( $_->{dev} // '' ) ne $n } @{ $dev->{routes} || [] } ];
Condition50%2/4
$$_{"dev"} // ""
l!l
150
$$dev{'routes'} || []
l!l
30
MC/DC0%0/1
$$_{"dev"} // ""
$$_{"dev"}
MC/DC0%0/1
$$dev{'routes'} || []
$$dev{'routes'}
Truth table50%1/2
A
A= $$_{"dev"}
Aresult
11
00
Truth table50%1/2
A
A= $$dev{'routes'}
Aresult
11
00
3405 3 ▶ if ( my $if = $dev->{interfaces}{$n} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $if = $$dev{"interfaces"}{$n}) 3 0 3
3406 3 $if->{state} = 'DOWN';
3407 3 ▶ $if->{downs} = ( $if->{downs} // 0 ) + 1; # Tunnel unterbrochen (Nebenschaden sichtbar)
Condition50%1/2
$$if{"downs"} // 0
l!l
03
MC/DC0%0/1
$$if{"downs"} // 0
$$if{"downs"}
Truth table50%1/2
A
A= $$if{"downs"}
Aresult
11
00
3408 }
3409 3 _wg_hooks( $dev, $n, $q->{postdown}, 1 );
3410 3 return "[#] ip link delete dev $n";
3411 }
3412  
3413 # Zeitpunkt des Simulators (wie date): Tue Oct 21 12:00:00 CEST 2026
3414 82 our $NOW = 1792576800;
3415  
3416 # "2 days, 3 hours ago" -> Sekunden seit 1970 (wie wg show latest-handshakes; nie = 0)
3417 6 ▶sub _wg_epoch {
Subroutine _wg_epoch: called CC=4 SCAR=13.9
3418 6 my ($h) = @_;
3419 6 ▶ return 0 unless defined $h && $h =~ /ago/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h and $h =~ /ago/ 3 3 6
Condition66%2/3
defined $h and $h =~ /ago/
!ll&&!rl&&r
303
MC/DC50%1/2
defined $h and $h =~ /ago/
defined $h $h =~ /ago/
Truth table66%2/3
A and B
A= defined $hB= $h =~ /ago/
ABresult
0X0
100
111
3420 3 my %u = ( year => 365 * 86400, day => 86400, hour => 3600, minute => 60, second => 1 );
3421 3 my $s = 0;
3422 3 ▶ $s += $1 * $u{$2} while $h =~ /(\d+)\s+(year|day|hour|minute|second)s?/g;
Branch: 1 branch
BranchTrueFalseTotal
$h =~ /(\d+)\s+(year|day|hour|minute|second)s?/g and do { $s += $1 * $u{$2} } 9 3 12
3423 3 return $NOW - $s;
3424 }
3425  
3426 5 ▶sub _wg_show_if {
Subroutine _wg_show_if: called CC=31 SCAR=41.8
3427 5 my ( $n, $w, $what ) = @_;
3428 5 my @l;
3429 5 ▶ my @peers = sort keys %{ $w->{peers} || {} };
Condition50%1/2
$$w{'peers'} || {}
l!l
50
MC/DC0%0/1
$$w{'peers'} || {}
$$w{'peers'}
Truth table50%1/2
A
A= $$w{'peers'}
Aresult
11
00
3430 5 ▶ if ( defined $what ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $what) 4 1 5
3431 0 ▶ return join "\n", map { "$_\t" . join( ' ', @{ $w->{peers}{$_}{allowed_ips} || [] } ) } @peers if $what eq 'allowed-ips';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "allowed-ips" 0 4 4
Condition0%0/2
$$w{'peers'}{$_}{'allowed_ips'} || []
l!l
00
MC/DC0%0/1
$$w{'peers'}{$_}{'allowed_ips'} || []
$$w{'peers'}{$_}{'allowed_ips'}
Truth table0%0/2
A
A= $$w{'peers'}{$_}{'allowed_ips'}
Aresult
11
00
3432 4 ▶ return join "\n", @peers if $what eq 'peers';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "peers" 0 4 4
3433 0 ▶ return join "\n", map { "$_\t" . ( $w->{peers}{$_}{endpoint} // '(none)' ) } @peers if $what eq 'endpoints';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "endpoints" 0 4 4
Condition0%0/2
$$w{"peers"}{$_}{"endpoint"} // "(none)"
l!l
00
MC/DC0%0/1
$$w{"peers"}{$_}{"endpoint"} // "(none)"
$$w{"peers"}{$_}{"endpoint"}
Truth table0%0/2
A
A= $$w{"peers"}{$_}{"endpoint"}
Aresult
11
00
3434 4 ▶ return $w->{public_key} // '' if $what eq 'public-key';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "public-key" 0 4 4
Condition0%0/2
$$w{"public_key"} // ""
l!l
00
MC/DC0%0/1
$$w{"public_key"} // ""
$$w{"public_key"}
Truth table0%0/2
A
A= $$w{"public_key"}
Aresult
11
00
3435 4 ▶ return $w->{listen_port} // '' if $what eq 'listen-port';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "listen-port" 0 4 4
Condition0%0/2
$$w{"listen_port"} // ""
l!l
00
MC/DC0%0/1
$$w{"listen_port"} // ""
$$w{"listen_port"}
Truth table0%0/2
A
A= $$w{"listen_port"}
Aresult
11
00
3436 4 ▶ return join "\n", map { "$_\t" . _wg_epoch( $w->{peers}{$_}{handshake} ) } @peers if $what eq 'latest-handshakes';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "latest-handshakes" 2 2 4
3437 2 ▶ return join "\n", map { "$_\t" . ( $w->{peers}{$_}{keepalive} // 'off' ) } @peers if $what eq 'persistent-keepalive';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "persistent-keepalive" 1 1 2
Condition100%2/2
$$w{"peers"}{$_}{"keepalive"} // "off"
l!l
11
MC/DC100%1/1
$$w{"peers"}{$_}{"keepalive"} // "off"
$$w{"peers"}{$_}{"keepalive"}
Truth table100%2/2
A
A= $$w{"peers"}{$_}{"keepalive"}
Aresult
11
00
3438 1 ▶ if ( $what eq 'dump' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "dump") 1 0 1
3439 return join "\n", join( "\t", '(hidden)', $w->{public_key} // '(none)', $w->{listen_port} // 0, 'off' ), map {
3440 1 ▶ my $p = $w->{peers}{$_};
Condition50%2/4
$$w{"public_key"} // "(none)"
l!l
10
$$w{"listen_port"} // 0
l!l
10
MC/DC0%0/1
$$w{"public_key"} // "(none)"
$$w{"public_key"}
MC/DC0%0/1
$$w{"listen_port"} // 0
$$w{"listen_port"}
Truth table50%1/2
A
A= $$w{"public_key"}
Aresult
11
00
Truth table50%1/2
A
A= $$w{"listen_port"}
Aresult
11
00
3441 join "\t", $_, '(none)', $p->{endpoint} // '(none)',
3442 2 ▶ ( @{ $p->{allowed_ips} || [] } ? join( ',', @{ $p->{allowed_ips} } ) : '(none)' ),
Condition75%3/4
$$p{'allowed_ips'} || []
l!l
20
$$p{"keepalive"} // 0
l!l
11
MC/DC0%0/1
$$p{'allowed_ips'} || []
$$p{'allowed_ips'}
MC/DC100%1/1
$$p{"keepalive"} // 0
$$p{"keepalive"}
Truth table50%1/2
A
A= $$p{'allowed_ips'}
Aresult
11
00
Truth table100%2/2
A
A= $$p{"keepalive"}
Aresult
11
00
3443 2 ▶ _wg_epoch( $p->{handshake} ), 0, 0, $p->{keepalive} // 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$$p{'allowed_ips'} or [];} ? : 2 0 2
Condition100%2/2
$$p{"endpoint"} // "(none)"
l!l
11
MC/DC100%1/1
$$p{"endpoint"} // "(none)"
$$p{"endpoint"}
Truth table100%2/2
A
A= $$p{"endpoint"}
Aresult
11
00
3444 } @peers;
3445 }
3446 0 die "Invalid parameter: `$what'\n";
3447 }
3448 push @l, "interface: $n", " public key: " . ( $w->{public_key} // '' ), ' private key: (hidden)',
3449 1 ▶ " listening port: " . ( $w->{listen_port} // '' );
Condition50%2/4
$$w{"public_key"} // ""
l!l
10
$$w{"listen_port"} // ""
l!l
10
MC/DC0%0/1
$$w{"public_key"} // ""
$$w{"public_key"}
MC/DC0%0/1
$$w{"listen_port"} // ""
$$w{"listen_port"}
Truth table50%1/2
A
A= $$w{"public_key"}
Aresult
11
00
Truth table50%1/2
A
A= $$w{"listen_port"}
Aresult
11
00
3450 1 for my $k (@peers) {
3451 1 my $p = $w->{peers}{$k};
3452 1 push @l, '', "peer: $k";
3453 1 ▶ push @l, " endpoint: $p->{endpoint}" if defined $p->{endpoint};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"endpoint"} 1 0 1
3454 1 ▶ push @l, ' allowed ips: ' . ( @{ $p->{allowed_ips} || [] } ? join( ', ', @{ $p->{allowed_ips} } ) : '(none)' );
Branch: 1 branch
BranchTrueFalseTotal
@{$$p{'allowed_ips'} or [];} ? : 1 0 1
Condition50%1/2
$$p{'allowed_ips'} || []
l!l
10
MC/DC0%0/1
$$p{'allowed_ips'} || []
$$p{'allowed_ips'}
Truth table50%1/2
A
A= $$p{'allowed_ips'}
Aresult
11
00
3455 1 ▶ push @l, " latest handshake: $p->{handshake}" if defined $p->{handshake};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"handshake"} 0 1 1
3456 1 ▶ push @l, " transfer: $p->{transfer}" if defined $p->{transfer};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"transfer"} 0 1 1
3457 1 ▶ push @l, " persistent keepalive: every $p->{keepalive} seconds" if defined $p->{keepalive};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"keepalive"} 0 1 1
3458 }
3459 1 return join "\n", @l;
3460 }
3461  
3462 12 ▶sub _wg {
Subroutine _wg: called CC=56 SCAR=53.5
3463 12 my ( $dev, $av ) = @_;
3464 12 my @a = @$av;
3465 12 ▶ my $wg = $dev->{wg} || {};
Condition50%1/2
$$dev{'wg'} || {}
l!l
120
MC/DC0%0/1
$$dev{'wg'} || {}
$$dev{'wg'}
Truth table50%1/2
A
A= $$dev{'wg'}
Aresult
11
00
3466 12 ▶ my $sub = shift(@a) // 'show';
Condition100%2/2
shift @a // "show"
l!l
111
MC/DC100%1/1
shift @a // "show"
shift @a
Truth table100%2/2
A
A= shift @a
Aresult
11
00
3467 12 ▶ if ( $sub eq 'show' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "show") 5 7 12
3468 5 my $n = shift @a;
3469 5 ▶ if ( !defined $n || ( $n eq 'all' && !@a ) || $n eq 'interfaces' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $n or $n eq "all" and not @a or $n eq "interfaces") 1 4 5
Condition66%6/9
not defined $n or $n eq "all" and not @a or $n eq "interfaces"
l!l&&r!l&&!r
104
not defined $n or $n eq "all" and not @a
l!l&&r!l&&!r
104
$n eq "all" and not @a
!ll&&!rl&&r
310
MC/DC25%1/4
not defined $n or $n eq "all" and not @a or $n eq "interfaces"
not defined $n $n eq "all" not @a $n eq "interfaces"
Truth table50%3/6
not(A) or B and not(C) or D
A= not defined $nB= $n eq "all"C= not @aD= $n eq "interfaces"
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
3470 1 ▶ return ( join( "\n", sort keys %$wg ), 1 ) if defined $n && $n eq 'interfaces';
Branch: 1 branch
BranchTrueFalseTotal
if defined $n and $n eq "interfaces" 0 1 1
Condition33%1/3
defined $n and $n eq "interfaces"
!ll&&!rl&&r
100
MC/DC0%0/2
defined $n and $n eq "interfaces"
defined $n $n eq "interfaces"
Truth table33%1/3
A and B
A= defined $nB= $n eq "interfaces"
ABresult
0X0
100
111
3471 1 return ( join( "\n\n", map { _wg_show_if( $_, $wg->{$_} ) } sort keys %$wg ), 1 );
3472 }
3473 4 ▶ if ( $n eq 'all' && @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "all" and @a) 1 3 4
Condition66%2/3
$n eq "all" and @a
!ll&&!rl&&r
301
MC/DC50%1/2
$n eq "all" and @a
$n eq "all" @a
Truth table66%2/3
A and B
A= $n eq "all"B= @a
ABresult
0X0
100
111
3474 1 my $what = shift @a;
3475 1 return ( join( "\n", map { my $i = $_; map {"$i\t$_"} split /\n/, _wg_show_if( $i, $wg->{$i}, $what ) } sort keys %$wg ), 1 );
3476 }
3477 3 ▶ return ( "Unable to access interface: No such device", 0 ) unless $wg->{$n};
Branch: 1 branch
BranchTrueFalseTotal
unless $$wg{$n} 0 3 3
3478 3 return ( _wg_show_if( $n, $wg->{$n}, shift @a ), 1 );
3479 }
3480 7 ▶ if ( $sub eq 'showconf' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "showconf") 1 6 7
3481 1 ▶ my $n = shift @a // return ( 'Usage: wg showconf <interface>', 0 );
Condition50%1/2
shift @a // (return "Usage: wg showconf <interface>", 0)
l!l
10
MC/DC0%0/1
shift @a // (return "Usage: wg showconf <interface>", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3482 1 ▶ return ( "Unable to access interface: No such device", 0 ) unless $wg->{$n};
Branch: 1 branch
BranchTrueFalseTotal
unless $$wg{$n} 0 1 1
3483 1 return ( _wg_conf( $wg->{$n} ) =~ s/\n\z//r, 1 );
3484 }
3485 6 ▶ if ( $sub eq 'set' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "set") 4 2 6
3486 4 ▶ my $n = shift @a // return ( 'Usage: wg set <interface> [listen-port <port>] … [peer <base64 public key> …]', 0 );
Condition50%1/2
shift @a // (return "Usage: wg set <interface> [listen-port <port>] \x{2026} [peer <base64 public key> \x{2026}]", 0)
l!l
40
MC/DC0%0/1
shift @a // (return "Usage: wg set <interface> [listen-port <port>] \x{2026} [peer <base64 public key> \x{2026}]", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3487 4 ▶ my $w = $wg->{$n} or return ( "Unable to modify interface: No such device", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $w = $$wg{$n} or return "Unable to modify interface: No such device", 0 4 0 4
3488 4 my $peer;
3489 4 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 7 3 10
3490 7 my $k = shift @a;
3491 0 ▶ if ( $k eq 'listen-port' ) { $w->{listen_port} = shift @a; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "listen-port") 0 7 7
3492 0 ▶ if ( $k eq 'fwmark' || $k eq 'private-key' ) { shift @a; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "fwmark" or $k eq "private-key") 0 7 7
Condition33%1/3
$k eq "fwmark" or $k eq "private-key"
l!l&&r!l&&!r
007
MC/DC0%0/2
$k eq "fwmark" or $k eq "private-key"
$k eq "fwmark" $k eq "private-key"
Truth table33%1/3
A or B
A= $k eq "fwmark"B= $k eq "private-key"
ABresult
1X1
011
000
3493 7 ▶ if ( $k eq 'peer' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "peer") 4 3 7
3494 4 ▶ my $key = shift @a // return ( 'Unable to parse peer key', 0 );
Condition50%1/2
shift @a // (return "Unable to parse peer key", 0)
l!l
40
MC/DC0%0/1
shift @a // (return "Unable to parse peer key", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3495 4 ▶ return ( "Key is not the correct length or format: `$key'", 0 ) unless $key =~ m{\A[A-Za-z0-9+/]{42,43}=\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ m[\A[A-Za-z0-9+/]{42,43}=\z] 1 3 4
3496 3 ▶ $w->{peers}{$key} //= { allowed_ips => [] };
Condition100%2/2
$$w{"peers"}{$key} //= {"allowed_ips", []}
l!l
12
MC/DC100%1/1
$$w{"peers"}{$key} //= {"allowed_ips", []}
$$w{"peers"}{$key}
Truth table100%2/2
A
A= $$w{"peers"}{$key}
Aresult
11
00
3497 3 $peer = $key;
3498 3 next;
3499 }
3500 3 ▶ return ( "Invalid argument: $k", 0 ) unless defined $peer;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $peer 0 3 3
3501 0 ▶ if ( $k eq 'remove' ) { delete $w->{peers}{$peer}; undef $peer; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "remove") 0 3 3
3502 3 my $v = shift @a;
3503 3 ▶ return ( "Invalid argument: $k", 0 ) unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 3 3
3504 3 ▶ if ( $k eq 'allowed-ips' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($k eq 'allowed-ips') { } 3 0 3
elsif ($k eq 'endpoint') { } 0 0 0
elsif ($k eq 'persistent-keepalive') { } 0 0 0
elsif ($k eq 'preshared-key') { } 0 0 0
3505 3 my @ips = grep {length} split /\s*,\s*/, $v;
3506 3 for (@ips) {
3507 5 ▶ return ( "Unable to parse IP address: `$_'", 0 ) unless m{\A[\d.]+/\d+\z|\A[\d.]+\z|:};
Branch: 1 branch
BranchTrueFalseTotal
unless m[\A[\d.]+/\d+\z|\A[\d.]+\z|:] 0 5 5
3508 5 ▶ $_ .= '/32' unless m{/} || /:/;
Branch: 1 branch
BranchTrueFalseTotal
unless m[/] or /:/ 0 5 5
Condition33%1/3
m[/] or /:/
l!l&&r!l&&!r
500
MC/DC0%0/2
m[/] or /:/
m[/] /:/
Truth table33%1/3
A or B
A= m[/]B= /:/
ABresult
1X1
011
000
3509 }
3510 3 $w->{peers}{$peer}{allowed_ips} = \@ips;
3511 3 _wg_claim( $w, $peer );
3512 }
3513 0 elsif ( $k eq 'endpoint' ) { $w->{peers}{$peer}{endpoint} = $v }
3514 0 elsif ( $k eq 'persistent-keepalive' ) { $w->{peers}{$peer}{keepalive} = $v }
3515 elsif ( $k eq 'preshared-key' ) { }
3516 0 else { return ( "Invalid argument: $k", 0 ) }
3517 }
3518 3 return ( '', 1 );
3519 }
3520 2 ▶ if ( $sub eq 'syncconf' || $sub eq 'setconf' || $sub eq 'addconf' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "syncconf" or $sub eq "setconf" or $sub eq "addconf") 2 0 2
Condition33%2/6
$sub eq "syncconf" or $sub eq "setconf" or $sub eq "addconf"
l!l&&r!l&&!r
200
$sub eq "syncconf" or $sub eq "setconf"
l!l&&r!l&&!r
200
MC/DC0%0/3
$sub eq "syncconf" or $sub eq "setconf" or $sub eq "addconf"
$sub eq "syncconf" $sub eq "setconf" $sub eq "addconf"
Truth table25%1/4
A or B or C
A= $sub eq "syncconf"B= $sub eq "setconf"C= $sub eq "addconf"
ABCresult
1XX1
01X1
0011
0000
3521 2 ▶ my $n = shift @a // return ( "Usage: wg $sub <interface> <configuration filename>", 0 );
Condition50%1/2
shift @a // (return "Usage: wg $sub <interface> <configuration filename>", 0)
l!l
20
MC/DC0%0/1
shift @a // (return "Usage: wg $sub <interface> <configuration filename>", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3522 2 ▶ my $src = shift @a // return ( "Usage: wg $sub <interface> <configuration filename>", 0 );
Condition50%1/2
shift @a // (return "Usage: wg $sub <interface> <configuration filename>", 0)
l!l
20
MC/DC0%0/1
shift @a // (return "Usage: wg $sub <interface> <configuration filename>", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3523 2 ▶ return ( "Unable to modify interface: No such device", 0 ) unless $wg->{$n};
Branch: 1 branch
BranchTrueFalseTotal
unless $$wg{$n} 0 2 2
3524 2 my $text;
3525 2 my ($in) = $src =~ /\A<\(\s*wg-quick\s+strip\s+(\S+?)\)?\z/;
3526 2 ▶ if ( defined $in || ( $src eq '<(wg-quick' && ( $a[0] // '' ) eq 'strip' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $in or $src eq '<(wg-quick' and ($a[0] // '') eq 'strip') { } 2 0 2
Condition37%3/8
defined $in or $src eq "<(wg-quick" and ($a[0] // "") eq "strip"
l!l&&r!l&&!r
020
$src eq "<(wg-quick" and ($a[0] // "") eq "strip"
!ll&&!rl&&r
002
$a[0] // ""
l!l
20
MC/DC0%0/3
defined $in or $src eq "<(wg-quick" and ($a[0] // "") eq "strip"
defined $in $src eq "<(wg-quick" $a[0]
Truth table25%1/4
A or B and C
A= defined $inB= $src eq "<(wg-quick"C= $a[0]
ABCresult
1XX1
0111
00X0
0100
3527 2 ▶ my $f = $in // ( $a[1] // '' ); # nie $1 einer frueheren Suche
Condition50%2/4
$in // ($a[1] // "")
l!l
02
$a[1] // ""
l!l
20
MC/DC0%0/1
$in // ($a[1] // "")
$in
Truth table50%1/2
A
A= $in
Aresult
11
00
3528 2 $f =~ s/\)\z//;
3529 2 ▶ $f = $1 if $f =~ m{(wg\d+)};
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /(wg\d+)/ 2 0 2
3530 2 $text = _file_text( $dev, "/etc/wireguard/$f.conf" );
3531 2 ▶ $text =~ s/^\s*(Address|DNS|MTU|Table|PreUp|PostUp|PreDown|PostDown|SaveConfig)\s*=.*\n?//mgi if defined $text;
Branch: 1 branch
BranchTrueFalseTotal
if defined $text 2 0 2
3532 }
3533 0 else { $text = _file_text( $dev, $src ) }
3534 2 ▶ return ( "fopen: No such file or directory", 0 ) unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 2 2
3535 2 $wg->{$n} = _wg_parse( $text, $wg->{$n} );
3536 2 return ( '', 1 );
3537 }
3538 0 ▶ if ( $sub eq 'genkey' || $sub eq 'pubkey' || $sub eq 'genpsk' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "genkey" or $sub eq "pubkey" or $sub eq "genpsk") 0 0 0
Condition0%0/6
$sub eq "genkey" or $sub eq "pubkey" or $sub eq "genpsk"
l!l&&r!l&&!r
000
$sub eq "genkey" or $sub eq "pubkey"
l!l&&r!l&&!r
000
MC/DC0%0/3
$sub eq "genkey" or $sub eq "pubkey" or $sub eq "genpsk"
$sub eq "genkey" $sub eq "pubkey" $sub eq "genpsk"
Truth table0%0/4
A or B or C
A= $sub eq "genkey"B= $sub eq "pubkey"C= $sub eq "genpsk"
ABCresult
1XX1
01X1
0011
0000
3539 0 return ( 'aGVsbG8tdGhpcy1pcy1hLXNpbXVsYXRlZC1rZXktMDA=', 1 );
3540 }
3541 0 return ( "Invalid subcommand: `$sub'\nUsage: wg <cmd> [<args>]", 0 );
3542 }
3543  
3544 5 ▶sub _wgquick {
Subroutine _wgquick: called CC=12 SCAR=31.0
3545 5 my ( $dev, $av ) = @_;
3546 5 my ( $sub, $n ) = @$av;
3547 5 ▶ return ( 'Usage: wg-quick [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]', 0 ) unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 5 5
3548 5 ▶ $n = $1 if $n =~ m{(wg\d+)};
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ /(wg\d+)/ 5 0 5
3549 5 my $file = "/etc/wireguard/$n.conf";
3550 5 ▶ if ( $sub eq 'strip' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "strip") 0 5 5
3551 0 ▶ my $t = _file_text( $dev, $file ) // return ( "wg-quick: `$file' does not exist", 0 );
Condition0%0/2
_file_text($dev, $file) // (return "wg-quick: `${file}' does not exist", 0)
l!l
00
MC/DC0%0/1
_file_text($dev, $file) // (return "wg-quick: `${file}' does not exist", 0)
_file_text($dev, $file)
Truth table0%0/2
A
A= _file_text($dev, $file)
Aresult
11
00
3552 0 $t =~ s/^\s*(Address|DNS|MTU|Table|PreUp|PostUp|PreDown|PostDown|SaveConfig)\s*=.*\n?//mgi;
3553 0 return ( $t =~ s/\n\z//r, 1 );
3554 }
3555 5 ▶ if ( $sub eq 'save' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "save") 0 5 5
3556 0 ▶ return ( "wg-quick: `$n' is not a WireGuard interface", 0 ) unless $dev->{wg}{$n};
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{"wg"}{$n} 0 0 0
3557 0 ▶ _file_set( $dev, $file, _wg_conf( $dev->{wg}{$n} ) ) if exists $dev->{files}{$file};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$dev{"files"}{$file} 0 0 0
3558 0 return ( '', 1 );
3559 }
3560 5 ▶ if ( $sub eq 'down' || $sub eq 'up' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "down" or $sub eq "up") 5 0 5
Condition66%2/3
$sub eq "down" or $sub eq "up"
l!l&&r!l&&!r
140
MC/DC0%0/2
$sub eq "down" or $sub eq "up"
$sub eq "down" $sub eq "up"
Truth table66%2/3
A or B
A= $sub eq "down"B= $sub eq "up"
ABresult
1X1
011
000
3561 5 my $copy = Langertha::Holmgang::Sim::Linux::clone_state($dev);
3562 5 ▶ my $out = eval { $sub eq 'up' ? _wg_up( $copy, $n ) : _wg_down( $copy, $n ) };
Branch: 1 branch
BranchTrueFalseTotal
$sub eq 'up' ? : 4 1 5
3563 5 ▶ if ( my $e = $@ ) { $e =~ s/\s+\z//; return ( $e, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 1 4 5
3564 4 %$dev = %$copy;
3565 4 return ( $out, 1 );
3566 }
3567 0 return ( 'Usage: wg-quick [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]', 0 );
3568 }
3569  
3570 # --- nftables ------------------------------------------------------------------------
3571  
3572 36 ▶sub _norm_rule {
Subroutine _norm_rule: called CC=1 SCAR=0.0
3573 36 my ($r) = @_;
3574 36 $r =~ s/\s+/ /g;
3575 36 $r =~ s/\A\s+|\s+\z//g;
3576 36 $r =~ s/\b(iifname|oifname)\s+(?!["{@]|!=|(?:v?map)\b)([^\s{}",]+)/$1 "$2"/g;
3577 36 $r =~ s/\b(iifname|oifname)\s+"([^"]+)"/$1 "$2"/g;
3578 36 return $r;
3579 }
3580  
3581 42 ▶sub _nft_tables { my ($dev) = @_; return $dev->{nft} //= {} }
Subroutine _nft_tables: called CC=2 SCAR=6.9
Condition100%2/2
$$dev{"nft"} //= {}
l!l
411
MC/DC100%1/1
$$dev{"nft"} //= {}
$$dev{"nft"}
Truth table100%2/2
A
A= $$dev{"nft"}
Aresult
11
00
3582  
3583 # Handles der Regeln einer Tabelle. Beim ersten Blick aus der Reihenfolge
3584 # gezaehlt, danach fest wie in nft: eine neue Regel bekommt die naechste
3585 # Nummer, die anderen behalten ihre. Gefuehrt in _handles/_next_handle
3586 # (Buchfuehrung des Simulators; der Diff des Endzustands sieht sie nicht).
3587 112 ▶sub _handles {
Subroutine _handles: called CC=10 SCAR=23.3
3588 112 my ($t) = @_;
3589 112 ▶ my $chains = $t->{chains} || {};
Condition50%1/2
$$t{'chains'} || {}
l!l
1120
MC/DC0%0/1
$$t{'chains'} || {}
$$t{'chains'}
Truth table50%1/2
A
A= $$t{'chains'}
Aresult
11
00
3590 112 ▶ if ( !defined $t->{_next_handle} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$t{"_next_handle"}) 21 91 112
3591 21 my $n = 1 + scalar keys %$chains;
3592 21 ▶ for my $c ( sort keys %$chains ) { $chains->{$c}{_handles} = [ map { ++$n } @{ $chains->{$c}{rules} || [] } ] }
Condition50%1/2
$$chains{$c}{'rules'} || []
l!l
220
MC/DC0%0/1
$$chains{$c}{'rules'} || []
$$chains{$c}{'rules'}
Truth table50%1/2
A
A= $$chains{$c}{'rules'}
Aresult
11
00
3593 21 $t->{_next_handle} = $n + 1;
3594 }
3595 112 my %h;
3596 112 for my $c ( sort keys %$chains ) {
3597 124 my $ch = $chains->{$c};
3598 124 ▶ my $n = @{ $ch->{rules} || [] };
Condition50%1/2
$$ch{'rules'} || []
l!l
1240
MC/DC0%0/1
$$ch{'rules'} || []
$$ch{'rules'}
Truth table50%1/2
A
A= $$ch{'rules'}
Aresult
11
00
3599 124 ▶ my $own = ref $ch->{_handles} eq 'ARRAY' ? $ch->{_handles} : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $$ch{'_handles'} eq 'ARRAY' ? : 123 1 124
3600 124 ▶ splice @$own, $n if @$own > $n;
Branch: 1 branch
BranchTrueFalseTotal
if @$own > $n 0 124 124
3601 124 ▶ push @$own, $t->{_next_handle}++ while @$own < $n;
Branch: 1 branch
BranchTrueFalseTotal
@$own < $n and do { push @$own, $$t{"_next_handle"}++ } 0 124 124
3602 124 $ch->{_handles} = $own;
3603 124 $h{$c} = [@$own];
3604 }
3605 112 return \%h;
3606 }
3607  
3608 21 ▶sub _nft_chain_text {
Subroutine _nft_chain_text: called CC=8 SCAR=20.9
3609 21 my ( $tname, $t, $c, $with_h, $handles ) = @_;
3610 21 my $ch = $t->{chains}{$c};
3611 21 ▶ my @l = ("\tchain $c {" . ( $with_h ? ' # handle ' . ( 1 + ( grep { $_ lt $c } keys %{ $t->{chains} } ) ) : '' ));
Branch: 1 branch
BranchTrueFalseTotal
$with_h ? : 7 14 21
3612 21 ▶ if ( $ch->{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$ch{"type"}) 20 1 21
3613 20 ▶ my $p = $ch->{priority} // 0;
Condition50%1/2
$$ch{"priority"} // 0
l!l
200
MC/DC0%0/1
$$ch{"priority"} // 0
$$ch{"priority"}
Truth table50%1/2
A
A= $$ch{"priority"}
Aresult
11
00
3614 20 ▶ push @l, "\t\ttype $ch->{type} hook $ch->{hook} priority $p; policy " . ( $ch->{policy} // 'accept' ) . ';';
Condition50%1/2
$$ch{"policy"} // "accept"
l!l
200
MC/DC0%0/1
$$ch{"policy"} // "accept"
$$ch{"policy"}
Truth table50%1/2
A
A= $$ch{"policy"}
Aresult
11
00
3615 }
3616 21 my $i = 0;
3617 21 ▶ for my $r ( @{ $ch->{rules} || [] } ) {
Condition50%1/2
$$ch{'rules'} || []
l!l
210
MC/DC0%0/1
$$ch{'rules'} || []
$$ch{'rules'}
Truth table50%1/2
A
A= $$ch{'rules'}
Aresult
11
00
3618 42 ▶ push @l, "\t\t$r" . ( $with_h ? " # handle $handles->{$c}[$i]" : '' );
Branch: 1 branch
BranchTrueFalseTotal
$with_h ? : 18 24 42
3619 42 $i++;
3620 }
3621 21 push @l, "\t}";
3622 21 return @l;
3623 }
3624  
3625 4 ▶sub _nft_set_text {
Subroutine _nft_set_text: called CC=6 SCAR=19.7
3626 4 my ( $name, $s ) = @_;
3627 4 ▶ my @l = ( "\tset $name {", "\t\ttype " . ( $s->{type} // 'ipv4_addr' ) );
Condition50%1/2
$$s{"type"} // "ipv4_addr"
l!l
40
MC/DC0%0/1
$$s{"type"} // "ipv4_addr"
$$s{"type"}
Truth table50%1/2
A
A= $$s{"type"}
Aresult
11
00
3628 4 ▶ push @l, "\t\tflags " . join( ',', @{ $s->{flags} } ) if ref $s->{flags} eq 'ARRAY' && @{ $s->{flags} };
Branch: 1 branch
BranchTrueFalseTotal
if ref $$s{"flags"} eq "ARRAY" and @{$$s{"flags"};} 4 0 4
Condition33%1/3
ref $$s{"flags"} eq "ARRAY" and @{$$s{"flags"};}
!ll&&!rl&&r
004
MC/DC0%0/2
ref $$s{"flags"} eq "ARRAY" and @{$$s{"flags"};}
ref $$s{"flags"} eq "ARRAY" @{$$s{"flags"};}
Truth table33%1/3
A and B
A= ref $$s{"flags"} eq "ARRAY"B= @{$$s{"flags"};}
ABresult
0X0
100
111
3629 4 ▶ push @l, "\t\telements = { " . join( ', ', @{ $s->{elements} } ) . ' }' if ref $s->{elements} eq 'ARRAY' && @{ $s->{elements} };
Branch: 1 branch
BranchTrueFalseTotal
if ref $$s{"elements"} eq "ARRAY" and @{$$s{"elements"};} 4 0 4
Condition33%1/3
ref $$s{"elements"} eq "ARRAY" and @{$$s{"elements"};}
!ll&&!rl&&r
004
MC/DC0%0/2
ref $$s{"elements"} eq "ARRAY" and @{$$s{"elements"};}
ref $$s{"elements"} eq "ARRAY" @{$$s{"elements"};}
Truth table33%1/3
A and B
A= ref $$s{"elements"} eq "ARRAY"B= @{$$s{"elements"};}
ABresult
0X0
100
111
3630 4 push @l, "\t}";
3631 4 return @l;
3632 }
3633  
3634 13 ▶sub _nft_table_text {
Subroutine _nft_table_text: called CC=7 SCAR=19.5
3635 13 my ( $tname, $t, $with_h ) = @_;
3636 13 my $h = _handles($t);
3637 13 ▶ my @l = ( "table $tname {" . ( $with_h ? ' # handle 1' : '' ) );
Branch: 1 branch
BranchTrueFalseTotal
$with_h ? : 1 12 13
3638 13 ▶ push @l, _nft_set_text( $_, $t->{sets}{$_} ), '' for sort keys %{ $t->{sets} || {} };
Condition100%2/2
$$t{'sets'} || {}
l!l
310
MC/DC100%1/1
$$t{'sets'} || {}
$$t{'sets'}
Truth table100%2/2
A
A= $$t{'sets'}
Aresult
11
00
3639 13 ▶ my @c = sort keys %{ $t->{chains} || {} };
Condition50%1/2
$$t{'chains'} || {}
l!l
130
MC/DC0%0/1
$$t{'chains'} || {}
$$t{'chains'}
Truth table50%1/2
A
A= $$t{'chains'}
Aresult
11
00
3640 13 for my $i ( 0 .. $#c ) {
3641 14 push @l, _nft_chain_text( $tname, $t, $c[$i], $with_h, $h );
3642 14 ▶ push @l, '' if $i < $#c;
Branch: 1 branch
BranchTrueFalseTotal
if $i < $#c 1 13 14
3643 }
3644 13 push @l, '}';
3645 13 return @l;
3646 }
3647  
3648 # Regelsatz im Dateiformat von nft (wie /etc/nftables.conf): flush ruleset,
3649 # table F T { chain C { type …; policy …; regel … } }, add/insert/delete-Zeilen.
3650 # Alles oder nichts, wie nft -f.
3651 9 ▶sub _nft_load {
Subroutine _nft_load: called CC=45 SCAR=43.1
3652 9 my ( $dev, $text, $file, $check_only ) = @_;
3653 9 ▶ my $copy = { nft => Langertha::Holmgang::Sim::Linux::clone_state( $dev->{nft} || {} ) };
Condition50%1/2
$$dev{'nft'} || {}
l!l
90
MC/DC0%0/1
$$dev{'nft'} || {}
$$dev{'nft'}
Truth table50%1/2
A
A= $$dev{'nft'}
Aresult
11
00
3654 9 my ( $table, $chain, $set, %def );
3655 9 my $n = 0;
3656 9 ▶ my $err = sub { ( "$file:$n:1-1: Error: syntax error, unexpected $_[0]\n$_[1]", 0 ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
3657 9 for my $raw ( split /\n/, $text ) {
3658 116 $n++;
3659 116 ( my $l = $raw ) =~ s/#.*//;
3660 116 $l =~ s/\A\s+|\s+\z//g;
3661 116 ▶ next unless length $l;
Branch: 1 branch
BranchTrueFalseTotal
unless length $l 18 98 116
3662 98 ▶ if ( $l =~ /\Adefine\s+(\w+)\s*=\s*(.+?)\s*;?\z/ ) { $def{$1} = $2; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\Adefine\s+(\w+)\s*=\s*(.+?)\s*;?\z/) 4 94 98
3663 94 ▶ if ( $l =~ /\Ainclude\b/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\Ainclude\b/) 0 94 94
3664 0 push @GAPS, "nft -f $file ($l)";
3665 0 return ( '', 0 );
3666 }
3667 94 ▶ $l =~ s/\$(\w+)/exists $def{$1} ? $def{$1} : "\$$1"/ge;
Branch: 1 branch
BranchTrueFalseTotal
exists $def{$1} ? : 4 0 4
3668 94 ▶ return ( "$file:$n: Error: unknown identifier '$1'\n$raw", 0 ) if $l =~ /\$(\w+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\$(\w+)/ 0 94 94
3669 94 ▶ if ( defined $set ) { # Set-Block: bis die Klammern aufgehen
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set) 16 78 94
3670 16 $set->{text} .= " $l";
3671 16 my $open = () = $set->{text} =~ /\{/g;
3672 16 my $close = () = $set->{text} =~ /\}/g;
3673 16 ▶ next if $open > $close;
Branch: 1 branch
BranchTrueFalseTotal
if $open > $close 12 4 16
3674 4 ( my $spec = $set->{text} ) =~ s/\A\s*\{|\}\s*\z//g;
3675 4 my $e = _nft_set_spec( $copy->{nft}{$table}, $set->{name}, $spec );
3676 4 ▶ return ( "$file:$n: $e", 0 ) if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 4 4
3677 4 undef $set;
3678 4 next;
3679 }
3680 78 ▶ if ( defined $table && !defined $chain && $l =~ /\Aset\s+([\w-]+)\s*(\{.*)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $table and not defined $chain and $l =~ /\Aset\s+([\w-]+)\s*(\{.*)\z/) 4 74 78
Condition100%6/6
defined $table and not defined $chain and $l =~ /\Aset\s+([\w-]+)\s*(\{.*)\z/
!ll&&!rl&&r
53214
defined $table and not defined $chain
!ll&&!rl&&r
193425
MC/DC100%3/3
defined $table and not defined $chain and $l =~ /\Aset\s+([\w-]+)\s*(\{.*)\z/
defined $table not defined $chain $l =~ /\Aset\s+([\w-]+)\s*(\{.*)\z/
Truth table100%4/4
A and not(B) and C
A= defined $tableB= not defined $chainC= $l =~ /\Aset\s+([\w-]+)\s*(\{.*)\z/
ABCresult
0XX0
10X0
1100
1111
3681 4 $set = { name => $1, text => $2 };
3682 4 $l = $2;
3683 4 my $open = () = $l =~ /\{/g;
3684 4 my $close = () = $l =~ /\}/g;
3685 4 ▶ next if $open > $close;
Branch: 1 branch
BranchTrueFalseTotal
if $open > $close 4 0 4
3686 0 ( my $spec = $l ) =~ s/\A\s*\{|\}\s*\z//g;
3687 0 my $e = _nft_set_spec( $copy->{nft}{$table}, $set->{name}, $spec );
3688 0 ▶ return ( "$file:$n: $e", 0 ) if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 0 0
3689 0 undef $set;
3690 0 next;
3691 }
3692 74 ▶ if ( !defined $table ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $table) 19 55 74
3693 19 ▶ if ( $l eq 'flush ruleset' ) { $copy->{nft} = {}; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l eq "flush ruleset") 8 11 19
3694 11 ▶ if ( $l =~ /\Atable\s+(?:(ip|ip6|inet|arp|bridge|netdev)\s+)?(\S+)\s*\{\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\Atable\s+(?:(ip|ip6|inet|arp|bridge|netdev)\s+)?(\S+)\s*\{\z/) 11 0 11
3695 11 ▶ $table = ( $1 // 'ip' ) . " $2";
Condition50%1/2
$1 // "ip"
l!l
110
MC/DC0%0/1
$1 // "ip"
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
3696 11 ▶ $copy->{nft}{$table} //= { chains => {} };
Condition50%1/2
$$copy{"nft"}{$table} //= {"chains", {}}
l!l
011
MC/DC0%0/1
$$copy{"nft"}{$table} //= {"chains", {}}
$$copy{"nft"}{$table}
Truth table50%1/2
A
A= $$copy{"nft"}{$table}
Aresult
11
00
3697 11 next;
3698 }
3699 0 ▶ if ( $l =~ /\A(?:add|insert|delete|flush|create|replace)\s/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A(?:add|insert|delete|flush|create|replace)\s/) 0 0 0
3700 0 my ( $o, $k ) = _nft( $copy, [ split /\s+/, $l ] );
3701 0 ▶ return ( "$file:$n: $o", 0 ) unless $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $k 0 0 0
3702 0 next;
3703 }
3704 0 return $err->( 'string', $raw );
3705 }
3706 55 ▶ if ( !defined $chain ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chain) 21 34 55
3707 21 ▶ if ( $l eq '}' ) { undef $table; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l eq "}") 10 11 21
3708 11 ▶ if ( $l =~ /\Achain\s+(\S+)\s*\{\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\Achain\s+(\S+)\s*\{\z/) 11 0 11
3709 11 $chain = $1;
3710 11 ▶ $copy->{nft}{$table}{chains}{$chain} //= { rules => [] };
Condition50%1/2
$$copy{"nft"}{$table}{"chains"}{$chain} //= {"rules", []}
l!l
011
MC/DC0%0/1
$$copy{"nft"}{$table}{"chains"}{$chain} //= {"rules", []}
$$copy{"nft"}{$table}{"chains"}{$chain}
Truth table50%1/2
A
A= $$copy{"nft"}{$table}{"chains"}{$chain}
Aresult
11
00
3711 11 next;
3712 }
3713 0 return $err->( 'string', $raw );
3714 }
3715 34 ▶ if ( $l eq '}' ) { undef $chain; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l eq "}") 10 24 34
3716 24 my $c = $copy->{nft}{$table}{chains}{$chain};
3717 24 ▶ if ( $l =~ /\Atype\s+(\w+)\s+hook\s+(\w+)\s+(?:device\s+\S+\s+)?priority\s+([\w-]+)\s*;\s*(?:policy\s+(accept|drop)\s*;?)?\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\Atype\s+(\w+)\s+hook\s+(\w+)\s+(?:device\s+\S+\s+)?priority\s+([\w-]+)\s*;\s*(?:policy\s+(accept|drop)\s*;?)?\z/) 10 14 24
3718 10 @{$c}{qw( type hook priority )} = ( $1, $2, $3 );
3719 10 ▶ $c->{policy} = $4 if defined $4;
Branch: 1 branch
BranchTrueFalseTotal
if defined $4 10 0 10
3720 10 next;
3721 }
3722 0 ▶ if ( $l =~ /\Apolicy\s+(accept|drop)\s*;?\z/ ) { $c->{policy} = $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\Apolicy\s+(accept|drop)\s*;?\z/) 0 14 14
3723 0 ▶ if ( my $bad = _nft_bad_type($l) ) { return ( "$file:$n:1-1: $bad\n$raw", 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $bad = _nft_bad_type($l)) 0 14 14
3724 14 push @{ $c->{rules} }, _norm_rule($l);
3725 }
3726 9 ▶ return $err->( 'end of file', '' ) if defined $table;
Branch: 1 branch
BranchTrueFalseTotal
if defined $table 1 8 9
3727 8 for my $t ( values %{ $copy->{nft} } ) {
3728 10 ▶ for my $r ( map { @{ $_->{rules} || [] } } values %{ $t->{chains} || {} } ) {
Condition50%2/4
$$_{'rules'} || []
l!l
100
$$t{'chains'} || {}
l!l
100
MC/DC0%0/1
$$_{'rules'} || []
$$_{'rules'}
MC/DC0%0/1
$$t{'chains'} || {}
$$t{'chains'}
Truth table50%1/2
A
A= $$_{'rules'}
Aresult
11
00
Truth table50%1/2
A
A= $$t{'chains'}
Aresult
11
00
3729 0 ▶ if ( my $se = Langertha::Holmgang::Sim::Linux::Nft::syntax_error($r) ) { return ( "$file: $se", 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $se = Langertha::Holmgang::Sim::Linux::Nft::syntax_error($r)) 0 14 14
3730 14 my $e = _nft_rule_refs( $t, $r );
3731 14 ▶ return ( "$file: $e\n$r", 0 ) if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 14 14
3732 }
3733 }
3734 # Regeln, die der Auswerter nicht versteht: Luecke (das Urteil daran waere geraten)
3735 8 for my $t ( values %{ $copy->{nft} } ) {
3736 10 ▶ for my $ch ( values %{ $t->{chains} || {} } ) { _nft_gap( $ch, $_ ) for @{ $ch->{rules} || [] } }
Condition50%2/4
$$t{'chains'} || {}
l!l
100
$$ch{'rules'} || []
l!l
100
MC/DC0%0/1
$$t{'chains'} || {}
$$t{'chains'}
MC/DC0%0/1
$$ch{'rules'} || []
$$ch{'rules'}
Truth table50%1/2
A
A= $$t{'chains'}
Aresult
11
00
Truth table50%1/2
A
A= $$ch{'rules'}
Aresult
11
00
3737 }
3738 8 ▶ $dev->{nft} = $copy->{nft} unless $check_only;
Branch: 1 branch
BranchTrueFalseTotal
unless $check_only 7 1 8
3739 8 return ( '', 1 );
3740 }
3741  
3742 # Typnamen fuer "icmp type" / "icmpv6 type" wie nft sie kennt; ein unbekannter Name ist
3743 # ein Fehler (nft lehnt die Regel ab), nicht still angenommen.
3744 82 our %ICMP_TYPES = map { $_ => 1 } qw( echo-reply destination-unreachable source-quench redirect echo-request
3745 router-advertisement router-solicitation time-exceeded parameter-problem timestamp-request timestamp-reply
3746 info-request info-reply address-mask-request address-mask-reply );
3747 82 our %ICMPV6_TYPES = map { $_ => 1 } qw( destination-unreachable packet-too-big time-exceeded parameter-problem
3748 echo-request echo-reply mld-listener-query mld-listener-report mld-listener-done mld-listener-reduction
3749 nd-router-solicit nd-router-advert nd-neighbor-solicit nd-neighbor-advert nd-redirect router-renumbering
3750 ind-neighbor-solicit ind-neighbor-advert mld2-listener-report );
3751  
3752 36 ▶sub _nft_bad_type {
Subroutine _nft_bad_type: called CC=7 SCAR=19.5
3753 36 my ($rule) = @_;
3754 36 ▶ while ( $rule =~ /\b(icmpv6|icmp)\s+type\s+(?:!=\s*)?(\{[^}]*\}|\S+)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule =~ /\b(icmpv6|icmp)\s+type\s+(?:!=\s*)?(\{[^}]*\}|\S+)/g) 4 34 38
3755 4 my ( $fam, $list ) = ( $1, $2 );
3756 4 ▶ my $known = $fam eq 'icmpv6' ? \%ICMPV6_TYPES : \%ICMP_TYPES;
Branch: 1 branch
BranchTrueFalseTotal
$fam eq 'icmpv6' ? : 3 1 4
3757 4 for my $t ( grep {length} split /[\s,{}]+/, $list ) {
3758 7 ▶ next if $t =~ /\A\d+\z/ || $known->{$t};
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /\A\d+\z/ or $$known{$t} 5 2 7
Condition66%2/3
$t =~ /\A\d+\z/ or $$known{$t}
l!l&&r!l&&!r
052
MC/DC50%1/2
$t =~ /\A\d+\z/ or $$known{$t}
$t =~ /\A\d+\z/ $$known{$t}
Truth table66%2/3
A or B
A= $t =~ /\A\d+\z/B= $$known{$t}
ABresult
1X1
011
000
3759 2 ▶ return 'Error: Could not parse ' . ( $fam eq 'icmpv6' ? 'ICMPv6' : 'ICMP' ) . " type\n$t";
Branch: 1 branch
BranchTrueFalseTotal
$fam eq 'icmpv6' ? : 2 0 2
3760 }
3761 }
3762 34 return undef;
3763 }
3764  
3765 # Regel einer Filter- oder Sprungkette, die der Auswerter (Sim::Nft) nicht
3766 # versteht: Luecke der Simulation — ein Urteil daran waere geraten. NAT-Ketten
3767 # urteilen nicht und bleiben aussen vor.
3768 30 ▶sub _nft_gap {
Subroutine _nft_gap: called CC=4 SCAR=13.9
3769 30 my ( $ch, $text ) = @_;
3770 30 ▶ return if defined $ch->{type} && $ch->{type} ne 'filter';
Branch: 1 branch
BranchTrueFalseTotal
if defined $$ch{"type"} and $$ch{"type"} ne "filter" 1 29 30
Condition66%2/3
defined $$ch{"type"} and $$ch{"type"} ne "filter"
!ll&&!rl&&r
0291
MC/DC50%1/2
defined $$ch{"type"} and $$ch{"type"} ne "filter"
defined $$ch{"type"} $$ch{"type"} ne "filter"
Truth table66%2/3
A and B
A= defined $$ch{"type"}B= $$ch{"type"} ne "filter"
ABresult
0X0
100
111
3771 29 my $why = Langertha::Holmgang::Sim::Linux::Nft::parse_error($text);
3772 29 ▶ push @GAPS, "nft: $why" if $why;
Branch: 1 branch
BranchTrueFalseTotal
if $why 1 28 29
3773 29 return;
3774 }
3775  
3776 # Set-Angabe "type ipv4_addr; flags interval; elements = { … }" in die Tabelle;
3777 # liefert einen Fehlertext oder undef.
3778 6 ▶sub _nft_set_spec {
Subroutine _nft_set_spec: called CC=10 SCAR=24.5
3779 6 my ( $t, $name, $spec ) = @_;
3780 6 my %s = ( elements => [] );
3781 6 ▶ my $type = $spec =~ /\btype\s+(\w+)/ ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$spec =~ /\btype\s+(\w+)/ ? : 6 0 6
3782 6 ▶ return "Error: set definition does not specify key\nset $name" unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 6 6
3783 6 ▶ return "Error: unknown datatype $type" unless $type =~ /\A(?:ipv4_addr|ipv6_addr|inet_service|ifname|inet_proto)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /\A(?:ipv4_addr|ipv6_addr|inet_service|ifname|inet_proto)\z/ 0 6 6
3784 6 $s{type} = $type;
3785 6 ▶ $s{flags} = [ split /\s*,\s*/, $1 ] if $spec =~ /\bflags\s+([\w,\s]+?)\s*(?:;|\z|elements|\})/;
Branch: 1 branch
BranchTrueFalseTotal
if $spec =~ /\bflags\s+([\w,\s]+?)\s*(?:;|\z|elements|\})/ 5 1 6
3786 6 ▶ my $old = ( $t->{sets} || {} )->{$name};
Condition100%2/2
$$t{'sets'} || {}
l!l
15
MC/DC100%1/1
$$t{'sets'} || {}
$$t{'sets'}
Truth table100%2/2
A
A= $$t{'sets'}
Aresult
11
00
3787 0 ▶ $t->{sets}{$name} = { %s, elements => $old ? [ @{ $old->{elements} || [] } ] : [] };
Branch: 1 branch
BranchTrueFalseTotal
$old ? : 0 6 6
Condition0%0/2
$$old{'elements'} || []
l!l
00
MC/DC0%0/1
$$old{'elements'} || []
$$old{'elements'}
Truth table0%0/2
A
A= $$old{'elements'}
Aresult
11
00
3788 6 ▶ if ( $spec =~ /\belements\s*=\s*\{([^}]*)\}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec =~ /\belements\s*=\s*\{([^}]*)\}/) 4 2 6
3789 4 my $e = _nft_add_elements( $t->{sets}{$name}, $1 );
3790 4 ▶ return $e if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 4 4
3791 }
3792 6 return undef;
3793 }
3794  
3795 6 ▶sub _nft_add_elements {
Subroutine _nft_add_elements: called CC=11 SCAR=25.4
3796 6 my ( $s, $list ) = @_;
3797 6 ▶ my $interval = grep { $_ eq 'interval' } @{ $s->{flags} || [] };
Condition100%2/2
$$s{'flags'} || []
l!l
51
MC/DC100%1/1
$$s{'flags'} || []
$$s{'flags'}
Truth table100%2/2
A
A= $$s{'flags'}
Aresult
11
00
3798 6 for my $e ( grep {length} map { s/\A\s+|\s+\z//gr } split /,/, $list ) {
3799 7 $e =~ s/\A"|"\z//g;
3800 7 ▶ if ( $s->{type} =~ /addr\z/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$s{'type'} =~ /addr\z/) { } 7 0 7
elsif ($$s{'type'} eq 'inet_service') { } 0 0 0
3801 7 my $want6 = $s->{type} eq 'ipv6_addr';
3802 7 ▶ return "Error: Could not resolve hostname: $e" unless $e =~ $want6 ? qr/:/ : qr{\A[\d./-]+\z};
Branch: 2 branches
BranchTrueFalseTotal
unless $e =~ /$want6/ ? qr/:/ : qr"\A[\d./-]+\z" 0 7 7
$e =~ /$want6/ ? : 0 7 7
3803 7 ▶ return "Error: You must add 'flags interval' to your set\nadd element $e" if $e =~ m{[/-]} && !$interval;
Branch: 1 branch
BranchTrueFalseTotal
if $e =~ m[[/-]] and not $interval 1 6 7
Condition100%3/3
$e =~ m[[/-]] and not $interval
!ll&&!rl&&r
511
MC/DC100%2/2
$e =~ m[[/-]] and not $interval
$e =~ m[[/-]] not $interval
Truth table100%3/3
A and not(B)
A= $e =~ m[[/-]]B= not $interval
ABresult
0X0
100
111
3804 }
3805 elsif ( $s->{type} eq 'inet_service' ) {
3806 0 ▶ return "Error: Could not resolve service: $e" unless $e =~ /\A\d+(?:-\d+)?\z|\A[a-z][\w-]*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /\A\d+(?:-\d+)?\z|\A[a-z][\w-]*\z/ 0 0 0
3807 }
3808 6 ▶ push @{ $s->{elements} }, $e unless grep { $_ eq $e } @{ $s->{elements} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $e;} @{$$s{"elements"};} 6 0 6
3809 }
3810 5 return undef;
3811 }
3812  
3813 # Verweise einer Regel: benannte Sets und Ketten muessen in der Tabelle stehen
3814 32 ▶sub _nft_rule_refs {
Subroutine _nft_rule_refs: called CC=7 SCAR=19.7
3815 32 my ( $t, $r ) = @_;
3816 32 for my $s ( $r =~ /@([\w-]+)/g ) {
3817 6 ▶ return "Error: Could not process rule: No such file or directory\nset \@$s" unless ( $t->{sets} || {} )->{$s};
Branch: 1 branch
BranchTrueFalseTotal
unless ($$t{"sets"} || {})->{$s} 1 5 6
Condition100%2/2
$$t{'sets'} || {}
l!l
51
MC/DC100%1/1
$$t{'sets'} || {}
$$t{'sets'}
Truth table100%2/2
A
A= $$t{'sets'}
Aresult
11
00
3818 }
3819 31 for my $c ( $r =~ /\b(?:jump|goto)\s+([^\s,}]+)/g ) {
3820 1 ▶ return "Error: Could not process rule: No such file or directory\nchain $c" unless ( $t->{chains} || {} )->{$c};
Branch: 1 branch
BranchTrueFalseTotal
unless ($$t{"chains"} || {})->{$c} 0 1 1
Condition50%1/2
$$t{'chains'} || {}
l!l
10
MC/DC0%0/1
$$t{'chains'} || {}
$$t{'chains'}
Truth table50%1/2
A
A= $$t{'chains'}
Aresult
11
00
3821 }
3822 31 return undef;
3823 }
3824  
3825 # nft add|create|delete|flush set …, nft add|delete element … { … }
3826 6 ▶sub _nft_set_cmd {
Subroutine _nft_set_cmd: called CC=23 SCAR=35.4
3827 6 my ( $t, $tn, $verb, $obj, $cn, $rest, $syntax ) = @_;
3828 6 ▶ my $s = ( $t->{sets} || {} )->{$cn};
Condition100%2/2
$$t{'sets'} || {}
l!l
51
MC/DC100%1/1
$$t{'sets'} || {}
$$t{'sets'}
Truth table100%2/2
A
A= $$t{'sets'}
Aresult
11
00
3829 6 ▶ if ( $obj eq 'set' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj eq "set") 3 3 6
3830 3 ▶ if ( $verb eq 'add' || $verb eq 'create' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "add" or $verb eq "create") 2 1 3
Condition66%2/3
$verb eq "add" or $verb eq "create"
l!l&&r!l&&!r
201
MC/DC50%1/2
$verb eq "add" or $verb eq "create"
$verb eq "add" $verb eq "create"
Truth table66%2/3
A or B
A= $verb eq "add"B= $verb eq "create"
ABresult
1X1
011
000
3831 2 ▶ return ( "Error: Could not process rule: File exists\n$verb set $tn $cn", 0 ) if $s && $verb eq 'create';
Branch: 1 branch
BranchTrueFalseTotal
if $s and $verb eq "create" 0 2 2
Condition33%1/3
$s and $verb eq "create"
!ll&&!rl&&r
200
MC/DC0%0/2
$s and $verb eq "create"
$s $verb eq "create"
Truth table33%1/3
A and B
A= $sB= $verb eq "create"
ABresult
0X0
100
111
3832 2 ( my $spec = $rest ) =~ s/\A\s*\{|\}\s*\z//g;
3833 2 my $copy = Langertha::Holmgang::Sim::Linux::clone_state($t);
3834 2 my $e = _nft_set_spec( $copy, $cn, $spec );
3835 2 ▶ return ( $e, 0 ) if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 2 2
3836 2 %$t = %$copy;
3837 2 return ( '', 1 );
3838 }
3839 1 ▶ return ( "Error: Could not process rule: No such file or directory\n$verb set $tn $cn", 0 ) unless $s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s 0 1 1
3840 1 ▶ if ( $verb eq 'delete' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($verb eq 'delete') { } 1 0 1
elsif ($verb eq 'flush') { } 0 0 0
3841 1 ▶ my $used = grep {/\@\Q$cn\E\b/} map { @{ $_->{rules} || [] } } values %{ $t->{chains} || {} };
Condition50%2/4
$$_{'rules'} || []
l!l
20
$$t{'chains'} || {}
l!l
10
MC/DC0%0/1
$$_{'rules'} || []
$$_{'rules'}
MC/DC0%0/1
$$t{'chains'} || {}
$$t{'chains'}
Truth table50%1/2
A
A= $$_{'rules'}
Aresult
11
00
Truth table50%1/2
A
A= $$t{'chains'}
Aresult
11
00
3842 1 ▶ return ( "Error: Could not process rule: Device or resource busy\ndelete set $tn $cn", 0 ) if $used;
Branch: 1 branch
BranchTrueFalseTotal
if $used 1 0 1
3843 0 delete $t->{sets}{$cn};
3844 0 ▶ delete $t->{sets} unless %{ $t->{sets} };
Branch: 1 branch
BranchTrueFalseTotal
unless %{$$t{"sets"};} 0 0 0
3845 }
3846 0 elsif ( $verb eq 'flush' ) { $s->{elements} = [] }
3847 0 else { return $syntax->(qq{string "$verb"}) }
3848 0 return ( '', 1 );
3849 }
3850 3 ▶ return ( "Error: Could not process rule: No such file or directory\n$verb element $tn $cn", 0 ) unless $s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s 0 3 3
3851 3 ▶ my ($list) = $rest =~ /\A\s*\{(.*)\}\s*\z/s or return $syntax->("end of file, expecting '\{'");
Branch: 1 branch
BranchTrueFalseTotal
my($list) = $rest =~ /\A\s*\{(.*)\}\s*\z/s or return &$syntax("end of file, expecting '{'") 3 0 3
3852 3 ▶ if ( $verb eq 'add' || $verb eq 'create' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "add" or $verb eq "create") 2 1 3
Condition66%2/3
$verb eq "add" or $verb eq "create"
l!l&&r!l&&!r
201
MC/DC50%1/2
$verb eq "add" or $verb eq "create"
$verb eq "add" $verb eq "create"
Truth table66%2/3
A or B
A= $verb eq "add"B= $verb eq "create"
ABresult
1X1
011
000
3853 2 my $copy = Langertha::Holmgang::Sim::Linux::clone_state($s);
3854 2 my $e = _nft_add_elements( $copy, $list );
3855 2 ▶ return ( $e, 0 ) if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 1 1 2
3856 1 %$s = %$copy;
3857 1 return ( '', 1 );
3858 }
3859 1 ▶ if ( $verb eq 'delete' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "delete") 1 0 1
3860 1 my @del = grep {length} map { s/\A\s+|\s+\z//gr } split /,/, $list;
3861 1 for my $d (@del) {
3862 return ( "Error: Could not process rule: No such file or directory\ndelete element $tn $cn { $d }", 0 )
3863 1 ▶ unless grep { $_ eq $d } @{ $s->{elements} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $d;} @{$$s{"elements"};} 0 1 1
3864 }
3865 1 my %d = map { $_ => 1 } @del;
3866 1 $s->{elements} = [ grep { !$d{$_} } @{ $s->{elements} } ];
3867 1 return ( '', 1 );
3868 }
3869 0 return $syntax->(qq{string "$verb"});
3870 }
3871  
3872 # /etc/nftables.conf, wenn die Datei nicht eigens im Zustand steht: der laufende
3873 # Regelsatz im Dateiformat (so wie ihn `nft list ruleset > …` schriebe).
3874 4 ▶sub _nft_conf {
Subroutine _nft_conf: called CC=3 SCAR=11.1
3875 4 my ($dev) = @_;
3876 4 my @l = ( '#!/usr/sbin/nft -f', '', 'flush ruleset', '' );
3877 4 ▶ push @l, _nft_table_text( $_, $dev->{nft}{$_}, 0 ), '' for sort keys %{ $dev->{nft} || {} };
Condition50%1/2
$$dev{'nft'} || {}
l!l
40
MC/DC0%0/1
$$dev{'nft'} || {}
$$dev{'nft'}
Truth table50%1/2
A
A= $$dev{'nft'}
Aresult
11
00
3878 4 return join( "\n", @l );
3879 }
3880  
3881 # Lesen legt keinen leeren Regelsatz an (sonst sieht "sonst nichts geaendert" eine Aenderung)
3882 67 ▶sub _nft {
Subroutine _nft: called CC=4 SCAR=14.0
3883 67 my ( $dev, $av ) = @_;
3884 67 my $had = exists $dev->{nft};
3885 67 my @r = _nft_cmd( $dev, $av );
3886 67 ▶ delete $dev->{nft} if !$had && ref $dev->{nft} eq 'HASH' && !%{ $dev->{nft} };
Branch: 1 branch
BranchTrueFalseTotal
if not $had and ref $$dev{"nft"} eq "HASH" and not %{$$dev{"nft"};} 0 67 67
Condition83%5/6
not $had and ref $$dev{"nft"} eq "HASH" and not %{$$dev{"nft"};}
!ll&&!rl&&r
6610
not $had and ref $$dev{"nft"} eq "HASH"
!ll&&!rl&&r
6151
MC/DC0%0/3
not $had and ref $$dev{"nft"} eq "HASH" and not %{$$dev{"nft"};}
not $had ref $$dev{"nft"} eq "HASH" not %{$$dev{"nft"};}
Truth table75%3/4
not(A) and B and not(C)
A= not $hadB= ref $$dev{"nft"} eq "HASH"C= not %{$$dev{"nft"};}
ABCresult
0XX0
10X0
1100
1111
3887 67 return @r;
3888 }
3889  
3890 67 ▶sub _nft_cmd {
Subroutine _nft_cmd: called CC=113 SCAR=59.6
3891 67 my ( $dev, $av ) = @_;
3892 67 my @a = @$av;
3893 67 my ( $with_h, $check ) = ( 0, 0 );
3894 # Optionen duerfen wie bei getopt auch hinter dem Befehl stehen (nft list ruleset -a);
3895 # "priority -10" ist keine Option
3896 67 ▶ @a = split /\s+/, $a[0] =~ s/\A\s+//r if @a == 1 && $a[0] =~ /\s/; # nft 'add rule …'
Branch: 1 branch
BranchTrueFalseTotal
if @a == 1 and $a[0] =~ /\s/ 2 65 67
Condition100%3/3
@a == 1 and $a[0] =~ /\s/
!ll&&!rl&&r
6412
MC/DC100%2/2
@a == 1 and $a[0] =~ /\s/
@a == 1 $a[0] =~ /\s/
Truth table100%3/3
A and B
A= @a == 1B= $a[0] =~ /\s/
ABresult
0X0
100
111
3897 67 my @opt;
3898 67 ▶ for ( my $i = 0; $i < @a; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @a) 412 67 479
3899 412 ▶ next unless $a[$i] =~ /\A-[acnsejtfy]+\z|\A--(?:handle|check|json|file|echo|numeric|stateless|terse)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $a[$i] =~ /\A-[acnsejtfy]+\z|\A--(?:handle|check|json|file|echo|numeric|stateless|terse)\z/ 398 14 412
3900 14 ▶ next if $i > 0 && $a[ $i - 1 ] =~ /\A(?:priority|-f|--file)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $i > 0 and $a[$i - 1] =~ /\A(?:priority|-f|--file)\z/ 0 14 14
Condition66%2/3
$i > 0 and $a[$i - 1] =~ /\A(?:priority|-f|--file)\z/
!ll&&!rl&&r
1220
MC/DC0%0/2
$i > 0 and $a[$i - 1] =~ /\A(?:priority|-f|--file)\z/
$i > 0 $a[$i - 1] =~ /\A(?:priority|-f|--file)\z/
Truth table66%2/3
A and B
A= $i > 0B= $a[$i - 1] =~ /\A(?:priority|-f|--file)\z/
ABresult
0X0
100
111
3901 14 ▶ my @take = splice @a, $i, ( $a[$i] =~ /f\z|\A--file\z/ ? 2 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$a[$i] =~ /f\z|\A--file\z/ ? : 4 10 14
3902 14 push @opt, @take;
3903 14 $i--;
3904 }
3905 67 unshift @a, @opt;
3906 67 ▶ while ( @a && $a[0] =~ /\A-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-/) 15 61 76
Condition66%2/3
@a and $a[0] =~ /\A-/
!ll&&!rl&&r
06115
MC/DC50%1/2
@a and $a[0] =~ /\A-/
@a $a[0] =~ /\A-/
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A-/
ABresult
0X0
100
111
3907 15 my $o = shift @a;
3908 15 ▶ $with_h = 1 if $o =~ /\A-[a-z]*a/ || $o eq '--handle';
Branch: 1 branch
BranchTrueFalseTotal
if $o =~ /\A-[a-z]*a/ or $o eq "--handle" 8 7 15
Condition66%2/3
$o =~ /\A-[a-z]*a/ or $o eq "--handle"
l!l&&r!l&&!r
807
MC/DC50%1/2
$o =~ /\A-[a-z]*a/ or $o eq "--handle"
$o =~ /\A-[a-z]*a/ $o eq "--handle"
Truth table66%2/3
A or B
A= $o =~ /\A-[a-z]*a/B= $o eq "--handle"
ABresult
1X1
011
000
3909 15 ▶ $check = 1 if $o =~ /\A-[a-z]*c/ || $o eq '--check';
Branch: 1 branch
BranchTrueFalseTotal
if $o =~ /\A-[a-z]*c/ or $o eq "--check" 1 14 15
Condition66%2/3
$o =~ /\A-[a-z]*c/ or $o eq "--check"
l!l&&r!l&&!r
1014
MC/DC50%1/2
$o =~ /\A-[a-z]*c/ or $o eq "--check"
$o =~ /\A-[a-z]*c/ $o eq "--check"
Truth table66%2/3
A or B
A= $o =~ /\A-[a-z]*c/B= $o eq "--check"
ABresult
1X1
011
000
3910 15 ▶ return ( 'nftables v1.0.6 (Lester Gooch #5)', 1 ) if $o eq '-v' || $o eq '--version' || $o eq '-V';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "-v" or $o eq "--version" or $o eq "-V" 1 14 15
Condition66%4/6
$o eq "-v" or $o eq "--version" or $o eq "-V"
l!l&&r!l&&!r
1014
$o eq "-v" or $o eq "--version"
l!l&&r!l&&!r
0114
MC/DC33%1/3
$o eq "-v" or $o eq "--version" or $o eq "-V"
$o eq "-v" $o eq "--version" $o eq "-V"
Truth table50%2/4
A or B or C
A= $o eq "-v"B= $o eq "--version"C= $o eq "-V"
ABCresult
1XX1
01X1
0011
0000
3911 14 ▶ if ( $o =~ /\A-[a-z]*f\z/ || $o eq '--file' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o =~ /\A-[a-z]*f\z/ or $o eq "--file") 4 10 14
Condition66%2/3
$o =~ /\A-[a-z]*f\z/ or $o eq "--file"
l!l&&r!l&&!r
4010
MC/DC50%1/2
$o =~ /\A-[a-z]*f\z/ or $o eq "--file"
$o =~ /\A-[a-z]*f\z/ $o eq "--file"
Truth table66%2/3
A or B
A= $o =~ /\A-[a-z]*f\z/B= $o eq "--file"
ABresult
1X1
011
000
3912 4 ▶ my $f = shift @a // return ( 'nft: option requires an argument -- \'f\'', 0 );
Condition50%1/2
shift @a // (return "nft: option requires an argument -- 'f'", 0)
l!l
40
MC/DC0%0/1
shift @a // (return "nft: option requires an argument -- 'f'", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3913 4 ▶ my $t = _file_text( $dev, $f ) // return ( "Error: Could not process rule: No such file or directory\n$f", 0 );
Condition50%1/2
_file_text($dev, $f) // (return "Error: Could not process rule: No such file or directory\n$f", 0)
l!l
40
MC/DC0%0/1
_file_text($dev, $f) // (return "Error: Could not process rule: No such file or directory\n$f", 0)
_file_text($dev, $f)
Truth table50%1/2
A
A= _file_text($dev, $f)
Aresult
11
00
3914 4 return _nft_load( $dev, $t, $f, $check );
3915 }
3916 10 ▶ if ( $o eq '-j' || $o eq '--json' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "-j" or $o eq "--json") 1 9 10
Condition66%2/3
$o eq "-j" or $o eq "--json"
l!l&&r!l&&!r
109
MC/DC50%1/2
$o eq "-j" or $o eq "--json"
$o eq "-j" $o eq "--json"
Truth table66%2/3
A or B
A= $o eq "-j"B= $o eq "--json"
ABresult
1X1
011
000
3917 1 push @GAPS, join( ' ', 'nft', @$av );
3918 1 return ( '', 0 );
3919 }
3920 }
3921 0 ▶ @a = map { split /\s+/ } @a if @a == 1; # nft 'add rule …'
Branch: 1 branch
BranchTrueFalseTotal
if @a == 1 0 61 61
3922 61 ▶ my $verb = shift @a // return ( "Error: syntax error, unexpected end of file", 0 );
Condition50%1/2
shift @a // (return "Error: syntax error, unexpected end of file", 0)
l!l
610
MC/DC0%0/1
shift @a // (return "Error: syntax error, unexpected end of file", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3923 # Lesen legt keinen nft-Zustand an (sonst saehe "sonst nichts geaendert" eine Aenderung; wie bei allen Lesebefehlen)
3924 61 ▶ my $T = $verb eq 'list' ? ( ref $dev->{nft} eq 'HASH' ? $dev->{nft} : {} ) : _nft_tables($dev);
Branch: 2 branches
BranchTrueFalseTotal
$verb eq 'list' ? : 19 42 61
ref $$dev{'nft'} eq 'HASH' ? : 14 5 19
3925 61 _handles($_) for values %$T; # Handles stehen fest, bevor sich etwas aendert (wie im Kernel von Anfang an)
3926 61 ▶ my $syntax = sub { ( "Error: syntax error, unexpected $_[0]\n" . join( ' ', @$av ), 0 ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
3927 61 ▶ if ( $verb eq 'list' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "list") 19 42 61
3928 19 ▶ my $what = shift @a // return $syntax->('end of file');
Condition50%1/2
shift @a // (return &$syntax("end of file"))
l!l
190
MC/DC0%0/1
shift @a // (return &$syntax("end of file"))
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3929 19 ▶ if ( $what eq 'ruleset' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "ruleset") 9 10 19
3930 9 my @l;
3931 9 push @l, _nft_table_text( $_, $T->{$_}, $with_h ) for sort keys %$T;
3932 9 return ( join( "\n", @l ), 1 );
3933 }
3934 0 ▶ if ( $what eq 'tables' ) { return ( join( "\n", map {"table $_"} sort keys %$T ), 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "tables") 1 9 10
3935 9 ▶ if ( $what eq 'sets' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "sets") 0 9 9
3936 0 my @l;
3937 0 for my $tn ( sort keys %$T ) {
3938 0 ▶ next unless %{ $T->{$tn}{sets} || {} };
Branch: 1 branch
BranchTrueFalseTotal
unless %{$$T{$tn}{"sets"} or {};} 0 0 0
Condition0%0/2
$$T{$tn}{'sets'} || {}
l!l
00
MC/DC0%0/1
$$T{$tn}{'sets'} || {}
$$T{$tn}{'sets'}
Truth table0%0/2
A
A= $$T{$tn}{'sets'}
Aresult
11
00
3939 0 push @l, "table $tn {", ( map { _nft_set_text( $_, $T->{$tn}{sets}{$_} ) } sort keys %{ $T->{$tn}{sets} } ), '}';
3940 }
3941 0 return ( join( "\n", @l ), 1 );
3942 }
3943 9 my ( $fam, $tab, $chain ) = @a;
3944 9 ▶ return $syntax->('end of file') unless defined $fam; # list ruleet u. a.: kein Objekt
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fam 1 8 9
3945 8 ▶ ( $fam, $tab, $chain ) = ( 'ip', $fam, $tab ) if defined $fam && $fam !~ /\A(?:ip|ip6|inet|arp|bridge|netdev)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fam and not $fam =~ /\A(?:ip|ip6|inet|arp|bridge|netdev)\z/ 0 8 8
Condition33%1/3
defined $fam and not $fam =~ /\A(?:ip|ip6|inet|arp|bridge|netdev)\z/
!ll&&!rl&&r
080
MC/DC0%0/2
defined $fam and not $fam =~ /\A(?:ip|ip6|inet|arp|bridge|netdev)\z/
defined $fam not $fam =~ /\A(?:ip|ip6|inet|arp|bridge|netdev)\z/
Truth table33%1/3
A and not(B)
A= defined $famB= not $fam =~ /\A(?:ip|ip6|inet|arp|bridge|netdev)\z/
ABresult
0X0
100
111
3946 8 my $tn = "$fam $tab";
3947 8 ▶ return ( "Error: No such file or directory\nlist $what $tn", 0 ) unless $T->{$tn};
Branch: 1 branch
BranchTrueFalseTotal
unless $$T{$tn} 0 8 8
3948 8 ▶ return ( join( "\n", _nft_table_text( $tn, $T->{$tn}, $with_h ) ), 1 ) if $what eq 'table';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "table" 0 8 8
3949 8 ▶ if ( $what eq 'set' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "set") 1 7 8
3950 1 ▶ my $sn = $chain // '';
Condition50%1/2
$chain // ""
l!l
10
MC/DC0%0/1
$chain // ""
$chain
Truth table50%1/2
A
A= $chain
Aresult
11
00
3951 1 ▶ return ( "Error: No such file or directory\nlist set $tn $sn", 0 ) unless ( $T->{$tn}{sets} || {} )->{$sn};
Branch: 1 branch
BranchTrueFalseTotal
unless ($$T{$tn}{"sets"} || {})->{$sn} 0 1 1
Condition50%1/2
$$T{$tn}{'sets'} || {}
l!l
10
MC/DC0%0/1
$$T{$tn}{'sets'} || {}
$$T{$tn}{'sets'}
Truth table50%1/2
A
A= $$T{$tn}{'sets'}
Aresult
11
00
3952 1 return ( join( "\n", "table $tn {", _nft_set_text( $sn, $T->{$tn}{sets}{$sn} ), '}' ), 1 );
3953 }
3954 7 ▶ if ( $what eq 'chain' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "chain") 7 0 7
3955 7 ▶ return ( "Error: No such file or directory\nlist chain $tn $chain", 0 ) unless defined $chain && $T->{$tn}{chains}{$chain};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chain and $$T{$tn}{"chains"}{$chain} 0 7 7
Condition33%1/3
defined $chain and $$T{$tn}{"chains"}{$chain}
!ll&&!rl&&r
007
MC/DC0%0/2
defined $chain and $$T{$tn}{"chains"}{$chain}
defined $chain $$T{$tn}{"chains"}{$chain}
Truth table33%1/3
A and B
A= defined $chainB= $$T{$tn}{"chains"}{$chain}
ABresult
0X0
100
111
3956 7 return ( join( "\n", "table $tn {", _nft_chain_text( $tn, $T->{$tn}, $chain, $with_h, _handles( $T->{$tn} ) ), '}' ), 1 );
3957 }
3958 0 return $syntax->("string \"$what\"");
3959 }
3960 42 ▶ if ( $verb eq 'flush' && ( $a[0] // '' ) eq 'ruleset' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "flush" and ($a[0] // "") eq "ruleset") 2 40 42
Condition80%4/5
$verb eq "flush" and ($a[0] // "") eq "ruleset"
!ll&&!rl&&r
3642
$a[0] // ""
l!l
60
MC/DC50%1/2
$verb eq "flush" and ($a[0] // "") eq "ruleset"
$verb eq "flush" $a[0]
Truth table66%2/3
A and B
A= $verb eq "flush"B= $a[0]
ABresult
0X0
100
111
3961 2 %$T = ();
3962 2 return ( '', 1 );
3963 }
3964 40 ▶ my $obj = shift @a // return $syntax->('end of file');
Condition50%1/2
shift @a // (return &$syntax("end of file"))
l!l
400
MC/DC0%0/1
shift @a // (return &$syntax("end of file"))
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3965 40 ▶ return $syntax->(qq{string "$verb"}) unless $verb =~ /\A(?:add|insert|delete|flush|create|replace)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $verb =~ /\A(?:add|insert|delete|flush|create|replace)\z/ 0 40 40
3966 40 ▶ my $fam = shift @a // return $syntax->('end of file');
Condition50%1/2
shift @a // (return &$syntax("end of file"))
l!l
400
MC/DC0%0/1
shift @a // (return &$syntax("end of file"))
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3967 40 my $tab;
3968 40 ▶ if ( $fam =~ /\A(?:ip|ip6|inet|arp|bridge|netdev)\z/ ) { $tab = shift @a }
Branch: 1 branch
BranchTrueFalseTotal
if ($fam =~ /\A(?:ip|ip6|inet|arp|bridge|netdev)\z/) { } 40 0 40
3969 0 else { ( $fam, $tab ) = ( 'ip', $fam ) }
3970 40 ▶ return $syntax->('end of file') unless defined $tab;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tab 0 40 40
3971 40 my $tn = "$fam $tab";
3972 40 ▶ if ( $obj eq 'table' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj eq "table") 1 39 40
3973 1 ▶ if ( $verb eq 'add' || $verb eq 'create' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "add" or $verb eq "create") 1 0 1
Condition33%1/3
$verb eq "add" or $verb eq "create"
l!l&&r!l&&!r
100
MC/DC0%0/2
$verb eq "add" or $verb eq "create"
$verb eq "add" $verb eq "create"
Truth table33%1/3
A or B
A= $verb eq "add"B= $verb eq "create"
ABresult
1X1
011
000
3974 1 ▶ return ( "Error: Could not process rule: File exists\n$verb table $tn", 0 ) if $verb eq 'create' && $T->{$tn};
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "create" and $$T{$tn} 0 1 1
Condition33%1/3
$verb eq "create" and $$T{$tn}
!ll&&!rl&&r
100
MC/DC0%0/2
$verb eq "create" and $$T{$tn}
$verb eq "create" $$T{$tn}
Truth table33%1/3
A and B
A= $verb eq "create"B= $$T{$tn}
ABresult
0X0
100
111
3975 1 ▶ $T->{$tn} //= { chains => {} };
Condition50%1/2
$$T{$tn} //= {"chains", {}}
l!l
01
MC/DC0%0/1
$$T{$tn} //= {"chains", {}}
$$T{$tn}
Truth table50%1/2
A
A= $$T{$tn}
Aresult
11
00
3976 1 return ( '', 1 );
3977 }
3978 0 ▶ return ( "Error: Could not process rule: No such file or directory\n$verb table $tn", 0 ) unless $T->{$tn};
Branch: 1 branch
BranchTrueFalseTotal
unless $$T{$tn} 0 0 0
3979 0 ▶ if ( $verb eq 'delete' ) { delete $T->{$tn} }
Branch: 2 branches
BranchTrueFalseTotal
if ($verb eq 'delete') { } 0 0 0
elsif ($verb eq 'flush') { } 0 0 0
3980 0 elsif ( $verb eq 'flush' ) { $_->{rules} = [] for values %{ $T->{$tn}{chains} } }
3981 0 return ( '', 1 );
3982 }
3983 39 ▶ return ( "Error: Could not process rule: No such file or directory\n$verb $obj $tn", 0 ) unless $T->{$tn};
Branch: 1 branch
BranchTrueFalseTotal
unless $$T{$tn} 0 39 39
3984 39 my $t = $T->{$tn};
3985 39 ▶ my $cn = shift @a // return $syntax->('end of file');
Condition50%1/2
shift @a // (return &$syntax("end of file"))
l!l
390
MC/DC0%0/1
shift @a // (return &$syntax("end of file"))
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
3986 39 ▶ return _nft_set_cmd( $t, $tn, $verb, $obj, $cn, join( ' ', @a ), $syntax ) if $obj eq 'set' || $obj eq 'element';
Branch: 1 branch
BranchTrueFalseTotal
if $obj eq "set" or $obj eq "element" 6 33 39
Condition100%3/3
$obj eq "set" or $obj eq "element"
l!l&&r!l&&!r
3333
MC/DC100%2/2
$obj eq "set" or $obj eq "element"
$obj eq "set" $obj eq "element"
Truth table100%3/3
A or B
A= $obj eq "set"B= $obj eq "element"
ABresult
1X1
011
000
3987 33 ▶ if ( $obj eq 'chain' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj eq "chain") 7 26 33
3988 7 ▶ if ( $verb eq 'add' || $verb eq 'create' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "add" or $verb eq "create") 3 4 7
Condition66%2/3
$verb eq "add" or $verb eq "create"
l!l&&r!l&&!r
304
MC/DC50%1/2
$verb eq "add" or $verb eq "create"
$verb eq "add" $verb eq "create"
Truth table66%2/3
A or B
A= $verb eq "add"B= $verb eq "create"
ABresult
1X1
011
000
3989 3 my $spec = join ' ', @a;
3990 3 $spec =~ s/\A\{|\}\z//g;
3991 3 my %c = ( rules => [] );
3992 3 ▶ if ( $spec =~ /type\s+(\w+)\s+hook\s+(\w+)\s+(?:device\s+\S+\s+)?priority\s+([\w-]+)/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($spec =~ /type\s+(\w+)\s+hook\s+(\w+)\s+(?:device\s+\S+\s+)?priority\s+([\w-]+)/) { } 1 2 3
elsif ($spec =~ /\A\s*policy\s+(accept|drop)\s*;?\s*\z/) { } 1 1 2
elsif ($spec =~ /\S/) { } 0 1 1
3993 1 @c{qw( type hook priority )} = ( $1, $2, $3 );
3994 1 ▶ $c{policy} = $1 if $spec =~ /policy\s+(accept|drop)/;
Branch: 1 branch
BranchTrueFalseTotal
if $spec =~ /policy\s+(accept|drop)/ 1 0 1
3995 }
3996 1 elsif ( $spec =~ /\A\s*policy\s+(accept|drop)\s*;?\s*\z/ ) { $c{policy} = $1 }
3997 0 elsif ( $spec =~ /\S/ ) { return $syntax->(qq{string "$spec"}) }
3998 3 ▶ return ( "Error: Could not process rule: File exists", 0 ) if $verb eq 'create' && $t->{chains}{$cn};
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "create" and $$t{"chains"}{$cn} 0 3 3
Condition33%1/3
$verb eq "create" and $$t{"chains"}{$cn}
!ll&&!rl&&r
300
MC/DC0%0/2
$verb eq "create" and $$t{"chains"}{$cn}
$verb eq "create" $$t{"chains"}{$cn}
Truth table33%1/3
A and B
A= $verb eq "create"B= $$t{"chains"}{$cn}
ABresult
0X0
100
111
3999 3 ▶ $t->{chains}{$cn} //= \%c;
Condition100%2/2
$$t{"chains"}{$cn} //= \%c
l!l
12
MC/DC100%1/1
$$t{"chains"}{$cn} //= \%c
$$t{"chains"}{$cn}
Truth table100%2/2
A
A= $$t{"chains"}{$cn}
Aresult
11
00
4000 3 ▶ $t->{chains}{$cn}{policy} = $c{policy} if $c{policy};
Branch: 1 branch
BranchTrueFalseTotal
if $c{"policy"} 2 1 3
4001 3 return ( '', 1 );
4002 }
4003 4 ▶ return ( "Error: Could not process rule: No such file or directory\n$verb chain $tn $cn", 0 ) unless $t->{chains}{$cn};
Branch: 1 branch
BranchTrueFalseTotal
unless $$t{"chains"}{$cn} 0 4 4
4004 0 ▶ if ( $verb eq 'delete' ) { delete $t->{chains}{$cn} }
Branch: 2 branches
BranchTrueFalseTotal
if ($verb eq 'delete') { } 0 4 4
elsif ($verb eq 'flush') { } 4 0 4
4005 4 elsif ( $verb eq 'flush' ) { $t->{chains}{$cn}{rules} = []; $t->{chains}{$cn}{_handles} = [] }
4006 4 return ( '', 1 );
4007 }
4008 26 ▶ return $syntax->(qq{string "$obj"}) unless $obj eq 'rule';
Branch: 1 branch
BranchTrueFalseTotal
unless $obj eq "rule" 0 26 26
4009 26 ▶ my $ch = $t->{chains}{$cn} or return ( "Error: Could not process rule: No such file or directory\n$verb rule $tn $cn", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $ch = $$t{"chains"}{$cn} or return "Error: Could not process rule: No such file or directory\n$verb rule $tn $cn", 0 25 1 26
4010 25 my $handles = _handles($t)->{$cn};
4011 25 ▶ my $rules = $ch->{rules} //= [];
Condition50%1/2
$$ch{"rules"} //= []
l!l
250
MC/DC0%0/1
$$ch{"rules"} //= []
$$ch{"rules"}
Truth table50%1/2
A
A= $$ch{"rules"}
Aresult
11
00
4012 25 my $pos;
4013 25 ▶ if ( @a >= 2 && ( $a[0] eq 'position' || $a[0] eq 'handle' || $a[0] eq 'index' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a >= 2 and $a[0] eq "position" || $a[0] eq "handle" || $a[0] eq "index") 3 22 25
Condition88%8/9
@a >= 2 and $a[0] eq "position" || $a[0] eq "handle" || $a[0] eq "index"
!ll&&!rl&&r
1213
$a[0] eq "position" or $a[0] eq "handle" or $a[0] eq "index"
l!l&&r!l&&!r
3021
$a[0] eq "position" or $a[0] eq "handle"
l!l&&r!l&&!r
1221
MC/DC75%3/4
@a >= 2 and $a[0] eq "position" || $a[0] eq "handle" || $a[0] eq "index"
@a >= 2 $a[0] eq "position" $a[0] eq "handle" $a[0] eq "index"
Truth table80%4/5
A and B or C or D
A= @a >= 2B= $a[0] eq "position"C= $a[0] eq "handle"D= $a[0] eq "index"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
4014 3 my ( $k, $v ) = splice @a, 0, 2;
4015 3 ▶ return $syntax->(qq{string "$v"}) unless $v =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ /\A\d+\z/ 0 3 3
4016 3 ▶ if ( $k eq 'index' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq 'index') { } 0 3 3
4017 0 ▶ return ( "Error: Could not process rule: No such file or directory", 0 ) if $v > $#$rules && !( $v == 0 && !@$rules );
Branch: 1 branch
BranchTrueFalseTotal
if $v > $rules->$#* and not $v == 0 && !@$rules 0 0 0
Condition0%0/6
$v > $rules->$#* and not $v == 0 && !@$rules
!ll&&!rl&&r
000
$v == 0 && !@$rules
!ll&&!rl&&r
000
MC/DC0%0/3
$v > $rules->$#* and not $v == 0 && !@$rules
$v > $rules->$#* $v == 0 !@$rules
Truth table0%0/4
A and not(B && not(C))
A= $v > $rules->$#*B= $v == 0C= !@$rules
ABCresult
0XX0
1110
10X1
1101
4018 0 $pos = $v;
4019 }
4020 else {
4021 3 my ($i) = grep { $handles->[$_] == $v } 0 .. $#$handles;
4022 3 ▶ return ( "Error: Could not process rule: No such file or directory\n$verb rule $tn $cn $k $v", 0 ) unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 3 3
4023 3 $pos = $i;
4024 }
4025 3 ▶ if ( $verb eq 'delete' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "delete") 2 1 3
4026 2 splice @$rules, $pos, 1;
4027 2 splice @{ $ch->{_handles} }, $pos, 1;
4028 2 return ( '', 1 );
4029 }
4030 }
4031 23 ▶ return ( 'Error: syntax error, unexpected ' . ( !@a ? 'end of file' : $a[0] =~ /\A\d+\z/ ? 'number' : 'string' )
Branch: 3 branches
BranchTrueFalseTotal
if $verb eq "delete" 1 22 23
!@a ? : 0 1 1
$a[0] =~ /\A\d+\z/ ? : 1 0 1
4032 . ", expecting handle\n" . join( ' ', 'delete rule', $tn, $cn, @a ), 0 ) if $verb eq 'delete';
4033 22 my $text = _norm_rule( join ' ', @a );
4034 22 ▶ return $syntax->('end of file') unless length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless length $text 0 22 22
4035 22 ▶ if ( my $bad = _nft_bad_type($text) ) { return ( "$bad\n$verb rule $tn $cn $text", 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $bad = _nft_bad_type($text)) 2 20 22
4036 20 ▶ return ( "Error: syntax error, unexpected number\n$verb rule $tn $cn $text", 0 ) if $text =~ /\A\d+\b/; # Position ohne "position"/"index"
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\A\d+\b/ 2 18 20
4037 18 ▶ return ( "Error: syntax error, unexpected string\n$verb rule $tn $cn $text", 0 )
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\b(?:accept|drop|reject|masquerade|snat|dnat|redirect|counter|log|jump|goto|return|continue|queue|set|notrack|meta|ct|limit|tcp|udp|icmp|icmpv6|ip|ip6)\b/ 0 18 18
4038 unless $text =~ /\b(?:accept|drop|reject|masquerade|snat|dnat|redirect|counter|log|jump|goto|return|continue|queue|set|notrack|meta|ct|limit|tcp|udp|icmp|icmpv6|ip|ip6)\b/;
4039 18 ▶ if ( my $e = _nft_rule_refs( $t, $text ) ) { return ( $e, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = _nft_rule_refs($t, $text)) 1 17 18
4040 17 ▶ if ( my $se = Langertha::Holmgang::Sim::Linux::Nft::syntax_error($text) ) { return ( $se, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $se = Langertha::Holmgang::Sim::Linux::Nft::syntax_error($text)) 1 16 17
4041 16 _nft_gap( $ch, $text );
4042 16 ▶ if ( $verb eq 'replace' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "replace") 0 16 16
4043 0 ▶ return ( "Error: syntax error, unexpected string, expecting handle", 0 ) unless defined $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
4044 0 $rules->[$pos] = $text;
4045 0 return ( '', 1 );
4046 }
4047 16 ▶ my $at = $verb eq 'insert' ? ( $pos // 0 ) : defined $pos ? $pos + 1 : scalar @$rules;
Branch: 2 branches
BranchTrueFalseTotal
$verb eq 'insert' ? : 3 13 16
defined $pos ? : 0 13 13
Condition100%2/2
$pos // 0
l!l
12
MC/DC100%1/1
$pos // 0
$pos
Truth table100%2/2
A
A= $pos
Aresult
11
00
4048 16 splice @$rules, $at, 0, $text;
4049 16 splice @{ $ch->{_handles} }, $at, 0, $t->{_next_handle}++;
4050 16 return ( '', 1 );
4051 }
4052  
4053 # --- sysctl ------------------------------------------------------------------------
4054  
4055 5 ▶sub _sysctl {
Subroutine _sysctl: called CC=35 SCAR=42.9
4056 5 my ( $dev, $av ) = @_;
4057 5 my @a = @$av;
4058 5 ▶ my $s = $dev->{sysctl} || {}; # nur lesen legt nichts an
Condition100%2/2
$$dev{'sysctl'} || {}
l!l
41
MC/DC100%1/1
$$dev{'sysctl'} || {}
$$dev{'sysctl'}
Truth table100%2/2
A
A= $$dev{'sysctl'}
Aresult
11
00
4059 5 my ( $w, $all, $load, $quiet ) = ( 0, 0, undef, 0 );
4060 5 my @keys;
4061 5 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 7 5 12
4062 7 my $x = shift @a;
4063 7 ▶ if ( $x eq '-w' ) { $w = 1 }
Branch: 6 branches
BranchTrueFalseTotal
if ($x eq '-w') { } 2 5 7
elsif ($x eq '-a' or $x eq '--all') { } 0 5 5
elsif ($x eq '-q') { } 0 5 5
elsif ($x eq '-n' or $x eq '-N' or $x eq '-e') { } 0 5 5
elsif ($x =~ /\A-p/ or $x eq '--load') { } 0 5 5
elsif ($x eq '--system') { } 1 4 5
4064 0 ▶ elsif ( $x eq '-a' || $x eq '--all' ) { $all = 1 }
Condition33%1/3
$x eq "-a" or $x eq "--all"
l!l&&r!l&&!r
005
MC/DC0%0/2
$x eq "-a" or $x eq "--all"
$x eq "-a" $x eq "--all"
Truth table33%1/3
A or B
A= $x eq "-a"B= $x eq "--all"
ABresult
1X1
011
000
4065 0 elsif ( $x eq '-q' ) { $quiet = 1 }
4066 ▶ elsif ( $x eq '-n' || $x eq '-N' || $x eq '-e' ) { }
Condition33%2/6
$x eq "-n" or $x eq "-N" or $x eq "-e"
l!l&&r!l&&!r
005
$x eq "-n" or $x eq "-N"
l!l&&r!l&&!r
005
MC/DC0%0/3
$x eq "-n" or $x eq "-N" or $x eq "-e"
$x eq "-n" $x eq "-N" $x eq "-e"
Truth table25%1/4
A or B or C
A= $x eq "-n"B= $x eq "-N"C= $x eq "-e"
ABCresult
1XX1
01X1
0011
0000
4067 0 ▶ elsif ( $x =~ /\A-p/ || $x eq '--load' ) { $load = @a && $a[0] !~ /\A-/ ? shift @a : '/etc/sysctl.conf' }
Branch: 1 branch
BranchTrueFalseTotal
@a && !($a[0] =~ /\A-/) ? : 0 0 0
Condition16%1/6
$x =~ /\A-p/ or $x eq "--load"
l!l&&r!l&&!r
005
@a and not $a[0] =~ /\A-/
!ll&&!rl&&r
000
MC/DC0%0/2
$x =~ /\A-p/ or $x eq "--load"
$x =~ /\A-p/ $x eq "--load"
MC/DC0%0/2
@a and not $a[0] =~ /\A-/
@a not $a[0] =~ /\A-/
Truth table33%1/3
A or B
A= $x =~ /\A-p/B= $x eq "--load"
ABresult
1X1
011
000
Truth table0%0/3
A and not(B)
A= @aB= not $a[0] =~ /\A-/
ABresult
0X0
100
111
4068 1 elsif ( $x eq '--system' ) { $load = '--system' }
4069 4 else { push @keys, $x }
4070 }
4071 3 ▶ my $set = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
4072 3 my ( $k, $v ) = @_;
4073 3 ( my $p = $k ) =~ s{\.}{/}g;
4074 3 ▶ return "sysctl: cannot stat /proc/sys/$p: No such file or directory" unless exists $s->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$s{$k} 1 2 3
4075 2 $s->{$k} = $v;
4076 2 return "$k = $v";
4077 5 };
4078 5 ▶ if ( defined $load ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $load) 1 4 5
4079 my @files = $load eq '--system'
4080 1 ▶ ? ( ( sort grep { m{\A/etc/sysctl\.d/.+\.conf\z} } keys %{ $dev->{files} || {} } ), '/etc/sysctl.conf' )
Branch: 1 branch
BranchTrueFalseTotal
$load eq '--system' ? : 1 0 1
Condition50%1/2
$$dev{'files'} || {}
l!l
10
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
4081 : ($load);
4082 1 my @out;
4083 1 my $ok = 1;
4084 1 for my $f (@files) {
4085 2 my $t = _file_text( $dev, $f );
4086 2 ▶ if ( !defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 1 1 2
4087 1 ▶ next if $load eq '--system';
Branch: 1 branch
BranchTrueFalseTotal
if $load eq "--system" 1 0 1
4088 0 return ( "sysctl: cannot open \"$f\": No such file or directory", 0 );
4089 }
4090 1 ▶ push @out, "* Applying $f ..." if $load eq '--system';
Branch: 1 branch
BranchTrueFalseTotal
if $load eq "--system" 1 0 1
4091 1 for my $l ( split /\n/, $t ) {
4092 1 $l =~ s/[#;].*//;
4093 1 ▶ next unless $l =~ /\A\s*([\w.\/-]+)\s*=\s*(.*?)\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $l =~ m[\A\s*([\w./-]+)\s*=\s*(.*?)\s*\z] 0 1 1
4094 1 ( my $k = $1 ) =~ s{/}{.}g;
4095 1 my $r = $set->( $k, $2 );
4096 1 ▶ $ok = 0 if $r =~ /\Asysctl:/;
Branch: 1 branch
BranchTrueFalseTotal
if $r =~ /\Asysctl:/ 0 1 1
4097 1 push @out, $r;
4098 }
4099 }
4100 1 return ( join( "\n", @out ), $ok );
4101 }
4102 4 ▶ if ( $all || !@keys ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all or not @keys) 0 4 4
Condition33%1/3
$all or not @keys
l!l&&r!l&&!r
004
MC/DC0%0/2
$all or not @keys
$all not @keys
Truth table33%1/3
A or not(B)
A= $allB= not @keys
ABresult
1X1
011
000
4103 0 ▶ return ( join( "\n", map {"$_ = $s->{$_}"} sort keys %$s ), 1 ) if $all;
Branch: 1 branch
BranchTrueFalseTotal
if $all 0 0 0
4104 0 return ( "Usage:\n sysctl [options] [variable[=value] ...]", 0 );
4105 }
4106 4 my @out;
4107 4 my $ok = 1;
4108 4 for my $k (@keys) {
4109 4 ▶ if ( $k =~ /\A([^=]+)=(.*)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /\A([^=]+)=(.*)\z/) 2 2 4
4110 2 my $r = $set->( $1, $2 );
4111 2 ▶ $ok = 0 if $r =~ /\Asysctl:/;
Branch: 1 branch
BranchTrueFalseTotal
if $r =~ /\Asysctl:/ 1 1 2
4112 2 ▶ push @out, $r unless $quiet && $r !~ /\Asysctl:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet and not $r =~ /\Asysctl:/ 2 0 2
Condition33%1/3
$quiet and not $r =~ /\Asysctl:/
!ll&&!rl&&r
200
MC/DC0%0/2
$quiet and not $r =~ /\Asysctl:/
$quiet not $r =~ /\Asysctl:/
Truth table33%1/3
A and not(B)
A= $quietB= not $r =~ /\Asysctl:/
ABresult
0X0
100
111
4113 2 next;
4114 }
4115 0 ▶ if ($w) { push @out, qq{sysctl: "$k" must be of the form name=value}; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($w) 0 2 2
4116 2 ( my $p = $k ) =~ s{\.}{/}g;
4117 2 ▶ if ( !exists $s->{$k} ) { push @out, "sysctl: cannot stat /proc/sys/$p: No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$s{$k}) 1 1 2
4118 1 push @out, "$k = $s->{$k}";
4119 }
4120 4 return ( join( "\n", @out ), $ok );
4121 }
4122  
4123 0 ▶sub _conntrack {
Subroutine _conntrack: not called CC=9 SCAR=45.0
4124 0 my ( $dev, $av ) = @_;
4125 0 ▶ my $s = $dev->{sysctl} || {};
Condition0%0/2
$$dev{'sysctl'} || {}
l!l
00
MC/DC0%0/1
$$dev{'sysctl'} || {}
$$dev{'sysctl'}
Truth table0%0/2
A
A= $$dev{'sysctl'}
Aresult
11
00
4126 0 ▶ my $x = $av->[0] // '';
Condition0%0/2
$$av[0] // ""
l!l
00
MC/DC0%0/1
$$av[0] // ""
$$av[0]
Truth table0%0/2
A
A= $$av[0]
Aresult
11
00
4127 0 ▶ return ( $s->{'net.netfilter.nf_conntrack_count'} // 0, 1 ) if $x eq '-C' || $x eq '--count';
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "-C" or $x eq "--count" 0 0 0
Condition0%0/5
$x eq "-C" or $x eq "--count"
l!l&&r!l&&!r
000
$$s{"net.netfilter.nf_conntrack_count"} // 0
l!l
00
MC/DC0%0/2
$x eq "-C" or $x eq "--count"
$x eq "-C" $x eq "--count"
MC/DC0%0/1
$$s{"net.netfilter.nf_conntrack_count"} // 0
$$s{"net.netfilter.nf_conntrack_count"}
Truth table0%0/3
A or B
A= $x eq "-C"B= $x eq "--count"
ABresult
1X1
011
000
Truth table0%0/2
A
A= $$s{"net.netfilter.nf_conntrack_count"}
Aresult
11
00
4128 0 ▶ if ( $x eq '-S' || $x eq '--stats' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "-S" or $x eq "--stats") 0 0 0
Condition0%0/3
$x eq "-S" or $x eq "--stats"
l!l&&r!l&&!r
000
MC/DC0%0/2
$x eq "-S" or $x eq "--stats"
$x eq "-S" $x eq "--stats"
Truth table0%0/3
A or B
A= $x eq "-S"B= $x eq "--stats"
ABresult
1X1
011
000
4129 return ( "cpu=0 \tfound=0 invalid=0 insert=0 insert_failed=0 drop="
4130 0 ▶ . ( $dev->{conntrack_drops} // 0 ) . " early_drop=0 error=0 search_restart=0", 1 );
Condition0%0/2
$$dev{"conntrack_drops"} // 0
l!l
00
MC/DC0%0/1
$$dev{"conntrack_drops"} // 0
$$dev{"conntrack_drops"}
Truth table0%0/2
A
A= $$dev{"conntrack_drops"}
Aresult
11
00
4131 }
4132 0 return ( "conntrack v1.4.7 (conntrack-tools): 0 flow entries have been shown.", 1 );
4133 }
4134  
4135 # --- Dateien mit Rechten und Groesse, Dateisysteme ----------------------------------
4136  
4137 82 my %UNIT = ( '' => 1, B => 1, K => 1024, M => 1024**2, G => 1024**3, T => 1024**4 );
4138  
4139 # Zeit der Simulation: Dienstag, 20.10.2026 12:00 (fest, deterministisch).
4140 82 my %MON = ( Jan => 0, Feb => 1, Mar => 2, Apr => 3, May => 4, Jun => 5, Jul => 6, Aug => 7, Sep => 8, Oct => 9, Nov => 10, Dec => 11 );
4141 177 ▶sub _sim_now { require Time::Local; return Time::Local::timegm( 0, 0, 12, 20, 9, 2026 ) }
Subroutine _sim_now: called CC=1 SCAR=0.0
4142  
4143 # Zeit der Umgebung aus pki.now (dieses Geraet, sonst eines im Zustand): Sekunden oder undef
4144 20 ▶sub _pki_now {
Subroutine _pki_now: called CC=7 SCAR=20.2
4145 20 my ($dev) = @_;
4146 20 ▶ for my $d ( $dev, map { values %$_ } grep { ref eq 'HASH' } ( $CTX && $CTX->{state} ) ) {
Condition33%1/3
$Langertha::Holmgang::Sim::Linux::CTX && $$Langertha::Holmgang::Sim::Linux::CTX{'state'}
!ll&&!rl&&r
0020
MC/DC0%0/2
$Langertha::Holmgang::Sim::Linux::CTX && $$Langertha::Holmgang::Sim::Linux::CTX{'state'}
$Langertha::Holmgang::Sim::Linux::CTX $$Langertha::Holmgang::Sim::Linux::CTX{'state'}
Truth table33%1/3
A && B
A= $Langertha::Holmgang::Sim::Linux::CTXB= $$Langertha::Holmgang::Sim::Linux::CTX{'state'}
ABresult
0X0
100
111
4147 39 ▶ next unless ref $d eq 'HASH' && ref $d->{pki} eq 'HASH' && $d->{pki}{now};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $d eq "HASH" and ref $$d{"pki"} eq "HASH" and $$d{"pki"}{"now"} 36 3 39
Condition66%4/6
ref $d eq "HASH" and ref $$d{"pki"} eq "HASH" and $$d{"pki"}{"now"}
!ll&&!rl&&r
3603
ref $d eq "HASH" and ref $$d{"pki"} eq "HASH"
!ll&&!rl&&r
0363
MC/DC33%1/3
ref $d eq "HASH" and ref $$d{"pki"} eq "HASH" and $$d{"pki"}{"now"}
ref $d eq "HASH" ref $$d{"pki"} eq "HASH" $$d{"pki"}{"now"}
Truth table50%2/4
A and B and C
A= ref $d eq "HASH"B= ref $$d{"pki"} eq "HASH"C= $$d{"pki"}{"now"}
ABCresult
0XX0
10X0
1100
1111
4148 3 ▶ my ( $Y, $M, $D, $h, $m, $sec ) = $d->{pki}{now} =~ /\A(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $$d{"pki"}{"now"} =~ /\A(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)/ or next 3 0 3
4149 3 require Time::Local;
4150 3 return Time::Local::timegm( $sec, $m, $h, $D, $M - 1, $Y );
4151 }
4152 17 return undef;
4153 }
4154  
4155 # free [-m|-h]: Speicher aus memory des Geraets (MB), sonst eine kleine VM
4156 2 ▶sub _free_mem {
Subroutine _free_mem: called CC=2 SCAR=7.1
4157 2 my ( $dev, $av ) = @_;
4158 2 ▶ my $m = $dev->{memory} || { total => 3936, used => 2210, free => 412, cache => 1314 };
Condition50%1/2
$$dev{'memory'} || {'total', 3936, 'used', 2210, 'free', 412, 'cache', 1314}
l!l
02
MC/DC0%0/1
$$dev{'memory'} || {'total', 3936, 'used', 2210, 'free', 412, 'cache', 1314}
$$dev{'memory'}
Truth table50%1/2
A
A= $$dev{'memory'}
Aresult
11
00
4159 2 my $h = grep { $_ eq '-h' } @$av;
4160 2 ▶ my $f = sub { $h ? sprintf( '%.1fGi', $_[0] / 1024 ) : $_[0] };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$h ? : 0 18 18
4161 return ( join( "\n", ' total used free shared buff/cache available',
4162 sprintf( 'Mem: %12s%12s%12s%12s%12s%12s', $f->( $m->{total} ), $f->( $m->{used} ), $f->( $m->{free} ), $f->(12), $f->( $m->{cache} ),
4163 2 $f->( $m->{total} - $m->{used} ) ), sprintf( 'Swap: %12s%12s%12s', $f->(0), $f->(0), $f->(0) ) ), 1 );
4164 }
4165  
4166 # "Aug 2 03:10" (Jahr 2026) -> Sekunden; ohne Angabe: jetzt
4167 73 ▶sub _mtime {
Subroutine _mtime: called CC=7 SCAR=20.1
4168 73 my ($e) = @_;
4169 73 ▶ my $m = ( ref $e eq 'HASH' ? $e->{mtime} : undef ) // return _sim_now();
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' ? : 73 0 73
Condition100%2/2
(ref $e eq "HASH" ? $$e{"mtime"} : undef) // (return _sim_now())
l!l
5122
MC/DC100%1/1
(ref $e eq "HASH" ? $$e{"mtime"} : undef) // (return _sim_now())
(ref $e eq "HASH" ? $$e{"mtime"} : undef)
Truth table100%2/2
A
A= (ref $e eq "HASH" ? $$e{"mtime"} : undef)
Aresult
11
00
4170 51 require Time::Local;
4171 # aeltere Dateien wie ls sie zeigt: "Mar 12 2025" (Mitternacht)
4172 51 ▶ if ( my ( $ym, $yd, $y ) = $m =~ /\A(\w{3})\s+(\d+)\s+(\d{4})\z/ ) { return Time::Local::timegm( 0, 0, 0, $yd, $MON{$ym} // 0, $y ) }
Branch: 1 branch
BranchTrueFalseTotal
if (() = $m =~ /\A(\w{3})\s+(\d+)\s+(\d{4})\z/) 1 50 51
Condition50%1/2
$MON{$ym} // 0
l!l
10
MC/DC0%0/1
$MON{$ym} // 0
$MON{$ym}
Truth table50%1/2
A
A= $MON{$ym}
Aresult
11
00
4173 50 ▶ my ( $mon, $d, $h, $mi ) = $m =~ /\A(\w{3})\s+(\d+)\s+(\d+):(\d+)\z/ or return _sim_now();
Branch: 1 branch
BranchTrueFalseTotal
() = $m =~ /\A(\w{3})\s+(\d+)\s+(\d+):(\d+)\z/ or return _sim_now() 50 0 50
4174 50 ▶ return Time::Local::timegm( 0, $mi, $h, $d, $MON{$mon} // 9, 2026 );
Condition50%1/2
$MON{$mon} // 9
l!l
500
MC/DC0%0/1
$MON{$mon} // 9
$MON{$mon}
Truth table50%1/2
A
A= $MON{$mon}
Aresult
11
00
4175 }
4176  
4177 # Alte Journal-Archive loeschen, bis hoechstens $limit Bytes belegt sind bzw.
4178 # keines aelter als $age Sekunden ist (system.journal bleibt).
4179 1 ▶sub _journal_vacuum {
Subroutine _journal_vacuum: called CC=11 SCAR=26.3
4180 1 my ( $dev, %o ) = @_;
4181 1 ▶ my @j = sort { _mtime( _file_entry( $dev, $a ) ) <=> _mtime( _file_entry( $dev, $b ) ) || $a cmp $b }
Condition33%1/3
_mtime(_file_entry($dev, $a)) <=> _mtime(_file_entry($dev, $b)) || $a cmp $b
l!l&&r!l&&!r
100
MC/DC0%0/2
_mtime(_file_entry($dev, $a)) <=> _mtime(_file_entry($dev, $b)) || $a cmp $b
_mtime(_file_entry($dev, $a)) <=> _mtime(_file_entry($dev, $b)) $a cmp $b
Truth table33%1/3
A || B
A= _mtime(_file_entry($dev, $a)) <=> _mtime(_file_entry($dev, $b))B= $a cmp $b
ABresult
1X1
011
000
4182 1 grep { $_ !~ m{/system\.journal\z|/user-\d+\.journal\z} } _under( $dev, '/var/log/journal' );
4183 1 my $t = 0;
4184 1 $t += _file_size( _file_entry( $dev, $_ ) ) for _under( $dev, '/var/log/journal' );
4185 1 my $freed = 0;
4186 1 for my $p (@j) {
4187 2 my $e = _file_entry( $dev, $p );
4188 2 ▶ my $old = defined $o{age} && _sim_now() - _mtime($e) > $o{age};
Condition66%2/3
defined $o{'age'} && _sim_now() - _mtime($e) > $o{'age'}
!ll&&!rl&&r
011
MC/DC50%1/2
defined $o{'age'} && _sim_now() - _mtime($e) > $o{'age'}
defined $o{'age'} _sim_now() - _mtime($e) > $o{'age'}
Truth table66%2/3
A && B
A= defined $o{'age'}B= _sim_now() - _mtime($e) > $o{'age'}
ABresult
0X0
100
111
4189 2 ▶ my $big = defined $o{size} && $t - $freed > $o{size};
Condition33%1/3
defined $o{'size'} && $t - $freed > $o{'size'}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $o{'size'} && $t - $freed > $o{'size'}
defined $o{'size'} $t - $freed > $o{'size'}
Truth table33%1/3
A && B
A= defined $o{'size'}B= $t - $freed > $o{'size'}
ABresult
0X0
100
111
4190 2 ▶ next unless $old || $big;
Branch: 1 branch
BranchTrueFalseTotal
unless $old or $big 1 1 2
Condition66%2/3
$old or $big
l!l&&r!l&&!r
101
MC/DC50%1/2
$old or $big
$old $big
Truth table66%2/3
A or B
A= $oldB= $big
ABresult
1X1
011
000
4191 1 ▶ last if defined $o{size} && !defined $o{age} && !$big;
Branch: 1 branch
BranchTrueFalseTotal
if defined $o{"size"} and not defined $o{"age"} and not $big 0 1 1
Condition33%2/6
defined $o{"size"} and not defined $o{"age"} and not $big
!ll&&!rl&&r
100
defined $o{"size"} and not defined $o{"age"}
!ll&&!rl&&r
100
MC/DC0%0/3
defined $o{"size"} and not defined $o{"age"} and not $big
defined $o{"size"} not defined $o{"age"} not $big
Truth table25%1/4
A and not(B) and not(C)
A= defined $o{"size"}B= not defined $o{"age"}C= not $big
ABCresult
0XX0
10X0
1100
1111
4192 1 $freed += _file_size($e);
4193 1 delete $dev->{files}{$p};
4194 }
4195 1 return $freed;
4196 }
4197  
4198 9 ▶sub _secs {
Subroutine _secs: called CC=5 SCAR=16.8
4199 9 my ($v) = @_;
4200 9 ▶ my ( $n, $u ) = ( $v // '' ) =~ /\A(\d+)\s*(s|min|m|h|d|w|weeks?|days?|months?|y|seconds?|secs?|minutes?|mins|hours?|hr)?\z/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = ($v // "") =~ /\A(\d+)\s*(s|min|m|h|d|w|weeks?|days?|months?|y|seconds?|secs?|minutes?|mins|hours?|hr)?\z/ or return undef 9 0 9
Condition50%1/2
$v // ""
l!l
90
MC/DC0%0/1
$v // ""
$v
Truth table50%1/2
A
A= $v
Aresult
11
00
4201 9 my %f = ( s => 1, min => 60, m => 60, h => 3600, d => 86400, day => 86400, days => 86400, w => 604800, week => 604800,
4202 weeks => 604800, month => 2592000, months => 2592000, y => 31536000, second => 1, seconds => 1, sec => 1, secs => 1,
4203 minute => 60, minutes => 60, mins => 60, hour => 3600, hours => 3600, hr => 3600 );
4204 9 ▶ return $n * ( $f{ $u // 's' } // 1 );
Condition75%3/4
$f{$u // "s"} // 1
l!l
90
$u // "s"
l!l
63
MC/DC0%0/1
$f{$u // "s"} // 1
$f{$u // "s"}
MC/DC100%1/1
$u // "s"
$u
Truth table50%1/2
A
A= $f{$u // "s"}
Aresult
11
00
Truth table100%2/2
A
A= $u
Aresult
11
00
4205 }
4206  
4207 # "14G", "1.5M", 12345 -> Bytes
4208 293 ▶sub _bytes {
Subroutine _bytes: called CC=4 SCAR=14.1
4209 293 my ($v) = @_;
4210 293 ▶ return 0 unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 293 293
4211 293 ▶ return 0 + $v if $v =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /\A\d+\z/ 19 274 293
4212 274 ▶ my ( $n, $u ) = $v =~ /\A(\d+(?:\.\d+)?)\s*([BKMGT]?)i?B?\z/i or return 0;
Branch: 1 branch
BranchTrueFalseTotal
() = $v =~ /\A(\d+(?:\.\d+)?)\s*([BKMGT]?)i?B?\z/i or return 0 274 0 274
4213 274 return int( $n * $UNIT{ uc $u } );
4214 }
4215  
4216 # Bytes -> wie df -h / ls -lh (1 Nachkommastelle unter 10)
4217 73 ▶sub _human {
Subroutine _human: called CC=4 SCAR=13.9
4218 73 my ($b) = @_;
4219 73 for my $u (qw( T G M K )) {
4220 156 my $f = $UNIT{$u};
4221 156 ▶ next if $b < $f;
Branch: 1 branch
BranchTrueFalseTotal
if $b < $f 84 72 156
4222 72 my $x = $b / $f;
4223 72 ▶ return $x < 10 ? sprintf( '%.1f%s', int( $x * 10 + 0.999 ) / 10, $u ) : sprintf( '%d%s', int( $x + 0.999 ), $u );
Branch: 1 branch
BranchTrueFalseTotal
$x < 10 ? : 26 46 72
4224 }
4225 1 return "$b";
4226 }
4227  
4228 # Ziel eines Symlinks als absoluter, bereinigter Pfad
4229 17 ▶sub _link_target {
Subroutine _link_target: called CC=3 SCAR=11.0
4230 17 my ( $from, $t ) = @_;
4231 17 ( my $dir = $from ) =~ s{/[^/]+\z}{};
4232 17 ▶ $t = "$dir/$t" unless $t =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ m[\A/] 7 10 17
4233 17 ▶ 1 while $t =~ s{/[^/]+/\.\./}{/};
Branch: 1 branch
BranchTrueFalseTotal
$t =~ s[/[^/]+/\.\./][/] and do { '???' } 2 17 19
4234 17 $t =~ s{/\./}{/}g;
4235 17 $t =~ s{(?<=.)/+\z}{};
4236 17 return $t;
4237 }
4238  
4239 # Pfad durch einen Symlink davor (/srv/app/current/x -> /srv/app/releases/1/x); undef ohne
4240 26573 ▶sub _via_link {
Subroutine _via_link: called CC=9 SCAR=22.5
4241 26573 my ( $dev, $path, $depth ) = @_;
4242 26573 ▶ return undef if ( $depth // 0 ) > 5 || ref $dev->{files} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ($depth // 0) > 5 or ref $$dev{"files"} ne "HASH" 66 26507 26573
Condition80%4/5
($depth // 0) > 5 or ref $$dev{"files"} ne "HASH"
l!l&&r!l&&!r
06626507
$depth // 0
l!l
626567
MC/DC50%1/2
($depth // 0) > 5 or ref $$dev{"files"} ne "HASH"
$depth ref $$dev{"files"} ne "HASH"
Truth table66%2/3
A or B
A= $depthB= ref $$dev{"files"} ne "HASH"
ABresult
1X1
011
000
4243 26507 my @seg = split m{/}, $path;
4244 26507 for my $i ( 1 .. $#seg - 1 ) {
4245 52576 my $pre = join '/', @seg[ 0 .. $i ];
4246 52576 my $e = $dev->{files}{$pre};
4247 52576 ▶ next unless ref $e eq 'HASH' && defined $e->{link};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" and defined $$e{"link"} 52570 6 52576
Condition66%2/3
ref $e eq "HASH" and defined $$e{"link"}
!ll&&!rl&&r
5257006
MC/DC50%1/2
ref $e eq "HASH" and defined $$e{"link"}
ref $e eq "HASH" defined $$e{"link"}
Truth table66%2/3
A and B
A= ref $e eq "HASH"B= defined $$e{"link"}
ABresult
0X0
100
111
4248 6 my $new = join '/', _link_target( $pre, $e->{link} ), @seg[ $i + 1 .. $#seg ];
4249 6 ▶ return _via_link( $dev, $new, ( $depth // 0 ) + 1 ) // $new;
Condition40%2/5
_via_link($dev, $new, ($depth // 0) + 1) // $new
l!l&&r!l&&!r
060
$depth // 0
l!l
06
MC/DC0%0/2
_via_link($dev, $new, ($depth // 0) + 1) // $new
_via_link($dev, $new, ($depth // 0) + 1) $new
MC/DC0%0/1
$depth // 0
$depth
Truth table33%1/3
A // B
A= _via_link($dev, $new, ($depth // 0) + 1)B= $new
ABresult
1X1
011
000
Truth table50%1/2
A
A= $depth
Aresult
11
00
4250 }
4251 26501 return undef;
4252 }
4253  
4254 # Eintrag einer Datei als Hash { content, size, mode, owner, group, open_by, link } (Kopie fuer Text)
4255 25771 ▶sub _file_entry {
Subroutine _file_entry: called CC=14 SCAR=26.4
4256 25771 my ( $dev, $path ) = @_;
4257 25771 ▶ return _file_entry( $dev, _dotdot($path) ) if $path =~ m{\A/.*/\.\.?(?:/|\z)};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[\A/.*/\.\.?(?:/|\z)] 1 25770 25771
4258 25770 ▶ if ( !( ref $dev->{files} eq 'HASH' && exists $dev->{files}{$path} ) && defined( my $r = _via_link( $dev, $path ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and defined(my $r = _via_link($dev, $path))) 3 25767 25770
Condition100%6/6
not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and defined(my $r = _via_link($dev, $path))
!ll&&!rl&&r
952248153
ref $$dev{'files'} eq 'HASH' && exists $$dev{'files'}{$path}
!ll&&!rl&&r
3624782952
MC/DC66%2/3
not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and defined(my $r = _via_link($dev, $path))
ref $$dev{'files'} eq 'HASH' exists $$dev{'files'}{$path} defined(my $r = _via_link($dev, $path))
Truth table80%4/5
not(A && B) and C
A= ref $$dev{'files'} eq 'HASH'B= exists $$dev{'files'}{$path}C= defined(my $r = _via_link($dev, $path))
ABCresult
11X0
0X00
1000
0X11
1011
4259 3 return _file_entry( $dev, $r );
4260 }
4261 25767 ▶ if ( !( ref $dev->{files} eq 'HASH' && exists $dev->{files}{$path} ) && ( my $v = _git_virtual( $dev, $path ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and my $v = _git_virtual($dev, $path)) 5 25762 25767
Condition100%6/6
not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and my $v = _git_virtual($dev, $path)
!ll&&!rl&&r
952248105
ref $$dev{'files'} eq 'HASH' && exists $$dev{'files'}{$path}
!ll&&!rl&&r
3624779952
MC/DC66%2/3
not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and my $v = _git_virtual($dev, $path)
ref $$dev{'files'} eq 'HASH' exists $$dev{'files'}{$path} my $v = _git_virtual($dev, $path)
Truth table80%4/5
not(A && B) and C
A= ref $$dev{'files'} eq 'HASH'B= exists $$dev{'files'}{$path}C= my $v = _git_virtual($dev, $path)
ABCresult
11X0
0X00
1000
0X11
1011
4262 5 ▶ return defined $v->{text} ? { content => $v->{text}, mode => '0644', owner => $dev->{forgejo} ? 'git' : 'root', group => $dev->{forgejo} ? 'git' : 'root' } : undef;
Branch: 3 branches
BranchTrueFalseTotal
defined $$v{'text'} ? : 4 1 5
$$dev{'forgejo'} ? : 1 3 4
$$dev{'forgejo'} ? : 1 3 4
4263 }
4264 25762 ▶ return undef unless ref $dev->{files} eq 'HASH' && exists $dev->{files}{$path};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{$path} 24810 952 25762
Condition100%3/3
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{$path}
!ll&&!rl&&r
3624774952
MC/DC100%2/2
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{$path}
ref $$dev{"files"} eq "HASH" exists $$dev{"files"}{$path}
Truth table100%3/3
A and B
A= ref $$dev{"files"} eq "HASH"B= exists $$dev{"files"}{$path}
ABresult
0X0
100
111
4265 952 my $e = $dev->{files}{$path};
4266 952 ▶ return ref $e eq 'HASH' ? $e : { content => $e };
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' ? : 472 480 952
4267 }
4268  
4269 204 ▶sub _file_size {
Subroutine _file_size: called CC=3 SCAR=11.0
4270 204 my ($e) = @_;
4271 204 ▶ return _bytes( $e->{size} ) if defined $e->{size};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$e{"size"} 43 161 204
4272 161 ▶ return length( $e->{content} // '' );
Condition100%2/2
$$e{"content"} // ""
l!l
1601
MC/DC100%1/1
$$e{"content"} // ""
$$e{"content"}
Truth table100%2/2
A
A= $$e{"content"}
Aresult
11
00
4273 }
4274  
4275 # Inhalt setzen; Metadaten (Rechte, Eigentuemer) bleiben, eine feste Groesse faellt weg.
4276 406 ▶sub _file_set {
Subroutine _file_set: called CC=2 SCAR=6.9
4277 406 my ( $dev, $path, $text ) = @_;
4278 406 my $old = $dev->{files}{$path};
4279 406 ▶ if ( ref $old eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $old eq 'HASH') { } 5 401 406
4280 5 my %e = %$old;
4281 5 delete @e{qw( size link )};
4282 5 $e{content} = $text;
4283 5 $dev->{files}{$path} = \%e;
4284 }
4285 401 else { $dev->{files}{$path} = $text }
4286 406 return;
4287 }
4288  
4289 # Verzeichnisse ergeben sich aus den Dateipfaden (und den Einhaengepunkten).
4290 # Verzeichnisse, die jedes Debian 12 (mit cron, OpenSSH, sudo) hat — leer, wenn der Zustand nichts darin nennt
4291 82 our %STD_DIRS = map { $_ => 1 } qw( /bin /boot /dev /etc /home /lib /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp
4292 /usr /usr/bin /usr/sbin /usr/lib /usr/local /usr/local/bin /usr/local/sbin /usr/local/etc /usr/local/lib /usr/share
4293 /var /var/backups /var/cache /var/lib /var/log /var/mail /var/spool /var/tmp /var/spool/cron /var/spool/cron/crontabs
4294 /etc/cron.d /etc/cron.daily /etc/cron.hourly /etc/cron.weekly /etc/cron.monthly /etc/default /etc/ssh /etc/ssh/sshd_config.d
4295 /etc/sudoers.d /etc/sysctl.d /etc/systemd /etc/systemd/system /etc/security /etc/ssl /etc/ssl/certs /etc/ssl/private
4296 /etc/logrotate.d /etc/apt /etc/network /lib/systemd /lib/systemd/system );
4297  
4298 1451 ▶sub _is_dir {
Subroutine _is_dir: called CC=21 SCAR=30.9
4299 1451 my ( $dev, $path ) = @_;
4300 1451 ▶ $path = _dotdot($path) if $path =~ m{\A/.*/\.\.?(?:/|\z)};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[\A/.*/\.\.?(?:/|\z)] 0 1451 1451
4301 1451 $path =~ s{/+\z}{};
4302 1451 ▶ return 1 if $STD_DIRS{$path};
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::STD_DIRS{$path} 473 978 1451
4303 978 ▶ return 1 if $path eq '' || exists( ( $dev->{mounts} || {} )->{$path} );
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "" or exists(($$dev{"mounts"} || {})->{$path}) 17 961 978
Condition100%5/5
$path eq "" or exists(($$dev{"mounts"} || {})->{$path})
l!l&&r!l&&!r
125961
$$dev{'mounts'} || {}
l!l
94872
MC/DC100%2/2
$path eq "" or exists(($$dev{"mounts"} || {})->{$path})
$path eq "" $$dev{'mounts'}
Truth table100%3/3
A or B
A= $path eq ""B= $$dev{'mounts'}
ABresult
1X1
011
000
4304 961 ▶ return 1 if exists( ( $dev->{dirs} || {} )->{$path} );
Branch: 1 branch
BranchTrueFalseTotal
if exists(($$dev{"dirs"} || {})->{$path}) 140 821 961
Condition100%2/2
$$dev{'dirs'} || {}
l!l
311650
MC/DC100%1/1
$$dev{'dirs'} || {}
$$dev{'dirs'}
Truth table100%2/2
A
A= $$dev{'dirs'}
Aresult
11
00
4305 821 ▶ return 1 if exists( ( $dev->{_dirs} || {} )->{$path} ); # leer geraeumt (rm, mv): bleibt
Branch: 1 branch
BranchTrueFalseTotal
if exists(($$dev{"_dirs"} || {})->{$path}) 7 814 821
Condition100%2/2
$$dev{'_dirs'} || {}
l!l
21800
MC/DC100%1/1
$$dev{'_dirs'} || {}
$$dev{'_dirs'}
Truth table100%2/2
A
A= $$dev{'_dirs'}
Aresult
11
00
4306 814 ▶ my $e = ref $dev->{files} eq 'HASH' ? $dev->{files}{$path} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'} eq 'HASH' ? : 802 12 814
4307 814 ▶ return _is_dir( $dev, _link_target( $path, $e->{link} ), ( $_[2] // 0 ) + 1 ) if ref $e eq 'HASH' && defined $e->{link} && ( $_[2] // 0 ) < 5;
Branch: 1 branch
BranchTrueFalseTotal
if ref $e eq "HASH" and defined $$e{"link"} and ($_[2] // 0) < 5 6 808 814
Condition70%7/10
ref $e eq "HASH" and defined $$e{"link"} and ($_[2] // 0) < 5
!ll&&!rl&&r
80806
ref $e eq "HASH" and defined $$e{"link"}
!ll&&!rl&&r
80266
$_[2] // 0
l!l
06
$_[2] // 0
l!l
06
MC/DC0%0/3
ref $e eq "HASH" and defined $$e{"link"} and ($_[2] // 0) < 5
ref $e eq "HASH" defined $$e{"link"} $_[2]
Truth table75%3/4
A and B and C
A= ref $e eq "HASH"B= defined $$e{"link"}C= $_[2]
ABCresult
0XX0
10X0
1100
1111
4308 0 ▶ if ( !defined $e && defined( my $r = _via_link( $dev, $path ) ) ) { return _is_dir( $dev, $r ) }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $e and defined(my $r = _via_link($dev, $path))) 0 808 808
Condition66%2/3
not defined $e and defined(my $r = _via_link($dev, $path))
!ll&&!rl&&r
397690
MC/DC0%0/2
not defined $e and defined(my $r = _via_link($dev, $path))
not defined $e defined(my $r = _via_link($dev, $path))
Truth table66%2/3
not(A) and B
A= not defined $eB= defined(my $r = _via_link($dev, $path))
ABresult
0X0
100
111
4309 808 ▶ if ( my $v = _git_virtual( $dev, $path ) ) { return 1 if $v->{dir} }
Branch: 2 branches
BranchTrueFalseTotal
if (my $v = _git_virtual($dev, $path)) 1 807 808
if $$v{"dir"} 1 0 1
4310 807 ▶ return scalar grep { index( $_, "$path/" ) == 0 } keys %{ $dev->{files} || {} };
Condition100%2/2
$$dev{'files'} || {}
l!l
79512
MC/DC100%1/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table100%2/2
A
A= $$dev{'files'}
Aresult
11
00
4311 }
4312  
4313 1541 ▶sub _under {
Subroutine _under: called CC=3 SCAR=11.0
4314 1541 my ( $dev, $path ) = @_;
4315 1541 $path =~ s{/+\z}{};
4316 1541 ▶ return sort grep { $path eq '' ? 1 : index( $_, "$path/" ) == 0 } keys %{ $dev->{files} || {} };
Branch: 1 branch
BranchTrueFalseTotal
$path eq '' ? : 0 8193 8193
Condition100%2/2
$$dev{'files'} || {}
l!l
149744
MC/DC100%1/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table100%2/2
A
A= $$dev{'files'}
Aresult
11
00
4317 }
4318  
4319 # Einhaengepunkte; ohne Angabe im Fall ein Wurzeldateisystem mit reichlich Platz
4320 176 ▶sub _mounts {
Subroutine _mounts: called CC=3 SCAR=11.0
4321 176 my ($dev) = @_;
4322 176 ▶ return $dev->{mounts} if ref $dev->{mounts} eq 'HASH' && %{ $dev->{mounts} };
Branch: 1 branch
BranchTrueFalseTotal
if ref $$dev{"mounts"} eq "HASH" and %{$$dev{"mounts"};} 139 37 176
Condition66%2/3
ref $$dev{"mounts"} eq "HASH" and %{$$dev{"mounts"};}
!ll&&!rl&&r
370139
MC/DC50%1/2
ref $$dev{"mounts"} eq "HASH" and %{$$dev{"mounts"};}
ref $$dev{"mounts"} eq "HASH" %{$$dev{"mounts"};}
Truth table66%2/3
A and B
A= ref $$dev{"mounts"} eq "HASH"B= %{$$dev{"mounts"};}
ABresult
0X0
100
111
4323 37 return { '/' => { dev => '/dev/vda1', size => '40G', used => '9G' } };
4324 }
4325  
4326 # mount: die Einhaengepunkte mit Typ und Optionen
4327 3 ▶sub _mount_cmd {
Subroutine _mount_cmd: called CC=7 SCAR=20.2
4328 3 my ( $dev, $av ) = @_;
4329 3 ▶ if ( grep { !/\A-/ } @$av ) { push @GAPS, join( ' ', 'mount', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not /\A-/;} @$av) 1 2 3
4330 2 my $m = _mounts($dev);
4331 2 my @l = map { my $x = $m->{$_}; sprintf '%s on %s type %s (%s)', $x->{dev} // '/dev/vda1', $_, $x->{fstype} // ( ( $x->{dev} // '' ) eq 'tmpfs' ? 'tmpfs' : 'ext4' ),
4332 2 ▶ $x->{options} // 'rw,relatime' } sort keys %$m;
Branch: 1 branch
BranchTrueFalseTotal
($$x{'dev'} // '') eq 'tmpfs' ? : 0 2 2
Condition50%4/8
$$x{"dev"} // "/dev/vda1"
l!l
20
$$x{"fstype"} // (($$x{"dev"} // "") eq "tmpfs" ? "tmpfs" : "ext4")
l!l
02
$$x{"dev"} // ""
l!l
20
$$x{"options"} // "rw,relatime"
l!l
02
MC/DC0%0/1
$$x{"dev"} // "/dev/vda1"
$$x{"dev"}
MC/DC0%0/1
$$x{"fstype"} // (($$x{"dev"} // "") eq "tmpfs" ? "tmpfs" : "ext4")
$$x{"fstype"}
MC/DC0%0/1
$$x{"options"} // "rw,relatime"
$$x{"options"}
Truth table50%1/2
A
A= $$x{"dev"}
Aresult
11
00
Truth table50%1/2
A
A= $$x{"fstype"}
Aresult
11
00
Truth table50%1/2
A
A= $$x{"options"}
Aresult
11
00
4333 2 unshift @l, 'proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)', 'sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)';
4334 2 return ( join( "\n", @l ), 1 );
4335 }
4336  
4337 142 ▶sub _mount_of {
Subroutine _mount_of: called CC=3 SCAR=11.0
4338 142 my ( $dev, $path ) = @_;
4339 38 my ($best) = sort { length $b <=> length $a }
4340 142 ▶ grep { $_ eq '/' || $path eq $_ || index( $path, "$_/" ) == 0 } keys %{ _mounts($dev) };
Condition100%6/6
$_ eq '/' || $path eq $_ || index($path, "$_/") == 0
l!l&&r!l&&!r
14531117
$_ eq "/" or $path eq $_
l!l&&r!l&&!r
13213148
MC/DC100%3/3
$_ eq '/' || $path eq $_ || index($path, "$_/") == 0
$_ eq "/" $path eq $_ index($path, "$_/") == 0
Truth table100%4/4
A or B || C
A= $_ eq "/"B= $path eq $_C= index($path, "$_/") == 0
ABCresult
1XX1
01X1
0011
0000
4341 142 return $best;
4342 }
4343  
4344 # Belegung je Einhaengepunkt: Grundlast + Dateien + geloeschte, noch offene Dateien
4345 29 ▶sub _df_rows {
Subroutine _df_rows: called CC=13 SCAR=25.9
4346 29 my ($dev) = @_;
4347 29 my $m = _mounts($dev);
4348 29 my %used = map { $_ => _bytes( $m->{$_}{used} ) } keys %$m;
4349 29 ▶ for my $p ( keys %{ $dev->{files} || {} } ) {
Condition50%1/2
$$dev{'files'} || {}
l!l
290
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
4350 126 ▶ my $mp = _mount_of( $dev, $p ) // next;
Condition100%2/2
_mount_of($dev, $p) // (next)
l!l
1224
MC/DC100%1/1
_mount_of($dev, $p) // (next)
_mount_of($dev, $p)
Truth table100%2/2
A
A= _mount_of($dev, $p)
Aresult
11
00
4351 122 $used{$mp} += _file_size( _file_entry( $dev, $p ) );
4352 }
4353 29 ▶ for my $d ( @{ $dev->{deleted_open} || [] } ) {
Condition100%2/2
$$dev{'deleted_open'} || []
l!l
326
MC/DC100%1/1
$$dev{'deleted_open'} || []
$$dev{'deleted_open'}
Truth table100%2/2
A
A= $$dev{'deleted_open'}
Aresult
11
00
4354 1 ▶ my $mp = _mount_of( $dev, $d->{path} ) // next;
Condition50%1/2
_mount_of($dev, $$d{"path"}) // (next)
l!l
10
MC/DC0%0/1
_mount_of($dev, $$d{"path"}) // (next)
_mount_of($dev, $$d{"path"})
Truth table50%1/2
A
A= _mount_of($dev, $$d{"path"})
Aresult
11
00
4355 1 $used{$mp} += _bytes( $d->{size} );
4356 }
4357 return map {
4358 29 my $size = _bytes( $m->{$_}{size} );
4359 67 ▶ my $u = $used{$_} > $size ? $size : $used{$_};
Branch: 1 branch
BranchTrueFalseTotal
$used{$_} > $size ? : 0 67 67
4360 # fuer root reservierte Bloecke (ext*, reserved_pct) stehen anderen nicht zur Verfuegung
4361 67 ▶ my $res = int( $size * ( $m->{$_}{reserved_pct} // 0 ) / 100 );
Condition100%2/2
$$m{$_}{"reserved_pct"} // 0
l!l
661
MC/DC100%1/1
$$m{$_}{"reserved_pct"} // 0
$$m{$_}{"reserved_pct"}
Truth table100%2/2
A
A= $$m{$_}{"reserved_pct"}
Aresult
11
00
4362 67 ▶ my $av = $size - $u - $res > 0 ? $size - $u - $res : 0;
Branch: 1 branch
BranchTrueFalseTotal
$size - $u - $res > 0 ? : 67 0 67
4363 67 ▶ +{ mount => $_, dev => $m->{$_}{dev} // '/dev/vda1', size => $size, used => $u, avail => $av, type => $m->{$_}{fstype} // 'ext4',
Branch: 1 branch
BranchTrueFalseTotal
$u + $av ? : 67 0 67
Condition100%4/4
$$m{$_}{"dev"} // "/dev/vda1"
l!l
589
$$m{$_}{"fstype"} // "ext4"
l!l
2443
MC/DC100%1/1
$$m{$_}{"dev"} // "/dev/vda1"
$$m{$_}{"dev"}
MC/DC100%1/1
$$m{$_}{"fstype"} // "ext4"
$$m{$_}{"fstype"}
Truth table100%2/2
A
A= $$m{$_}{"dev"}
Aresult
11
00
Truth table100%2/2
A
A= $$m{$_}{"fstype"}
Aresult
11
00
4364 pct => $u + $av ? int( 100 * $u / ( $u + $av ) + 0.999 ) : 0 };
4365 } sort keys %$m;
4366 }
4367  
4368 9 ▶sub _free {
Subroutine _free: called CC=2 SCAR=7.0
4369 9 my ( $dev, $mount ) = @_;
4370 9 my ($r) = grep { $_->{mount} eq $mount } _df_rows($dev);
4371 9 ▶ return $r ? $r->{avail} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 9 0 9
4372 }
4373  
4374 14 ▶sub _df {
Subroutine _df: called CC=15 SCAR=31.1
4375 14 my ( $dev, $av ) = @_;
4376 14 my $h = grep {/\A-\w*h/} @$av;
4377 14 my @paths = grep { !/\A-/ } @$av;
4378 14 my @rows = _df_rows($dev);
4379 14 ▶ return ( 'df: no file systems processed', 0 ) unless @rows;
Branch: 1 branch
BranchTrueFalseTotal
unless @rows 0 14 14
4380 14 ▶ if (@paths) {
Branch: 1 branch
BranchTrueFalseTotal
if (@paths) 14 0 14
4381 14 my %want;
4382 14 for my $p (@paths) {
4383 14 my $mp = _mount_of( $dev, $p );
4384 14 ▶ return ( "df: $p: No such file or directory", 0 ) unless defined $mp && ( _is_dir( $dev, $p ) || _file_entry( $dev, $p ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mp and _is_dir($dev, $p) || _file_entry($dev, $p) 0 14 14
Condition33%2/6
defined $mp and _is_dir($dev, $p) || _file_entry($dev, $p)
!ll&&!rl&&r
0014
_is_dir($dev, $p) or _file_entry($dev, $p)
l!l&&r!l&&!r
1400
MC/DC0%0/3
defined $mp and _is_dir($dev, $p) || _file_entry($dev, $p)
defined $mp _is_dir($dev, $p) _file_entry($dev, $p)
Truth table25%1/4
A and B or C
A= defined $mpB= _is_dir($dev, $p)C= _file_entry($dev, $p)
ABCresult
0XX0
1000
11X1
1011
4385 14 $want{$mp} = 1;
4386 }
4387 14 @rows = grep { $want{ $_->{mount} } } @rows;
4388 }
4389 0 ▶ my $f = $h ? sub { _human( $_[0] ) } : sub { int( $_[0] / 1024 ) };
Subroutine __ANON__: called CC=1 SCAR=0.6
Subroutine __ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
BranchTrueFalseTotal
$h ? : 14 0 14
4390 14 ▶ my $ty = grep { /\A-\w*T/ || $_ eq '--print-type' } @$av;
Condition33%1/3
/\A-\w*T/ || $_ eq '--print-type'
l!l&&r!l&&!r
0028
MC/DC0%0/2
/\A-\w*T/ || $_ eq '--print-type'
/\A-\w*T/ $_ eq '--print-type'
Truth table33%1/3
A || B
A= /\A-\w*T/B= $_ eq '--print-type'
ABresult
1X1
011
000
4391 14 ▶ my @l = ( sprintf( '%-15s ' . ( $ty ? '%-5s ' : '%s' ) . '%6s %6s %6s %4s %s', 'Filesystem', $ty ? 'Type' : '', $h ? 'Size' : '1K-blocks', 'Used', 'Avail', 'Use%', 'Mounted on' ) );
Branch: 3 branches
BranchTrueFalseTotal
$ty ? : 0 14 14
$ty ? : 0 14 14
$h ? : 14 0 14
4392 push @l, sprintf( '%-15s ' . ( $ty ? '%-5s ' : '%s' ) . '%6s %6s %6s %4s %s', $_->{dev}, $ty ? $_->{type} : '', $f->( $_->{size} ), $f->( $_->{used} ), $f->( $_->{avail} ), "$_->{pct}%", $_->{mount} )
4393 14 ▶ for @rows;
Branch: 2 branches
BranchTrueFalseTotal
$ty ? : 0 14 14
$ty ? : 0 14 14
4394 14 return ( join( "\n", @l ), 1 );
4395 }
4396  
4397 1 ▶sub _du {
Subroutine _du: called CC=12 SCAR=29.8
4398 1 my ( $dev, $av ) = @_;
4399 1 my $h = grep {/\A-\w*h/} @$av;
4400 1 my $sum = grep {/\A-\w*s/} @$av;
4401 1 my @paths = grep { !/\A-/ } @$av;
4402 1 ▶ @paths = ('.') unless @paths;
Branch: 1 branch
BranchTrueFalseTotal
unless @paths 0 1 1
4403 1 my @l;
4404 1 for my $p (@paths) {
4405 1 my $total;
4406 0 ▶ if ( my $e = _file_entry( $dev, $p ) ) { $total = _file_size($e) }
Branch: 2 branches
BranchTrueFalseTotal
if (my $e = _file_entry($dev, $p)) { } 0 1 1
elsif (_is_dir($dev, $p)) { } 1 0 1
4407 elsif ( _is_dir( $dev, $p ) ) {
4408 1 $total = 0;
4409 1 my %sub;
4410 1 for my $f ( _under( $dev, $p ) ) {
4411 1 my $sz = _file_size( _file_entry( $dev, $f ) );
4412 1 $total += $sz;
4413 1 ( my $d = $f ) =~ s{/[^/]+\z}{};
4414 0 ▶ while ( length $d > length $p ) { $sub{$d} += $sz; $d =~ s{/[^/]+\z}{} }
Branch: 1 branch
BranchTrueFalseTotal
if (length $d > length $p) 0 1 1
4415 }
4416 0 ▶ if ( !$sum ) { push @l, ( $h ? _human( $sub{$_} ) : int( $sub{$_} / 1024 ) ) . "\t$_" for sort { length $b <=> length $a || $a cmp $b } keys %sub }
Branch: 2 branches
BranchTrueFalseTotal
unless ($sum) 0 1 1
$h ? : 0 0 0
Condition0%0/3
length $b <=> length $a || $a cmp $b
l!l&&r!l&&!r
000
MC/DC0%0/2
length $b <=> length $a || $a cmp $b
length $b <=> length $a $a cmp $b
Truth table0%0/3
A || B
A= length $b <=> length $aB= $a cmp $b
ABresult
1X1
011
000
4417 }
4418 0 else { return ( "du: cannot access '$p': No such file or directory", 0 ) }
4419 1 ▶ push @l, ( $h ? _human($total) : int( $total / 1024 ) ) . "\t$p";
Branch: 1 branch
BranchTrueFalseTotal
$h ? : 1 0 1
4420 }
4421 1 return ( join( "\n", @l ), 1 );
4422 }
4423  
4424 244 ▶sub _mode_of { my ($e) = @_; return oct( $e->{mode} // '0644' ) }
Subroutine _mode_of: called CC=2 SCAR=6.9
Condition100%2/2
$$e{"mode"} // "0644"
l!l
19153
MC/DC100%1/1
$$e{"mode"} // "0644"
$$e{"mode"}
Truth table100%2/2
A
A= $$e{"mode"}
Aresult
11
00
4425  
4426 111 ▶sub _mode_text {
Subroutine _mode_text: called CC=11 SCAR=24.0
4427 111 my ( $m, $dir, $link ) = @_;
4428 111 ▶ my $s = $link ? 'l' : $dir ? 'd' : '-';
Branch: 2 branches
BranchTrueFalseTotal
$link ? : 1 110 111
$dir ? : 68 42 110
4429 111 for my $sh ( 6, 3, 0 ) {
4430 333 my $b = ( $m >> $sh ) & 7;
4431 333 my $sp = $m & { 6 => 04000, 3 => 02000, 0 => 01000 }->{$sh};
4432 333 ▶ my $x = $sp ? ( $sh ? ( $b & 1 ? 's' : 'S' ) : ( $b & 1 ? 't' : 'T' ) ) : ( $b & 1 ? 'x' : '-' );
Branch: 5 branches
BranchTrueFalseTotal
$sp ? : 8 325 333
$sh ? : 7 1 8
$b & 1 ? : 7 0 7
$b & 1 ? : 1 0 1
$b & 1 ? : 207 118 325
4433 333 ▶ $s .= ( $b & 4 ? 'r' : '-' ) . ( $b & 2 ? 'w' : '-' ) . $x;
Branch: 2 branches
BranchTrueFalseTotal
$b & 4 ? : 310 23 333
$b & 2 ? : 118 215 333
4434 }
4435 111 return $s;
4436 }
4437  
4438 87 ▶sub _ls_line {
Subroutine _ls_line: called CC=16 SCAR=27.9
4439 87 my ( $dev, $path, $name, $h ) = @_;
4440 87 my $e = _file_entry( $dev, $path );
4441 0 ▶ if ( !$e && defined( my $b = _virtual_bin( $dev, $path ) ) ) { return _bin_ls_line( $b, $name ) }
Branch: 1 branch
BranchTrueFalseTotal
if (not $e and defined(my $b = _virtual_bin($dev, $path))) 0 87 87
Condition66%2/3
not $e and defined(my $b = _virtual_bin($dev, $path))
!ll&&!rl&&r
28590
MC/DC0%0/2
not $e and defined(my $b = _virtual_bin($dev, $path))
not $e defined(my $b = _virtual_bin($dev, $path))
Truth table66%2/3
not(A) and B
A= not $eB= defined(my $b = _virtual_bin($dev, $path))
ABresult
0X0
100
111
4442 87 ▶ if ( !$e ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($e) 59 28 87
4443 59 ▶ my $d = ( $dev->{dirs} || {} )->{$path} || {};
Condition100%4/4
($$dev{'dirs'} || {})->{$path} || {}
l!l
851
$$dev{'dirs'} || {}
l!l
3524
MC/DC100%1/1
($$dev{'dirs'} || {})->{$path} || {}
$$dev{'dirs'}
Truth table100%2/2
A
A= $$dev{'dirs'}
Aresult
11
00
4444 return sprintf( '%s 2 %-8s %-8s %8s %s %s', _mode_text( oct( $d->{mode} // '0755' ), 1 ), $d->{owner} // 'root',
4445 59 ▶ $d->{group} // 'root', 4096, _ls_time($d), $name );
Condition100%6/6
$$d{"mode"} // "0755"
l!l
653
$$d{"owner"} // "root"
l!l
356
$$d{"group"} // "root"
l!l
356
MC/DC100%1/1
$$d{"mode"} // "0755"
$$d{"mode"}
MC/DC100%1/1
$$d{"owner"} // "root"
$$d{"owner"}
MC/DC100%1/1
$$d{"group"} // "root"
$$d{"group"}
Truth table100%2/2
A
A= $$d{"mode"}
Aresult
11
00
Truth table100%2/2
A
A= $$d{"owner"}
Aresult
11
00
Truth table100%2/2
A
A= $$d{"group"}
Aresult
11
00
4446 }
4447 28 my $size = _file_size($e);
4448 27 ▶ return sprintf( '%s 1 %-8s %-8s %8s %s %s%s', _mode_text( $e->{link} ? 0777 : _mode_of($e), 0, $e->{link} ) =~ s/\A-/( $e->{type} \/\/ '' ) eq 'socket' ? 's' : '-'/er,
Branch: 3 branches
BranchTrueFalseTotal
($$e{'type'} // '') eq 'socket' ? : 1 26 27
$h ? : 0 28 28
$$e{'link'} ? : 1 27 28
Condition100%6/6
$$e{"type"} // ""
l!l
126
$$e{"owner"} // "root"
l!l
1117
$$e{"group"} // "root"
l!l
1018
MC/DC100%1/1
$$e{"type"} // ""
$$e{"type"}
MC/DC100%1/1
$$e{"owner"} // "root"
$$e{"owner"}
MC/DC100%1/1
$$e{"group"} // "root"
$$e{"group"}
Truth table100%2/2
A
A= $$e{"type"}
Aresult
11
00
Truth table100%2/2
A
A= $$e{"owner"}
Aresult
11
00
Truth table100%2/2
A
A= $$e{"group"}
Aresult
11
00
4449 $e->{owner} // 'root', $e->{group} // 'root', $h ? _human($size) : $size, _ls_time($e), $name,
4450 28 ▶ $e->{link} ? " -> $e->{link}" : '' );
Branch: 1 branch
BranchTrueFalseTotal
$$e{'link'} ? : 1 27 28
4451 }
4452  
4453 82 ▶sub _ls {
Subroutine _ls: called CC=78 SCAR=47.9
4454 82 my ( $dev, $av ) = @_;
4455 82 local $BIN_MEMO = {};
4456 82 local $LS_TIME;
4457 82 for (@$av) {
4458 128 ▶ if ( $_ eq '--full-time' ) { $LS_TIME = 'full-iso' }
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq '--full-time') { } 1 127 128
elsif (/\A--time-style=(?:posix-)?(full-iso|long-iso|iso)\z/) { } 2 125 127
4459 2 elsif (/\A--time-style=(?:posix-)?(full-iso|long-iso|iso)\z/) { $LS_TIME = $1 }
4460 }
4461 82 ▶ my $opt = join '', map { /\A-(\w+)\z/ ? $1 : '' } @$av;
Branch: 1 branch
BranchTrueFalseTotal
/\A-(\w+)\z/ ? : 38 90 128
4462 82 ▶ $opt .= 'l' if grep { $_ eq '--full-time' } @$av;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "--full-time";} @$av 1 81 82
4463 82 my @paths = grep { !/\A-/ } @$av;
4464 82 ▶ @paths = ('.') unless @paths; # ohne Pfad: das aktuelle Verzeichnis
Branch: 1 branch
BranchTrueFalseTotal
unless @paths 3 79 82
4465 82 ▶ @paths = sort @paths unless $opt =~ /[fU]/; # Operanden sortiert wie GNU ls
Branch: 1 branch
BranchTrueFalseTotal
unless $opt =~ /[fU]/ 82 0 82
4466 82 ▶ my ( $long, $h, $rec ) = ( $opt =~ /[ln]/ ? 1 : 0, $opt =~ /h/ ? 1 : 0, $opt =~ /R/ ? 1 : 0 );
Branch: 3 branches
BranchTrueFalseTotal
$opt =~ /[ln]/ ? : 32 50 82
$opt =~ /h/ ? : 0 82 82
$opt =~ /R/ ? : 1 81 82
4467 82 my $all = $opt =~ /a/;
4468 82 ▶ my $hidden_ok = $all || $opt =~ /A/;
Condition100%3/3
$all || $opt =~ /A/
l!l&&r!l&&!r
7174
MC/DC100%2/2
$all || $opt =~ /A/
$all $opt =~ /A/
Truth table100%3/3
A || B
A= $allB= $opt =~ /A/
ABresult
1X1
011
000
4469 82 ▶ my $multi = @paths > 1 || $rec;
Condition100%3/3
@paths > 1 || $rec
l!l&&r!l&&!r
6175
MC/DC100%2/2
@paths > 1 || $rec
@paths > 1 $rec
Truth table100%3/3
A || B
A= @paths > 1B= $rec
ABresult
1X1
011
000
4470 82 my ( @out, @files_out );
4471 82 my $ok = 1;
4472 # erst Dateien, dann Verzeichnisse (wie GNU ls)
4473 82 my @dirs;
4474 82 for my $p (@paths) {
4475 90 ( my $dir = _absp($p) ) =~ s{(?<=.)/+\z}{}; # relativ zum aktuellen Verzeichnis, angezeigt wie angegeben
4476 90 ▶ my $le = ref $dev->{files} eq 'HASH' ? $dev->{files}{$dir} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'} eq 'HASH' ? : 90 0 90
4477 90 my $followed;
4478 90 ▶ if ( ref $le eq 'HASH' && defined $le->{link} && ( $opt !~ /[ld]/ || $p =~ m{/\z} ) && _is_dir( $dev, $dir ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $le eq 'HASH' and defined $$le{'link'} and !($opt =~ /[ld]/) || $p =~ m[/\z] and _is_dir($dev, $dir)) { } 1 89 90
elsif (not $le and defined(my $r = _via_link($dev, $dir))) { } 0 108 108
Condition66%8/12
ref $le eq "HASH" and defined $$le{"link"} and !($opt =~ /[ld]/) || $p =~ m[/\z] and _is_dir($dev, $dir)
!ll&&!rl&&r
8901
ref $le eq "HASH" and defined $$le{"link"} and !($opt =~ /[ld]/) || $p =~ m[/\z]
!ll&&!rl&&r
8901
ref $le eq "HASH" and defined $$le{"link"}
!ll&&!rl&&r
71181
not $opt =~ /[ld]/ or $p =~ m[/\z]
l!l&&r!l&&!r
100
MC/DC40%2/5
ref $le eq "HASH" and defined $$le{"link"} and !($opt =~ /[ld]/) || $p =~ m[/\z] and _is_dir($dev, $dir)
ref $le eq "HASH" defined $$le{"link"} not $opt =~ /[ld]/ $p =~ m[/\z] _is_dir($dev, $dir)
Truth table42%3/7
A and B and not(C) or D and E
A= ref $le eq "HASH"B= defined $$le{"link"}C= not $opt =~ /[ld]/D= $p =~ m[/\z]E= _is_dir($dev, $dir)
ABCDEresult
0XXXX0
10XXX0
1100X0
111X00
110100
111X11
110111
4479 1 $dir = _link_target( $dir, $le->{link} ); # ls link/ bzw. ohne -l: Inhalt des Ziels
4480 1 $followed = 1;
4481 }
4482 0 ▶ elsif ( !$le && defined( my $r = _via_link( $dev, $dir ) ) ) { $dir = $r }
Condition66%2/3
not $le and defined(my $r = _via_link($dev, $dir))
!ll&&!rl&&r
19700
MC/DC0%0/2
not $le and defined(my $r = _via_link($dev, $dir))
not $le defined(my $r = _via_link($dev, $dir))
Truth table66%2/3
not(A) and B
A= not $leB= defined(my $r = _via_link($dev, $dir))
ABresult
0X0
100
111
4483 # als Benutzer: x auf dem Weg, r am Verzeichnis
4484 90 ▶ if ( _who() ne 'root' && ( _file_entry( $dev, $dir ) || _is_dir( $dev, $dir ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_who() ne "root" and _file_entry($dev, $dir) || _is_dir($dev, $dir)) 3 87 90
Condition50%3/6
_who() ne "root" and _file_entry($dev, $dir) || _is_dir($dev, $dir)
!ll&&!rl&&r
8703
_file_entry($dev, $dir) or _is_dir($dev, $dir)
l!l&&r!l&&!r
030
MC/DC33%1/3
_who() ne "root" and _file_entry($dev, $dir) || _is_dir($dev, $dir)
_who() ne "root" _file_entry($dev, $dir) _is_dir($dev, $dir)
Truth table50%2/4
A and B or C
A= _who() ne "root"B= _file_entry($dev, $dir)C= _is_dir($dev, $dir)
ABCresult
0XX0
1000
11X1
1011
4485 3 ▶ if ( !_traverse_ok( $dev, $dir ) ) { push @out, "ls: cannot access '$p': Permission denied"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (_traverse_ok($dev, $dir)) 1 2 3
4486 2 ▶ if ( !_file_entry( $dev, $dir ) && $opt !~ /d/ && !_dir_ok( $dev, $dir, 4 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_file_entry($dev, $dir) or $opt =~ /d/ or _dir_ok($dev, $dir, 4)) 1 1 2
Condition50%3/6
_file_entry($dev, $dir) or $opt =~ /d/ or _dir_ok($dev, $dir, 4)
l!l&&r!l&&!r
011
_file_entry($dev, $dir) or $opt =~ /d/
l!l&&r!l&&!r
002
MC/DC33%1/3
_file_entry($dev, $dir) or $opt =~ /d/ or _dir_ok($dev, $dir, 4)
_file_entry($dev, $dir) $opt =~ /d/ _dir_ok($dev, $dir, 4)
Truth table50%2/4
A or B or C
A= _file_entry($dev, $dir)B= $opt =~ /d/C= _dir_ok($dev, $dir, 4)
ABCresult
1XX1
01X1
0011
0000
4487 1 push @out, "ls: cannot open directory '$p': Permission denied";
4488 1 $ok = 0;
4489 1 next;
4490 }
4491 }
4492 # usrmerge: /bin und /sbin sind Verweise nach usr/ (ls -l zeigt den Verweis)
4493 88 ▶ if ( $dir =~ m{\A/s?bin\z} && $opt =~ /[ld]/ && $p !~ m{/\z} && !$le ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ m[\A/s?bin\z] and $opt =~ /[ld]/ and not $p =~ m[/\z] and not $le) 1 87 88
Condition77%7/9
$dir =~ m[\A/s?bin\z] and $opt =~ /[ld]/ and not $p =~ m[/\z] and not $le
!ll&&!rl&&r
8701
$dir =~ m[\A/s?bin\z] and $opt =~ /[ld]/ and not $p =~ m[/\z]
!ll&&!rl&&r
8701
$dir =~ m[\A/s?bin\z] and $opt =~ /[ld]/
!ll&&!rl&&r
8521
MC/DC50%2/4
$dir =~ m[\A/s?bin\z] and $opt =~ /[ld]/ and not $p =~ m[/\z] and not $le
$dir =~ m[\A/s?bin\z] $opt =~ /[ld]/ not $p =~ m[/\z] not $le
Truth table60%3/5
A and B and not(C) and not(D)
A= $dir =~ m[\A/s?bin\z]B= $opt =~ /[ld]/C= not $p =~ m[/\z]D= not $le
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4494 1 ▶ push @files_out, $long ? sprintf( 'lrwxrwxrwx 1 root root %d Oct 20 09:00 %s -> usr%s', length("usr$dir"), $p, $dir ) : $p;
Branch: 1 branch
BranchTrueFalseTotal
$long ? : 1 0 1
4495 1 next;
4496 }
4497 87 ▶ if ( defined( my $b = _virtual_bin( $dev, $dir ) ) ) { push @files_out, $long ? _bin_ls_line( $b, $p ) : $p; next }
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $b = _virtual_bin($dev, $dir))) 2 85 87
$long ? : 2 0 2
4498 85 ▶ if ( $opt =~ /d/ && _is_dir( $dev, $dir ) && !_file_entry( $dev, $dir ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt =~ /d/ and _is_dir($dev, $dir) and not _file_entry($dev, $dir)) 5 80 85
Condition83%5/6
$opt =~ /d/ and _is_dir($dev, $dir) and not _file_entry($dev, $dir)
!ll&&!rl&&r
8005
$opt =~ /d/ and _is_dir($dev, $dir)
!ll&&!rl&&r
7915
MC/DC66%2/3
$opt =~ /d/ and _is_dir($dev, $dir) and not _file_entry($dev, $dir)
$opt =~ /d/ _is_dir($dev, $dir) not _file_entry($dev, $dir)
Truth table75%3/4
A and B and not(C)
A= $opt =~ /d/B= _is_dir($dev, $dir)C= not _file_entry($dev, $dir)
ABCresult
0XX0
10X0
1100
1111
4499 5 ▶ push @files_out, $long ? _ls_line( $dev, $dir, $p, $h ) : $p;
Branch: 1 branch
BranchTrueFalseTotal
$long ? : 5 0 5
4500 5 next;
4501 }
4502 80 ▶ if ( !$followed && _file_entry( $dev, $dir ) ) { # auch mit / am Ende (pg_wal/ steht als ein Eintrag im Zustand)
Branch: 1 branch
BranchTrueFalseTotal
if (not $followed and _file_entry($dev, $dir)) 19 61 80
Condition100%3/3
not $followed and _file_entry($dev, $dir)
!ll&&!rl&&r
16019
MC/DC100%2/2
not $followed and _file_entry($dev, $dir)
not $followed _file_entry($dev, $dir)
Truth table100%3/3
not(A) and B
A= not $followedB= _file_entry($dev, $dir)
ABresult
0X0
100
111
4503 19 ▶ push @files_out, $long ? _ls_line( $dev, $dir, $p, $h ) : $p;
Branch: 1 branch
BranchTrueFalseTotal
$long ? : 16 3 19
4504 19 next;
4505 }
4506 61 ▶ if ( $dev->{storage} && $dir =~ m{\A/dev/} ) { # Blockgeraete
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"storage"} and $dir =~ m[\A/dev/]) 0 61 61
Condition33%1/3
$$dev{"storage"} and $dir =~ m[\A/dev/]
!ll&&!rl&&r
6100
MC/DC0%0/2
$$dev{"storage"} and $dir =~ m[\A/dev/]
$$dev{"storage"} $dir =~ m[\A/dev/]
Truth table33%1/3
A and B
A= $$dev{"storage"}B= $dir =~ m[\A/dev/]
ABresult
0X0
100
111
4507 0 _part('Storage');
4508 0 ▶ if ( Langertha::Holmgang::Sim::Linux::Storage::canon( $dev, $dir ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (Langertha::Holmgang::Sim::Linux::Storage::canon($dev, $dir)) 0 0 0
4509 0 ▶ push @files_out, $long ? "brw-rw---- 1 root disk 254, 0 Oct 20 09:00 $p" : $p;
Branch: 1 branch
BranchTrueFalseTotal
$long ? : 0 0 0
4510 0 next;
4511 }
4512 }
4513 61 my $names = _ls_names( $dev, $dir );
4514 61 ▶ if ( !%$names && !_is_dir( $dev, $dir ) && $dir ne '/root' && $dir ne '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %$names || _is_dir($dev, $dir) and $dir ne "/root" and $dir ne "/") 9 52 61
Condition77%7/9
not %$names || _is_dir($dev, $dir) and $dir ne "/root" and $dir ne "/"
!ll&&!rl&&r
5209
not %$names || _is_dir($dev, $dir) and $dir ne "/root"
!ll&&!rl&&r
5209
%$names || _is_dir($dev, $dir)
l!l&&r!l&&!r
4579
MC/DC50%2/4
not %$names || _is_dir($dev, $dir) and $dir ne "/root" and $dir ne "/"
%$names _is_dir($dev, $dir) $dir ne "/root" $dir ne "/"
Truth table60%3/5
not(A || B) and C and D
A= %$namesB= _is_dir($dev, $dir)C= $dir ne "/root"D= $dir ne "/"
ABCDresult
1XXX0
01XX0
000X0
00100
00111
4515 9 push @out, "ls: cannot access '$p': No such file or directory";
4516 9 $ok = 0;
4517 9 next;
4518 }
4519 52 push @dirs, [ $p, $dir ]; # wie angegeben, aufgeloest (Symlink)
4520 }
4521 82 push @out, @files_out;
4522 82 my @queue = @dirs;
4523 82 ▶ while ( defined( my $q = shift @queue ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $q = shift @queue)) 54 82 136
4524 54 my ( $p, $dir ) = @$q;
4525 54 my $names = _ls_names( $dev, $dir );
4526 54 ▶ my @n = sort grep { $hidden_ok || !/\A\./ } keys %$names;
Condition100%3/3
$hidden_ok || !/\A\./
l!l&&r!l&&!r
507892
MC/DC100%2/2
$hidden_ok || !/\A\./
$hidden_ok !/\A\./
Truth table100%3/3
A || not(B)
A= $hidden_okB= !/\A\./
ABresult
1X1
011
000
4527 54 ▶ if ( $opt =~ /t/ ) { # -t: neueste zuerst (gleich alt: nach Namen)
Branch: 1 branch
BranchTrueFalseTotal
if ($opt =~ /t/) 3 51 54
4528 3 ▶ my %mt = map { my $e = _file_entry( $dev, "$dir/$_" ); ( $_ => $e ? _mtime($e) : _mtime( ( $dev->{dirs} || {} )->{"$dir/$_"} ) ) } @n;
Branch: 1 branch
BranchTrueFalseTotal
$e ? : 9 0 9
Condition0%0/2
$$dev{'dirs'} || {}
l!l
00
MC/DC0%0/1
$$dev{'dirs'} || {}
$$dev{'dirs'}
Truth table0%0/2
A
A= $$dev{'dirs'}
Aresult
11
00
4529 3 ▶ @n = sort { $mt{$b} <=> $mt{$a} || $a cmp $b } @n;
Condition33%1/3
$mt{$b} <=> $mt{$a} || $a cmp $b
l!l&&r!l&&!r
900
MC/DC0%0/2
$mt{$b} <=> $mt{$a} || $a cmp $b
$mt{$b} <=> $mt{$a} $a cmp $b
Truth table33%1/3
A || B
A= $mt{$b} <=> $mt{$a}B= $a cmp $b
ABresult
1X1
011
000
4530 }
4531 54 ▶ @n = reverse @n if $opt =~ /r/;
Branch: 1 branch
BranchTrueFalseTotal
if $opt =~ /r/ 1 53 54
4532 54 ▶ push @out, '' if $multi && @out;
Branch: 1 branch
BranchTrueFalseTotal
if $multi and @out 5 49 54
Condition100%3/3
$multi and @out
!ll&&!rl&&r
4635
MC/DC100%2/2
$multi and @out
$multi @out
Truth table100%3/3
A and B
A= $multiB= @out
ABresult
0X0
100
111
4533 54 ▶ push @out, "$p:" if $multi;
Branch: 1 branch
BranchTrueFalseTotal
if $multi 8 46 54
4534 54 ▶ if ($long) {
Branch: 1 branch
BranchTrueFalseTotal
if ($long) { } 11 43 54
4535 11 ▶ push @out, 'total ' . 4 * ( @n + ( $all ? 2 : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
$all ? : 6 5 11
4536 11 ▶ if ($all) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all) 6 5 11
4537 6 ( my $up = $dir ) =~ s{/[^/]+\z}{};
4538 6 ▶ push @out, _ls_line( $dev, $dir, '.', $h ), _ls_line( $dev, length $up ? $up : '/', '..', $h );
Branch: 1 branch
BranchTrueFalseTotal
length $up ? : 6 0 6
4539 }
4540 11 for (@n) {
4541 push @out, ref $names->{$_}
4542 3 ▶ ? sprintf( 'lrwxrwxrwx 1 root root %8d Oct 20 09:00 %s -> %s', length ${ $names->{$_} }, $_, ${ $names->{$_} } )
Branch: 2 branches
BranchTrueFalseTotal
$dir eq '/dev' && $$dev{'storage'} && !_file_entry($dev, "/dev/$_") && !_is_dir($dev, "/dev/$_") ? : 0 51 51
$dir eq '/' ? : 40 11 51
Condition33%3/9
$dir eq "/dev" and $$dev{"storage"} and not _file_entry($dev, "/dev/$_") and not _is_dir($dev, "/dev/$_")
!ll&&!rl&&r
5100
$dir eq "/dev" and $$dev{"storage"} and not _file_entry($dev, "/dev/$_")
!ll&&!rl&&r
5100
$dir eq "/dev" and $$dev{"storage"}
!ll&&!rl&&r
5100
MC/DC0%0/4
$dir eq "/dev" and $$dev{"storage"} and not _file_entry($dev, "/dev/$_") and not _is_dir($dev, "/dev/$_")
$dir eq "/dev" $$dev{"storage"} not _file_entry($dev, "/dev/$_") not _is_dir($dev, "/dev/$_")
Truth table20%1/5
A and B and not(C) and not(D)
A= $dir eq "/dev"B= $$dev{"storage"}C= not _file_entry($dev, "/dev/$_")D= not _is_dir($dev, "/dev/$_")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4543 54 ▶ : $dir eq '/dev' && $dev->{storage} && !_file_entry( $dev, "/dev/$_" ) && !_is_dir( $dev, "/dev/$_" )
Branch: 1 branch
BranchTrueFalseTotal
ref $$names{$_} ? : 3 51 54
4544 ? "brw-rw---- 1 root disk 254, 0 Oct 20 09:00 $_"
4545 : _ls_line( $dev, ( $dir eq "/" ? "" : $dir ) . "/$_", $_, $h );
4546 }
4547 }
4548 else {
4549 43 ▶ my @x = ( $all ? ( '.', '..' ) : (), @n );
Branch: 1 branch
BranchTrueFalseTotal
$all ? : 1 42 43
4550 43 push @out, @x; # ohne Terminal (Werkzeug-Aufruf): ein Name je Zeile
4551 }
4552 54 ▶ if ($rec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rec) 3 51 54
4553 3 ▶ my $base = $p =~ m{/\z} ? $p : "$p/";
Branch: 1 branch
BranchTrueFalseTotal
$p =~ m[/\z] ? : 0 3 3
4554 3 ▶ unshift @queue, map { [ "$base$_", ( $dir eq "/" ? "" : $dir ) . "/$_" ] } grep { !ref $names->{$_} && !_file_entry( $dev, "$dir/$_" ) && _is_dir( $dev, "$dir/$_" ) } @n;
Branch: 1 branch
BranchTrueFalseTotal
$dir eq '/' ? : 0 2 2
Condition66%4/6
!(ref $$names{$_} || _file_entry($dev, "$dir/$_")) && _is_dir($dev, "$dir/$_")
!ll&&!rl&&r
102
ref $$names{$_} || _file_entry($dev, "$dir/$_")
l!l&&r!l&&!r
012
MC/DC33%1/3
!(ref $$names{$_} || _file_entry($dev, "$dir/$_")) && _is_dir($dev, "$dir/$_")
ref $$names{$_} _file_entry($dev, "$dir/$_") _is_dir($dev, "$dir/$_")
Truth table50%2/4
not(A || B) && C
A= ref $$names{$_}B= _file_entry($dev, "$dir/$_")C= _is_dir($dev, "$dir/$_")
ABCresult
1XX0
01X0
0000
0011
4555 }
4556 }
4557 82 return ( join( "\n", @out ), $ok );
4558 }
4559  
4560 # Namen in einem Verzeichnis: Dateien, Unterverzeichnisse, virtuelle Eintraege
4561 # (wg, /proc/sys, *.wants von systemd als Verweise: Wert ist dann \"ziel")
4562 116 ▶sub _ls_names {
Subroutine _ls_names: called CC=45 SCAR=44.8
4563 116 my ( $dev, $dir ) = @_;
4564 116 my %names;
4565 116 ▶ my $pre = $dir eq '/' ? '/' : "$dir/";
Branch: 1 branch
BranchTrueFalseTotal
$dir eq '/' ? : 8 108 116
4566 116 ▶ for my $f ( keys %{ $dev->{files} || {} } ) {
Condition50%1/2
$$dev{'files'} || {}
l!l
1160
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
4567 726 ▶ $names{$1} = 1 if index( $f, $pre ) == 0 && substr( $f, length $pre ) =~ m{\A([^/]+)};
Branch: 1 branch
BranchTrueFalseTotal
if index($f, $pre) == 0 and substr($f, length $pre) =~ m[\A([^/]+)] 157 569 726
Condition66%2/3
index($f, $pre) == 0 and substr($f, length $pre) =~ m[\A([^/]+)]
!ll&&!rl&&r
5690157
MC/DC50%1/2
index($f, $pre) == 0 and substr($f, length $pre) =~ m[\A([^/]+)]
index($f, $pre) == 0 substr($f, length $pre) =~ m[\A([^/]+)]
Truth table66%2/3
A and B
A= index($f, $pre) == 0B= substr($f, length $pre) =~ m[\A([^/]+)]
ABresult
0X0
100
111
4568 }
4569 116 ▶ for my $d ( keys %{ $dev->{dirs} || {} }, keys %{ $dev->{_dirs} || {} }, keys %{ $dev->{mounts} || {} } ) { $names{$1} = 1 if index( $d, $pre ) == 0 && substr( $d, length $pre ) =~ m{\A([^/]+)} }
Branch: 1 branch
BranchTrueFalseTotal
if index($d, $pre) == 0 and substr($d, length $pre) =~ m[\A([^/]+)] 14 154 168
Condition100%9/9
$$dev{'dirs'} || {}
l!l
5462
$$dev{'_dirs'} || {}
l!l
7109
$$dev{'mounts'} || {}
l!l
12104
index($d, $pre) == 0 and substr($d, length $pre) =~ m[\A([^/]+)]
!ll&&!rl&&r
150414
MC/DC100%1/1
$$dev{'dirs'} || {}
$$dev{'dirs'}
MC/DC100%1/1
$$dev{'_dirs'} || {}
$$dev{'_dirs'}
MC/DC100%1/1
$$dev{'mounts'} || {}
$$dev{'mounts'}
MC/DC100%2/2
index($d, $pre) == 0 and substr($d, length $pre) =~ m[\A([^/]+)]
index($d, $pre) == 0 substr($d, length $pre) =~ m[\A([^/]+)]
Truth table100%2/2
A
A= $$dev{'dirs'}
Aresult
11
00
Truth table100%2/2
A
A= $$dev{'_dirs'}
Aresult
11
00
Truth table100%2/2
A
A= $$dev{'mounts'}
Aresult
11
00
Truth table100%3/3
A and B
A= index($d, $pre) == 0B= substr($d, length $pre) =~ m[\A([^/]+)]
ABresult
0X0
100
111
4570 0 ▶ if ( $dir eq '/dev' && $dev->{storage} ) { $names{$_} = 1 for grep {defined} map { m{\A/dev/([^/]+)\z} ? $1 : () } keys %{ $dev->{storage}{disks} || {} }, keys %{ $dev->{storage}{md} || {} } }
Branch: 2 branches
BranchTrueFalseTotal
if ($dir eq "/dev" and $$dev{"storage"}) 0 116 116
m[\A/dev/([^/]+)\z] ? : 0 0 0
Condition14%1/7
$dir eq "/dev" and $$dev{"storage"}
!ll&&!rl&&r
11600
$$dev{'storage'}{'disks'} || {}
l!l
00
$$dev{'storage'}{'md'} || {}
l!l
00
MC/DC0%0/2
$dir eq "/dev" and $$dev{"storage"}
$dir eq "/dev" $$dev{"storage"}
MC/DC0%0/1
$$dev{'storage'}{'disks'} || {}
$$dev{'storage'}{'disks'}
MC/DC0%0/1
$$dev{'storage'}{'md'} || {}
$$dev{'storage'}{'md'}
Truth table33%1/3
A and B
A= $dir eq "/dev"B= $$dev{"storage"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $$dev{'storage'}{'disks'}
Aresult
11
00
Truth table0%0/2
A
A= $$dev{'storage'}{'md'}
Aresult
11
00
4571 116 ▶ if ( $dir eq '/' ) { $names{$_} //= 1 for @ROOT_DIRS }
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq "/") 8 108 116
Condition100%2/2
$names{$_} //= 1
l!l
12140
MC/DC100%1/1
$names{$_} //= 1
$names{$_}
Truth table100%2/2
A
A= $names{$_}
Aresult
11
00
4572 116 ▶ if ( my $v = _git_virtual( $dev, $dir ) ) { $names{$_} //= 1 for @{ $v->{dir} || [] } }
Branch: 1 branch
BranchTrueFalseTotal
if (my $v = _git_virtual($dev, $dir)) 2 114 116
Condition50%2/4
$$v{'dir'} || []
l!l
20
$names{$_} //= 1
l!l
012
MC/DC0%0/1
$$v{'dir'} || []
$$v{'dir'}
MC/DC0%0/1
$names{$_} //= 1
$names{$_}
Truth table50%1/2
A
A= $$v{'dir'}
Aresult
11
00
Truth table50%1/2
A
A= $names{$_}
Aresult
11
00
4573 116 ▶ $names{'.git'} //= 1 if exists( ( ( $dev->{git} || {} )->{repos} || {} )->{$dir} );
Branch: 1 branch
BranchTrueFalseTotal
if exists((($$dev{"git"} || {})->{"repos"} || {})->{$dir}) 2 114 116
Condition83%5/6
($$dev{'git'} || {})->{'repos'} || {}
l!l
6110
$$dev{'git'} || {}
l!l
6110
$names{".git"} //= 1
l!l
02
MC/DC100%1/1
($$dev{'git'} || {})->{'repos'} || {}
$$dev{'git'}
MC/DC0%0/1
$names{".git"} //= 1
$names{".git"}
Truth table100%2/2
A
A= $$dev{'git'}
Aresult
11
00
Truth table50%1/2
A
A= $names{".git"}
Aresult
11
00
4574 0 ▶ if ( $dir eq '/etc/wireguard' ) { $names{"$_.conf"} = 1 for keys %{ $dev->{wg} || {} } }
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq "/etc/wireguard") 0 116 116
Condition0%0/2
$$dev{'wg'} || {}
l!l
00
MC/DC0%0/1
$$dev{'wg'} || {}
$$dev{'wg'}
Truth table0%0/2
A
A= $$dev{'wg'}
Aresult
11
00
4575 116 ▶ if ( $dir =~ m{\A/proc/sys(?:/(.+))?\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ m[\A/proc/sys(?:/(.+))?\z]) 4 112 116
4576 4 ▶ my $p = defined $1 ? ( $1 =~ tr{/}{.}r ) . '.' : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 4 0 4
4577 4 ▶ for my $k ( keys %{ $dev->{sysctl} || {} } ) { $names{$1} = 1 if $k =~ /\A\Q$p\E([^.]+)/ }
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /\A\Q$p\E([^.]+)/ 6 2 8
Condition50%1/2
$$dev{'sysctl'} || {}
l!l
40
MC/DC0%0/1
$$dev{'sysctl'} || {}
$$dev{'sysctl'}
Truth table50%1/2
A
A= $$dev{'sysctl'}
Aresult
11
00
4578 }
4579 116 ▶ if ( $dir =~ m{\A/etc/systemd/system/([\w.@-]+\.(?:target|service))\.wants\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ m[\A/etc/systemd/system/([\w.\@-]+\.(?:target|service))\.wants\z]) 2 114 116
4580 2 my $w = _wants($dev);
4581 2 ▶ $names{ $_->[0] } = \$_->[1] for @{ $w->{$1} || [] };
Condition50%1/2
$$w{$1} || []
l!l
20
MC/DC0%0/1
$$w{$1} || []
$$w{$1}
Truth table50%1/2
A
A= $$w{$1}
Aresult
11
00
4582 }
4583 0 ▶ if ( $dir eq '/etc/systemd/system' ) { $names{"$_.wants"} = 1 for keys %{ _wants($dev) } }
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq "/etc/systemd/system") 0 116 116
4584 116 ▶ if ( $dir =~ m{\A(?:/usr)?/(s?bin)\z} ) { $names{$_} //= 1 for _bin_names( $dev, $1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ m[\A(?:/usr)?/(s?bin)\z]) 12 104 116
Condition50%1/2
$names{$_} //= 1
l!l
01362
MC/DC0%0/1
$names{$_} //= 1
$names{$_}
Truth table50%1/2
A
A= $names{$_}
Aresult
11
00
4585 116 return \%names;
4586 }
4587  
4588 # Programme in /usr/bin bzw. /usr/sbin (usrmerge: /bin und /sbin verweisen dorthin): genau
4589 # die, die which auf diesem Geraet findet — was ls zeigt, passt zu which, type und
4590 # "command not found"
4591 15 ▶sub _bin_names {
Subroutine _bin_names: called CC=3 SCAR=11.4
4592 15 my ( $dev, $kind ) = @_;
4593 15 ▶ return @{ $BIN_MEMO->{$kind} //= [ _bin_names_all( $dev, $kind ) ] } if $BIN_MEMO;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::BIN_MEMO 15 0 15
Condition100%2/2
$$Langertha::Holmgang::Sim::Linux::BIN_MEMO{$kind} //= [_bin_names_all($dev, $kind)]
l!l
69
MC/DC100%1/1
$$Langertha::Holmgang::Sim::Linux::BIN_MEMO{$kind} //= [_bin_names_all($dev, $kind)]
$$Langertha::Holmgang::Sim::Linux::BIN_MEMO{$kind}
Truth table100%2/2
A
A= $$Langertha::Holmgang::Sim::Linux::BIN_MEMO{$kind}
Aresult
11
00
4594 0 return _bin_names_all( $dev, $kind );
4595 }
4596  
4597 9 ▶sub _bin_names_all {
Subroutine _bin_names_all: called CC=6 SCAR=17.9
4598 9 my ( $dev, $kind ) = @_;
4599 9 ▶ my %exec = map { ( $_->{exec} // '' ) => 1 } grep { ref eq 'HASH' } values %{ $dev->{services} || {} };
Condition75%3/4
$$_{"exec"} // ""
l!l
240
$$dev{'services'} || {}
l!l
81
MC/DC0%0/1
$$_{"exec"} // ""
$$_{"exec"}
MC/DC100%1/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$_{"exec"}
Aresult
11
00
Truth table100%2/2
A
A= $$dev{'services'}
Aresult
11
00
4600 9 my @cand = grep { /\A(?:\[|[A-Za-z0-9_][\w.+@-]*)\z/ } keys %CMD, keys %REAL, keys %FILTER, keys %INTERACTIVE, keys %exec,
4601 qw( ls bash sh cat cp mv rm mkdir tail head grep sed awk find echo printf true false test [ );
4602 9 my %seen;
4603 my @n;
4604 9 for my $n ( sort grep { !$seen{$_}++ } @cand ) {
4605 2329 my ( $p, $ok ) = _which( 'which', $dev, [$n] );
4606 2329 ▶ push @n, $n if $ok && $p eq "/usr/$kind/$n";
Branch: 1 branch
BranchTrueFalseTotal
if $ok and $p eq "/usr/$kind/$n" 1192 1137 2329
Condition100%3/3
$ok and $p eq "/usr/$kind/$n"
!ll&&!rl&&r
2708671192
MC/DC100%2/2
$ok and $p eq "/usr/$kind/$n"
$ok $p eq "/usr/$kind/$n"
Truth table100%3/3
A and B
A= $okB= $p eq "/usr/$kind/$n"
ABresult
0X0
100
111
4607 }
4608 9 return @n;
4609 }
4610  
4611 # Programm aus _bin_names unter /usr/bin, /bin, /usr/sbin, /sbin? Liefert den Namen oder undef
4612 146 ▶sub _virtual_bin {
Subroutine _virtual_bin: called CC=4 SCAR=13.9
4613 146 my ( $dev, $path ) = @_;
4614 146 ▶ my ( $kind, $n ) = $path =~ m{\A(?:/usr)?/(s?bin)/([^/]+)\z} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = $path =~ m[\A(?:/usr)?/(s?bin)/([^/]+)\z] or return undef 4 142 146
4615 4 ▶ return undef if _file_entry( $dev, $path );
Branch: 1 branch
BranchTrueFalseTotal
if _file_entry($dev, $path) 1 3 4
4616 3 ▶ return ( grep { $_ eq $n } _bin_names( $dev, $kind ) ) ? $n : undef;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq $n;} _bin_names($dev, $kind)) ? : 2 1 3
4617 }
4618  
4619 2 ▶sub _bin_ls_line {
Subroutine _bin_ls_line: called CC=1 SCAR=0.0
4620 2 my ( $n, $shown ) = @_;
4621 2 return sprintf( '-rwxr-xr-x 1 root root %8d Oct 20 09:00 %s', 30000 + 113 * unpack( '%32C*', $n ), $shown );
4622 }
4623  
4624 # Welche Units in welchem *.wants haengen (enabled): { ziel => [ [ unit, unit-datei ] ] }
4625 2 ▶sub _wants {
Subroutine _wants: called CC=9 SCAR=23.6
4626 2 my ($dev) = @_;
4627 2 my %w;
4628 2 ▶ for my $n ( sort keys %{ $dev->{services} || {} } ) {
Condition50%1/2
$$dev{'services'} || {}
l!l
20
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
4629 6 my $svc = $dev->{services}{$n};
4630 6 ▶ next if $svc->{masked} || !_symlinked( $dev, $n, $svc );
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"masked"} or not _symlinked($dev, $n, $svc) 0 6 6
Condition33%1/3
$$svc{"masked"} or not _symlinked($dev, $n, $svc)
l!l&&r!l&&!r
006
MC/DC0%0/2
$$svc{"masked"} or not _symlinked($dev, $n, $svc)
$$svc{"masked"} not _symlinked($dev, $n, $svc)
Truth table33%1/3
A or not(B)
A= $$svc{"masked"}B= not _symlinked($dev, $n, $svc)
ABresult
1X1
011
000
4631 6 ▶ my ($wb) = ( _unit_text( $dev, $n, $svc ) // '' ) =~ /^\s*WantedBy\s*=\s*(\S+)/m;
Condition100%2/2
_unit_text($dev, $n, $svc) // ""
l!l
24
MC/DC100%1/1
_unit_text($dev, $n, $svc) // ""
_unit_text($dev, $n, $svc)
Truth table100%2/2
A
A= _unit_text($dev, $n, $svc)
Aresult
11
00
4632 6 ▶ $wb //= $svc->{wanted_by} // ( $n =~ /\.timer\z/ ? 'timers.target' : 'multi-user.target' );
Branch: 1 branch
BranchTrueFalseTotal
$n =~ /\.timer\z/ ? : 0 6 6
Condition50%2/4
$wb //= $$svc{"wanted_by"} // ($n =~ /\.timer\z/ ? "timers.target" : "multi-user.target")
l!l
06
$$svc{"wanted_by"} // ($n =~ /\.timer\z/ ? "timers.target" : "multi-user.target")
l!l
06
MC/DC0%0/1
$wb //= $$svc{"wanted_by"} // ($n =~ /\.timer\z/ ? "timers.target" : "multi-user.target")
$wb
Truth table50%1/2
A
A= $wb
Aresult
11
00
4633 6 push @{ $w{$wb} }, [ _uname($n), _unit_file( $n, $svc ) ];
4634 }
4635 2 return \%w;
4636 }
4637  
4638 # Hat die Unit einen Verweis in einem *.wants? (enabled; static nur, wenn ausdruecklich enabled)
4639 11 ▶sub _symlinked {
Subroutine _symlinked: called CC=4 SCAR=13.9
4640 11 my ( $dev, $n, $svc ) = @_;
4641 11 ▶ return $svc->{enabled} ? 1 : 0 if exists $svc->{enabled};
Branch: 2 branches
BranchTrueFalseTotal
if exists $$svc{"enabled"} 7 4 11
$$svc{'enabled'} ? : 3 4 7
4642 4 ▶ return _static( $dev, $n, $svc ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
_static($dev, $n, $svc) ? : 0 4 4
4643 }
4644  
4645 21 ▶sub _stat {
Subroutine _stat: called CC=35 SCAR=40.6
4646 21 my ( $dev, $av ) = @_;
4647 21 my @a = @$av;
4648 21 my $fmt;
4649 21 ▶ for ( my $i = 0; $i < @a; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @a) 21 1 22
4650 21 ▶ if ( $a[$i] eq '-c' || $a[$i] eq '--format' || $a[$i] eq '--printf' ) { $fmt = $a[ $i + 1 ]; splice @a, $i, 2; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($a[$i] eq "-c" or $a[$i] eq "--format" or $a[$i] eq "--printf") 20 1 21
Condition66%4/6
$a[$i] eq "-c" or $a[$i] eq "--format" or $a[$i] eq "--printf"
l!l&&r!l&&!r
2001
$a[$i] eq "-c" or $a[$i] eq "--format"
l!l&&r!l&&!r
2001
MC/DC33%1/3
$a[$i] eq "-c" or $a[$i] eq "--format" or $a[$i] eq "--printf"
$a[$i] eq "-c" $a[$i] eq "--format" $a[$i] eq "--printf"
Truth table50%2/4
A or B or C
A= $a[$i] eq "-c"B= $a[$i] eq "--format"C= $a[$i] eq "--printf"
ABCresult
1XX1
01X1
0011
0000
4651 0 ▶ if ( $a[$i] =~ /\A--(?:format|printf)=(.*)\z/s ) { $fmt = $1; splice @a, $i, 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($a[$i] =~ /\A--(?:format|printf)=(.*)\z/s) 0 1 1
4652 }
4653 21 ▶ if ( defined $fmt ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fmt) 20 1 21
4654 20 my @out;
4655 20 for my $p ( grep { !/\A-/ } @a ) {
4656 20 my $e = _file_entry( $dev, $p );
4657 20 ▶ my $d = !$e && _is_dir( $dev, $p ) ? ( ( $dev->{dirs} || {} )->{$p} || {} ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
!$e && _is_dir($dev, $p) ? : 8 12 20
Condition85%6/7
not $e and _is_dir($dev, $p)
!ll&&!rl&&r
1208
($$dev{"dirs"} || {})->{$p} or {}
l!l
53
$$dev{'dirs'} || {}
l!l
53
MC/DC50%1/2
not $e and _is_dir($dev, $p)
not $e _is_dir($dev, $p)
MC/DC100%1/1
($$dev{"dirs"} || {})->{$p} or {}
$$dev{'dirs'}
Truth table66%2/3
not(A) and B
A= not $eB= _is_dir($dev, $p)
ABresult
0X0
100
111
Truth table100%2/2
A
A= $$dev{'dirs'}
Aresult
11
00
4658 20 ▶ return ( "stat: cannot statx '$p': No such file or directory", 0 ) unless $e || $d;
Branch: 1 branch
BranchTrueFalseTotal
unless $e or $d 0 20 20
Condition66%2/3
$e or $d
l!l&&r!l&&!r
1280
MC/DC0%0/2
$e or $d
$e $d
Truth table66%2/3
A or B
A= $eB= $d
ABresult
1X1
011
000
4659 20 ▶ my $m = $e ? _mode_of($e) : oct( $d->{mode} // '0755' );
Branch: 1 branch
BranchTrueFalseTotal
$e ? : 12 8 20
Condition100%2/2
$$d{"mode"} // "0755"
l!l
53
MC/DC100%1/1
$$d{"mode"} // "0755"
$$d{"mode"}
Truth table100%2/2
A
A= $$d{"mode"}
Aresult
11
00
4660 20 ▶ my $x = $e // $d;
Condition66%2/3
$e // $d
l!l&&r!l&&!r
1280
MC/DC0%0/2
$e // $d
$e $d
Truth table66%2/3
A // B
A= $eB= $d
ABresult
1X1
011
000
4661 my %v = ( a => sprintf( '%o', $m ), A => _mode_text( $m, !$e ), U => $x->{owner} // 'root', G => $x->{group} // 'root',
4662 20 ▶ n => $p, s => $e ? _file_size($e) : 4096, u => _uid( $dev, $x->{owner} ), g => _gid( $dev, $x->{group} ),
Branch: 2 branches
BranchTrueFalseTotal
$e ? : 12 8 20
$e ? : 12 8 20
Condition100%4/4
$$x{"owner"} // "root"
l!l
128
$$x{"group"} // "root"
l!l
128
MC/DC100%1/1
$$x{"owner"} // "root"
$$x{"owner"}
MC/DC100%1/1
$$x{"group"} // "root"
$$x{"group"}
Truth table100%2/2
A
A= $$x{"owner"}
Aresult
11
00
Truth table100%2/2
A
A= $$x{"group"}
Aresult
11
00
4663 F => $e ? 'regular file' : 'directory', '%' => '%' );
4664 20 my ( $iso, $ep ) = _mtime_iso( $x );
4665 20 $v{$_} = $iso for qw( y x z );
4666 20 $v{$_} = $ep for qw( Y X Z );
4667 20 ▶ ( my $line = $fmt ) =~ s/%(.)/$v{$1} \/\/ "%$1"/ge;
Condition50%1/2
$v{$1} // "%$1"
l!l
370
MC/DC0%0/1
$v{$1} // "%$1"
$v{$1}
Truth table50%1/2
A
A= $v{$1}
Aresult
11
00
4668 20 $line =~ s/\\n/\n/g;
4669 20 push @out, $line;
4670 }
4671 20 return ( join( "\n", @out ), 1 );
4672 }
4673 1 my @out;
4674 1 for my $p ( grep { !/\A-/ } @a ) {
4675 1 ▶ if ( !_file_entry( $dev, $p ) && _is_dir( $dev, $p ) ) { # Verzeichnis
Branch: 1 branch
BranchTrueFalseTotal
if (not _file_entry($dev, $p) and _is_dir($dev, $p)) 1 0 1
Condition33%1/3
not _file_entry($dev, $p) and _is_dir($dev, $p)
!ll&&!rl&&r
001
MC/DC0%0/2
not _file_entry($dev, $p) and _is_dir($dev, $p)
not _file_entry($dev, $p) _is_dir($dev, $p)
Truth table33%1/3
not(A) and B
A= not _file_entry($dev, $p)B= _is_dir($dev, $p)
ABresult
0X0
100
111
4676 1 ▶ my $d = ( $dev->{dirs} || {} )->{ $p =~ s{(?<=.)/+\z}{}r } || {};
Condition50%2/4
($$dev{'dirs'} || {})->{$p =~ s[(?<=.)/+\z][]r} || {}
l!l
10
$$dev{'dirs'} || {}
l!l
10
MC/DC0%0/1
($$dev{'dirs'} || {})->{$p =~ s[(?<=.)/+\z][]r} || {}
$$dev{'dirs'}
Truth table50%1/2
A
A= $$dev{'dirs'}
Aresult
11
00
4677 1 ▶ my $m = oct( $d->{mode} // '0755' );
Condition50%1/2
$$d{"mode"} // "0755"
l!l
10
MC/DC0%0/1
$$d{"mode"} // "0755"
$$d{"mode"}
Truth table50%1/2
A
A= $$d{"mode"}
Aresult
11
00
4678 push @out, " File: $p", " Size: 4096\tBlocks: 8\tIO Block: 4096 directory",
4679 sprintf( 'Access: (%04o/%s) Uid: (%5d/%8s) Gid: (%5d/%8s)', $m, _mode_text( $m, 1 ), _uid( $dev, $d->{owner} ), $d->{owner} // 'root',
4680 1 ▶ _gid( $dev, $d->{group} ), $d->{group} // 'root' );
Condition50%2/4
$$d{"owner"} // "root"
l!l
10
$$d{"group"} // "root"
l!l
10
MC/DC0%0/1
$$d{"owner"} // "root"
$$d{"owner"}
MC/DC0%0/1
$$d{"group"} // "root"
$$d{"group"}
Truth table50%1/2
A
A= $$d{"owner"}
Aresult
11
00
Truth table50%1/2
A
A= $$d{"group"}
Aresult
11
00
4681 1 next;
4682 }
4683 0 ▶ my $e = _file_entry( $dev, $p ) or return ( "stat: cannot statx '$p': No such file or directory", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $e = _file_entry($dev, $p) or return "stat: cannot statx '${p}': No such file or directory", 0 0 0 0
4684 0 my $m = _mode_of($e);
4685 push @out, " File: $p", " Size: " . _file_size($e) . "\tBlocks: 8\tIO Block: 4096 regular file",
4686 sprintf( 'Access: (%04o/%s) Uid: (%5d/%8s) Gid: (%5d/%8s)', $m, _mode_text($m), _uid( $dev, $e->{owner} ), $e->{owner} // 'root',
4687 _gid( $dev, $e->{group} ), $e->{group} // 'root' ),
4688 0 ▶ ( map { "$_: " . ( _mtime_iso($e) )[0] } qw( Access Modify Change ) ), ' Birth: -';
Condition0%0/4
$$e{"owner"} // "root"
l!l
00
$$e{"group"} // "root"
l!l
00
MC/DC0%0/1
$$e{"owner"} // "root"
$$e{"owner"}
MC/DC0%0/1
$$e{"group"} // "root"
$$e{"group"}
Truth table0%0/2
A
A= $$e{"owner"}
Aresult
11
00
Truth table0%0/2
A
A= $$e{"group"}
Aresult
11
00
4689 }
4690 1 return ( join( "\n", @out ), 1 );
4691 }
4692  
4693 # Prozesse: je laufender Dienst einer (exec), PID fest nach Namen sortiert
4694 # Prozesse der laufenden Dienste: Befehlszeile aus der Fassung, mit der sie laufen (_started,
4695 # ExecStart), sonst exec; gunicorn mit seinen Workern (--workers/-w, sonst workers = in der
4696 # --config-Datei, sonst 1) als Kinder des Masters
4697 96 ▶sub _procs {
Subroutine _procs: called CC=16 SCAR=28.1
4698 96 my ($dev) = @_;
4699 96 ▶ my $s = $dev->{services} || {};
Condition50%1/2
$$dev{'services'} || {}
l!l
960
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
4700 96 my $pid = 400;
4701 96 my @p;
4702 96 for my $n ( grep { $s->{$_}{active} } sort keys %$s ) {
4703 234 $pid += 37;
4704 234 my $svc = $s->{$n};
4705 234 ▶ my $pid = $svc->{_pid} // $pid; # im Simulator (neu) gestartet: eigene PID
Condition66%2/3
$$svc{"_pid"} // $pid
l!l&&r!l&&!r
302040
MC/DC0%0/2
$$svc{"_pid"} // $pid
$$svc{"_pid"} $pid
Truth table66%2/3
A // B
A= $$svc{"_pid"}B= $pid
ABresult
1X1
011
000
4706 234 ▶ my $line = ( ( $svc->{_started} || {} )->{ExecStart} || [] )->[0];
Condition100%4/4
($$svc{'_started'} || {})->{'ExecStart'} || []
l!l
34200
$$svc{'_started'} || {}
l!l
37197
MC/DC100%1/1
($$svc{'_started'} || {})->{'ExecStart'} || []
$$svc{'_started'}
Truth table100%2/2
A
A= $$svc{'_started'}
Aresult
11
00
4707 234 ▶ my $cmd = defined $line ? ( $line =~ s/\A[-@+!:]+//r ) : $svc->{exec} // $n;
Branch: 1 branch
BranchTrueFalseTotal
defined $line ? : 34 200 234
Condition66%2/3
$$svc{"exec"} // $n
l!l&&r!l&&!r
157430
MC/DC0%0/2
$$svc{"exec"} // $n
$$svc{"exec"} $n
Truth table66%2/3
A // B
A= $$svc{"exec"}B= $n
ABresult
1X1
011
000
4708 234 $cmd =~ s/\$\{?MAINPID\}?/$pid/g;
4709 234 ▶ my $user = $svc->{user} // ( $svc->{_started} || {} )->{User} // 'root';
Condition85%6/7
($$svc{"user"} // ($$svc{"_started"} || {})->{"User"}) // "root"
l!l
48186
$$svc{"user"} // ($$svc{"_started"} || {})->{"User"}
l!l&&r!l&&!r
480186
$$svc{'_started'} || {}
l!l
5181
MC/DC100%2/2
($$svc{"user"} // ($$svc{"_started"} || {})->{"User"}) // "root"
$$svc{"user"} $$svc{'_started'}
Truth table100%3/3
A // B
A= $$svc{"user"}B= $$svc{'_started'}
ABresult
1X1
011
000
4710 234 push @p, { pid => $pid, ppid => 1, user => $user, cmd => $cmd, unit => $n };
4711 234 ▶ if ( $cmd =~ /\bgunicorn\b/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /\bgunicorn\b/) 16 218 234
4712 16 my ($w) = $cmd =~ /(?:--workers[ =]|-w\s*)(\d+)/;
4713 16 ▶ if ( !defined $w && $cmd =~ /(?:--config[ =]|-c\s+)(\S+)/ ) { ($w) = ( _file_text( $dev, $1 ) // '' ) =~ /^\s*workers\s*=\s*(\d+)/m }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $w and $cmd =~ /(?:--config[ =]|-c\s+)(\S+)/) 8 8 16
Condition60%3/5
not defined $w and $cmd =~ /(?:--config[ =]|-c\s+)(\S+)/
!ll&&!rl&&r
808
_file_text($dev, $1) // ""
l!l
80
MC/DC50%1/2
not defined $w and $cmd =~ /(?:--config[ =]|-c\s+)(\S+)/
not defined $w $cmd =~ /(?:--config[ =]|-c\s+)(\S+)/
MC/DC0%0/1
_file_text($dev, $1) // ""
_file_text($dev, $1)
Truth table66%2/3
not(A) and B
A= not defined $wB= $cmd =~ /(?:--config[ =]|-c\s+)(\S+)/
ABresult
0X0
100
111
Truth table50%1/2
A
A= _file_text($dev, $1)
Aresult
11
00
4714 16 ▶ push @p, map { { pid => $pid + $_, ppid => $pid, user => $user, cmd => $cmd, unit => $n } } 1 .. ( $w // 1 );
Condition50%1/2
$w // 1
l!l
160
MC/DC0%0/1
$w // 1
$w
Truth table50%1/2
A
A= $w
Aresult
11
00
4715 }
4716 }
4717 96 return @p;
4718 }
4719  
4720 51 ▶sub _main_pid {
Subroutine _main_pid: called CC=2 SCAR=6.9
4721 51 my ( $dev, $n ) = @_;
4722 51 my ($p) = grep { $_->{unit} eq $n } _procs($dev);
4723 51 ▶ return $p ? $p->{pid} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 47 4 51
4724 }
4725  
4726 # Startzeit eines Dienstes (Epoche): der letzte Start im Simulator (_since, Zeit der
4727 # Journalzeile "Started"), sonst since im Zustand ("Thu 2026-10-29 06:10:12 CET"), sonst undef
4728 82 our $BOOT_STAMP = 'Tue 2026-10-20 09:00:00 CEST'; # Vorgabe fuer laufende Dienste ohne Angabe
4729 73 ▶sub _svc_since {
Subroutine _svc_since: called CC=2 SCAR=6.9
4730 73 my ($svc) = @_;
4731 73 ▶ return $svc->{_since} if defined $svc->{_since};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$svc{"_since"} 20 53 73
4732 53 return _parse_stamp( $svc->{since} );
4733 }
4734  
4735 # Jetzt auf dem Geraet (Epoche): seine Uhr (clock), sonst die der Simulation
4736 113 ▶sub _dev_now {
Subroutine _dev_now: called CC=2 SCAR=6.9
4737 113 my ($dev) = @_;
4738 113 ▶ return _sim_now() unless defined $dev->{clock};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$dev{"clock"} 101 12 113
4739 12 _part('Monitoring');
4740 12 return Langertha::Holmgang::Sim::Linux::Monitoring::now_epoch($dev);
4741 }
4742  
4743 # "5h ago" wie systemd; ein Start in derselben Minute wie die Uhr ist "1s ago"
4744 9 ▶sub _ago {
Subroutine _ago: called CC=2 SCAR=6.9
4745 9 my ( $dev, $t ) = @_;
4746 9 my $s = _dev_now($dev) - $t;
4747 9 ▶ return Langertha::Holmgang::Sim::Linux::Calendar::left( $s > 0 ? $s : 1 ) . ' ago';
Branch: 1 branch
BranchTrueFalseTotal
$s > 0 ? : 8 1 9
4748 }
4749  
4750 # Startzeit eines Prozesses fuer ps: die seines Dienstes oder undef (Vorgabe von ps)
4751 36 ▶sub _proc_since {
Subroutine _proc_since: called CC=4 SCAR=13.9
4752 36 my ( $dev, $p ) = @_;
4753 36 ▶ my $svc = defined $p->{unit} ? ( $dev->{services} || {} )->{ $p->{unit} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $$p{'unit'} ? : 32 4 36
Condition50%1/2
$$dev{'services'} || {}
l!l
320
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
4754 36 ▶ return $svc ? _svc_since($svc) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$svc ? : 32 4 36
4755 }
4756  
4757 # Zeilen, die ein laufender Dienst in seine Logdatei geschrieben hat (app_log), als
4758 # Laufzeitspur _append: { pfad => { base => inhalt beim Schreiben, lines => [ … ] } } —
4759 # sie gelten nur, solange die Datei den Inhalt von damals hat (sonst neu geschrieben)
4760 1626 ▶sub _with_append {
Subroutine _with_append: called CC=7 SCAR=20.0
4761 1626 my ( $dev, $path, $t ) = @_;
4762 1626 ▶ return $t unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 1626 1626
4763 1626 ▶ my $a = ( $dev->{_append} || {} )->{$path} or return $t;
Branch: 1 branch
BranchTrueFalseTotal
my $a = ($$dev{"_append"} || {})->{$path} or return $t 13 1613 1626
Condition100%2/2
$$dev{'_append'} || {}
l!l
191607
MC/DC100%1/1
$$dev{'_append'} || {}
$$dev{'_append'}
Truth table100%2/2
A
A= $$dev{'_append'}
Aresult
11
00
4764 13 ▶ return $t unless $a->{base} eq $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $$a{"base"} eq $t 1 12 13
4765 12 ▶ return $t . ( length $t && $t !~ /\n\z/ ? "\n" : '' ) . join( '', map {"$_\n"} @{ $a->{lines} } );
Branch: 1 branch
BranchTrueFalseTotal
length $t && !($t =~ /\n\z/) ? : 0 12 12
Condition33%1/3
length $t and not $t =~ /\n\z/
!ll&&!rl&&r
0120
MC/DC0%0/2
length $t and not $t =~ /\n\z/
length $t not $t =~ /\n\z/
Truth table33%1/3
A and not(B)
A= length $tB= not $t =~ /\n\z/
ABresult
0X0
100
111
4766 }
4767  
4768 # app_log eines Dienstes: { file, start: [ zeilen ], fail: [ zeilen ] } — bei Start bzw.
4769 # Fehlstart angehaengt; {ts} (JJJJ-MM-TT HH:MM:SS, Uhr des Geraets), {listen}, {pid}
4770 66 ▶sub _app_log {
Subroutine _app_log: called CC=18 SCAR=30.5
4771 66 my ( $dev, $n, $svc, $kind, $t ) = @_;
4772 66 my $al = $svc->{app_log};
4773 66 ▶ return unless ref $al eq 'HASH' && defined $al->{file};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $al eq "HASH" and defined $$al{"file"} 64 2 66
Condition66%2/3
ref $al eq "HASH" and defined $$al{"file"}
!ll&&!rl&&r
6402
MC/DC50%1/2
ref $al eq "HASH" and defined $$al{"file"}
ref $al eq "HASH" defined $$al{"file"}
Truth table66%2/3
A and B
A= ref $al eq "HASH"B= defined $$al{"file"}
ABresult
0X0
100
111
4774 2 ▶ my @lines = @{ $al->{$kind} || [] } or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@lines) = @{$$al{$kind} or [];} or return 2 0 2
Condition50%1/2
$$al{$kind} || []
l!l
20
MC/DC0%0/1
$$al{$kind} || []
$$al{$kind}
Truth table50%1/2
A
A= $$al{$kind}
Aresult
11
00
4775 2 require POSIX;
4776 2 ▶ $t //= _jtime( sprintf '%s:%02d x', _clock($dev), 3 + ( ( $dev->{_tick} // 0 ) + 1 ) % 57 );
Condition60%3/5
$t //= _jtime(sprintf("%s:%02d x", _clock($dev), 3 + (($$dev{"_tick"} // 0) + 1) % 57))
l!l&&r!l&&!r
110
$$dev{"_tick"} // 0
l!l
01
MC/DC0%0/2
$t //= _jtime(sprintf("%s:%02d x", _clock($dev), 3 + (($$dev{"_tick"} // 0) + 1) % 57))
$t _jtime(sprintf("%s:%02d x", _clock($dev), 3 + (($$dev{"_tick"} // 0) + 1) % 57))
MC/DC0%0/1
$$dev{"_tick"} // 0
$$dev{"_tick"}
Truth table66%2/3
A //= B
A= $tB= _jtime(sprintf("%s:%02d x", _clock($dev), 3 + (($$dev{"_tick"} // 0) + 1) % 57))
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$dev{"_tick"}
Aresult
11
00
4777 my %v = ( ts => POSIX::strftime( '%Y-%m-%d %H:%M:%S', _local_tm($t) ), pid => _main_pid( $dev, $n ) || 3120,
4778 2 ▶ listen => ( $kind eq 'start' && $svc->{_listen} ? $svc->{_listen} : [ _svc_listen( $dev, $n, $svc ) ] )->[0] // '' );
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'start' && $$svc{'_listen'} ? : 1 1 2
Condition71%5/7
_main_pid($dev, $n) || 3120
l!l
11
($kind eq "start" && $$svc{"_listen"} ? $$svc{"_listen"} : [_svc_listen($dev, $n, $svc)])->[0] // ""
l!l
20
$kind eq "start" and $$svc{"_listen"}
!ll&&!rl&&r
101
MC/DC100%1/1
_main_pid($dev, $n) || 3120
_main_pid($dev, $n)
MC/DC50%1/2
($kind eq "start" && $$svc{"_listen"} ? $$svc{"_listen"} : [_svc_listen($dev, $n, $svc)])->[0] // ""
$kind eq "start" $$svc{"_listen"}
Truth table100%2/2
A
A= _main_pid($dev, $n)
Aresult
11
00
Truth table66%2/3
A and B
A= $kind eq "start"B= $$svc{"_listen"}
ABresult
111
0X0
100
4779 2 my $p = $al->{file};
4780 2 ▶ my $e = ( $dev->{files} || {} )->{$p};
Condition50%1/2
$$dev{'files'} || {}
l!l
20
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
4781 2 ▶ my $raw = ref $e eq 'HASH' ? $e->{content} // '' : $e;
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' ? : 2 0 2
Condition50%1/2
$$e{"content"} // ""
l!l
20
MC/DC0%0/1
$$e{"content"} // ""
$$e{"content"}
Truth table50%1/2
A
A= $$e{"content"}
Aresult
11
00
4782 2 ▶ return unless defined $raw; # keine Datei (z. B. geloescht): der Dienst legt sie hier nicht an
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw 0 2 2
4783 2 ▶ my $old = ( $dev->{_append} || {} )->{$p};
Condition100%2/2
$$dev{'_append'} || {}
l!l
11
MC/DC100%1/1
$$dev{'_append'} || {}
$$dev{'_append'}
Truth table100%2/2
A
A= $$dev{'_append'}
Aresult
11
00
4784 2 ▶ my @keep = $old && $old->{base} eq $raw ? @{ $old->{lines} } : ();
Branch: 1 branch
BranchTrueFalseTotal
$old && $$old{'base'} eq $raw ? : 1 1 2
Condition66%2/3
$old and $$old{"base"} eq $raw
!ll&&!rl&&r
101
MC/DC50%1/2
$old and $$old{"base"} eq $raw
$old $$old{"base"} eq $raw
Truth table66%2/3
A and B
A= $oldB= $$old{"base"} eq $raw
ABresult
0X0
100
111
4785 2 $dev->{_append}{$p} = { base => $raw, lines => [ @keep, map { s/\{(ts|listen|pid)\}/$v{$1}/gr } @lines ] };
4786 2 return;
4787 }
4788  
4789 # Lauscher eines Dienstes ( "adresse:port", … ): listen am Dienst (Liste, oder { file, regex }
4790 # — die Fangruppen aus der Datei, wie der Dienst sie gelesen hat), sonst fuer nginx die
4791 # listen-Zeilen seiner Konfiguration (nginx.conf, conf.d/*.conf, sites-enabled/*)
4792 18 ▶sub _svc_listen {
Subroutine _svc_listen: called CC=15 SCAR=28.6
4793 18 my ( $dev, $n, $svc ) = @_;
4794 18 my $l = $svc->{listen};
4795 18 ▶ my $run = ref $svc->{running} eq 'HASH' ? $svc->{running} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'running'} eq 'HASH' ? : 0 18 18
4796 22 ▶ my $norm = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
4797 22 my ($a) = @_;
4798 22 $a =~ s/\Alocalhost:/127.0.0.1:/;
4799 22 ▶ $a =~ s/\A(?:\*|0\.0\.0\.0)?:?(?=\d+\z)/0.0.0.0:/ unless $a =~ /\A[\d.]+:\d+\z|\A\[/;
Branch: 1 branch
BranchTrueFalseTotal
unless $a =~ /\A[\d.]+:\d+\z|\A\[/ 12 10 22
4800 22 ▶ return $a =~ /\A(?:[\d.]+|\[[0-9a-f:]*\]):\d+\z/i ? $a : ();
Branch: 1 branch
BranchTrueFalseTotal
$a =~ /\A(?:[\d.]+|\[[0-9a-f:]*\]):\d+\z/i ? : 22 0 22
4801 18 };
4802 18 ▶ return map { $norm->($_) } @$l if ref $l eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $l eq "ARRAY" 4 14 18
4803 14 ▶ if ( ref $l eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $l eq "HASH") 2 12 14
4804 2 ▶ my $t = $run->{ $l->{file} } // _file_text( $dev, $l->{file} ) // '';
Condition40%2/5
($$run{$$l{"file"}} // _file_text($dev, $$l{"file"})) // ""
l!l
20
$$run{$$l{"file"}} // _file_text($dev, $$l{"file"})
l!l&&r!l&&!r
020
MC/DC0%0/2
($$run{$$l{"file"}} // _file_text($dev, $$l{"file"})) // ""
$$run{$$l{"file"}} _file_text($dev, $$l{"file"})
Truth table33%1/3
A // B
A= $$run{$$l{"file"}}B= _file_text($dev, $$l{"file"})
ABresult
1X1
011
000
4805 2 ▶ my $re = eval { qr/$l->{regex}/ } or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $re = eval { do { qr/$$l{"regex"}/ } } or return () 2 0 2
4806 2 my @a;
4807 2 ▶ while ( $t =~ /$re/g ) { push @a, $1 if defined $1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($t =~ /$re/g) 2 2 4
if defined $1 2 0 2
4808 2 return map { $norm->($_) } @a;
4809 }
4810 12 ▶ return () unless ( $svc->{exec} // $n ) eq 'nginx';
Branch: 1 branch
BranchTrueFalseTotal
unless ($$svc{"exec"} // $n) eq "nginx" 0 12 12
Condition33%1/3
$$svc{"exec"} // $n
l!l&&r!l&&!r
1200
MC/DC0%0/2
$$svc{"exec"} // $n
$$svc{"exec"} $n
Truth table33%1/3
A // B
A= $$svc{"exec"}B= $n
ABresult
1X1
011
000
4811 12 my %seen;
4812 my @a;
4813 12 ▶ for my $p ( sort grep { m{\A/etc/nginx/(?:nginx\.conf|conf\.d/[^/]+\.conf|sites-enabled/[^/]+)\z} } keys %{ $dev->{files} || {} } ) {
Condition50%1/2
$$dev{'files'} || {}
l!l
120
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
4814 12 ▶ my $t = $run->{$p} // _file_text( $dev, $p ) // '';
Condition40%2/5
($$run{$p} // _file_text($dev, $p)) // ""
l!l
120
$$run{$p} // _file_text($dev, $p)
l!l&&r!l&&!r
0120
MC/DC0%0/2
($$run{$p} // _file_text($dev, $p)) // ""
$$run{$p} _file_text($dev, $p)
Truth table33%1/3
A // B
A= $$run{$p}B= _file_text($dev, $p)
ABresult
1X1
011
000
4815 12 $t =~ s/#[^\n]*//g;
4816 12 push @a, grep { !$seen{$_}++ } map { $norm->($_) } $t =~ /^\s*listen\s+([^;\s]+)[^;]*;/mg;
4817 }
4818 12 return @a;
4819 }
4820  
4821 # Jetzt als Ortszeit-Sekunden (wie _mtime sie liefert: timegm der Ortszeit)
4822 28 ▶sub _local_now { my ($dev) = @_; my $t = _dev_now($dev); return $t + Langertha::Holmgang::Sim::Linux::Calendar::offset($t) }
Subroutine _local_now: called CC=1 SCAR=0.0
4823  
4824 # mtime eines Eintrags wie stat %y ("2026-09-30 01:30:00.000000000 +0200") und als Epoche (%Y)
4825 23 ▶sub _mtime_iso {
Subroutine _mtime_iso: called CC=1 SCAR=0.0
4826 23 my ($e) = @_;
4827 23 require POSIX;
4828 23 my $lt = _mtime($e);
4829 23 my $off = Langertha::Holmgang::Sim::Linux::Calendar::offset( $lt - 3600 );
4830 23 return ( POSIX::strftime( '%Y-%m-%d %H:%M:%S', gmtime $lt ) . sprintf( '.000000000 %+03d%02d', $off / 3600, abs( $off % 3600 ) / 60 ), $lt - $off );
4831 }
4832  
4833 # Epoche -> mtime im Zustand ("Sep 30 01:30", in einem anderen Jahr "Sep 30 2025")
4834 16 ▶sub _mtime_str {
Subroutine _mtime_str: called CC=2 SCAR=7.0
4835 16 my ($t) = @_;
4836 16 my @g = _local_tm($t);
4837 16 my $mon = (qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ))[ $g[4] ];
4838 16 ▶ return $g[5] + 1900 == 2026 ? sprintf( '%s %2d %02d:%02d', $mon, $g[3], $g[2], $g[1] ) : sprintf( '%s %2d %04d', $mon, $g[3], $g[5] + 1900 );
Branch: 1 branch
BranchTrueFalseTotal
$g[5] + 1900 == 2026 ? : 16 0 16
4839 }
4840  
4841 # Zeitspalte von ls -l nach --time-style (full-iso, long-iso, iso; sonst wie im Zustand)
4842 87 ▶sub _ls_time {
Subroutine _ls_time: called CC=8 SCAR=22.3
4843 87 my ($e) = @_;
4844 87 ▶ my $m = ref $e eq 'HASH' ? $e->{mtime} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' ? : 87 0 87
4845 87 ▶ return $m // 'Oct 20 09:00' unless $LS_TIME;
Branch: 1 branch
BranchTrueFalseTotal
unless $Langertha::Holmgang::Sim::Linux::LS_TIME 84 3 87
Condition100%2/2
$m // "Oct 20 09:00"
l!l
1470
MC/DC100%1/1
$m // "Oct 20 09:00"
$m
Truth table100%2/2
A
A= $m
Aresult
11
00
4846 3 ▶ my ($iso) = _mtime_iso( ref $e eq 'HASH' && defined $m ? $e : { mtime => 'Oct 20 09:00' } );
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' && defined $m ? : 3 0 3
Condition33%1/3
ref $e eq "HASH" and defined $m
!ll&&!rl&&r
003
MC/DC0%0/2
ref $e eq "HASH" and defined $m
ref $e eq "HASH" defined $m
Truth table33%1/3
A and B
A= ref $e eq "HASH"B= defined $m
ABresult
0X0
100
111
4847 3 ▶ return $iso if $LS_TIME eq 'full-iso';
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::LS_TIME eq "full-iso" 2 1 3
4848 1 ▶ return substr( $iso, 0, 16 ) if $LS_TIME eq 'long-iso';
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::LS_TIME eq "long-iso" 1 0 1
4849 0 return substr( $iso, 5, 11 ); # iso
4850 }
4851  
4852 # Epoche -> Ortszeit als gmtime-Liste (wie localtime in Europe/Berlin)
4853 80 ▶sub _local_tm { my ($t) = @_; return gmtime( $t + Langertha::Holmgang::Sim::Linux::Calendar::offset($t) ) }
Subroutine _local_tm: called CC=1 SCAR=0.0
4854  
4855 # /proc/<pid>/limits eines Dienstes: offene Dateien aus der Fassung, mit der er laeuft
4856 1 ▶sub _proc_limits {
Subroutine _proc_limits: called CC=8 SCAR=22.3
4857 1 my ( $dev, $pid ) = @_;
4858 1 ▶ my ($p) = grep { $_->{pid} == $pid } _procs($dev) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my($p) = grep({$$_{"pid"} == $pid;} _procs($dev)) or return undef 1 0 1
4859 1 ▶ my $st = ( $dev->{services}{ $p->{unit} } || {} )->{_started} || {};
Condition50%2/4
($$dev{'services'}{$$p{'unit'}} || {})->{'_started'} || {}
l!l
10
$$dev{'services'}{$$p{'unit'}} || {}
l!l
10
MC/DC0%0/1
($$dev{'services'}{$$p{'unit'}} || {})->{'_started'} || {}
$$dev{'services'}{$$p{'unit'}}
Truth table50%1/2
A
A= $$dev{'services'}{$$p{'unit'}}
Aresult
11
00
4860 1 my ( $soft, $hard ) = ( 1024, 524288 );
4861 1 ▶ if ( defined( my $l = $st->{LimitNOFILE} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = $$st{"LimitNOFILE"})) 1 0 1
4862 1 ▶ ( $soft, $hard ) = $l =~ /\A(\w+):(\w+)\z/ ? ( $1, $2 ) : ( $l, $l );
Branch: 1 branch
BranchTrueFalseTotal
$l =~ /\A(\w+):(\w+)\z/ ? : 0 1 1
4863 1 ▶ $_ = $_ eq 'infinity' ? 'unlimited' : $_ for $soft, $hard;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'infinity' ? : 0 2 2
4864 }
4865 1 my $f = '%-26s%-21s%-21s%-10s';
4866 1 return join "\n", sprintf( $f, 'Limit', 'Soft Limit', 'Hard Limit', 'Units' ),
4867 sprintf( $f, 'Max cpu time', 'unlimited', 'unlimited', 'seconds' ),
4868 sprintf( $f, 'Max file size', 'unlimited', 'unlimited', 'bytes' ),
4869 sprintf( $f, 'Max core file size', 0, 'unlimited', 'bytes' ),
4870 sprintf( $f, 'Max processes', 63238, 63238, 'processes' ),
4871 sprintf( $f, 'Max open files', $soft, $hard, 'files' ),
4872 sprintf( $f, 'Max locked memory', 8388608, 8388608, 'bytes' );
4873 }
4874  
4875 12 ▶sub _base64 {
Subroutine _base64: called CC=10 SCAR=24.2
4876 12 my ( $dev, $av, $ctx, $stdin ) = @_;
4877 12 require MIME::Base64;
4878 12 my ($decode) = grep { /\A(?:-d|--decode)\z/ } @$av;
4879 12 my @files = grep { !/\A-/ } @$av;
4880 12 my $in;
4881 12 ▶ if (@files) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) { } 0 12 12
4882 0 $in = _file_text( $dev, $files[0] );
4883 0 ▶ return ( "base64: $files[0]: No such file or directory", 0 ) unless defined $in;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in 0 0 0
4884 }
4885 12 ▶ else { $in = ( $stdin // '' ) . ( defined $stdin && length $stdin && $STDIN_NL ? "\n" : '' ) }
Branch: 1 branch
BranchTrueFalseTotal
defined $stdin && length $stdin && $Langertha::Holmgang::Sim::Linux::STDIN_NL ? : 10 2 12
Condition50%4/8
$stdin // ""
l!l
120
defined $stdin and length $stdin and $Langertha::Holmgang::Sim::Linux::STDIN_NL
!ll&&!rl&&r
0210
defined $stdin and length $stdin
!ll&&!rl&&r
0012
MC/DC0%0/1
$stdin // ""
$stdin
MC/DC33%1/3
defined $stdin and length $stdin and $Langertha::Holmgang::Sim::Linux::STDIN_NL
defined $stdin length $stdin $Langertha::Holmgang::Sim::Linux::STDIN_NL
Truth table50%1/2
A
A= $stdin
Aresult
11
00
Truth table50%2/4
A and B and C
A= defined $stdinB= length $stdinC= $Langertha::Holmgang::Sim::Linux::STDIN_NL
ABCresult
0XX0
10X0
1100
1111
4886 12 ▶ if ($decode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decode) 9 3 12
4887 9 ( my $b = $in ) =~ s/\s+//g;
4888 9 ▶ return ( 'base64: invalid input', 0 ) if $b =~ m{[^A-Za-z0-9+/=]};
Branch: 1 branch
BranchTrueFalseTotal
if $b =~ m[[^A-Za-z0-9+/=]] 0 9 9
4889 9 my $d = MIME::Base64::decode_base64($b);
4890 9 utf8::decode($d); # Text der Simulation sind Zeichen; gueltiges UTF-8 als Zeichen zurueck
4891 9 return ( $d =~ s/\n\z//r, 1 );
4892 }
4893 3 my $wrap = !grep { /\A(?:-w0|--wrap=0)\z/ } @$av;
4894 3 utf8::encode( my $bytes = $in ); # kodiert werden die Bytes (UTF-8), wie GNU base64
4895 3 my $e = MIME::Base64::encode_base64( $bytes, '' );
4896 3 ▶ $e =~ s/(.{76})(?=.)/$1\n/g if $wrap;
Branch: 1 branch
BranchTrueFalseTotal
if $wrap 2 1 3
4897 3 return ( $e, 1 );
4898 }
4899  
4900 # ps [aux] | -ef | -eo spalten | --ppid N | -p N | -C name
4901 17 ▶sub _ps {
Subroutine _ps: called CC=48 SCAR=46.9
4902 17 my ( $dev, $av ) = @_;
4903 17 require POSIX;
4904 17 my @all = ( { pid => 1, ppid => 0, user => 'root', cmd => '/sbin/init' }, _procs($dev) );
4905 @all = map { # nginx: Master und Worker wie echt
4906 17 ( split ' ', $_->{cmd} )[0] =~ m{(?:\A|/)nginx\z}
4907 ? ( { %$_, cmd => 'nginx: master process /usr/sbin/nginx -g daemon on; master_process on;' },
4908 101 ▶ { %$_, ppid => $_->{pid}, pid => $_->{pid} + 1, user => 'www-data', cmd => 'nginx: worker process' } )
Branch: 1 branch
BranchTrueFalseTotal
(split(' ', $$_{'cmd'}, 0))[0] =~ m[(?:\A|/)nginx\z] ? : 3 98 101
4909 : $_
4910 } @all;
4911 17 my ( $fmt, @filt ) = ('aux');
4912 17 ▶ my @a = @{ $av || [] };
Condition50%1/2
$av || []
l!l
170
MC/DC0%0/1
$av || []
$av
Truth table50%1/2
A
A= $av
Aresult
11
00
4913 17 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 26 17 43
4914 26 my $x = shift @a;
4915 26 ▶ if ( $x =~ /\A-[eA]?f\z|\A-fe\z|\A-ef\z/ ) { $fmt = 'ef' }
Branch: 9 branches
BranchTrueFalseTotal
if ($x =~ /\A-[eA]?f\z|\A-fe\z|\A-ef\z/) { } 2 24 26
elsif ($x =~ /\A-e?o\z/ or $x eq '-eo' or $x eq '--format') { } 10 14 24
elsif ($x =~ /\A-e?o(\S+)\z/) { } 0 14 14
elsif ($x eq '--ppid') { } 2 12 14
elsif ($x eq '-p' or $x eq '--pid') { } 2 10 12
elsif ($x eq '-C') { } 4 6 10
elsif ($x =~ /\A-([fFeAl]+)([pCuU])\z/) { } 1 5 6
elsif ($x eq '-u' or $x eq '-U' or $x eq '--user') { } 1 4 5
elsif ($x =~ /\A(?:aux|-aux|ax|-e|-A|auxf|axu|-ww|ww|--no-headers|h)\z/) { } 4 0 4
4916 10 ▶ elsif ( $x =~ /\A-e?o\z/ || $x eq '-eo' || $x eq '--format' ) { $fmt = 'o:' . ( shift(@a) // '' ) }
Condition62%5/8
$x =~ /\A-e?o\z/ or $x eq "-eo" or $x eq "--format"
l!l&&r!l&&!r
10014
$x =~ /\A-e?o\z/ or $x eq "-eo"
l!l&&r!l&&!r
10014
shift @a // ""
l!l
100
MC/DC33%1/3
$x =~ /\A-e?o\z/ or $x eq "-eo" or $x eq "--format"
$x =~ /\A-e?o\z/ $x eq "-eo" $x eq "--format"
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%2/4
A or B or C
A= $x =~ /\A-e?o\z/B= $x eq "-eo"C= $x eq "--format"
ABCresult
1XX1
01X1
0011
0000
Truth table50%1/2
A
A= shift @a
Aresult
11
00
4917 0 elsif ( $x =~ /\A-e?o(\S+)\z/ ) { $fmt = "o:$1" }
4918 2 ▶ elsif ( $x eq '--ppid' ) { my $v = shift @a // ''; push @filt, sub { grep { $_ == $_[0]{ppid} } split /,/, $v } }
Subroutine __ANON__: called CC=1 SCAR=0.0
Condition50%1/2
shift @a // ""
l!l
20
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
4919 2 ▶ elsif ( $x eq '-p' || $x eq '--pid' ) { my $v = shift @a // ''; push @filt, sub { grep { $_ == $_[0]{pid} } split /,/, $v } }
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition60%3/5
$x eq "-p" or $x eq "--pid"
l!l&&r!l&&!r
2010
shift @a // ""
l!l
20
MC/DC50%1/2
$x eq "-p" or $x eq "--pid"
$x eq "-p" $x eq "--pid"
MC/DC0%0/1
shift @a // ""
shift @a
Truth table66%2/3
A or B
A= $x eq "-p"B= $x eq "--pid"
ABresult
1X1
011
000
Truth table50%1/2
A
A= shift @a
Aresult
11
00
4920 4 ▶ elsif ( $x eq '-C' ) { my $v = shift @a // ''; push @filt, sub { ( ( split ' ', $_[0]{cmd} )[0] =~ s{.*/}{}r ) eq $v } }
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition50%1/2
shift @a // ""
l!l
40
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
4921 elsif ( $x =~ /\A-([fFeAl]+)([pCuU])\z/ ) { # -fp PID, -fu benutzer, …
4922 1 my ( $fl, $o ) = ( $1, $2 );
4923 1 ▶ $fmt = 'ef' if $fl =~ /f/i && $fmt !~ /\Ao:/;
Branch: 1 branch
BranchTrueFalseTotal
if $fl =~ /f/i and not $fmt =~ /\Ao:/ 1 0 1
Condition33%1/3
$fl =~ /f/i and not $fmt =~ /\Ao:/
!ll&&!rl&&r
001
MC/DC0%0/2
$fl =~ /f/i and not $fmt =~ /\Ao:/
$fl =~ /f/i not $fmt =~ /\Ao:/
Truth table33%1/3
A and not(B)
A= $fl =~ /f/iB= not $fmt =~ /\Ao:/
ABresult
0X0
100
111
4924 1 unshift @a, "-$o";
4925 }
4926 ▶ elsif ( $x eq '-u' || $x eq '-U' || $x eq '--user' ) {
Condition66%4/6
$x eq "-u" or $x eq "-U" or $x eq "--user"
l!l&&r!l&&!r
104
$x eq "-u" or $x eq "-U"
l!l&&r!l&&!r
104
MC/DC33%1/3
$x eq "-u" or $x eq "-U" or $x eq "--user"
$x eq "-u" $x eq "-U" $x eq "--user"
Truth table50%2/4
A or B or C
A= $x eq "-u"B= $x eq "-U"C= $x eq "--user"
ABCresult
1XX1
01X1
0011
0000
4927 1 ▶ my $v = shift @a // '';
Condition50%1/2
shift @a // ""
l!l
10
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
4928 1 my %u = map { $_ => 1 } split /,/, $v;
4929 1 ▶ push @filt, sub { $u{ $_[0]{user} } || $u{ _uid( $dev, $_[0]{user} ) } };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$u{$_[0]{"user"}} or $u{_uid($dev, $_[0]{"user"})} 1 2 3
4930 }
4931 4 ▶ elsif ( $x =~ /\A(?:aux|-aux|ax|-e|-A|auxf|axu|-ww|ww|--no-headers|h)\z/ ) { $fmt = 'aux' if $x =~ /u/ && $fmt !~ /\Ao:/ }
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /u/ and not $fmt =~ /\Ao:/ 4 0 4
Condition33%1/3
$x =~ /u/ and not $fmt =~ /\Ao:/
!ll&&!rl&&r
004
MC/DC0%0/2
$x =~ /u/ and not $fmt =~ /\Ao:/
$x =~ /u/ not $fmt =~ /\Ao:/
Truth table33%1/3
A and not(B)
A= $x =~ /u/B= not $fmt =~ /\Ao:/
ABresult
0X0
100
111
4932 0 ▶ else { push @GAPS, join( ' ', 'ps', @{ $av || [] } ); return ( '', 0 ) }
Condition0%0/2
$av || []
l!l
00
MC/DC0%0/1
$av || []
$av
Truth table0%0/2
A
A= $av
Aresult
11
00
4933 }
4934 17 my @p = grep { my $p = $_; !grep { !$_->($p) } @filt } @all;
4935 17 ▶ my $noh = grep { $_ eq '--no-headers' || $_ eq 'h' } @{ $av || [] };
Condition40%2/5
$_ eq '--no-headers' || $_ eq 'h'
l!l&&r!l&&!r
0044
$av || []
l!l
170
MC/DC0%0/2
$_ eq '--no-headers' || $_ eq 'h'
$_ eq '--no-headers' $_ eq 'h'
MC/DC0%0/1
$av || []
$av
Truth table33%1/3
A || B
A= $_ eq '--no-headers'B= $_ eq 'h'
ABresult
1X1
011
000
Truth table50%1/2
A
A= $av
Aresult
11
00
4936 17 my @l;
4937 17 ▶ if ( $fmt eq 'ef' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fmt eq 'ef') { } 3 14 17
elsif ($fmt =~ /\Ao:(.*)\z/) { } 10 4 14
4938 3 ▶ push @l, 'UID PID PPID C STIME TTY TIME CMD' unless $noh;
Branch: 1 branch
BranchTrueFalseTotal
unless $noh 3 0 3
4939 3 push @l, map { sprintf( '%-8s %7d %7d 0 %-5s ? 00:00:12 %s', $_->{user}, $_->{pid}, $_->{ppid}, _ps_start( $dev, $_ ), $_->{cmd} ) } @p;
4940 }
4941 elsif ( $fmt =~ /\Ao:(.*)\z/ ) {
4942 10 my @spec = split /[,\s]+/, $1;
4943 10 my @c = map { lc s/=.*//r } @spec;
4944 10 ▶ $noh = 1 if @spec && !grep { !/=/ } @spec; # pid= : leere Ueberschrift
Branch: 1 branch
BranchTrueFalseTotal
if @spec and not grep({not /=/;} @spec) 3 7 10
Condition66%2/3
@spec and not grep({not /=/;} @spec)
!ll&&!rl&&r
073
MC/DC50%1/2
@spec and not grep({not /=/;} @spec)
@spec not grep({not /=/;} @spec)
Truth table66%2/3
A and not(B)
A= @specB= not grep({not /=/;} @spec)
ABresult
0X0
100
111
4945 10 my %head = ( etimes => 'ELAPSED', comm => 'COMMAND', ucomm => 'COMMAND', args => 'COMMAND', command => 'COMMAND', cmd => 'CMD', '%cpu' => '%CPU', '%mem' => '%MEM' );
4946 10 my %w = ( pid => 7, ppid => 7, etime => 11, etimes => 7, user => 8, uid => 5, comm => 15 );
4947 my %val = (
4948 0 ▶ pid => sub { $_[0]{pid} }, ppid => sub { $_[0]{ppid} }, user => sub { $_[0]{user} }, uid => sub { _uid( $dev, $_[0]{user} ) },
Subroutine __ANON__: called CC=1 SCAR=0.2
Subroutine __ANON__: called CC=1 SCAR=0.2
Subroutine __ANON__: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
4949 0 ▶ comm => sub { ( split ' ', $_[0]{cmd} )[0] =~ s{.*/}{}r }, ucomm => sub { ( split ' ', $_[0]{cmd} )[0] =~ s{.*/}{}r },
Subroutine __ANON__: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=1.2
4950 0 ▶ args => sub { $_[0]{cmd} }, cmd => sub { $_[0]{cmd} }, command => sub { $_[0]{cmd} },
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: not called CC=1 SCAR=0.4
4951 3 ▶ etime => sub {
Subroutine __ANON__: called CC=5 SCAR=28.4
4952 3 my $t = _proc_since( $dev, $_[0] );
4953 3 ▶ return '4-00:12:00' unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 3 0 3
4954 0 my $s = _dev_now($dev) - $t;
4955 0 ▶ $s = 1 if $s < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $s < 1 0 0 0
4956 0 my ( $d, $h, $m ) = ( int( $s / 86400 ), int( $s % 86400 / 3600 ), int( $s % 3600 / 60 ) );
4957 0 ▶ return $d ? sprintf( '%d-%02d:%02d:%02d', $d, $h, $m, $s % 60 ) : $h ? sprintf( '%02d:%02d:%02d', $h, $m, $s % 60 ) : sprintf( '%02d:%02d', $m, $s % 60 );
Branch: 2 branches
BranchTrueFalseTotal
$d ? : 0 0 0
$h ? : 0 0 0
4958 },
4959 0 ▶ etimes => sub { my $t = _proc_since( $dev, $_[0] ); return 346320 unless defined $t; my $s = _dev_now($dev) - $t; $s < 1 ? 1 : $s },
Subroutine __ANON__: called CC=3 SCAR=16.5
Branch: 2 branches
BranchTrueFalseTotal
unless defined $t 3 0 3
$s < 1 ? : 0 0 0
4960 0 ▶ stat => sub { 'Ss' }, '%cpu' => sub { '0.1' }, '%mem' => sub { '0.5' }, rss => sub { 41000 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
4961 2 ▶ lstart => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
4962 2 my $t = _proc_since( $dev, $_[0] );
4963 2 ▶ return defined $t ? POSIX::strftime( '%a %b %e %H:%M:%S %Y', _local_tm($t) ) : 'Tue Oct 20 09:00:00 2026';
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 2 0 2
4964 },
4965 0 ▶ nlwp => sub { 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4966 10 );
4967 0 ▶ for (@c) { if ( !$val{$_} ) { push @GAPS, join( ' ', 'ps', @{ $av || [] } ); return ( '', 0 ) } }
Branch: 1 branch
BranchTrueFalseTotal
unless ($val{$_}) 0 24 24
Condition0%0/2
$av || []
l!l
00
MC/DC0%0/1
$av || []
$av
Truth table0%0/2
A
A= $av
Aresult
11
00
4968 10 ▶ my $f = join ' ', map { $w{$_} ? ( /pid|etime/ ? "%$w{$_}s" : "%-$w{$_}s" ) : '%s' } @c;
Branch: 2 branches
BranchTrueFalseTotal
$w{$_} ? : 19 5 24
/pid|etime/ ? : 13 6 19
4969 10 ▶ push @l, sprintf( $f, map { $head{$_} // uc } @c ) =~ s/\s+\z//r unless $noh;
Branch: 1 branch
BranchTrueFalseTotal
unless $noh 7 3 10
Condition100%2/2
$head{$_} // uc $_
l!l
813
MC/DC100%1/1
$head{$_} // uc $_
$head{$_}
Truth table100%2/2
A
A= $head{$_}
Aresult
11
00
4970 10 for my $p (@p) { push @l, sprintf( $f, map { $val{$_}->($p) } @c ) =~ s/\s+\z//r }
4971 }
4972 else {
4973 4 ▶ push @l, 'USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND' unless $noh;
Branch: 1 branch
BranchTrueFalseTotal
unless $noh 4 0 4
4974 push @l, $_->{pid} == 1 ? 'root 1 0.0 0.1 168000 12000 ? Ss Oct20 0:04 /sbin/init'
4975 4 ▶ : sprintf( '%-8s %7d 0.1 0.5 220000 41000 ? %-4s %-5s 0:12 %s', $_->{user}, $_->{pid}, $_->{ppid} == 1 ? 'Ss' : 'S', _ps_start( $dev, $_ ), $_->{cmd} ) for @p;
Branch: 2 branches
BranchTrueFalseTotal
$$_{'pid'} == 1 ? : 4 10 14
$$_{'ppid'} == 1 ? : 8 2 10
4976 }
4977 17 ▶ return ( join( "\n", @l ), @p ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
@p ? : 17 0 17
4978 }
4979  
4980 # Spalte START/STIME von ps: heute gestartet "09:12", sonst "Oct20"
4981 28 ▶sub _ps_start {
Subroutine _ps_start: called CC=4 SCAR=22.9
4982 28 my ( $dev, $p ) = @_;
4983 28 my $t = _proc_since( $dev, $p );
4984 28 ▶ return 'Oct20' unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 28 0 28
4985 0 require POSIX;
4986 0 my @s = _local_tm($t);
4987 0 my @n = _local_tm( _dev_now($dev) );
4988 0 ▶ return $s[7] == $n[7] && $s[5] == $n[5] ? POSIX::strftime( '%H:%M', @s ) : POSIX::strftime( '%b%d', @s );
Branch: 1 branch
BranchTrueFalseTotal
$s[7] == $n[7] && $s[5] == $n[5] ? : 0 0 0
Condition0%0/3
$s[7] == $n[7] and $s[5] == $n[5]
!ll&&!rl&&r
000
MC/DC0%0/2
$s[7] == $n[7] and $s[5] == $n[5]
$s[7] == $n[7] $s[5] == $n[5]
Truth table0%0/3
A and B
A= $s[7] == $n[7]B= $s[5] == $n[5]
ABresult
0X0
100
111
4989 }
4990  
4991 # Signal an einen Dienst: HUP liest neu ein (wie reload), sonst endet er (KILL: failed)
4992 6 ▶sub _signal {
Subroutine _signal: called CC=17 SCAR=29.6
4993 6 my ( $dev, $unit, $sig ) = @_;
4994 6 ▶ my $svc = $dev->{services}{$unit} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $svc = $$dev{"services"}{$unit} or return 6 0 6
4995 6 ▶ if ( $sig eq 'HUP' ) { _restart_effect( $dev, $unit, 'reload' ); return }
Branch: 1 branch
BranchTrueFalseTotal
if ($sig eq "HUP") 1 5 6
4996 5 ▶ return unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 0 5 5
4997 5 ▶ $svc->{restarts} = ( $svc->{restarts} // 0 ) + 1;
Condition100%2/2
$$svc{"restarts"} // 0
l!l
14
MC/DC100%1/1
$$svc{"restarts"} // 0
$$svc{"restarts"}
Truth table100%2/2
A
A= $$svc{"restarts"}
Aresult
11
00
4998 5 $svc->{active} = JSON::MaybeXS::false();
4999 5 ▶ $svc->{failed} = JSON::MaybeXS::true() if $sig eq 'KILL' && !$svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $sig eq "KILL" and not $$svc{"failed"} 2 3 5
Condition66%2/3
$sig eq "KILL" and not $$svc{"failed"}
!ll&&!rl&&r
302
MC/DC50%1/2
$sig eq "KILL" and not $$svc{"failed"}
$sig eq "KILL" not $$svc{"failed"}
Truth table66%2/3
A and not(B)
A= $sig eq "KILL"B= not $$svc{"failed"}
ABresult
0X0
100
111
5000 0 ▶ $dev->{deleted_open} = [ grep { ( $_->{by} // '' ) ne $unit } @{ $dev->{deleted_open} } ] if $dev->{deleted_open};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"deleted_open"} 0 5 5
Condition0%0/2
$$_{"by"} // ""
l!l
00
MC/DC0%0/1
$$_{"by"} // ""
$$_{"by"}
Truth table0%0/2
A
A= $$_{"by"}
Aresult
11
00
5001 # Restart= der geladenen Unit: systemd startet den Dienst neu — always immer, on-failure,
5002 # on-abnormal und on-abort nach einem unsauberen Signal (nicht TERM, INT, HUP, PIPE),
5003 # on-success nach einem sauberen
5004 5 ▶ my $pol = _unit_props( _unit_loaded_text( $dev, $unit, $svc ) // '' )->{Restart} // 'no';
Condition100%4/4
_unit_props(_unit_loaded_text($dev, $unit, $svc) // "")->{"Restart"} // "no"
l!l
32
_unit_loaded_text($dev, $unit, $svc) // ""
l!l
41
MC/DC100%1/1
_unit_props(_unit_loaded_text($dev, $unit, $svc) // "")->{"Restart"} // "no"
_unit_props(_unit_loaded_text($dev, $unit, $svc) // "")->{"Restart"}
MC/DC100%1/1
_unit_loaded_text($dev, $unit, $svc) // ""
_unit_loaded_text($dev, $unit, $svc)
Truth table100%2/2
A
A= _unit_props(_unit_loaded_text($dev, $unit, $svc) // "")->{"Restart"}
Aresult
11
00
Truth table100%2/2
A
A= _unit_loaded_text($dev, $unit, $svc)
Aresult
11
00
5005 5 my $clean = $sig =~ /\A(?:TERM|INT|HUP|PIPE)\z/;
5006 5 ▶ if ( $pol eq 'always' || ( $clean ? $pol eq 'on-success' : $pol =~ /\Aon-(?:failure|abnormal|abort)\z/ ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pol eq "always" or $clean ? $pol eq "on-success" : $pol =~ /\Aon-(?:failure|abnormal|abort)\z/) 2 3 5
$clean ? : 2 2 4
Condition100%3/3
$pol eq "always" or $clean ? $pol eq "on-success" : $pol =~ /\Aon-(?:failure|abnormal|abort)\z/
l!l&&r!l&&!r
113
MC/DC100%2/2
$pol eq "always" or $clean ? $pol eq "on-success" : $pol =~ /\Aon-(?:failure|abnormal|abort)\z/
$pol eq "always" $clean ? $pol eq "on-success" : $pol =~ /\Aon-(?:failure|abnormal|abort)\z/
Truth table100%3/3
A or B
A= $pol eq "always"B= $clean ? $pol eq "on-success" : $pol =~ /\Aon-(?:failure|abnormal|abort)\z/
ABresult
1X1
011
000
5007 2 ▶ $svc->{failed} = JSON::MaybeXS::false() if $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"failed"} 1 1 2
5008 2 _systemd_start( $dev, $unit, $svc, 'start' );
5009 2 ▶ if ( $svc->{active} ) { $svc->{_nrestarts} = ( $svc->{_nrestarts} // 0 ) + 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($$svc{'active'}) { } 2 0 2
Condition50%1/2
$$svc{"_nrestarts"} // 0
l!l
02
MC/DC0%0/1
$$svc{"_nrestarts"} // 0
$$svc{"_nrestarts"}
Truth table50%1/2
A
A= $$svc{"_nrestarts"}
Aresult
11
00
5010 0 else { $svc->{failed} = JSON::MaybeXS::true() } # Neustart gescheitert: die Unit steht auf failed
5011 }
5012 5 return;
5013 }
5014  
5015 8 ▶sub _sig_of {
Subroutine _sig_of: called CC=2 SCAR=7.0
5016 8 my ($x) = @_;
5017 8 my $s = uc( $x =~ s/\A-(?:s\s*)?//r );
5018 8 $s =~ s/\ASIG//;
5019 8 ▶ return { 1 => 'HUP', 9 => 'KILL', 15 => 'TERM', 2 => 'INT' }->{$s} // $s;
Condition66%2/3
{1, "HUP", 9, "KILL", 15, "TERM", 2, "INT"}->{$s} // $s
l!l&&r!l&&!r
170
MC/DC0%0/2
{1, "HUP", 9, "KILL", 15, "TERM", 2, "INT"}->{$s} // $s
{1, "HUP", 9, "KILL", 15, "TERM", 2, "INT"}->{$s} $s
Truth table66%2/3
A // B
A= {1, "HUP", 9, "KILL", 15, "TERM", 2, "INT"}->{$s}B= $s
ABresult
1X1
011
000
5020 }
5021  
5022 1 ▶sub _pkill {
Subroutine _pkill: called CC=16 SCAR=34.3
5023 1 my ( $dev, $av ) = @_;
5024 1 my ( $sig, $exact, @pat ) = ( 'TERM', 0 );
5025 1 my @a = @$av;
5026 1 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 2 1 3
5027 2 my $x = shift @a;
5028 0 ▶ if ( $x eq '-x' || $x eq '--exact' ) { $exact = 1 }
Branch: 5 branches
BranchTrueFalseTotal
if ($x eq '-x' or $x eq '--exact') { } 0 2 2
elsif ($x eq '-f' or $x eq '--full') { } 0 2 2
elsif ($x eq '-u' or $x eq '-U') { } 0 2 2
elsif ($x eq '--signal') { } 0 2 2
elsif ($x =~ /\A-(?:[A-Z]+|\d+)\z/) { } 1 1 2
Condition33%1/3
$x eq "-x" or $x eq "--exact"
l!l&&r!l&&!r
002
MC/DC0%0/2
$x eq "-x" or $x eq "--exact"
$x eq "-x" $x eq "--exact"
Truth table33%1/3
A or B
A= $x eq "-x"B= $x eq "--exact"
ABresult
1X1
011
000
5029 ▶ elsif ( $x eq '-f' || $x eq '--full' ) { }
Condition33%1/3
$x eq "-f" or $x eq "--full"
l!l&&r!l&&!r
002
MC/DC0%0/2
$x eq "-f" or $x eq "--full"
$x eq "-f" $x eq "--full"
Truth table33%1/3
A or B
A= $x eq "-f"B= $x eq "--full"
ABresult
1X1
011
000
5030 0 ▶ elsif ( $x eq '-u' || $x eq '-U' ) { shift @a }
Condition33%1/3
$x eq "-u" or $x eq "-U"
l!l&&r!l&&!r
002
MC/DC0%0/2
$x eq "-u" or $x eq "-U"
$x eq "-u" $x eq "-U"
Truth table33%1/3
A or B
A= $x eq "-u"B= $x eq "-U"
ABresult
1X1
011
000
5031 0 ▶ elsif ( $x eq '--signal' ) { $sig = _sig_of( shift(@a) // '' ) }
Condition0%0/2
shift @a // ""
l!l
00
MC/DC0%0/1
shift @a // ""
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
5032 1 elsif ( $x =~ /\A-(?:[A-Z]+|\d+)\z/ ) { $sig = _sig_of($x) }
5033 1 else { push @pat, $x }
5034 }
5035 1 ▶ return ( "pkill: no matching criteria specified\nTry `pkill --help' for more information.", 0 ) unless @pat;
Branch: 1 branch
BranchTrueFalseTotal
unless @pat 0 1 1
5036 1 ▶ my $re = $exact ? qr/\A\Q$pat[0]\E\z/ : ( eval { qr/$pat[0]/ } // qr/\Q$pat[0]\E/ );
Branch: 1 branch
BranchTrueFalseTotal
$exact ? : 0 1 1
Condition50%1/2
eval { do { qr/$pat[0]/ } } // qr/\Q$pat[0]\E/
l!l
10
MC/DC0%0/1
eval { do { qr/$pat[0]/ } } // qr/\Q$pat[0]\E/
eval { do { qr/$pat[0]/ } }
Truth table50%1/2
A
A= eval { do { qr/$pat[0]/ } }
Aresult
11
00
5037 1 my @hit = grep { ( $_->{cmd} =~ s{.*/}{}r ) =~ $re } _procs($dev);
5038 1 _signal( $dev, $_->{unit}, $sig ) for @hit;
5039 1 ▶ return ( '', @hit ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
@hit ? : 1 0 1
5040 }
5041  
5042 3 ▶sub _kill {
Subroutine _kill: called CC=9 SCAR=22.6
5043 3 my ( $dev, $av ) = @_;
5044 3 my ( $sig, @pids ) = ('TERM');
5045 3 my @a = @$av;
5046 3 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 4 3 7
5047 4 my $x = shift @a;
5048 0 ▶ if ( $x eq '-s' ) { $sig = _sig_of( shift(@a) // '' ) }
Branch: 3 branches
BranchTrueFalseTotal
if ($x eq '-s') { } 0 4 4
elsif ($x eq '-l') { } 0 4 4
elsif ($x =~ /\A-/) { } 1 3 4
Condition0%0/2
shift @a // ""
l!l
00
MC/DC0%0/1
shift @a // ""
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
5049 0 elsif ( $x eq '-l' ) { return ( ' 1) SIGHUP 2) SIGINT 3) SIGQUIT 9) SIGKILL 15) SIGTERM', 1 ) }
5050 1 elsif ( $x =~ /\A-/ ) { $sig = _sig_of($x) }
5051 3 else { push @pids, $x }
5052 }
5053 3 ▶ return ( 'kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]', 0 ) unless @pids;
Branch: 1 branch
BranchTrueFalseTotal
unless @pids 0 3 3
5054 3 my %by = map { $_->{pid} => $_ } _procs($dev);
5055 3 my ( @out, $ok ) = ();
5056 3 $ok = 1;
5057 3 for my $p (@pids) {
5058 3 ▶ if ( my $pr = $by{$p} ) { _signal( $dev, $pr->{unit}, $sig ); next }
Branch: 1 branch
BranchTrueFalseTotal
if (my $pr = $by{$p}) 2 1 3
5059 1 push @out, "bash: kill: ($p) - No such process";
5060 1 $ok = 0;
5061 }
5062 3 return ( join( "\n", @out ), $ok );
5063 }
5064  
5065 # getfacl: die Rechte als ACL (der Zustand kennt keine erweiterten ACLs)
5066 1 ▶sub _getfacl {
Subroutine _getfacl: called CC=23 SCAR=40.2
5067 1 my ( $dev, $av ) = @_;
5068 1 my @p = grep { !/\A-/ } @$av;
5069 1 ▶ return ( "Usage: getfacl [-aceEsRLPtpndvh] file ...\nTry `getfacl --help' for more information.", 0 ) unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 1 1
5070 1 my ( @out, $ok, $strip );
5071 1 $ok = 1;
5072 1 for my $p (@p) {
5073 1 my $e = _file_entry( $dev, $p );
5074 0 ▶ my $d = !$e && _is_dir( $dev, $p ) ? { mode => '0755', %{ ( $dev->{dirs} || {} )->{$p} || {} } } : undef;
Branch: 1 branch
BranchTrueFalseTotal
!$e && _is_dir($dev, $p) ? : 0 1 1
Condition14%1/7
not $e and _is_dir($dev, $p)
!ll&&!rl&&r
100
($$dev{'dirs'} || {})->{$p} || {}
l!l
00
$$dev{'dirs'} || {}
l!l
00
MC/DC0%0/2
not $e and _is_dir($dev, $p)
not $e _is_dir($dev, $p)
MC/DC0%0/1
($$dev{'dirs'} || {})->{$p} || {}
$$dev{'dirs'}
Truth table33%1/3
not(A) and B
A= not $eB= _is_dir($dev, $p)
ABresult
0X0
100
111
Truth table0%0/2
A
A= $$dev{'dirs'}
Aresult
11
00
5075 0 ▶ if ( !$e && !$d ) { push @out, "getfacl: $p: No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($e or $d) 0 1 1
Condition33%1/3
$e or $d
l!l&&r!l&&!r
100
MC/DC0%0/2
$e or $d
$e $d
Truth table33%1/3
A or B
A= $eB= $d
ABresult
1X1
011
000
5076 1 ▶ my $m = $e ? _mode_of($e) : oct( $d->{mode} );
Branch: 1 branch
BranchTrueFalseTotal
$e ? : 1 0 1
5077 1 ▶ my $x = $e // $d;
Condition33%1/3
$e // $d
l!l&&r!l&&!r
100
MC/DC0%0/2
$e // $d
$e $d
Truth table33%1/3
A // B
A= $eB= $d
ABresult
1X1
011
000
5078 1 ▶ my $rwx = sub { my $b = shift; ( $b & 4 ? 'r' : '-' ) . ( $b & 2 ? 'w' : '-' ) . ( $b & 1 ? 'x' : '-' ) };
Subroutine __ANON__: called CC=4 SCAR=14.3
Branch: 3 branches
BranchTrueFalseTotal
$b & 4 ? : 3 0 3
$b & 2 ? : 1 2 3
$b & 1 ? : 3 0 3
5079 1 ( my $shown = $p ) =~ s{\A/+}{};
5080 1 ▶ $strip = 1 if $p =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ m[\A/] 1 0 1
5081 1 ▶ push @out, '' if @out && $out[-1] ne '';
Branch: 1 branch
BranchTrueFalseTotal
if @out and $out[-1] ne "" 0 1 1
Condition33%1/3
@out and $out[-1] ne ""
!ll&&!rl&&r
100
MC/DC0%0/2
@out and $out[-1] ne ""
@out $out[-1] ne ""
Truth table33%1/3
A and B
A= @outB= $out[-1] ne ""
ABresult
0X0
100
111
5082 1 ▶ push @out, "# file: $shown", '# owner: ' . ( $x->{owner} // 'root' ), '# group: ' . ( $x->{group} // 'root' );
Condition50%2/4
$$x{"owner"} // "root"
l!l
01
$$x{"group"} // "root"
l!l
01
MC/DC0%0/1
$$x{"owner"} // "root"
$$x{"owner"}
MC/DC0%0/1
$$x{"group"} // "root"
$$x{"group"}
Truth table50%1/2
A
A= $$x{"owner"}
Aresult
11
00
Truth table50%1/2
A
A= $$x{"group"}
Aresult
11
00
5083 1 ▶ push @out, '# flags: ' . ( $m & 04000 ? 's' : '-' ) . ( $m & 02000 ? 's' : '-' ) . ( $m & 01000 ? 't' : '-' ) if $m & 07000;
Branch: 4 branches
BranchTrueFalseTotal
if $m & 3584 1 0 1
$m & 2048 ? : 1 0 1
$m & 1024 ? : 0 1 1
$m & 512 ? : 0 1 1
5084 1 push @out, 'user::' . $rwx->( $m >> 6 ), 'group::' . $rwx->( $m >> 3 ), 'other::' . $rwx->($m), '';
5085 }
5086 1 ▶ pop @out while @out && $out[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
@out and $out[-1] eq "" and do { pop @out } 1 1 2
Condition66%2/3
@out and $out[-1] eq ""
!ll&&!rl&&r
011
MC/DC50%1/2
@out and $out[-1] eq ""
@out $out[-1] eq ""
Truth table66%2/3
A and B
A= @outB= $out[-1] eq ""
ABresult
0X0
100
111
5087 1 ▶ unshift @out, "getfacl: Removing leading '/' from absolute path names" if $strip;
Branch: 1 branch
BranchTrueFalseTotal
if $strip 1 0 1
5088 1 return ( join( "\n", @out ), $ok );
5089 }
5090  
5091 # crontab -l [-u benutzer] liest /var/spool/cron/crontabs/<benutzer>
5092 17 ▶sub _crontab {
Subroutine _crontab: called CC=27 SCAR=37.3
5093 17 my ( $dev, $av, $ctx, $stdin ) = @_;
5094 17 my @a = @$av;
5095 17 ▶ my ( $user, $verb, $file ) = ( $AS_USER // 'root' );
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
017
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
$Langertha::Holmgang::Sim::Linux::AS_USER
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::AS_USER
Aresult
11
00
5096 17 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 31 17 48
5097 31 my $x = shift @a;
5098 31 ▶ if ( $x eq '-u' ) { $user = shift(@a) // $user }
Branch: 2 branches
BranchTrueFalseTotal
if ($x eq '-u') { } 14 17 31
elsif ($x =~ /\A-([lre])\z/) { } 11 6 17
Condition33%1/3
shift @a // $user
l!l&&r!l&&!r
1400
MC/DC0%0/2
shift @a // $user
shift @a $user
Truth table33%1/3
A // B
A= shift @aB= $user
ABresult
1X1
011
000
5099 11 elsif ( $x =~ /\A-([lre])\z/ ) { $verb = $1 }
5100 6 ▶ else { $verb //= 'install'; $file = $x }
Condition50%1/2
$verb //= "install"
l!l
06
MC/DC0%0/1
$verb //= "install"
$verb
Truth table50%1/2
A
A= $verb
Aresult
11
00
5101 }
5102 17 ▶ return ( "crontab: user `$user' unknown", 0 ) unless $user eq 'root' || ( $dev->{users} || {} )->{$user};
Branch: 1 branch
BranchTrueFalseTotal
unless $user eq "root" or ($$dev{"users"} || {})->{$user} 1 16 17
Condition80%4/5
$user eq "root" or ($$dev{"users"} || {})->{$user}
l!l&&r!l&&!r
3131
$$dev{'users'} || {}
l!l
140
MC/DC0%0/2
$user eq "root" or ($$dev{"users"} || {})->{$user}
$user eq "root" $$dev{'users'}
Truth table66%2/3
A or B
A= $user eq "root"B= $$dev{'users'}
ABresult
1X1
011
000
5103 16 my $f = "/var/spool/cron/crontabs/$user";
5104 16 ▶ if ( ( $verb // '' ) eq 'l' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($verb // "") eq "l") 10 6 16
Condition50%1/2
$verb // ""
l!l
160
MC/DC0%0/1
$verb // ""
$verb
Truth table50%1/2
A
A= $verb
Aresult
11
00
5105 10 ▶ my $t = _file_text( $dev, $f ) // return ( "no crontab for $user", 0 );
Condition100%2/2
_file_text($dev, $f) // (return "no crontab for $user", 0)
l!l
91
MC/DC100%1/1
_file_text($dev, $f) // (return "no crontab for $user", 0)
_file_text($dev, $f)
Truth table100%2/2
A
A= _file_text($dev, $f)
Aresult
11
00
5106 9 $t =~ s/\A# DO NOT EDIT THIS FILE[^\n]*\n(?:#[^\n]*\n){0,2}//; # Kopf, den crontab beim Installieren schreibt
5107 9 return ( $t =~ s/\n\z//r, 1 );
5108 }
5109 6 ▶ if ( ( $verb // '' ) eq 'r' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($verb // "") eq "r") 0 6 6
Condition50%1/2
$verb // ""
l!l
60
MC/DC0%0/1
$verb // ""
$verb
Truth table50%1/2
A
A= $verb
Aresult
11
00
5110 0 ▶ return ( "no crontab for $user", 0 ) unless exists( ( $dev->{files} || {} )->{$f} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists(($$dev{"files"} || {})->{$f}) 0 0 0
Condition0%0/2
$$dev{'files'} || {}
l!l
00
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table0%0/2
A
A= $$dev{'files'}
Aresult
11
00
5111 0 delete $dev->{files}{$f};
5112 0 return ( '', 1 );
5113 }
5114 6 ▶ if ( ( $verb // '' ) eq 'install' && defined $file ) { # crontab [-u benutzer] DATEI|-: ersetzt den ganzen crontab
Branch: 1 branch
BranchTrueFalseTotal
if (($verb // "") eq "install" and defined $file) 6 0 6
Condition40%2/5
($verb // "") eq "install" and defined $file
!ll&&!rl&&r
006
$verb // ""
l!l
60
MC/DC0%0/2
($verb // "") eq "install" and defined $file
$verb defined $file
Truth table33%1/3
A and B
A= $verbB= defined $file
ABresult
0X0
100
111
5115 6 ▶ my $t = $file eq '-' ? $stdin // '' : _file_text( $dev, _absp($file) );
Branch: 1 branch
BranchTrueFalseTotal
$file eq '-' ? : 4 2 6
Condition50%1/2
$stdin // ""
l!l
40
MC/DC0%0/1
$stdin // ""
$stdin
Truth table50%1/2
A
A= $stdin
Aresult
11
00
5116 6 ▶ return ( "$file: No such file or directory", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 6 6
5117 6 my $n = 0;
5118 6 for my $l ( split /\n/, $t ) {
5119 12 my $bad = _cron_line_error($l);
5120 12 ▶ return ( qq{"$file":$n: $bad\nerrors in crontab file, can't install.}, 0 ) if defined $bad;
Branch: 1 branch
BranchTrueFalseTotal
if defined $bad 2 10 12
5121 10 $n++;
5122 }
5123 4 ▶ $t .= "\n" if length $t && $t !~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
if length $t and not $t =~ /\n\z/ 2 2 4
Condition66%2/3
length $t and not $t =~ /\n\z/
!ll&&!rl&&r
022
MC/DC50%1/2
length $t and not $t =~ /\n\z/
length $t not $t =~ /\n\z/
Truth table66%2/3
A and not(B)
A= length $tB= not $t =~ /\n\z/
ABresult
0X0
100
111
5124 4 my $head = "# DO NOT EDIT THIS FILE - edit the master and reinstall.\n# ($file installed on Tue Oct 20 12:00:00 2026)\n"
5125 . "# (Cron version -- \$Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp \$)\n";
5126 4 $dev->{files}{$f} = { content => $head . $t, owner => $user, group => 'crontab', mode => '0600' };
5127 4 return ( '', 1 );
5128 }
5129 0 push @GAPS, join( ' ', 'crontab', @$av );
5130 0 return ( '', 0 );
5131 }
5132  
5133 # Zeile eines crontab wie Debian-cron sie prueft: undef oder der Fehler ("bad minute" …)
5134 82 my %CRON_NAMES = ( month => [qw( jan feb mar apr may jun jul aug sep oct nov dec )], 'day-of-week' => [qw( sun mon tue wed thu fri sat )] );
5135 12 ▶sub _cron_line_error {
Subroutine _cron_line_error: called CC=21 SCAR=34.1
5136 12 my ($l) = @_;
5137 12 ▶ return undef if $l =~ /\A\s*(?:#|\z)/ || $l =~ /\A\s*[A-Za-z_]\w*\s*=/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\A\s*(?:#|\z)/ or $l =~ /\A\s*[A-Za-z_]\w*\s*=/ 3 9 12
Condition100%3/3
$l =~ /\A\s*(?:#|\z)/ or $l =~ /\A\s*[A-Za-z_]\w*\s*=/
l!l&&r!l&&!r
219
MC/DC100%2/2
$l =~ /\A\s*(?:#|\z)/ or $l =~ /\A\s*[A-Za-z_]\w*\s*=/
$l =~ /\A\s*(?:#|\z)/ $l =~ /\A\s*[A-Za-z_]\w*\s*=/
Truth table100%3/3
A or B
A= $l =~ /\A\s*(?:#|\z)/B= $l =~ /\A\s*[A-Za-z_]\w*\s*=/
ABresult
1X1
011
000
5138 9 ▶ if ( $l =~ /\A\s*@(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A\s*@(\S+)/) 1 8 9
5139 1 ▶ return 'bad time specifier' unless $1 =~ /\A(?:reboot|yearly|annually|monthly|weekly|daily|midnight|hourly)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 =~ /\A(?:reboot|yearly|annually|monthly|weekly|daily|midnight|hourly)\z/ 0 1 1
5140 1 ▶ return $l =~ /\A\s*@\S+\s+\S/ ? undef : 'bad command';
Branch: 1 branch
BranchTrueFalseTotal
$l =~ /\A\s*\@\S+\s+\S/ ? : 1 0 1
5141 }
5142 8 my @f = split ' ', $l, 6;
5143 8 my @spec = ( [ minute => 0, 59 ], [ hour => 0, 23 ], [ 'day-of-month' => 1, 31 ], [ month => 1, 12 ], [ 'day-of-week' => 0, 7 ] );
5144 8 for my $i ( 0 .. 4 ) {
5145 36 my ( $name, $lo, $hi ) = @{ $spec[$i] };
5146 36 ▶ my $v = $f[$i] // return "bad $name";
Condition50%1/2
$f[$i] // (return "bad $name")
l!l
360
MC/DC0%0/1
$f[$i] // (return "bad $name")
$f[$i]
Truth table50%1/2
A
A= $f[$i]
Aresult
11
00
5147 36 my $names = $CRON_NAMES{$name};
5148 36 for my $part ( split /,/, $v, -1 ) {
5149 36 my ( $range, $step ) = split m{/}, $part, 2;
5150 36 ▶ return "bad $name" if defined $step && $step !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $step and not $step =~ /\A\d+\z/ 1 35 36
Condition100%3/3
defined $step and not $step =~ /\A\d+\z/
!ll&&!rl&&r
3321
MC/DC100%2/2
defined $step and not $step =~ /\A\d+\z/
defined $step not $step =~ /\A\d+\z/
Truth table100%3/3
A and not(B)
A= defined $stepB= not $step =~ /\A\d+\z/
ABresult
0X0
100
111
5151 35 ▶ next if $range eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $range eq "*" 24 11 35
5152 11 my @ends = split /-/, $range, 2;
5153 11 for (@ends) {
5154 0 ▶ if ( $names && /\A[a-z]{3}\z/i ) { my $x = lc; return "bad $name" unless grep { $_ eq $x } @$names; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($names and /\A[a-z]{3}\z/i) 0 11 11
unless grep {$_ eq $x;} @$names 0 0 0
Condition33%1/3
$names and /\A[a-z]{3}\z/i
!ll&&!rl&&r
1100
MC/DC0%0/2
$names and /\A[a-z]{3}\z/i
$names /\A[a-z]{3}\z/i
Truth table33%1/3
A and B
A= $namesB= /\A[a-z]{3}\z/i
ABresult
0X0
100
111
5155 11 ▶ return "bad $name" unless /\A\d+\z/ && $_ >= $lo && $_ <= $hi;
Branch: 1 branch
BranchTrueFalseTotal
unless /\A\d+\z/ and $_ >= $lo and $_ <= $hi 1 10 11
Condition50%3/6
/\A\d+\z/ and $_ >= $lo and $_ <= $hi
!ll&&!rl&&r
0110
/\A\d+\z/ and $_ >= $lo
!ll&&!rl&&r
0011
MC/DC33%1/3
/\A\d+\z/ and $_ >= $lo and $_ <= $hi
/\A\d+\z/ $_ >= $lo $_ <= $hi
Truth table50%2/4
A and B and C
A= /\A\d+\z/B= $_ >= $loC= $_ <= $hi
ABCresult
0XX0
10X0
1100
1111
5156 }
5157 }
5158 }
5159 6 ▶ return defined $f[5] && $f[5] =~ /\S/ ? undef : 'bad command';
Branch: 1 branch
BranchTrueFalseTotal
defined $f[5] && $f[5] =~ /\S/ ? : 6 0 6
Condition33%1/3
defined $f[5] and $f[5] =~ /\S/
!ll&&!rl&&r
006
MC/DC0%0/2
defined $f[5] and $f[5] =~ /\S/
defined $f[5] $f[5] =~ /\S/
Truth table33%1/3
A and B
A= defined $f[5]B= $f[5] =~ /\S/
ABresult
0X0
100
111
5160 }
5161  
5162 2 ▶sub _pgrep {
Subroutine _pgrep: called CC=8 SCAR=21.1
5163 2 my ( $dev, $av ) = @_;
5164 2 my ( $long, @pat ) = ( 0 );
5165 2 ▶ for (@$av) { if (/\A-(\w+)\z/) { $long = 1 if /[al]/ } else { push @pat, $_ } }
Branch: 2 branches
BranchTrueFalseTotal
if (/\A-(\w+)\z/) { } 1 2 3
if /[al]/ 1 0 1
5166 2 ▶ return ( "pgrep: no matching criteria specified\nTry `pgrep --help' for more information.", 0 ) unless @pat;
Branch: 1 branch
BranchTrueFalseTotal
unless @pat 0 2 2
5167 2 ▶ my $re = eval { qr/$pat[0]/ } // qr/\Q$pat[0]\E/;
Condition50%1/2
eval { do { qr/$pat[0]/ } } // qr/\Q$pat[0]\E/
l!l
20
MC/DC0%0/1
eval { do { qr/$pat[0]/ } } // qr/\Q$pat[0]\E/
eval { do { qr/$pat[0]/ } }
Truth table50%1/2
A
A= eval { do { qr/$pat[0]/ } }
Aresult
11
00
5168 2 my @hit = grep { $_->{cmd} =~ $re } _procs($dev);
5169 2 ▶ return ( join( "\n", map { $long ? "$_->{pid} $_->{cmd}" : $_->{pid} } @hit ), @hit ? 1 : 0 );
Branch: 2 branches
BranchTrueFalseTotal
$long ? : 1 0 1
@hit ? : 1 1 2
5170 }
5171  
5172 36 ▶sub _uid { my ( $dev, $u ) = @_; return 0 if !defined $u || $u eq 'root'; return ( ( $dev->{users} || {} )->{$u} || {} )->{uid} // 1000 }
Subroutine _uid: called CC=6 SCAR=18.5
Branch: 1 branch
BranchTrueFalseTotal
if not defined $u or $u eq "root" 22 14 36
Condition66%6/9
not defined $u or $u eq "root"
l!l&&r!l&&!r
81414
(($$dev{"users"} || {})->{$u} || {})->{"uid"} // 1000
l!l
140
($$dev{'users'} || {})->{$u} || {}
l!l
140
$$dev{'users'} || {}
l!l
140
MC/DC100%2/2
not defined $u or $u eq "root"
not defined $u $u eq "root"
MC/DC0%0/1
(($$dev{"users"} || {})->{$u} || {})->{"uid"} // 1000
$$dev{'users'}
Truth table100%3/3
not(A) or B
A= not defined $uB= $u eq "root"
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
5173 63 ▶sub _gid { my ( $dev, $g ) = @_; return 0 if !defined $g || $g eq 'root'; return ( ( $dev->{groups} || {} )->{$g} || {} )->{gid} // 1000 }
Subroutine _gid: called CC=6 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if not defined $g or $g eq "root" 18 45 63
Condition100%9/9
not defined $g or $g eq "root"
l!l&&r!l&&!r
81045
(($$dev{"groups"} || {})->{$g} || {})->{"gid"} // 1000
l!l
3411
($$dev{'groups'} || {})->{$g} || {}
l!l
3411
$$dev{'groups'} || {}
l!l
432
MC/DC100%2/2
not defined $g or $g eq "root"
not defined $g $g eq "root"
MC/DC100%1/1
(($$dev{"groups"} || {})->{$g} || {})->{"gid"} // 1000
$$dev{'groups'}
Truth table100%3/3
not(A) or B
A= not defined $gB= $g eq "root"
ABresult
1X1
011
000
Truth table100%2/2
A
A= $$dev{'groups'}
Aresult
11
00
5174  
5175 # Darf $user die Datei lesen/schreiben/ausfuehren? (r|w|x)
5176 32 ▶sub _can {
Subroutine _can: called CC=18 SCAR=30.6
5177 32 my ( $dev, $user, $path, $what ) = @_;
5178 32 ▶ my $e = _file_entry( $dev, $path ) // ( ( $dev->{dirs} || {} )->{$path} ? { mode => '0755', %{ $dev->{dirs}{$path} } } : undef ) or return 0;
Branch: 2 branches
BranchTrueFalseTotal
my $e = _file_entry($dev, $path) // (($$dev{"dirs"} || {})->{$path} ? {"mode", "0755", %{$$dev{"dirs"}{$path};}} : undef) or return 0 32 0 32
($$dev{'dirs'} || {})->{$path} ? : 11 0 11
Condition75%3/4
_file_entry($dev, $path) // (($$dev{"dirs"} || {})->{$path} ? {"mode", "0755", %{$$dev{"dirs"}{$path};}} : undef)
l!l
2111
$$dev{'dirs'} || {}
l!l
110
MC/DC100%1/1
_file_entry($dev, $path) // (($$dev{"dirs"} || {})->{$path} ? {"mode", "0755", %{$$dev{"dirs"}{$path};}} : undef)
_file_entry($dev, $path)
Truth table100%2/2
A
A= _file_entry($dev, $path)
Aresult
11
00
5179 32 ▶ return 1 if ( $user // 'root' ) eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if ($user // "root") eq "root" 2 30 32
Condition50%1/2
$user // "root"
l!l
320
MC/DC0%0/1
$user // "root"
$user
Truth table50%1/2
A
A= $user
Aresult
11
00
5180 30 ▶ my $bit = { r => 4, w => 2, x => 1 }->{$what} // 4;
Condition50%1/2
{"r", 4, "w", 2, "x", 1}->{$what} // 4
l!l
300
MC/DC0%0/1
{"r", 4, "w", 2, "x", 1}->{$what} // 4
{"r", 4, "w", 2, "x", 1}->{$what}
Truth table50%1/2
A
A= {"r", 4, "w", 2, "x", 1}->{$what}
Aresult
11
00
5181 30 my $m = _mode_of($e);
5182 30 ▶ return ( ( $m >> 6 ) & $bit ) ? 1 : 0 if ( $e->{owner} // 'root' ) eq $user;
Branch: 2 branches
BranchTrueFalseTotal
if ($$e{"owner"} // "root") eq $user 8 22 30
$m >> 6 & $bit ? : 7 1 8
Condition50%1/2
$$e{"owner"} // "root"
l!l
300
MC/DC0%0/1
$$e{"owner"} // "root"
$$e{"owner"}
Truth table50%1/2
A
A= $$e{"owner"}
Aresult
11
00
5183 22 ▶ my @groups = @{ ( ( $dev->{users} || {} )->{$user} || {} )->{groups} || [] };
Condition50%3/6
(($$dev{'users'} || {})->{$user} || {})->{'groups'} || []
l!l
220
($$dev{'users'} || {})->{$user} || {}
l!l
220
$$dev{'users'} || {}
l!l
220
MC/DC0%0/1
(($$dev{'users'} || {})->{$user} || {})->{'groups'} || []
$$dev{'users'}
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
5184 22 ▶ return ( ( $m >> 3 ) & $bit ) ? 1 : 0 if grep { $_ eq ( $e->{group} // 'root' ) } @groups;
Branch: 2 branches
BranchTrueFalseTotal
if grep {$_ eq ($$e{"group"} // "root");} @groups 3 19 22
$m >> 3 & $bit ? : 3 0 3
Condition100%2/2
$$e{"group"} // "root"
l!l
916
MC/DC100%1/1
$$e{"group"} // "root"
$$e{"group"}
Truth table100%2/2
A
A= $$e{"group"}
Aresult
11
00
5185 19 ▶ return ( $m & $bit ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$m & $bit ? : 14 5 19
5186 }
5187  
5188 # Datei-Eintrag als Hash im Zustand (fuer Rechte/Eigentuemer)
5189 20 ▶sub _entry_rw {
Subroutine _entry_rw: called CC=2 SCAR=6.9
5190 20 my ( $dev, $path ) = @_;
5191 20 my $e = $dev->{files}{$path};
5192 20 ▶ $dev->{files}{$path} = $e = { content => $e } unless ref $e eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" 2 18 20
5193 20 return $e;
5194 }
5195  
5196 # Ziele von chmod/chown: Dateien und (mit -R bzw. ausdruecklich) Verzeichnisse
5197 # als 'dir:<pfad>'.
5198 23 ▶sub _targets {
Subroutine _targets: called CC=10 SCAR=23.2
5199 23 my ( $dev, $rec, @paths ) = @_;
5200 23 my @t;
5201 23 for my $p (@paths) {
5202 23 ( my $q = $p ) =~ s{(?<=.)/+\z}{};
5203 23 ▶ if ( _file_entry( $dev, $q ) ) { push @t, $q; next }
Branch: 1 branch
BranchTrueFalseTotal
if (_file_entry($dev, $q)) 15 8 23
5204 8 ▶ if ( _is_dir( $dev, $q ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_dir($dev, $q)) 8 0 8
5205 8 push @t, "dir:$q";
5206 8 ▶ if ($rec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rec) 1 7 8
5207 1 my %d;
5208 1 for my $f ( _under( $dev, $q ) ) {
5209 2 push @t, $f;
5210 2 ( my $x = $f ) =~ s{/[^/]+\z}{};
5211 2 ▶ while ( length $x > length $q ) { $d{$x} = 1; $x =~ s{/+[^/]*\z}{} or last }
Branch: 2 branches
BranchTrueFalseTotal
if (length $x > length $q) 1 2 3
$x =~ s[/+[^/]*\z][] or last 1 0 1
5212 }
5213 1 ▶ $d{$_} = 1 for grep { index( $_, "$q/" ) == 0 } keys %{ $dev->{dirs} || {} };
Condition50%1/2
$$dev{'dirs'} || {}
l!l
10
MC/DC0%0/1
$$dev{'dirs'} || {}
$$dev{'dirs'}
Truth table50%1/2
A
A= $$dev{'dirs'}
Aresult
11
00
5214 1 push @t, map {"dir:$_"} sort keys %d;
5215 }
5216 8 next;
5217 }
5218 0 return ( undef, $p );
5219 }
5220 23 return \@t;
5221 }
5222  
5223 26 ▶sub _target_entry {
Subroutine _target_entry: called CC=3 SCAR=11.1
5224 26 my ( $dev, $t ) = @_;
5225 26 ▶ return _entry_rw( $dev, $t ) unless $t =~ /\Adir:(.*)\z/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ /\Adir:(.*)\z/s 17 9 26
5226 9 ▶ return $dev->{dirs}{$1} //= { mode => '0755' };
Condition50%1/2
$$dev{"dirs"}{$1} //= {"mode", "0755"}
l!l
90
MC/DC0%0/1
$$dev{"dirs"}{$1} //= {"mode", "0755"}
$$dev{"dirs"}{$1}
Truth table50%1/2
A
A= $$dev{"dirs"}{$1}
Aresult
11
00
5227 }
5228  
5229 16 ▶sub _chmod {
Subroutine _chmod: called CC=32 SCAR=40.0
5230 16 my ( $dev, $av ) = @_;
5231 16 my @a = @$av;
5232 16 my $rec = 0;
5233 0 ▶ while ( @a && $a[0] =~ /\A-[Rvf]+\z/ ) { $rec = 1 if shift(@a) =~ /R/ }
Branch: 2 branches
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-[Rvf]+\z/) 0 16 16
if shift(@a) =~ /R/ 0 0 0
Condition33%1/3
@a and $a[0] =~ /\A-[Rvf]+\z/
!ll&&!rl&&r
0160
MC/DC0%0/2
@a and $a[0] =~ /\A-[Rvf]+\z/
@a $a[0] =~ /\A-[Rvf]+\z/
Truth table33%1/3
A and B
A= @aB= $a[0] =~ /\A-[Rvf]+\z/
ABresult
0X0
100
111
5234 16 ▶ my $spec = shift @a // return ( "chmod: missing operand", 0 );
Condition50%1/2
shift @a // (return "chmod: missing operand", 0)
l!l
160
MC/DC0%0/1
shift @a // (return "chmod: missing operand", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
5235 16 ▶ return ( "chmod: missing operand after '$spec'", 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 16 16
5236 16 my ( $t, $bad ) = _targets( $dev, $rec, @a );
5237 16 ▶ return ( "chmod: cannot access '$bad': No such file or directory", 0 ) unless $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 16 16
5238 16 for my $p (@$t) {
5239 16 my $isdir = $p =~ /\Adir:/;
5240 16 my $e = _target_entry( $dev, $p );
5241 16 ▶ my $m = $isdir ? oct( $e->{mode} // '0755' ) : _mode_of($e);
Branch: 1 branch
BranchTrueFalseTotal
$isdir ? : 2 14 16
Condition50%1/2
$$e{"mode"} // "0755"
l!l
20
MC/DC0%0/1
$$e{"mode"} // "0755"
$$e{"mode"}
Truth table50%1/2
A
A= $$e{"mode"}
Aresult
11
00
5242 16 ▶ if ( $spec =~ /\A[0-7]{3,4}\z/ ) { $m = oct $spec }
Branch: 1 branch
BranchTrueFalseTotal
if ($spec =~ /\A[0-7]{3,4}\z/) { } 13 3 16
5243 else {
5244 3 for my $part ( split /,/, $spec ) {
5245 4 ▶ my ( $who, $op, $perm ) = $part =~ /\A([ugoa]*)([+=-])([rwxXst]*)\z/ or return ( "chmod: invalid mode: '$spec'", 0 );
Branch: 1 branch
BranchTrueFalseTotal
() = $part =~ /\A([ugoa]*)([+=-])([rwxXst]*)\z/ or return "chmod: invalid mode: '${spec}'", 0 4 0 4
5246 4 ▶ $who = 'a' if $who eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $who eq "" 0 4 4
5247 4 my $bits = 0;
5248 4 ▶ my ( $s, $t ) = ( $perm =~ /s/ ? 1 : 0, $perm =~ /t/ ? 1 : 0 );
Branch: 2 branches
BranchTrueFalseTotal
$perm =~ /s/ ? : 2 2 4
$perm =~ /t/ ? : 1 3 4
5249 4 for ( split //, $perm ) {
5250 4 ▶ next if $_ eq 's' || $_ eq 't';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "s" or $_ eq "t" 3 1 4
Condition100%3/3
$_ eq "s" or $_ eq "t"
l!l&&r!l&&!r
211
MC/DC100%2/2
$_ eq "s" or $_ eq "t"
$_ eq "s" $_ eq "t"
Truth table100%3/3
A or B
A= $_ eq "s"B= $_ eq "t"
ABresult
1X1
011
000
5251 0 ▶ if ( $_ eq 'X' ) { $bits |= 1 if $isdir || ( $m & 0111 ); next }
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq "X") 0 1 1
if $isdir or $m & 73 0 0 0
Condition0%0/3
$isdir or $m & 73
l!l&&r!l&&!r
000
MC/DC0%0/2
$isdir or $m & 73
$isdir $m & 73
Truth table0%0/3
A or B
A= $isdirB= $m & 73
ABresult
1X1
011
000
5252 1 $bits |= { r => 4, w => 2, x => 1 }->{$_};
5253 }
5254 4 ▶ for my $w ( $who =~ /a/ ? qw( u g o ) : split //, $who ) {
Branch: 1 branch
BranchTrueFalseTotal
$who =~ /a/ ? : 0 4 4
5255 4 my $sh = { u => 6, g => 3, o => 0 }->{$w};
5256 4 my $sp = { u => 04000, g => 02000, o => 01000 }->{$w};
5257 4 ▶ my $spb = ( $w eq 'o' ? $t : $s ) ? $sp : 0;
Branch: 2 branches
BranchTrueFalseTotal
($w eq 'o' ? $t : $s) ? : 3 1 4
$w eq 'o' ? : 2 2 4
5258 4 ▶ if ( $op eq '+' ) { $m |= ( $bits << $sh ) | $spb }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '+') { } 3 1 4
elsif ($op eq '-') { } 1 0 1
5259 1 elsif ( $op eq '-' ) { $m &= ~( ( $bits << $sh ) | $spb ) }
5260 0 else { $m = ( $m & ~( ( 7 << $sh ) | $sp ) ) | ( $bits << $sh ) | $spb }
5261 }
5262 }
5263 }
5264 16 my $new = sprintf '%04o', $m & 07777;
5265 16 ▶ my $cur = $isdir ? ( $e->{mode} // '0755' ) : sprintf( '%04o', _mode_of($e) );
Branch: 1 branch
BranchTrueFalseTotal
$isdir ? : 2 14 16
Condition50%1/2
$$e{"mode"} // "0755"
l!l
20
MC/DC0%0/1
$$e{"mode"} // "0755"
$$e{"mode"}
Truth table50%1/2
A
A= $$e{"mode"}
Aresult
11
00
5266 16 ▶ $e->{mode} = $new unless $cur eq $new && defined $e->{mode};
Branch: 1 branch
BranchTrueFalseTotal
unless $cur eq $new and defined $$e{"mode"} 16 0 16
Condition33%1/3
$cur eq $new and defined $$e{"mode"}
!ll&&!rl&&r
1600
MC/DC0%0/2
$cur eq $new and defined $$e{"mode"}
$cur eq $new defined $$e{"mode"}
Truth table33%1/3
A and B
A= $cur eq $newB= defined $$e{"mode"}
ABresult
0X0
100
111
5267 }
5268 16 return ( '', 1 );
5269 }
5270  
5271 8 ▶sub _chown {
Subroutine _chown: called CC=39 SCAR=41.2
5272 8 my ( $dev, $av, $ctx, $stdin, $only_group ) = @_;
5273 8 my @a = @$av;
5274 8 my $rec = 0;
5275 8 ▶ while ( @a && $a[0] =~ /\A-[Rvfh]+\z/ ) { $rec = 1 if shift(@a) =~ /R/ }
Branch: 2 branches
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-[Rvfh]+\z/) 1 8 9
if shift(@a) =~ /R/ 1 0 1
Condition66%2/3
@a and $a[0] =~ /\A-[Rvfh]+\z/
!ll&&!rl&&r
081
MC/DC50%1/2
@a and $a[0] =~ /\A-[Rvfh]+\z/
@a $a[0] =~ /\A-[Rvfh]+\z/
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A-[Rvfh]+\z/
ABresult
0X0
100
111
5276 8 ▶ my $spec = shift @a // return ( 'chown: missing operand', 0 );
Condition50%1/2
shift @a // (return "chown: missing operand", 0)
l!l
80
MC/DC0%0/1
shift @a // (return "chown: missing operand", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
5277 8 ▶ my ( $u, $g ) = $only_group ? ( undef, $spec ) : split /[:.]/, $spec, 2;
Branch: 1 branch
BranchTrueFalseTotal
$only_group ? : 0 8 8
5278 8 ▶ my $users = $dev->{users} || {};
Condition50%1/2
$$dev{'users'} || {}
l!l
80
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
5279 8 ▶ my %groups = ( root => 1, map { $_ => 1 } keys %{ $dev->{groups} || {} }, map { @{ $_->{groups} || [] } } values %$users );
Condition75%3/4
$$dev{'groups'} || {}
l!l
53
$$_{'groups'} || []
l!l
100
MC/DC100%1/1
$$dev{'groups'} || {}
$$dev{'groups'}
MC/DC0%0/1
$$_{'groups'} || []
$$_{'groups'}
Truth table100%2/2
A
A= $$dev{'groups'}
Aresult
11
00
Truth table50%1/2
A
A= $$_{'groups'}
Aresult
11
00
5280 # numerische IDs: auf den Namen abbilden, sonst die Zahl selbst (wie ls -l ohne Eintrag)
5281 8 ▶ if ( defined $u && $u =~ /\A\d+\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $u and $u =~ /\A\d+\z/) 1 7 8
Condition66%2/3
defined $u and $u =~ /\A\d+\z/
!ll&&!rl&&r
071
MC/DC50%1/2
defined $u and $u =~ /\A\d+\z/
defined $u $u =~ /\A\d+\z/
Truth table66%2/3
A and B
A= defined $uB= $u =~ /\A\d+\z/
ABresult
0X0
100
111
5282 1 ▶ my ($n) = grep { ( $users->{$_}{uid} // -1 ) == $u } sort keys %$users;
Condition50%1/2
$$users{$_}{"uid"} // -1
l!l
10
MC/DC0%0/1
$$users{$_}{"uid"} // -1
$$users{$_}{"uid"}
Truth table50%1/2
A
A= $$users{$_}{"uid"}
Aresult
11
00
5283 1 ▶ $u = $u == 0 ? 'root' : $n // $u;
Branch: 1 branch
BranchTrueFalseTotal
$u == 0 ? : 0 1 1
Condition33%1/3
$n // $u
l!l&&r!l&&!r
100
MC/DC0%0/2
$n // $u
$n $u
Truth table33%1/3
A // B
A= $nB= $u
ABresult
1X1
011
000
5284 1 ▶ $users = { %$users, $u => { uid => $u } } unless $users->{$u} || $u eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
unless $$users{$u} or $u eq "root" 0 1 1
Condition33%1/3
$$users{$u} or $u eq "root"
l!l&&r!l&&!r
100
MC/DC0%0/2
$$users{$u} or $u eq "root"
$$users{$u} $u eq "root"
Truth table33%1/3
A or B
A= $$users{$u}B= $u eq "root"
ABresult
1X1
011
000
5285 }
5286 8 ▶ if ( defined $g && $g =~ /\A\d+\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $g and $g =~ /\A\d+\z/) 1 7 8
Condition100%3/3
defined $g and $g =~ /\A\d+\z/
!ll&&!rl&&r
341
MC/DC100%2/2
defined $g and $g =~ /\A\d+\z/
defined $g $g =~ /\A\d+\z/
Truth table100%3/3
A and B
A= defined $gB= $g =~ /\A\d+\z/
ABresult
0X0
100
111
5287 1 ▶ my ($n) = grep { ( $dev->{groups}{$_}{gid} // -1 ) == $g } sort keys %{ $dev->{groups} || {} };
Condition50%2/4
$$dev{"groups"}{$_}{"gid"} // -1
l!l
10
$$dev{'groups'} || {}
l!l
10
MC/DC0%0/1
$$dev{"groups"}{$_}{"gid"} // -1
$$dev{"groups"}{$_}{"gid"}
MC/DC0%0/1
$$dev{'groups'} || {}
$$dev{'groups'}
Truth table50%1/2
A
A= $$dev{"groups"}{$_}{"gid"}
Aresult
11
00
Truth table50%1/2
A
A= $$dev{'groups'}
Aresult
11
00
5288 1 ▶ $g = $g == 0 ? 'root' : $n // $g;
Branch: 1 branch
BranchTrueFalseTotal
$g == 0 ? : 0 1 1
Condition33%1/3
$n // $g
l!l&&r!l&&!r
100
MC/DC0%0/2
$n // $g
$n $g
Truth table33%1/3
A // B
A= $nB= $g
ABresult
1X1
011
000
5289 1 $groups{$g} = 1;
5290 }
5291 8 ▶ return ( "chown: invalid user: '$spec'", 0 ) if defined $u && length $u && $u ne 'root' && !$users->{$u};
Branch: 1 branch
BranchTrueFalseTotal
if defined $u and length $u and $u ne "root" and not $$users{$u} 1 7 8
Condition66%6/9
defined $u and length $u and $u ne "root" and not $$users{$u}
!ll&&!rl&&r
161
defined $u and length $u and $u ne "root"
!ll&&!rl&&r
017
defined $u and length $u
!ll&&!rl&&r
008
MC/DC50%2/4
defined $u and length $u and $u ne "root" and not $$users{$u}
defined $u length $u $u ne "root" not $$users{$u}
Truth table60%3/5
A and B and C and not(D)
A= defined $uB= length $uC= $u ne "root"D= not $$users{$u}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
5292 7 ▶ return ( "chown: invalid group: '$spec'", 0 ) if defined $g && length $g && !$groups{$g};
Branch: 1 branch
BranchTrueFalseTotal
if defined $g and length $g and not $groups{$g} 0 7 7
Condition66%4/6
defined $g and length $g and not $groups{$g}
!ll&&!rl&&r
250
defined $g and length $g
!ll&&!rl&&r
205
MC/DC0%0/3
defined $g and length $g and not $groups{$g}
defined $g length $g not $groups{$g}
Truth table50%2/4
A and B and not(C)
A= defined $gB= length $gC= not $groups{$g}
ABCresult
0XX0
10X0
1100
1111
5293 7 my ( $t, $bad ) = _targets( $dev, $rec, @a );
5294 7 ▶ return ( "chown: cannot access '$bad': No such file or directory", 0 ) unless $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 7 7
5295 7 for my $p (@$t) {
5296 10 my $e = _target_entry( $dev, $p );
5297 10 ▶ $e->{owner} = $u if defined $u && length $u && ( $e->{owner} // 'root' ) ne $u;
Branch: 1 branch
BranchTrueFalseTotal
if defined $u and length $u and ($$e{"owner"} // "root") ne $u 7 3 10
Condition62%5/8
defined $u and length $u and ($$e{"owner"} // "root") ne $u
!ll&&!rl&&r
037
defined $u and length $u
!ll&&!rl&&r
0010
$$e{"owner"} // "root"
l!l
91
MC/DC33%1/3
defined $u and length $u and ($$e{"owner"} // "root") ne $u
defined $u length $u $$e{"owner"}
Truth table50%2/4
A and B and C
A= defined $uB= length $uC= $$e{"owner"}
ABCresult
0XX0
10X0
1100
1111
5298 10 ▶ $e->{group} = $g if defined $g && length $g && ( $e->{group} // 'root' ) ne $g;
Branch: 1 branch
BranchTrueFalseTotal
if defined $g and length $g and ($$e{"group"} // "root") ne $g 4 6 10
Condition87%7/8
defined $g and length $g and ($$e{"group"} // "root") ne $g
!ll&&!rl&&r
244
defined $g and length $g
!ll&&!rl&&r
208
$$e{"group"} // "root"
l!l
71
MC/DC66%2/3
defined $g and length $g and ($$e{"group"} // "root") ne $g
defined $g length $g $$e{"group"}
Truth table75%3/4
A and B and C
A= defined $gB= length $gC= $$e{"group"}
ABCresult
0XX0
10X0
1100
1111
5299 }
5300 7 return ( '', 1 );
5301 }
5302  
5303 25 ▶sub _rm {
Subroutine _rm: called CC=40 SCAR=39.2
5304 25 my ( $dev, $av ) = @_;
5305 25 my @a = @$av;
5306 25 my ( $f, $r, $v ) = ( 0, 0, 0 );
5307 25 ▶ while ( @a && $a[0] =~ /\A-[rRfvi]+\z|\A--(?:force|recursive|verbose)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-[rRfvi]+\z|\A--(?:force|recursive|verbose)\z/) 8 25 33
Condition66%2/3
@a and $a[0] =~ /\A-[rRfvi]+\z|\A--(?:force|recursive|verbose)\z/
!ll&&!rl&&r
0258
MC/DC50%1/2
@a and $a[0] =~ /\A-[rRfvi]+\z|\A--(?:force|recursive|verbose)\z/
@a $a[0] =~ /\A-[rRfvi]+\z|\A--(?:force|recursive|verbose)\z/
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A-[rRfvi]+\z|\A--(?:force|recursive|verbose)\z/
ABresult
0X0
100
111
5308 8 my $o = shift @a;
5309 8 ▶ $f = 1 if $o =~ /f/;
Branch: 1 branch
BranchTrueFalseTotal
if $o =~ /f/ 6 2 8
5310 8 ▶ $r = 1 if $o =~ /r/i;
Branch: 1 branch
BranchTrueFalseTotal
if $o =~ /r/i 3 5 8
5311 8 ▶ $v = 1 if $o =~ /v/;
Branch: 1 branch
BranchTrueFalseTotal
if $o =~ /v/ 1 7 8
5312 }
5313 25 ▶ return ( 'rm: missing operand', 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 25 25
5314 25 my ( @out, $ok ) = ();
5315 25 $ok = 1;
5316 25 for my $raw (@a) { # wie GNU rm: Fehler je Operand, die uebrigen laufen weiter
5317 26 my $p = _absp($raw) =~ s{(?<=.)/+\z}{}r;
5318 26 my @gone;
5319 # als Benutzer: w und x am Elternordner (sticky: nur der Eigentuemer), x auf dem Weg
5320 26 ▶ if ( _who() ne 'root' && ( _file_entry( $dev, $p ) || _is_dir( $dev, $p ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_who() ne "root" and _file_entry($dev, $p) || _is_dir($dev, $p)) 4 22 26
Condition50%3/6
_who() ne "root" and _file_entry($dev, $p) || _is_dir($dev, $p)
!ll&&!rl&&r
2204
_file_entry($dev, $p) or _is_dir($dev, $p)
l!l&&r!l&&!r
400
MC/DC33%1/3
_who() ne "root" and _file_entry($dev, $p) || _is_dir($dev, $p)
_who() ne "root" _file_entry($dev, $p) _is_dir($dev, $p)
Truth table50%2/4
A and B or C
A= _who() ne "root"B= _file_entry($dev, $p)C= _is_dir($dev, $p)
ABCresult
0XX0
1000
11X1
1011
5321 4 ( my $par = $p ) =~ s{/[^/]+\z}{};
5322 4 ▶ $par = '/' unless length $par;
Branch: 1 branch
BranchTrueFalseTotal
unless length $par 0 4 4
5323 4 my $pm = _dir_meta( $dev, $par );
5324 4 ▶ my $owner = ( _file_entry( $dev, $p ) || _dir_meta( $dev, $p ) )->{owner} // 'root';
Condition40%2/5
(_file_entry($dev, $p) || _dir_meta($dev, $p))->{"owner"} // "root"
l!l
40
_file_entry($dev, $p) || _dir_meta($dev, $p)
l!l&&r!l&&!r
400
MC/DC0%0/2
(_file_entry($dev, $p) || _dir_meta($dev, $p))->{"owner"} // "root"
_file_entry($dev, $p) _dir_meta($dev, $p)
Truth table33%1/3
A || B
A= _file_entry($dev, $p)B= _dir_meta($dev, $p)
ABresult
1X1
011
000
5325 4 ▶ if ( !_traverse_ok( $dev, $p ) || !_dir_ok( $dev, $par, 2 ) || !_dir_ok( $dev, $par, 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (not _traverse_ok($dev, $p) && _dir_ok($dev, $par, 2) && _dir_ok($dev, $par, 1) or oct($$pm{"mode"} // "0755") & 512 and $owner ne _who() and ($$pm{"owner"} // "root") ne _who()) 3 1 4
Condition68%13/19
not _traverse_ok($dev, $p) && _dir_ok($dev, $par, 2) && _dir_ok($dev, $par, 1) or oct($$pm{"mode"} // "0755") & 512 and $owner ne _who() and ($$pm{"owner"} // "root") ne _who()
l!l&&r!l&&!r
211
_traverse_ok($dev, $p) && _dir_ok($dev, $par, 2) && _dir_ok($dev, $par, 1)
!ll&&!rl&&r
202
_traverse_ok($dev, $p) and _dir_ok($dev, $par, 2)
!ll&&!rl&&r
202
oct($$pm{"mode"} // "0755") & 512 and $owner ne _who() and ($$pm{"owner"} // "root") ne _who()
!ll&&!rl&&r
101
oct($$pm{"mode"} // "0755") & 512 and $owner ne _who()
!ll&&!rl&&r
101
$$pm{"mode"} // "0755"
l!l
20
$$pm{"owner"} // "root"
l!l
01
MC/DC16%1/6
not _traverse_ok($dev, $p) && _dir_ok($dev, $par, 2) && _dir_ok($dev, $par, 1) or oct($$pm{"mode"} // "0755") & 512 and $owner ne _who() and ($$pm{"owner"} // "root") ne _who()
_traverse_ok($dev, $p) _dir_ok($dev, $par, 2) _dir_ok($dev, $par, 1) $$pm{"mode"} $owner ne _who() $$pm{"owner"}
Truth table28%2/7
not(A and B && C) or D and E and F
A= _traverse_ok($dev, $p)B= _dir_ok($dev, $par, 2)C= _dir_ok($dev, $par, 1)D= $$pm{"mode"}E= $owner ne _who()F= $$pm{"owner"}
ABCDEFresult
0XXXXX1
10XXXX1
110XXX1
1111111
1110XX0
11110X0
1111100
5326 || ( oct( $pm->{mode} // '0755' ) & 01000 ) && $owner ne _who() && ( $pm->{owner} // 'root' ) ne _who() ) {
5327 3 push @out, "rm: cannot remove '$raw': Permission denied";
5328 3 $ok = 0;
5329 3 next;
5330 }
5331 }
5332 23 ▶ if ( _file_entry( $dev, $p ) ) { @gone = ($p) }
Branch: 2 branches
BranchTrueFalseTotal
if (_file_entry($dev, $p)) { } 21 2 23
elsif (_is_dir($dev, $p)) { } 1 1 2
5333 elsif ( _is_dir( $dev, $p ) ) {
5334 0 ▶ if ( !$r ) { push @out, "rm: cannot remove '$raw': Is a directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 1 1
5335 1 ▶ return ( "rm: it is dangerous to operate recursively on '/'", 0 ) if $p =~ m{\A/+\z};
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ m[\A/+\z] 0 1 1
5336 1 @gone = _under( $dev, $p );
5337 }
5338 else {
5339 1 ▶ next if $f;
Branch: 1 branch
BranchTrueFalseTotal
if $f 0 1 1
5340 1 push @out, "rm: cannot remove '$raw': No such file or directory";
5341 1 $ok = 0;
5342 1 next;
5343 }
5344 22 my @keep = _parents_of( $dev, $p );
5345 22 for my $g (@gone) {
5346 21 my $e = _file_entry( $dev, $g );
5347 21 ▶ my $svc = defined $e->{open_by} ? ( $dev->{services} || {} )->{ $e->{open_by} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $$e{'open_by'} ? : 1 20 21
Condition50%1/2
$$dev{'services'} || {}
l!l
10
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
5348 21 ▶ push @{ $dev->{deleted_open} }, { path => $g, size => _file_size($e), by => $e->{open_by} } if $svc && $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $svc and $$svc{"active"} 1 20 21
Condition66%2/3
$svc and $$svc{"active"}
!ll&&!rl&&r
2001
MC/DC50%1/2
$svc and $$svc{"active"}
$svc $$svc{"active"}
Truth table66%2/3
A and B
A= $svcB= $$svc{"active"}
ABresult
0X0
100
111
5349 21 delete $dev->{files}{$g};
5350 21 ▶ _maria()->can('file_removed')->( $dev, $g ) if $dev->{mariadb};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"mariadb"} 1 20 21
5351 21 ▶ push @out, "removed '$g'" if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 1 20 21
5352 }
5353 22 ▶ if ( !_file_entry( $dev, $p ) && _is_dir( $dev, $p ) ) { # rm -r: auch die angelegten Verzeichnisse darunter
Branch: 1 branch
BranchTrueFalseTotal
if (not _file_entry($dev, $p) and _is_dir($dev, $p)) 1 21 22
Condition66%2/3
not _file_entry($dev, $p) and _is_dir($dev, $p)
!ll&&!rl&&r
0211
MC/DC50%1/2
not _file_entry($dev, $p) and _is_dir($dev, $p)
not _file_entry($dev, $p) _is_dir($dev, $p)
Truth table66%2/3
not(A) and B
A= not _file_entry($dev, $p)B= _is_dir($dev, $p)
ABresult
0X0
100
111
5354 1 ( my $q = $p ) =~ s{(?<=.)/+\z}{};
5355 1 ▶ for my $k (qw( dirs _dirs )) { delete $dev->{$k}{$_} for grep { $_ eq $q || index( $_, "$q/" ) == 0 } keys %{ $dev->{$k} || {} } }
Condition80%4/5
$_ eq $q || index($_, "$q/") == 0
l!l&&r!l&&!r
125
$$dev{$k} || {}
l!l
20
MC/DC100%2/2
$_ eq $q || index($_, "$q/") == 0
$_ eq $q index($_, "$q/") == 0
MC/DC0%0/1
$$dev{$k} || {}
$$dev{$k}
Truth table100%3/3
A || B
A= $_ eq $qB= index($_, "$q/") == 0
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$dev{$k}
Aresult
11
00
5356 }
5357 22 _keep_dirs( $dev, @keep );
5358 }
5359 25 return ( join( "\n", @out ), $ok );
5360 }
5361  
5362 2 ▶sub _truncate {
Subroutine _truncate: called CC=8 SCAR=21.2
5363 2 my ( $dev, $av ) = @_;
5364 2 my @a = @$av;
5365 2 my $size;
5366 my @files;
5367 2 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 4 2 6
5368 4 my $x = shift @a;
5369 4 ▶ if ( $x eq '-s' ) { $size = shift @a }
Branch: 2 branches
BranchTrueFalseTotal
if ($x eq '-s') { } 2 2 4
elsif ($x =~ /\A--size=(.+)\z/) { } 0 2 2
5370 0 elsif ( $x =~ /\A--size=(.+)\z/ ) { $size = $1 }
5371 2 else { push @files, $x }
5372 }
5373 2 ▶ return ( "truncate: you must specify either '--size' or '--reference'", 0 ) unless defined $size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 0 2 2
5374 2 for my $p (@files) {
5375 2 my $e = _entry_rw( $dev, $p );
5376 2 my $b = _bytes($size);
5377 2 delete $e->{size};
5378 2 ▶ $e->{content} = substr( $e->{content} // '', 0, $b );
Condition50%1/2
$$e{"content"} // ""
l!l
20
MC/DC0%0/1
$$e{"content"} // ""
$$e{"content"}
Truth table50%1/2
A
A= $$e{"content"}
Aresult
11
00
5379 2 ▶ $e->{size} = $b if $b > length $e->{content};
Branch: 1 branch
BranchTrueFalseTotal
if $b > length $$e{"content"} 0 2 2
5380 }
5381 2 return ( '', 1 );
5382 }
5383  
5384 # touch [-a|-m|-c] [-d DATUM|--date=DATUM|-t [[CC]JJ]MMTThhmm[.ss]|-r DATEI] DATEI…:
5385 # setzt die Zeit (mtime) wie GNU — ohne Angabe jetzt (Uhr des Geraets), -d wie date -d
5386 # ("20 days ago", "2026-09-30 01:30", yesterday); -c legt nichts an
5387 19 ▶sub _touch {
Subroutine _touch: called CC=57 SCAR=52.5
5388 19 my ( $dev, $av ) = @_;
5389 19 my ( $when, $ref, $nocreate, @files );
5390 19 my @a = @$av;
5391 19 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 26 19 45
5392 26 my $x = shift @a;
5393 26 ▶ if ( $x eq '-d' || $x eq '--date' ) { $when = [ d => shift(@a) // '' ] }
Branch: 11 branches
BranchTrueFalseTotal
if ($x eq '-d' or $x eq '--date') { } 4 22 26
elsif ($x =~ /\A--date=(.*)\z/s) { } 0 22 22
elsif ($x =~ /\A-[acmhf]*d(.+)\z/s) { } 0 22 22
elsif ($x =~ /\A-[acmhf]*d\z/) { } 0 22 22
elsif ($x =~ /\A-[acmhf]*t\z/) { } 1 21 22
elsif ($x =~ /\A-[acmhf]*r\z/ or $x eq '--reference') { } 1 20 21
elsif ($x =~ /\A--reference=(.*)\z/) { } 0 20 20
elsif ($x =~ /\A-[acmhf]+\z/ or $x eq '--no-create') { } 1 19 20
elsif ($x eq '--') { } 0 19 19
elsif ($x =~ /\A--/) { } 0 19 19
elsif ($x =~ /\A-(.)/) { } 0 19 19
Condition60%3/5
$x eq "-d" or $x eq "--date"
l!l&&r!l&&!r
4022
shift @a // ""
l!l
40
MC/DC50%1/2
$x eq "-d" or $x eq "--date"
$x eq "-d" $x eq "--date"
MC/DC0%0/1
shift @a // ""
shift @a
Truth table66%2/3
A or B
A= $x eq "-d"B= $x eq "--date"
ABresult
1X1
011
000
Truth table50%1/2
A
A= shift @a
Aresult
11
00
5394 0 elsif ( $x =~ /\A--date=(.*)\z/s ) { $when = [ d => $1 ] }
5395 0 elsif ( $x =~ /\A-[acmhf]*d(.+)\z/s ) { $when = [ d => $1 ] }
5396 0 ▶ elsif ( $x =~ /\A-[acmhf]*d\z/ ) { $nocreate = 1 if $x =~ /c/; $when = [ d => shift(@a) // '' ] }
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /c/ 0 0 0
Condition0%0/2
shift @a // ""
l!l
00
MC/DC0%0/1
shift @a // ""
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
5397 1 ▶ elsif ( $x =~ /\A-[acmhf]*t\z/ ) { $nocreate = 1 if $x =~ /c/; $when = [ t => shift(@a) // '' ] }
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /c/ 0 1 1
Condition50%1/2
shift @a // ""
l!l
10
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
5398 1 ▶ elsif ( $x =~ /\A-[acmhf]*r\z/ || $x eq '--reference' ) { $nocreate = 1 if $x =~ /c/; $ref = shift(@a) // '' }
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /c/ 0 1 1
Condition60%3/5
$x =~ /\A-[acmhf]*r\z/ or $x eq "--reference"
l!l&&r!l&&!r
1020
shift @a // ""
l!l
10
MC/DC50%1/2
$x =~ /\A-[acmhf]*r\z/ or $x eq "--reference"
$x =~ /\A-[acmhf]*r\z/ $x eq "--reference"
MC/DC0%0/1
shift @a // ""
shift @a
Truth table66%2/3
A or B
A= $x =~ /\A-[acmhf]*r\z/B= $x eq "--reference"
ABresult
1X1
011
000
Truth table50%1/2
A
A= shift @a
Aresult
11
00
5399 0 elsif ( $x =~ /\A--reference=(.*)\z/ ) { $ref = $1 }
5400 1 ▶ elsif ( $x =~ /\A-[acmhf]+\z/ || $x eq '--no-create' ) { $nocreate = 1 if $x =~ /c/ || $x eq '--no-create' }
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /c/ or $x eq "--no-create" 1 0 1
Condition50%3/6
$x =~ /\A-[acmhf]+\z/ or $x eq "--no-create"
l!l&&r!l&&!r
1019
$x =~ /c/ or $x eq "--no-create"
l!l&&r!l&&!r
100
MC/DC50%1/2
$x =~ /\A-[acmhf]+\z/ or $x eq "--no-create"
$x =~ /\A-[acmhf]+\z/ $x eq "--no-create"
MC/DC0%0/2
$x =~ /c/ or $x eq "--no-create"
$x =~ /c/ $x eq "--no-create"
Truth table66%2/3
A or B
A= $x =~ /\A-[acmhf]+\z/B= $x eq "--no-create"
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $x =~ /c/B= $x eq "--no-create"
ABresult
1X1
011
000
5401 0 elsif ( $x eq '--' ) { push @files, @a; last }
5402 0 elsif ( $x =~ /\A--/ ) { return ( "touch: unrecognized option '$x'\nTry 'touch --help' for more information.", 0 ) }
5403 0 elsif ( $x =~ /\A-(.)/ ) { return ( "touch: invalid option -- '$1'\nTry 'touch --help' for more information.", 0 ) }
5404 19 else { push @files, $x }
5405 }
5406 19 ▶ return ( "touch: missing file operand\nTry 'touch --help' for more information.", 0 ) unless @files;
Branch: 1 branch
BranchTrueFalseTotal
unless @files 0 19 19
5407 19 my $mtime;
5408 19 ▶ if ( defined $ref ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $ref) { } 1 18 19
elsif ($when and $$when[0] eq 'd') { } 4 14 18
elsif ($when) { } 1 13 14
5409 1 ▶ my $re = _file_entry( $dev, _absp($ref) ) or return ( "touch: failed to get attributes of '$ref': No such file or directory", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $re = _file_entry($dev, _absp($ref)) or return "touch: failed to get attributes of '${ref}': No such file or directory", 0 1 0 1
5410 1 ▶ $mtime = $re->{mtime} // 'Oct 20 09:00';
Condition50%1/2
$$re{"mtime"} // "Oct 20 09:00"
l!l
10
MC/DC0%0/1
$$re{"mtime"} // "Oct 20 09:00"
$$re{"mtime"}
Truth table50%1/2
A
A= $$re{"mtime"}
Aresult
11
00
5411 }
5412 ▶ elsif ( $when && $when->[0] eq 'd' ) {
Condition100%3/3
$when and $$when[0] eq "d"
!ll&&!rl&&r
1314
MC/DC100%2/2
$when and $$when[0] eq "d"
$when $$when[0] eq "d"
Truth table100%3/3
A and B
A= $whenB= $$when[0] eq "d"
ABresult
0X0
100
111
5413 4 ▶ my $t = _date_parse( $when->[1], $dev->{timezone} // 'Europe/Berlin', 'Langertha::Holmgang::Sim::Linux::Calendar', _dev_now($dev) );
Condition50%1/2
$$dev{"timezone"} // "Europe/Berlin"
l!l
04
MC/DC0%0/1
$$dev{"timezone"} // "Europe/Berlin"
$$dev{"timezone"}
Truth table50%1/2
A
A= $$dev{"timezone"}
Aresult
11
00
5414 4 ▶ return ( "touch: invalid date format '$when->[1]'", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 1 3 4
5415 3 $mtime = _mtime_str($t);
5416 }
5417 elsif ($when) {
5418 1 ▶ my ( $y, $mo, $d, $h, $mi ) = $when->[1] =~ /\A(\d{4}|\d{2})?(\d\d)(\d\d)(\d\d)(\d\d)(?:\.\d\d)?\z/
Branch: 1 branch
BranchTrueFalseTotal
() = $$when[1] =~ /\A(\d{4}|\d{2})?(\d\d)(\d\d)(\d\d)(\d\d)(?:\.\d\d)?\z/ or return "touch: invalid date format '$$when[1]'", 0 1 0 1
5419 or return ( "touch: invalid date format '$when->[1]'", 0 );
5420 1 ▶ $y = !defined $y ? 2026 : length $y == 2 ? ( $y < 69 ? 2000 + $y : 1900 + $y ) : $y;
Branch: 3 branches
BranchTrueFalseTotal
!defined($y) ? : 0 1 1
length $y == 2 ? : 0 1 1
$y < 69 ? : 0 0 0
5421 1 ▶ return ( "touch: invalid date format '$when->[1]'", 0 ) if $mo < 1 || $mo > 12 || $d < 1 || $d > 31 || $h > 23 || $mi > 59;
Branch: 1 branch
BranchTrueFalseTotal
if $mo < 1 or $mo > 12 or $d < 1 or $d > 31 or $h > 23 or $mi > 59 0 1 1
Condition33%5/15
$mo < 1 or $mo > 12 or $d < 1 or $d > 31 or $h > 23 or $mi > 59
l!l&&r!l&&!r
001
$mo < 1 or $mo > 12 or $d < 1 or $d > 31 or $h > 23
l!l&&r!l&&!r
001
$mo < 1 or $mo > 12 or $d < 1 or $d > 31
l!l&&r!l&&!r
001
$mo < 1 or $mo > 12 or $d < 1
l!l&&r!l&&!r
001
$mo < 1 or $mo > 12
l!l&&r!l&&!r
001
MC/DC0%0/6
$mo < 1 or $mo > 12 or $d < 1 or $d > 31 or $h > 23 or $mi > 59
$mo < 1 $mo > 12 $d < 1 $d > 31 $h > 23 $mi > 59
Truth table14%1/7
A or B or C or D or E or F
A= $mo < 1B= $mo > 12C= $d < 1D= $d > 31E= $h > 23F= $mi > 59
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
5422 1 my $mon = (qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ))[ $mo - 1 ];
5423 1 ▶ $mtime = $y == 2026 ? sprintf( '%s %2d %02d:%02d', $mon, $d, $h, $mi ) : sprintf( '%s %2d %04d', $mon, $d, $y );
Branch: 1 branch
BranchTrueFalseTotal
$y == 2026 ? : 1 0 1
5424 }
5425 13 else { $mtime = _mtime_str( _dev_now($dev) ) }
5426 18 for my $raw (@files) {
5427 18 my $p = _absp($raw);
5428 18 ▶ if ( _file_entry( $dev, $p ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_file_entry($dev, $p)) 1 17 18
5429 1 ▶ return ( "touch: cannot touch '$raw': Permission denied", 0 ) if _may_create( $dev, $p );
Branch: 1 branch
BranchTrueFalseTotal
if _may_create($dev, $p) 0 1 1
5430 1 my $e = _entry_rw( $dev, $p );
5431 1 ▶ $e->{mtime} = $mtime unless ( $e->{mtime} // '' ) eq $mtime;
Branch: 1 branch
BranchTrueFalseTotal
unless ($$e{"mtime"} // "") eq $mtime 1 0 1
Condition50%1/2
$$e{"mtime"} // ""
l!l
01
MC/DC0%0/1
$$e{"mtime"} // ""
$$e{"mtime"}
Truth table50%1/2
A
A= $$e{"mtime"}
Aresult
11
00
5432 1 next;
5433 }
5434 17 ▶ next if _is_dir( $dev, $p ) || $nocreate;
Branch: 1 branch
BranchTrueFalseTotal
if _is_dir($dev, $p) or $nocreate 1 16 17
Condition66%2/3
_is_dir($dev, $p) or $nocreate
l!l&&r!l&&!r
0116
MC/DC50%1/2
_is_dir($dev, $p) or $nocreate
_is_dir($dev, $p) $nocreate
Truth table66%2/3
A or B
A= _is_dir($dev, $p)B= $nocreate
ABresult
1X1
011
000
5435 16 my ($dir) = $p =~ m{\A(.*)/[^/]+\z};
5436 16 ▶ return ( "touch: cannot touch '$raw': No such file or directory", 0 ) unless defined $dir && _is_dir( $dev, length $dir ? $dir : '/' );
Branch: 2 branches
BranchTrueFalseTotal
unless defined $dir and _is_dir($dev, length $dir ? $dir : "/") 0 16 16
length $dir ? : 16 0 16
Condition33%1/3
defined $dir and _is_dir($dev, length $dir ? $dir : "/")
!ll&&!rl&&r
0016
MC/DC0%0/2
defined $dir and _is_dir($dev, length $dir ? $dir : "/")
defined $dir _is_dir($dev, length $dir ? $dir : "/")
Truth table33%1/3
A and B
A= defined $dirB= _is_dir($dev, length $dir ? $dir : "/")
ABresult
0X0
100
111
5437 16 ▶ if ( my $err = _may_create( $dev, $p ) ) { return ( "touch: cannot touch '$raw': $err", 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = _may_create($dev, $p)) 4 12 16
5438 12 my $meta = _new_meta( $dev, $p, 0 );
5439 12 ▶ $dev->{files}{$p} = { content => '', %{ $meta || {} }, mtime => $mtime };
Condition100%2/2
$meta || {}
l!l
48
MC/DC100%1/1
$meta || {}
$meta
Truth table100%2/2
A
A= $meta
Aresult
11
00
5440 }
5441 14 return ( '', 1 );
5442 }
5443  
5444 # Forgejo-Server, den curl/wget mit dieser URL erreicht (das Geraet selbst oder ueber den Namen)
5445 60 ▶sub _forgejo_for {
Subroutine _forgejo_for: called CC=13 SCAR=27.6
5446 60 my ( $dev, $a ) = @_;
5447 60 my ($url) = grep {m{\Ahttps?://}} @$a;
5448 60 ▶ return $dev->{forgejo} ? $dev : undef unless defined $url;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $url 0 60 60
$$dev{'forgejo'} ? : 0 0 0
5449 60 my ($h) = $url =~ m{\Ahttps?://([^/:]+)};
5450 60 ▶ return $dev if $dev->{forgejo};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"forgejo"} 2 58 60
5451 58 ▶ my $st = ( $CTX || {} )->{state} || {};
Condition50%2/4
($Langertha::Holmgang::Sim::Linux::CTX || {})->{'state'} || {}
l!l
580
$Langertha::Holmgang::Sim::Linux::CTX || {}
l!l
580
MC/DC0%0/1
($Langertha::Holmgang::Sim::Linux::CTX || {})->{'state'} || {}
$Langertha::Holmgang::Sim::Linux::CTX
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::CTX
Aresult
11
00
5452 58 my $any;
5453 58 for my $k ( sort keys %$st ) {
5454 128 ▶ my $f = ref $st->{$k} eq 'HASH' && $st->{$k}{forgejo} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $f = ref $$st{$k} eq "HASH" && $$st{$k}{"forgejo"} or next 4 124 128
Condition66%2/3
ref $$st{$k} eq 'HASH' && $$st{$k}{'forgejo'}
!ll&&!rl&&r
01244
MC/DC50%1/2
ref $$st{$k} eq 'HASH' && $$st{$k}{'forgejo'}
ref $$st{$k} eq 'HASH' $$st{$k}{'forgejo'}
Truth table66%2/3
A && B
A= ref $$st{$k} eq 'HASH'B= $$st{$k}{'forgejo'}
ABresult
0X0
100
111
5455 4 ▶ ( my $root = $f->{root_url} // '' ) =~ s{\Ahttps?://([^/:]+).*}{$1}s;
Condition50%1/2
$$f{"root_url"} // ""
l!l
40
MC/DC0%0/1
$$f{"root_url"} // ""
$$f{"root_url"}
Truth table50%1/2
A
A= $$f{"root_url"}
Aresult
11
00
5456 4 ▶ return $st->{$k} if length $root && $h eq $root;
Branch: 1 branch
BranchTrueFalseTotal
if length $root and $h eq $root 2 2 4
Condition66%2/3
length $root and $h eq $root
!ll&&!rl&&r
022
MC/DC50%1/2
length $root and $h eq $root
length $root $h eq $root
Truth table66%2/3
A and B
A= length $rootB= $h eq $root
ABresult
0X0
100
111
5457 2 ▶ $any //= $st->{$k};
Condition33%1/3
$any //= $$st{$k}
l!l&&r!l&&!r
020
MC/DC0%0/2
$any //= $$st{$k}
$any $$st{$k}
Truth table33%1/3
A //= B
A= $anyB= $$st{$k}
ABresult
1X1
011
000
5458 }
5459 56 return $any; # in einer Welt mit Forgejo gibt es curl/wget; andere Ziele sind nicht erreichbar
5460 }
5461  
5462 0 ▶sub _dirname {
Subroutine _dirname: not called CC=5 SCAR=34.0
5463 0 my ( $dev, $av ) = @_;
5464 0 ▶ my @p = grep { !/\A-/ } @$av or return ( 'dirname: missing operand', 0 );
Branch: 1 branch
BranchTrueFalseTotal
my(@p) = grep({not /\A-/;} @$av) or return "dirname: missing operand", 0 0 0 0
5465 0 ▶ return ( join( "\n", map { my $d = $_; $d =~ s{/+\z}{} if length $d > 1; $d =~ s{/*[^/]*\z}{}; length $d ? $d : m{\A/} ? '/' : '.' } @p ), 1 );
Branch: 3 branches
BranchTrueFalseTotal
if length $d > 1 0 0 0
length $d ? : 0 0 0
m[\A/] ? : 0 0 0
5466 }
5467  
5468 0 ▶sub _basename {
Subroutine _basename: not called CC=4 SCAR=30.0
5469 0 my ( $dev, $av ) = @_;
5470 0 ▶ my @p = grep { !/\A-/ } @$av or return ( 'basename: missing operand', 0 );
Branch: 1 branch
BranchTrueFalseTotal
my(@p) = grep({not /\A-/;} @$av) or return "basename: missing operand", 0 0 0 0
5471 0 my ( $p, $suf ) = @p;
5472 0 ( my $b = $p ) =~ s{/+\z}{};
5473 0 $b =~ s{.*/}{};
5474 0 ▶ $b =~ s/\Q$suf\E\z// if defined $suf && $b ne $suf;
Branch: 1 branch
BranchTrueFalseTotal
if defined $suf and $b ne $suf 0 0 0
Condition0%0/3
defined $suf and $b ne $suf
!ll&&!rl&&r
000
MC/DC0%0/2
defined $suf and $b ne $suf
defined $suf $b ne $suf
Truth table0%0/3
A and B
A= defined $sufB= $b ne $suf
ABresult
0X0
100
111
5475 0 return ( $b, 1 );
5476 }
5477  
5478 0 ▶sub _hashsum {
Subroutine _hashsum: not called CC=5 SCAR=34.0
5479 0 my ( $alg, $dev, $av ) = @_;
5480 0 require Digest::MD5;
5481 0 require Digest::SHA;
5482 0 my ( @out, $ok );
5483 0 $ok = 1;
5484 0 for my $p ( grep { !/\A-/ } @$av ) {
5485 0 ▶ my $t = _file_entry( $dev, $p ) ? _file_text( $dev, $p ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
_file_entry($dev, $p) ? : 0 0 0
5486 0 ▶ if ( !defined $t ) { push @out, "${alg}sum: $p: No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 0 0 0
5487 0 my $bytes = Encode::encode( 'UTF-8', $t );
5488 0 ▶ push @out, ( $alg eq 'md5' ? Digest::MD5::md5_hex($bytes) : Digest::SHA::sha256_hex($bytes) ) . " $p";
Branch: 1 branch
BranchTrueFalseTotal
$alg eq 'md5' ? : 0 0 0
5489 }
5490 0 return ( join( "\n", @out ), $ok );
5491 }
5492  
5493 # gzip -d/-dc/-t, gunzip, zcat: echte gzip-Daten (z. B. aus einem Helm-Release-Secret)
5494 2 ▶sub _gzip {
Subroutine _gzip: called CC=23 SCAR=42.9
5495 2 my ( $mode, $dev, $av, $ctx, $stdin ) = @_;
5496 2 require IO::Uncompress::Gunzip;
5497 2 ▶ my $opt = join '', map { /\A-([a-z]+)\z/ ? $1 : '' } @$av;
Branch: 1 branch
BranchTrueFalseTotal
/\A-([a-z]+)\z/ ? : 1 0 1
5498 0 ▶ my $dec = $mode ne 'gzip' || $opt =~ /d/ || grep { $_ eq '--decompress' } @$av;
Condition50%3/6
$mode ne 'gzip' || $opt =~ /d/ || grep({$_ eq '--decompress';} @$av)
l!l&&r!l&&!r
200
$mode ne "gzip" or $opt =~ /d/
l!l&&r!l&&!r
110
MC/DC0%0/3
$mode ne 'gzip' || $opt =~ /d/ || grep({$_ eq '--decompress';} @$av)
$mode ne "gzip" $opt =~ /d/ grep({$_ eq '--decompress';} @$av)
Truth table50%2/4
A or B || C
A= $mode ne "gzip"B= $opt =~ /d/C= grep({$_ eq '--decompress';} @$av)
ABCresult
1XX1
01X1
0011
0000
5499 2 ▶ my $toout = $mode eq 'zcat' || $opt =~ /c/ || grep { $_ eq '--stdout' } @$av;
Condition66%4/6
$mode eq 'zcat' || $opt =~ /c/ || grep({$_ eq '--stdout';} @$av)
l!l&&r!l&&!r
101
$mode eq "zcat" or $opt =~ /c/
l!l&&r!l&&!r
101
MC/DC33%1/3
$mode eq 'zcat' || $opt =~ /c/ || grep({$_ eq '--stdout';} @$av)
$mode eq "zcat" $opt =~ /c/ grep({$_ eq '--stdout';} @$av)
Truth table50%2/4
A or B || C
A= $mode eq "zcat"B= $opt =~ /c/C= grep({$_ eq '--stdout';} @$av)
ABCresult
1XX1
01X1
0011
0000
5500 2 my $test = $opt =~ /t/;
5501 0 ▶ do { push @GAPS, join( ' ', $mode, @$av ); return ( '', 0 ) } unless $dec || $test;
Branch: 1 branch
BranchTrueFalseTotal
unless ($dec or $test) 0 2 2
Condition33%1/3
$dec or $test
l!l&&r!l&&!r
200
MC/DC0%0/2
$dec or $test
$dec $test
Truth table33%1/3
A or B
A= $decB= $test
ABresult
1X1
011
000
5502 2 my @f = grep { !/\A-/ } @$av;
5503 2 ▶ my @src = @f ? @f : (undef);
Branch: 1 branch
BranchTrueFalseTotal
@f ? : 0 2 2
5504 2 my ( @out, $ok );
5505 2 $ok = 1;
5506 2 for my $p (@src) {
5507 2 ▶ my $raw = defined $p ? ( _file_entry( $dev, $p ) ? _file_text( $dev, $p ) : undef ) : $stdin // '';
Branch: 2 branches
BranchTrueFalseTotal
defined $p ? : 0 2 2
_file_entry($dev, $p) ? : 0 0 0
Condition50%1/2
$stdin // ""
l!l
20
MC/DC0%0/1
$stdin // ""
$stdin
Truth table50%1/2
A
A= $stdin
Aresult
11
00
5508 0 ▶ if ( !defined $raw ) { push @out, "gzip: $p: No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $raw) 0 2 2
5509 2 ▶ my $bytes = utf8::is_utf8($raw) ? Encode::encode( 'UTF-8', $raw ) : $raw;
Branch: 1 branch
BranchTrueFalseTotal
utf8::is_utf8($raw) ? : 0 2 2
5510 2 my $plain;
5511 2 ▶ if ( substr( $bytes, 0, 2 ) ne "\x1f\x8b" || !IO::Uncompress::Gunzip::gunzip( \$bytes => \$plain ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($bytes, 0, 2) ne "\37\213" or not IO::Uncompress::Gunzip::gunzip(\$bytes, \$plain)) 0 2 2
Condition33%1/3
substr($bytes, 0, 2) ne "\37\213" or not IO::Uncompress::Gunzip::gunzip(\$bytes, \$plain)
l!l&&r!l&&!r
002
MC/DC0%0/2
substr($bytes, 0, 2) ne "\37\213" or not IO::Uncompress::Gunzip::gunzip(\$bytes, \$plain)
substr($bytes, 0, 2) ne "\37\213" not IO::Uncompress::Gunzip::gunzip(\$bytes, \$plain)
Truth table33%1/3
A or not(B)
A= substr($bytes, 0, 2) ne "\37\213"B= not IO::Uncompress::Gunzip::gunzip(\$bytes, \$plain)
ABresult
1X1
011
000
5512 0 ▶ push @out, 'gzip: ' . ( $p // 'stdin' ) . ': not in gzip format';
Condition0%0/2
$p // "stdin"
l!l
00
MC/DC0%0/1
$p // "stdin"
$p
Truth table0%0/2
A
A= $p
Aresult
11
00
5513 0 $ok = 0;
5514 0 next;
5515 }
5516 2 ▶ next if $test;
Branch: 1 branch
BranchTrueFalseTotal
if $test 0 2 2
5517 2 ▶ my $text = eval { Encode::decode( 'UTF-8', $plain, Encode::FB_CROAK() ) } // $plain;
Condition33%1/3
eval { do { &Encode::decode("UTF-8", $plain, 1) } } // $plain
l!l&&r!l&&!r
200
MC/DC0%0/2
eval { do { &Encode::decode("UTF-8", $plain, 1) } } // $plain
eval { do { &Encode::decode("UTF-8", $plain, 1) } } $plain
Truth table33%1/3
A // B
A= eval { do { &Encode::decode("UTF-8", $plain, 1) } }B= $plain
ABresult
1X1
011
000
5518 2 ▶ if ( $toout || !defined $p ) { push @out, $text; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($toout or not defined $p) 2 0 2
Condition66%2/3
$toout or not defined $p
l!l&&r!l&&!r
110
MC/DC0%0/2
$toout or not defined $p
$toout not defined $p
Truth table66%2/3
A or not(B)
A= $tooutB= not defined $p
ABresult
1X1
011
000
5519 0 ( my $to = $p ) =~ s/\.(?:gz|z|tgz)\z//i;
5520 0 ▶ $to = "$p.out" if $to eq $p;
Branch: 1 branch
BranchTrueFalseTotal
if $to eq $p 0 0 0
5521 0 $dev->{files}{$to} = $text;
5522 0 delete $dev->{files}{$p};
5523 }
5524 2 return ( join( '', @out ) =~ s/\n\z//r, $ok );
5525 }
5526  
5527 58 ▶sub _find {
Subroutine _find: called CC=116 SCAR=55.1
5528 58 my ( $dev, $av, $ctx ) = @_;
5529 58 my @a = @$av;
5530 58 my @roots;
5531 58 ▶ push @roots, shift @a while @a && $a[0] !~ /\A[-(!]/;
Branch: 1 branch
BranchTrueFalseTotal
@a and not $a[0] =~ /\A[-(!]/ and do { push @roots, shift @a } 58 58 116
Condition66%2/3
@a and not $a[0] =~ /\A[-(!]/
!ll&&!rl&&r
05858
MC/DC50%1/2
@a and not $a[0] =~ /\A[-(!]/
@a not $a[0] =~ /\A[-(!]/
Truth table66%2/3
A and not(B)
A= @aB= not $a[0] =~ /\A[-(!]/
ABresult
0X0
100
111
5532 58 ▶ @roots = ('.') unless @roots;
Branch: 1 branch
BranchTrueFalseTotal
unless @roots 0 58 58
5533 58 my ( $maxd, $mind, @exec, $has_action );
5534 # Ausdruck wie find: Tests und Aktionen als Code, Operatoren ! -a -o ( ) als Text
5535 58 my @tok;
5536 58 our ( @FIND_ACT, $FIND_PRUNE );
5537 58 ▶ my $glob = sub { my ( $g, $i ) = @_; ( my $r = quotemeta $g ) =~ s/\\\*/.*/g; $r =~ s/\\\?/./g; $r =~ s/\\\[/[/g; $r =~ s/\\\]/]/g; $i ? qr/\A$r\z/is : qr/\A$r\z/s };
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
$i ? : 0 31 31
5538 58 ▶ my $add = sub { push @tok, $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
5539 58 ▶ my $act = sub { my @x = @_; $has_action = 1; push @tok, sub { push @FIND_ACT, [@x]; 1 } };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
5540 58 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 152 57 209
5541 152 my $x = shift @a;
5542 152 ▶ my $need = sub { my $v = shift @a; defined $v or die "find: missing argument to `$x'\n"; $v };
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
defined $v or die "find: missing argument to `${x}'\n" 88 0 88
5543 152 my $v;
5544 152 ▶ if ( $x eq '!' || $x eq '-not' ) { push @tok, '!' }
Branch: 27 branches
BranchTrueFalseTotal
if ($x eq '!' or $x eq '-not') { } 5 147 152
elsif ($x eq '-o' or $x eq '-or') { } 13 134 147
elsif ($x eq '-a' or $x eq '-and') { } 1 133 134
elsif ($x eq '(' or $x eq ')') { } 11 122 133
elsif ($x eq '-name' or $x eq '-iname') { } 29 93 122
elsif ($x eq '-path' or $x eq '-wholename' or $x eq '-ipath') { } 2 91 93
elsif ($x eq '-perm') { } 18 73 91
elsif ($x eq '-size') { } 1 72 73
elsif ($x eq '-type') { } 26 46 72
elsif ($x eq '-user') { } 0 46 46
elsif ($x eq '-group') { } 0 46 46
elsif ($x eq '-nouser') { } 0 46 46
elsif ($x eq '-nogroup') { } 0 46 46
elsif ($x eq '-empty') { } 0 46 46
elsif ($x eq '-true') { } 0 46 46
elsif ($x eq '-false') { } 0 46 46
elsif ($x eq '-mtime' or $x eq '-mmin') { } 9 37 46
elsif ($x eq '-newer') { } 1 36 37
elsif ($x eq '-newermt') { } 1 35 36
elsif ($x eq '-maxdepth' or $x eq '-mindepth') { } 8 27 35
elsif ($x eq '-prune') { } 3 24 27
elsif ($x =~ /\A-(?:xdev|mount|depth|noleaf|ignore_readdir_race|follow)\z/ or $x eq '-L' or $x eq '-H' or $x eq '-P') { } 2 22 24
elsif ($x eq '-print' or $x eq '-print0') { } 7 15 22
elsif ($x eq '-ls') { } 2 13 15
elsif ($x eq '-printf') { } 1 12 13
elsif ($x eq '-exec' or $x eq '-execdir') { } 8 4 12
elsif ($x eq '-delete') { } 3 1 4
Condition100%3/3
$x eq "!" or $x eq "-not"
l!l&&r!l&&!r
23147
MC/DC100%2/2
$x eq "!" or $x eq "-not"
$x eq "!" $x eq "-not"
Truth table100%3/3
A or B
A= $x eq "!"B= $x eq "-not"
ABresult
1X1
011
000
5545 13 ▶ elsif ( $x eq '-o' || $x eq '-or' ) { push @tok, '-o' }
Condition66%2/3
$x eq "-o" or $x eq "-or"
l!l&&r!l&&!r
130134
MC/DC50%1/2
$x eq "-o" or $x eq "-or"
$x eq "-o" $x eq "-or"
Truth table66%2/3
A or B
A= $x eq "-o"B= $x eq "-or"
ABresult
1X1
011
000
5546 1 ▶ elsif ( $x eq '-a' || $x eq '-and' ) { push @tok, '-a' }
Condition66%2/3
$x eq "-a" or $x eq "-and"
l!l&&r!l&&!r
10133
MC/DC50%1/2
$x eq "-a" or $x eq "-and"
$x eq "-a" $x eq "-and"
Truth table66%2/3
A or B
A= $x eq "-a"B= $x eq "-and"
ABresult
1X1
011
000
5547 11 ▶ elsif ( $x eq '(' || $x eq ')' ) { push @tok, $x }
Condition100%3/3
$x eq "(" or $x eq ")"
l!l&&r!l&&!r
65122
MC/DC100%2/2
$x eq "(" or $x eq ")"
$x eq "(" $x eq ")"
Truth table100%3/3
A or B
A= $x eq "("B= $x eq ")"
ABresult
1X1
011
000
5548 ▶ elsif ( $x eq '-name' || $x eq '-iname' ) {
Condition66%2/3
$x eq "-name" or $x eq "-iname"
l!l&&r!l&&!r
29093
MC/DC50%1/2
$x eq "-name" or $x eq "-iname"
$x eq "-name" $x eq "-iname"
Truth table66%2/3
A or B
A= $x eq "-name"B= $x eq "-iname"
ABresult
1X1
011
000
5549 29 my $re = $glob->( $need->(), $x eq '-iname' );
5550 29 ▶ $add->( sub { ( my $b = $_[0] ) =~ s{.*/}{}; $b =~ $re } );
Subroutine __ANON__: called CC=1 SCAR=0.0
5551 }
5552 2 ▶ elsif ( $x eq '-path' || $x eq '-wholename' || $x eq '-ipath' ) { my $re = $glob->( $need->(), $x eq '-ipath' ); $add->( sub { $_[0] =~ $re } ) }
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition66%4/6
$x eq "-path" or $x eq "-wholename" or $x eq "-ipath"
l!l&&r!l&&!r
2091
$x eq "-path" or $x eq "-wholename"
l!l&&r!l&&!r
2091
MC/DC33%1/3
$x eq "-path" or $x eq "-wholename" or $x eq "-ipath"
$x eq "-path" $x eq "-wholename" $x eq "-ipath"
Truth table50%2/4
A or B or C
A= $x eq "-path"B= $x eq "-wholename"C= $x eq "-ipath"
ABCresult
1XX1
01X1
0011
0000
5553 elsif ( $x eq '-perm' ) {
5554 18 $v = $need->();
5555 18 ▶ my $perm = _find_perm($v) // return ( "find: invalid mode `$v'", 0 );
Condition50%1/2
_find_perm($v) // (return "find: invalid mode `${v}'", 0)
l!l
180
MC/DC0%0/1
_find_perm($v) // (return "find: invalid mode `${v}'", 0)
_find_perm($v)
Truth table50%1/2
A
A= _find_perm($v)
Aresult
11
00
5556 165 ▶ $add->( sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
5557 165 ▶ my $m = ( $_[2] eq 'd' ? oct( $_[1]{mode} // '0755' ) : _mode_of( $_[1] ) ) & 07777;
Branch: 1 branch
BranchTrueFalseTotal
$_[2] eq 'd' ? : 58 107 165
Condition50%1/2
$_[1]{"mode"} // "0755"
l!l
580
MC/DC0%0/1
$_[1]{"mode"} // "0755"
$_[1]{"mode"}
Truth table50%1/2
A
A= $_[1]{"mode"}
Aresult
11
00
5558 165 my ( $k, $want ) = @$perm;
5559 165 ▶ !( $k eq '-' && ( $m & $want ) != $want || $k eq '/' && $want && !( $m & $want ) || $k eq '' && $m != $want );
Condition94%17/18
$k eq '-' && ($m & $want) != $want || $k eq '/' && $want && !($m & $want) || $k eq '' && $m != $want
l!l&&r!l&&!r
1311123
$k eq "-" and ($m & $want) != $want or $k eq "/" and $want and not $m & $want
l!l&&r!l&&!r
1092234
$k eq "-" and ($m & $want) != $want
!ll&&!rl&&r
3719109
$k eq "/" and $want and not $m & $want
!ll&&!rl&&r
32222
$k eq "/" and $want
!ll&&!rl&&r
32024
$k eq "" and $m != $want
!ll&&!rl&&r
21211
MC/DC71%5/7
$k eq '-' && ($m & $want) != $want || $k eq '/' && $want && !($m & $want) || $k eq '' && $m != $want
$k eq "-" ($m & $want) != $want $k eq "/" $want not $m & $want $k eq "" $m != $want
Truth table28%6/21
A and B or C and D and not(E) || F and G
A= $k eq "-"B= ($m & $want) != $wantC= $k eq "/"D= $wantE= not $m & $wantF= $k eq ""G= $m != $want
ABCDEFGresult
11XXXXX1
0X111XX1
10111XX1
0X0XX111
0X10X111
0X110111
100XX111
1010X111
10110111
0X0XX0X0
0X0XX100
0X10X0X0
0X10X100
0X1100X0
0X110100
100XX0X0
100XX100
1010X0X0
1010X100
101100X0
10110100
5560 18 } );
5561 }
5562 elsif ( $x eq '-size' ) {
5563 1 $v = $need->();
5564 1 ▶ my ( $s, $n, $u ) = $v =~ /\A([+-]?)(\d+)([ckMG]?)\z/ or return ( "find: invalid -size argument `$v'", 0 );
Branch: 1 branch
BranchTrueFalseTotal
() = $v =~ /\A([+-]?)(\d+)([ckMG]?)\z/ or return "find: invalid -size argument `${v}'", 0 1 0 1
5565 1 my $lim = $n * { '' => 512, c => 1, k => 1024, M => 1024**2, G => 1024**3 }->{$u};
5566 1 ▶ $add->( sub { my $sz = $_[2] eq 'd' ? 4096 : _file_size( $_[1] ); $s eq '+' ? $sz > $lim : $s eq '-' ? $sz < $lim : $sz == $lim } );
Subroutine __ANON__: called CC=4 SCAR=15.2
Branch: 3 branches
BranchTrueFalseTotal
$_[2] eq 'd' ? : 3 1 4
$s eq '+' ? : 4 0 4
$s eq '-' ? : 0 0 0
5567 }
5568 elsif ( $x eq '-type' ) {
5569 26 $v = $need->();
5570 26 ▶ return ( "find: Unknown argument to -type: $v", 0 ) unless $v =~ /\A[fdl](?:,[fdl])*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ /\A[fdl](?:,[fdl])*\z/ 0 26 26
5571 26 my %t = map { $_ => 1 } split /,/, $v;
5572 26 ▶ $add->( sub { $t{ $_[2] } } );
Subroutine __ANON__: called CC=1 SCAR=0.0
5573 }
5574 0 ▶ elsif ( $x eq '-user' ) { $v = $need->(); $add->( sub { ( $_[1]{owner} // 'root' ) eq $v } ) }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[1]{"owner"} // "root"
l!l
00
MC/DC0%0/1
$_[1]{"owner"} // "root"
$_[1]{"owner"}
Truth table0%0/2
A
A= $_[1]{"owner"}
Aresult
11
00
5575 0 ▶ elsif ( $x eq '-group' ) { $v = $need->(); $add->( sub { ( $_[1]{group} // 'root' ) eq $v } ) }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[1]{"group"} // "root"
l!l
00
MC/DC0%0/1
$_[1]{"group"} // "root"
$_[1]{"group"}
Truth table0%0/2
A
A= $_[1]{"group"}
Aresult
11
00
5576 0 ▶ elsif ( $x eq '-nouser' ) { $add->( sub { my $o = $_[1]{owner} // 'root'; $o ne 'root' && !( $dev->{users} || {} )->{$o} } ) }
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
$o ne "root" and not +($$dev{"users"} || {})->{$o} 0 0 0
Condition0%0/4
$_[1]{"owner"} // "root"
l!l
00
$$dev{'users'} || {}
l!l
00
MC/DC0%0/1
$_[1]{"owner"} // "root"
$_[1]{"owner"}
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
Truth table0%0/2
A
A= $_[1]{"owner"}
Aresult
11
00
Truth table0%0/2
A
A= $$dev{'users'}
Aresult
11
00
5577 0 ▶ elsif ( $x eq '-nogroup' ) { $add->( sub { my $g = $_[1]{group} // 'root'; $g ne 'root' && !( $dev->{groups} || {} )->{$g} && !grep { $_ eq $g } map { @{ $_->{groups} || [] } } values %{ $dev->{users} || {} } } ) }
Subroutine __ANON__: not called CC=7 SCAR=40.3
Branch: 1 branch
BranchTrueFalseTotal
$g ne "root" and not +($$dev{"groups"} || {})->{$g} and not grep({$_ eq $g;} map({@{$$_{"groups"} or [];};} values %{$$dev{"users"} or {};})) 0 0 0
Condition0%0/11
$_[1]{"group"} // "root"
l!l
00
$g ne "root" and not +($$dev{"groups"} || {})->{$g}
!ll&&!rl&&r
000
$$dev{'groups'} || {}
l!l
00
$$_{'groups'} || []
l!l
00
$$dev{'users'} || {}
l!l
00
MC/DC0%0/1
$_[1]{"group"} // "root"
$_[1]{"group"}
MC/DC0%0/2
$g ne "root" and not +($$dev{"groups"} || {})->{$g}
$g ne "root" $$dev{'groups'}
MC/DC0%0/1
$$_{'groups'} || []
$$_{'groups'}
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
Truth table0%0/2
A
A= $_[1]{"group"}
Aresult
11
00
Truth table0%0/3
A and not(B)
A= $g ne "root"B= $$dev{'groups'}
ABresult
0X0
110
101
Truth table0%0/2
A
A= $$_{'groups'}
Aresult
11
00
Truth table0%0/2
A
A= $$dev{'users'}
Aresult
11
00
5578 0 ▶ elsif ( $x eq '-empty' ) { $add->( sub { $_[2] eq 'd' ? _ls_names_empty( $dev, $_[0] ) : _file_size( $_[1] ) == 0 } ) }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[2] eq 'd' ? : 0 0 0
5579 0 ▶ elsif ( $x eq '-true' ) { $add->( sub {1} ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
5580 0 ▶ elsif ( $x eq '-false' ) { $add->( sub {0} ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
5581 ▶ elsif ( $x eq '-mtime' || $x eq '-mmin' ) {
Condition66%2/3
$x eq "-mtime" or $x eq "-mmin"
l!l&&r!l&&!r
9037
MC/DC50%1/2
$x eq "-mtime" or $x eq "-mmin"
$x eq "-mtime" $x eq "-mmin"
Truth table66%2/3
A or B
A= $x eq "-mtime"B= $x eq "-mmin"
ABresult
1X1
011
000
5582 9 $v = $need->();
5583 9 ▶ my ( $sg, $n ) = $v =~ /\A([+-]?)(\d+)\z/ or return ( "find: invalid argument `$v' to `$x'", 0 );
Branch: 1 branch
BranchTrueFalseTotal
() = $v =~ /\A([+-]?)(\d+)\z/ or return "find: invalid argument `${v}' to `${x}'", 0 9 0 9
5584 9 ▶ my $unit = $x eq '-mtime' ? 86400 : 60;
Branch: 1 branch
BranchTrueFalseTotal
$x eq '-mtime' ? : 9 0 9
5585 9 my $lim = $n * $unit;
5586 22 ▶ $add->( sub {
Subroutine __ANON__: called CC=8 SCAR=23.7
5587 # ohne mtime im Zustand (Verzeichnisse, Vorgabe): gerade eben
5588 22 ▶ my $mt = ref $_[1] eq 'HASH' && defined $_[1]{mtime} ? _mtime( $_[1] ) : _local_now($dev);
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] eq 'HASH' && defined $_[1]{'mtime'} ? : 16 6 22
Condition66%2/3
ref $_[1] eq "HASH" and defined $_[1]{"mtime"}
!ll&&!rl&&r
0616
MC/DC50%1/2
ref $_[1] eq "HASH" and defined $_[1]{"mtime"}
ref $_[1] eq "HASH" defined $_[1]{"mtime"}
Truth table66%2/3
A and B
A= ref $_[1] eq "HASH"B= defined $_[1]{"mtime"}
ABresult
0X0
100
111
5589 22 my $d = int( ( _local_now($dev) - $mt ) / $unit ) * $unit;
5590 22 ▶ !( $sg eq '+' && $d <= $lim || $sg eq '-' && $d >= $lim || $sg eq '' && $d != $lim );
Condition53%8/15
$sg eq '+' && $d <= $lim || $sg eq '-' && $d >= $lim || $sg eq '' && $d != $lim
l!l&&r!l&&!r
10012
$sg eq "+" and $d <= $lim or $sg eq "-" and $d >= $lim
l!l&&r!l&&!r
10012
$sg eq "+" and $d <= $lim
!ll&&!rl&&r
01210
$sg eq "-" and $d >= $lim
!ll&&!rl&&r
1200
$sg eq "" and $d != $lim
!ll&&!rl&&r
1200
MC/DC16%1/6
$sg eq '+' && $d <= $lim || $sg eq '-' && $d >= $lim || $sg eq '' && $d != $lim
$sg eq "+" $d <= $lim $sg eq "-" $d >= $lim $sg eq "" $d != $lim
Truth table13%2/15
A and B or C and D || E and F
A= $sg eq "+"B= $d <= $limC= $sg eq "-"D= $d >= $limE= $sg eq ""F= $d != $lim
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
5591 9 } );
5592 }
5593 elsif ( $x eq '-newer' ) {
5594 1 $v = $need->();
5595 1 ▶ my $r = _file_entry( $dev, $v ) or return ( "find: '$v': No such file or directory", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $r = _file_entry($dev, $v) or return "find: '${v}': No such file or directory", 0 1 0 1
5596 1 my $t = _mtime($r);
5597 1 ▶ $add->( sub { _mtime( $_[1] ) > $t } );
Subroutine __ANON__: called CC=1 SCAR=0.0
5598 }
5599 elsif ( $x eq '-newermt' ) {
5600 1 $v = $need->();
5601 1 ▶ my $t = _parse_since( $v, _dev_now($dev) ) // return ( "find: I cannot figure out how to interpret '$v' as a date or time", 0 );
Condition50%1/2
_parse_since($v, _dev_now($dev)) // (return "find: I cannot figure out how to interpret '${v}' as a date or time", 0)
l!l
10
MC/DC0%0/1
_parse_since($v, _dev_now($dev)) // (return "find: I cannot figure out how to interpret '${v}' as a date or time", 0)
_parse_since($v, _dev_now($dev))
Truth table50%1/2
A
A= _parse_since($v, _dev_now($dev))
Aresult
11
00
5602 1 $t += Langertha::Holmgang::Sim::Linux::Calendar::offset($t); # mtime im Zustand ist Ortszeit
5603 1 ▶ $add->( sub { _mtime( $_[1] ) > $t } );
Subroutine __ANON__: called CC=1 SCAR=0.0
5604 }
5605 ▶ elsif ( $x eq '-maxdepth' || $x eq '-mindepth' ) {
Condition100%3/3
$x eq "-maxdepth" or $x eq "-mindepth"
l!l&&r!l&&!r
7127
MC/DC100%2/2
$x eq "-maxdepth" or $x eq "-mindepth"
$x eq "-maxdepth" $x eq "-mindepth"
Truth table100%3/3
A or B
A= $x eq "-maxdepth"B= $x eq "-mindepth"
ABresult
1X1
011
000
5606 8 ▶ $v = shift(@a) // '';
Condition50%1/2
shift @a // ""
l!l
80
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
5607 8 ▶ return ( "find: Expected a positive decimal integer argument to $x, but got `$v'", 0 ) unless $v =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ /\A\d+\z/ 0 8 8
5608 8 ▶ ( $x eq '-maxdepth' ? $maxd : $mind ) = $v;
Branch: 1 branch
BranchTrueFalseTotal
$x eq '-maxdepth' ? : 7 1 8
5609 }
5610 3 ▶ elsif ( $x eq '-prune' ) { $add->( sub { $FIND_PRUNE = 1 if $_[2] eq 'd'; 1 } ) } # wahr; nicht hinabsteigen
Subroutine __ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
if $_[2] eq "d" 3 0 3
5611 ▶ elsif ( $x =~ /\A-(?:xdev|mount|depth|noleaf|ignore_readdir_race|follow)\z/ || $x eq '-L' || $x eq '-H' || $x eq '-P' ) { }
Condition66%6/9
$x =~ /\A-(?:xdev|mount|depth|noleaf|ignore_readdir_race|follow)\z/ or $x eq "-L" or $x eq "-H" or $x eq "-P"
l!l&&r!l&&!r
2022
$x =~ /\A-(?:xdev|mount|depth|noleaf|ignore_readdir_race|follow)\z/ or $x eq "-L" or $x eq "-H"
l!l&&r!l&&!r
2022
$x =~ /\A-(?:xdev|mount|depth|noleaf|ignore_readdir_race|follow)\z/ or $x eq "-L"
l!l&&r!l&&!r
2022
MC/DC25%1/4
$x =~ /\A-(?:xdev|mount|depth|noleaf|ignore_readdir_race|follow)\z/ or $x eq "-L" or $x eq "-H" or $x eq "-P"
$x =~ /\A-(?:xdev|mount|depth|noleaf|ignore_readdir_race|follow)\z/ $x eq "-L" $x eq "-H" $x eq "-P"
Truth table40%2/5
A or B or C or D
A= $x =~ /\A-(?:xdev|mount|depth|noleaf|ignore_readdir_race|follow)\z/B= $x eq "-L"C= $x eq "-H"D= $x eq "-P"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
5612 7 ▶ elsif ( $x eq '-print' || $x eq '-print0' ) { $act->('print') }
Condition100%3/3
$x eq "-print" or $x eq "-print0"
l!l&&r!l&&!r
4315
MC/DC100%2/2
$x eq "-print" or $x eq "-print0"
$x eq "-print" $x eq "-print0"
Truth table100%3/3
A or B
A= $x eq "-print"B= $x eq "-print0"
ABresult
1X1
011
000
5613 2 elsif ( $x eq '-ls' ) { $act->('ls') }
5614 1 elsif ( $x eq '-printf' ) { $act->( 'printf', $need->() ) }
5615 ▶ elsif ( $x eq '-exec' || $x eq '-execdir' ) {
Condition66%2/3
$x eq "-exec" or $x eq "-execdir"
l!l&&r!l&&!r
804
MC/DC50%1/2
$x eq "-exec" or $x eq "-execdir"
$x eq "-exec" $x eq "-execdir"
Truth table66%2/3
A or B
A= $x eq "-exec"B= $x eq "-execdir"
ABresult
1X1
011
000
5616 8 my @c;
5617 8 ▶ push @c, shift @a while @a && $a[0] !~ /\A(?:;|\\;|\+)\z/;
Branch: 1 branch
BranchTrueFalseTotal
@a and not $a[0] =~ /\A(?:;|\\;|\+)\z/ and do { push @c, shift @a } 27 8 35
Condition66%2/3
@a and not $a[0] =~ /\A(?:;|\\;|\+)\z/
!ll&&!rl&&r
0827
MC/DC50%1/2
@a and not $a[0] =~ /\A(?:;|\\;|\+)\z/
@a not $a[0] =~ /\A(?:;|\\;|\+)\z/
Truth table66%2/3
A and not(B)
A= @aB= not $a[0] =~ /\A(?:;|\\;|\+)\z/
ABresult
0X0
100
111
5618 8 ▶ my $end = shift @a // return ( "find: missing argument to `$x'", 0 );
Condition50%1/2
shift @a // (return "find: missing argument to `${x}'", 0)
l!l
80
MC/DC0%0/1
shift @a // (return "find: missing argument to `${x}'", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
5619 8 ▶ $end = ';' if $end eq '\\;';
Branch: 1 branch
BranchTrueFalseTotal
if $end eq "\\;" 0 8 8
5620 8 ▶ return ( "find: In '$x ... {} +' you must place {} at the end", 0 ) if $end eq '+' && ( !@c || $c[-1] ne '{}' );
Branch: 1 branch
BranchTrueFalseTotal
if $end eq "+" and !@c || $c[-1] ne "{}" 0 8 8
Condition50%3/6
$end eq "+" and !@c || $c[-1] ne "{}"
!ll&&!rl&&r
620
not @c or $c[-1] ne "{}"
l!l&&r!l&&!r
002
MC/DC0%0/3
$end eq "+" and !@c || $c[-1] ne "{}"
$end eq "+" not @c $c[-1] ne "{}"
Truth table50%2/4
A and not(B) or C
A= $end eq "+"B= not @cC= $c[-1] ne "{}"
ABCresult
0XX0
1000
11X1
1011
5621 8 push @exec, [ \@c, $end ];
5622 8 $act->( 'exec', $#exec );
5623 }
5624 3 elsif ( $x eq '-delete' ) { $act->('delete') }
5625 1 else { return ( "find: unknown predicate `$x'", 0 ) }
5626 }
5627 # Vorrang wie find: ( ) vor ! vor -a (auch ohne Wort) vor -o
5628 57 my $pos = 0;
5629 57 my ( $p_or, $p_and, $p_un );
5630 122 ▶ $p_un = sub {
Subroutine __ANON__: called CC=15 SCAR=28.0
5631 122 my $t = $tok[$pos];
5632 122 ▶ die "find: expected an expression at the end\n" unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 122 122
5633 122 ▶ if ( !ref $t && $t eq '!' ) { $pos++; my $e = $p_un->(); return sub { !$e->(@_) } }
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $t and $t eq "!") 5 117 122
Condition100%3/3
not ref $t and $t eq "!"
!ll&&!rl&&r
11075
MC/DC100%2/2
not ref $t and $t eq "!"
not ref $t $t eq "!"
Truth table100%3/3
not(A) and B
A= not ref $tB= $t eq "!"
ABresult
0X0
100
111
5634 117 ▶ if ( !ref $t && $t eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $t and $t eq "(") 6 111 117
Condition100%3/3
not ref $t and $t eq "("
!ll&&!rl&&r
11016
MC/DC100%2/2
not ref $t and $t eq "("
not ref $t $t eq "("
Truth table100%3/3
not(A) and B
A= not ref $tB= $t eq "("
ABresult
0X0
100
111
5635 6 $pos++;
5636 6 ▶ die "find: empty parentheses are not allowed in argument list\n" if defined $tok[$pos] && $tok[$pos] eq ')';
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok[$pos] and $tok[$pos] eq ")" 0 6 6
Condition33%1/3
defined $tok[$pos] and $tok[$pos] eq ")"
!ll&&!rl&&r
060
MC/DC0%0/2
defined $tok[$pos] and $tok[$pos] eq ")"
defined $tok[$pos] $tok[$pos] eq ")"
Truth table33%1/3
A and B
A= defined $tok[$pos]B= $tok[$pos] eq ")"
ABresult
0X0
100
111
5637 6 my $e = $p_or->();
5638 6 ▶ die "find: invalid expression; you have too many '('\n" unless defined $tok[$pos] && !ref $tok[$pos] && $tok[$pos] eq ')';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tok[$pos] and not ref $tok[$pos] and $tok[$pos] eq ")" 1 5 6
Condition66%4/6
defined $tok[$pos] and not ref $tok[$pos] and $tok[$pos] eq ")"
!ll&&!rl&&r
105
defined $tok[$pos] and not ref $tok[$pos]
!ll&&!rl&&r
105
MC/DC33%1/3
defined $tok[$pos] and not ref $tok[$pos] and $tok[$pos] eq ")"
defined $tok[$pos] not ref $tok[$pos] $tok[$pos] eq ")"
Truth table50%2/4
A and not(B) and C
A= defined $tok[$pos]B= not ref $tok[$pos]C= $tok[$pos] eq ")"
ABCresult
0XX0
10X0
1100
1111
5639 5 $pos++;
5640 5 return $e;
5641 }
5642 111 ▶ die "find: invalid expression; you have used a binary operator '$t' with nothing before it.\n" if !ref $t && ( $t eq '-o' || $t eq '-a' );
Branch: 1 branch
BranchTrueFalseTotal
if not ref $t and $t eq "-o" || $t eq "-a" 1 110 111
Condition50%3/6
not ref $t and $t eq "-o" || $t eq "-a"
!ll&&!rl&&r
11001
$t eq "-o" or $t eq "-a"
l!l&&r!l&&!r
100
MC/DC33%1/3
not ref $t and $t eq "-o" || $t eq "-a"
not ref $t $t eq "-o" $t eq "-a"
Truth table50%2/4
not(A) and B or C
A= not ref $tB= $t eq "-o"C= $t eq "-a"
ABCresult
0XX0
1000
11X1
1011
5643 110 ▶ die "find: invalid expression; you have too many ')'\n" if !ref $t;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $t 0 110 110
5644 110 $pos++;
5645 110 return $t;
5646 57 };
5647 72 ▶ $p_and = sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
5648 72 my @e = ( $p_un->() );
5649 70 ▶ while ( defined( my $t = $tok[$pos] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $t = $tok[$pos])) 62 53 115
5650 62 ▶ last if !ref $t && ( $t eq '-o' || $t eq ')' );
Branch: 1 branch
BranchTrueFalseTotal
if not ref $t and $t eq "-o" || $t eq ")" 17 45 62
Condition100%6/6
not ref $t and $t eq "-o" || $t eq ")"
!ll&&!rl&&r
38717
$t eq "-o" or $t eq ")"
l!l&&r!l&&!r
1257
MC/DC100%3/3
not ref $t and $t eq "-o" || $t eq ")"
not ref $t $t eq "-o" $t eq ")"
Truth table100%4/4
not(A) and B or C
A= not ref $tB= $t eq "-o"C= $t eq ")"
ABCresult
0XX0
1000
11X1
1011
5651 45 ▶ $pos++ if !ref $t && $t eq '-a';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $t and $t eq "-a" 1 44 45
Condition100%3/3
not ref $t and $t eq "-a"
!ll&&!rl&&r
3861
MC/DC100%2/2
not ref $t and $t eq "-a"
not ref $t $t eq "-a"
Truth table100%3/3
not(A) and B
A= not ref $tB= $t eq "-a"
ABresult
0X0
100
111
5652 45 push @e, $p_un->();
5653 }
5654 70 ▶ return @e == 1 ? $e[0] : sub { for my $f (@e) { return 0 unless $f->(@_) } 1 };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@e == 1 ? : 32 38 70
unless &$f(@_) 187 174 361
5655 57 };
5656 60 ▶ $p_or = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
5657 60 my @e = ( $p_and->() );
5658 58 ▶ while ( defined( my $t = $tok[$pos] ) && !ref $tok[$pos] && $tok[$pos] eq '-o' ) { $pos++; push @e, $p_and->() }
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $t = $tok[$pos]) and not ref $tok[$pos] and $tok[$pos] eq "-o") 12 58 70
Condition83%5/6
defined(my $t = $tok[$pos]) and not ref $tok[$pos] and $tok[$pos] eq "-o"
!ll&&!rl&&r
53512
defined(my $t = $tok[$pos]) and not ref $tok[$pos]
!ll&&!rl&&r
53017
MC/DC66%2/3
defined(my $t = $tok[$pos]) and not ref $tok[$pos] and $tok[$pos] eq "-o"
defined(my $t = $tok[$pos]) not ref $tok[$pos] $tok[$pos] eq "-o"
Truth table75%3/4
A and not(B) and C
A= defined(my $t = $tok[$pos])B= not ref $tok[$pos]C= $tok[$pos] eq "-o"
ABCresult
0XX0
10X0
1100
1111
5659 58 ▶ return @e == 1 ? $e[0] : sub { for my $f (@e) { return 1 if $f->(@_) } 0 };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@e == 1 ? : 46 12 58
if &$f(@_) 30 132 162
5660 57 };
5661 57 ▶ my $expr = sub {1};
Subroutine __ANON__: called CC=1 SCAR=0.0
5662 57 ▶ if (@tok) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tok) 54 3 57
5663 54 ▶ $expr = eval { my $e = $p_or->(); die "find: invalid expression; you have too many ')'\n" if $pos < @tok; $e };
Branch: 1 branch
BranchTrueFalseTotal
if $pos < @tok 0 52 52
5664 54 ▶ if ( my $err = $@ ) { $err =~ s/\s+\z//; return ( $err, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 2 52 54
5665 }
5666 55 my ( @hit, @err );
5667 55 for my $r (@roots) {
5668 55 ( my $root = $r ) =~ s{(?<=.)/+\z}{};
5669 0 ▶ if ( !_is_dir( $dev, $root ) && !_file_entry( $dev, $root ) ) { push @err, "find: '$r': No such file or directory"; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (_is_dir($dev, $root) or _file_entry($dev, $root)) 0 55 55
Condition33%1/3
_is_dir($dev, $root) or _file_entry($dev, $root)
l!l&&r!l&&!r
5500
MC/DC0%0/2
_is_dir($dev, $root) or _file_entry($dev, $root)
_is_dir($dev, $root) _file_entry($dev, $root)
Truth table33%1/3
A or B
A= _is_dir($dev, $root)B= _file_entry($dev, $root)
ABresult
1X1
011
000
5670 55 my @cand = ( [ $root, 0 ] );
5671 55 ▶ if ( !_file_entry( $dev, $root ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_file_entry($dev, $root)) 55 0 55
5672 55 my %seen;
5673 55 ▶ my $pre = $root eq '/' ? '/' : "$root/";
Branch: 1 branch
BranchTrueFalseTotal
$root eq '/' ? : 6 49 55
5674 55 ▶ for my $p ( keys %{ $dev->{files} || {} }, keys %{ $dev->{dirs} || {} }, keys %{ $dev->{_dirs} || {} } ) {
Condition83%5/6
$$dev{'files'} || {}
l!l
550
$$dev{'dirs'} || {}
l!l
1441
$$dev{'_dirs'} || {}
l!l
154
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
MC/DC100%1/1
$$dev{'dirs'} || {}
$$dev{'dirs'}
MC/DC100%1/1
$$dev{'_dirs'} || {}
$$dev{'_dirs'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
Truth table100%2/2
A
A= $$dev{'dirs'}
Aresult
11
00
Truth table100%2/2
A
A= $$dev{'_dirs'}
Aresult
11
00
5675 490 ▶ next unless index( $p, $pre ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless index($p, $pre) == 0 293 197 490
5676 197 my @seg = split m{/}, substr( $p, length $pre );
5677 197 $seen{ $pre . join( '/', @seg[ 0 .. $_ ] ) } = $_ + 1 for 0 .. $#seg;
5678 }
5679 55 push @cand, map { [ $_, $seen{$_} ] } sort keys %seen;
5680 }
5681 55 my @pruned; # Eltern stehen vor ihren Kindern (sortiert)
5682 55 for my $c (@cand) {
5683 355 my ( $p, $depth ) = @$c;
5684 355 ▶ next if grep { index( $p, "$_/" ) == 0 } @pruned;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($p, "$_/") == 0;} @pruned 3 352 355
5685 352 ▶ next if defined $maxd && $depth > $maxd;
Branch: 1 branch
BranchTrueFalseTotal
if defined $maxd and $depth > $maxd 7 345 352
Condition100%3/3
defined $maxd and $depth > $maxd
!ll&&!rl&&r
321247
MC/DC100%2/2
defined $maxd and $depth > $maxd
defined $maxd $depth > $maxd
Truth table100%3/3
A and B
A= defined $maxdB= $depth > $maxd
ABresult
0X0
100
111
5686 345 ▶ next if defined $mind && $depth < $mind;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mind and $depth < $mind 1 344 345
Condition100%3/3
defined $mind and $depth < $mind
!ll&&!rl&&r
34041
MC/DC100%2/2
defined $mind and $depth < $mind
defined $mind $depth < $mind
Truth table100%3/3
A and B
A= defined $mindB= $depth < $mind
ABresult
0X0
100
111
5687 344 my $fe = _file_entry( $dev, $p );
5688 344 ▶ my $kind = $fe ? ( defined $fe->{link} ? 'l' : 'f' ) : 'd';
Branch: 2 branches
BranchTrueFalseTotal
$fe ? : 177 167 344
defined $$fe{'link'} ? : 0 177 177
5689 344 ▶ my $e = $fe // { mode => '0755', %{ ( $dev->{dirs} || {} )->{$p} || {} } };
Condition100%6/6
$fe // {"mode", "0755", %{($$dev{"dirs"} || {})->{$p} or {};}}
l!l
177167
($$dev{'dirs'} || {})->{$p} || {}
l!l
18149
$$dev{'dirs'} || {}
l!l
32135
MC/DC100%1/1
$fe // {"mode", "0755", %{($$dev{"dirs"} || {})->{$p} or {};}}
$fe
MC/DC100%1/1
($$dev{'dirs'} || {})->{$p} || {}
$$dev{'dirs'}
Truth table100%2/2
A
A= $fe
Aresult
11
00
Truth table100%2/2
A
A= $$dev{'dirs'}
Aresult
11
00
5690 344 local @FIND_ACT = ();
5691 344 local $FIND_PRUNE;
5692 344 my $match = $expr->( $p, $e, $kind );
5693 344 ▶ push @pruned, $p if $FIND_PRUNE;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::FIND_PRUNE 3 341 344
5694 344 ▶ if ($has_action) { push @hit, [ $p, $e, $kind, [@FIND_ACT] ] if @FIND_ACT }
Branch: 3 branches
BranchTrueFalseTotal
if ($has_action) { } 112 232 344
elsif ($match) { } 61 171 232
if @Langertha::Holmgang::Sim::Linux::FIND_ACT 39 73 112
5695 61 elsif ($match) { push @hit, [ $p, $e, $kind, [ ['print'] ] ] }
5696 }
5697 }
5698 55 my @out = @err;
5699 55 ▶ my $ok = @err ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
@err ? : 0 55 55
5700 55 my ( %exec_paths, @del, $txt );
5701 55 $txt = '';
5702 55 for my $h (@hit) {
5703 100 my ( $p, $e, $kind, $acts ) = @$h;
5704 100 for my $a (@$acts) {
5705 100 ▶ if ( $a->[0] eq 'print' ) { $txt .= "$p\n" }
Branch: 5 branches
BranchTrueFalseTotal
if ($$a[0] eq 'print') { } 75 25 100
elsif ($$a[0] eq 'ls') { } 3 22 25
elsif ($$a[0] eq 'printf') { } 1 21 22
elsif ($$a[0] eq 'exec') { } 16 5 21
elsif ($$a[0] eq 'delete') { } 5 0 5
5706 3 elsif ( $a->[0] eq 'ls' ) { $txt .= _ls_line( $dev, $p, $p ) . "\n" }
5707 1 elsif ( $a->[0] eq 'printf' ) { $txt .= _find_printf( $dev, $a->[1], $p, $e, $kind ) }
5708 16 elsif ( $a->[0] eq 'exec' ) { push @{ $exec_paths{ $a->[1] } }, $p }
5709 5 elsif ( $a->[0] eq 'delete' ) { push @del, $p }
5710 }
5711 }
5712 55 $txt =~ s/\n\z//;
5713 55 ▶ push @out, $txt if length $txt;
Branch: 1 branch
BranchTrueFalseTotal
if length $txt 42 13 55
5714 55 for my $i ( 0 .. $#exec ) {
5715 8 my ( $c, $end ) = @{ $exec[$i] };
5716 8 ▶ my @paths = @{ $exec_paths{$i} || [] };
Condition50%1/2
$exec_paths{$i} || []
l!l
80
MC/DC0%0/1
$exec_paths{$i} || []
$exec_paths{$i}
Truth table50%1/2
A
A= $exec_paths{$i}
Aresult
11
00
5717 6 ▶ my @runs = $end eq '+' ? ( @paths ? [ map { $_ eq '{}' ? @paths : $_ } @$c ] : () )
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '{}' ? : 2 4 6
5718 8 ▶ : map { my $h = $_; [ map { $_ eq '{}' ? $h : s/\{\}/$h/gr } @$c ] } @paths;
Branch: 3 branches
BranchTrueFalseTotal
$end eq '+' ? : 2 6 8
@paths ? : 2 0 2
$_ eq '{}' ? : 12 31 43
5719 8 for my $argv (@runs) {
5720 14 my ( $o, $k ) = __PACKAGE__->_command( $dev, $argv, $ctx, undef );
5721 14 ▶ push @out, $o if defined $o && length $o;
Branch: 1 branch
BranchTrueFalseTotal
if defined $o and length $o 9 5 14
Condition66%2/3
defined $o and length $o
!ll&&!rl&&r
059
MC/DC50%1/2
defined $o and length $o
defined $o length $o
Truth table66%2/3
A and B
A= defined $oB= length $o
ABresult
0X0
100
111
5722 14 ▶ $ok = 0 unless $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $k 2 12 14
5723 }
5724 }
5725 55 for my $p ( reverse @del ) {
5726 5 ▶ if ( _file_entry( $dev, $p ) ) { my ( $o, $k ) = _rm( $dev, [$p] ); push @out, $o if length $o }
Branch: 3 branches
BranchTrueFalseTotal
if (_file_entry($dev, $p)) { } 5 0 5
elsif (_ls_names_empty($dev, $p)) { } 0 0 0
if length $o 0 5 5
5727 0 ▶ elsif ( _ls_names_empty( $dev, $p ) ) { delete $dev->{dirs}{$p}; delete $dev->{_dirs}{$p} if $dev->{_dirs} }
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"_dirs"} 0 0 0
5728 0 else { push @out, "find: cannot delete '$p': Directory not empty"; $ok = 0 }
5729 }
5730 55 return ( join( "\n", @out ), $ok );
5731 }
5732  
5733 # find -printf: %p %f %h %s %u %g %m %M %l %y %t %T+ %TY-%Tm-%Td, \n \t
5734 1 ▶sub _find_printf {
Subroutine _find_printf: called CC=9 SCAR=24.1
5735 1 my ( $dev, $fmt, $p, $e, $kind ) = @_;
5736 1 my $t = _mtime($e); # Ortszeit
5737 1 my @g = gmtime $t;
5738 1 my ( $base, $dir ) = ( $p =~ m{([^/]*)\z} )[0];
5739 1 ( $dir = $p ) =~ s{/[^/]*\z}{};
5740 1 ▶ my $m = $kind eq 'd' ? oct( $e->{mode} // '0755' ) : _mode_of($e);
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'd' ? : 0 1 1
Condition0%0/2
$$e{"mode"} // "0755"
l!l
00
MC/DC0%0/1
$$e{"mode"} // "0755"
$$e{"mode"}
Truth table0%0/2
A
A= $$e{"mode"}
Aresult
11
00
5741 my %f = (
5742 p => $p, f => $base, h => length $dir ? $dir : '.', s => $kind eq 'd' ? 4096 : _file_size($e), u => $e->{owner} // 'root',
5743 g => $e->{group} // 'root', m => sprintf( '%o', $m & 07777 ), M => _mode_text( $m, $kind eq 'd', $kind eq 'l' ),
5744 1 ▶ l => $kind eq 'l' ? $e->{link} : '', y => $kind, t => scalar gmtime($t),
Branch: 3 branches
BranchTrueFalseTotal
length $dir ? : 1 0 1
$kind eq 'd' ? : 0 1 1
$kind eq 'l' ? : 0 1 1
Condition50%2/4
$$e{"owner"} // "root"
l!l
10
$$e{"group"} // "root"
l!l
01
MC/DC0%0/1
$$e{"owner"} // "root"
$$e{"owner"}
MC/DC0%0/1
$$e{"group"} // "root"
$$e{"group"}
Truth table50%1/2
A
A= $$e{"owner"}
Aresult
11
00
Truth table50%1/2
A
A= $$e{"group"}
Aresult
11
00
5745 '%' => '%',
5746 );
5747 1 my %T = ( '+' => sprintf( '%04d-%02d-%02d+%02d:%02d:%02d.0000000000', $g[5] + 1900, $g[4] + 1, $g[3], $g[2], $g[1], $g[0] ),
5748 Y => sprintf( '%04d', $g[5] + 1900 ), m => sprintf( '%02d', $g[4] + 1 ), d => sprintf( '%02d', $g[3] ), H => sprintf( '%02d', $g[2] ),
5749 M => sprintf( '%02d', $g[1] ), S => sprintf( '%02d', $g[0] ), F => sprintf( '%04d-%02d-%02d', $g[5] + 1900, $g[4] + 1, $g[3] ),
5750 T => sprintf( '%02d:%02d:%02d', $g[2], $g[1], $g[0] ) );
5751 1 ( my $s = $fmt ) =~ s/\\n/\n/g;
5752 1 $s =~ s/\\t/\t/g;
5753 1 $s =~ s/%[TA]([+YmdHMSFT])/$T{$1}/g;
5754 1 ▶ $s =~ s/%(-?\d*)([pfhsugmMlyt%])/length $1 ? sprintf( "%$1s", $f{$2} ) : $f{$2}/ge;
Branch: 1 branch
BranchTrueFalseTotal
length $1 ? : 0 3 3
5755 1 return $s;
5756 }
5757  
5758 0 ▶sub _ls_names_empty { my ( $dev, $p ) = @_; return !%{ _ls_names( $dev, $p ) } }
Subroutine _ls_names_empty: not called CC=1 SCAR=6.9
5759  
5760 # -perm [-/]oktal | [-/]u=s,g+w… -> [ art, maske ]
5761 18 ▶sub _find_perm {
Subroutine _find_perm: called CC=11 SCAR=26.8
5762 18 my ($v) = @_;
5763 18 ▶ my ( $kind, $rest ) = $v =~ /\A([-\/]?)(.+)\z/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = $v =~ m[\A([-/]?)(.+)\z] or return undef 18 0 18
5764 18 ▶ return [ $kind, oct $rest ] if $rest =~ /\A[0-7]{1,4}\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\A[0-7]{1,4}\z/ 17 1 18
5765 1 my $m = 0;
5766 1 for my $part ( split /,/, $rest ) {
5767 2 ▶ my ( $who, $p ) = $part =~ /\A([ugoa]*)[+=]([rwxst]+)\z/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = $part =~ /\A([ugoa]*)[+=]([rwxst]+)\z/ or return undef 2 0 2
5768 2 ▶ $who = 'a' if $who eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $who eq "" 0 2 2
5769 2 ▶ for my $w ( $who =~ /a/ ? qw( u g o ) : split //, $who ) {
Branch: 1 branch
BranchTrueFalseTotal
$who =~ /a/ ? : 0 2 2
5770 2 my $sh = { u => 6, g => 3, o => 0 }->{$w};
5771 2 for ( split //, $p ) {
5772 2 ▶ if ( $_ eq 's' ) { $m |= { u => 04000, g => 02000, o => 0 }->{$w} }
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq 's') { } 2 0 2
elsif ($_ eq 't') { } 0 0 0
5773 0 elsif ( $_ eq 't' ) { $m |= 01000 }
5774 0 else { $m |= { r => 4, w => 2, x => 1 }->{$_} << $sh }
5775 }
5776 }
5777 }
5778 1 return [ $kind, $m ];
5779 }
5780  
5781 1 ▶sub _lsof {
Subroutine _lsof: called CC=15 SCAR=40.6
5782 1 my ( $dev, $av ) = @_;
5783 1 my @l = ('COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME');
5784 1 my $pid = 1200;
5785 1 ▶ for my $d ( @{ $dev->{deleted_open} || [] } ) {
Condition50%1/2
$$dev{'deleted_open'} || []
l!l
10
MC/DC0%0/1
$$dev{'deleted_open'} || []
$$dev{'deleted_open'}
Truth table50%1/2
A
A= $$dev{'deleted_open'}
Aresult
11
00
5786 1 ▶ my $u = ( ( $dev->{services} || {} )->{ $d->{by} // '' } || {} )->{user} // 'root';
Condition50%4/8
(($$dev{"services"} || {})->{$$d{"by"} // ""} || {})->{"user"} // "root"
l!l
10
($$dev{'services'} || {})->{$$d{'by'} // ''} || {}
l!l
10
$$dev{'services'} || {}
l!l
10
$$d{"by"} // ""
l!l
10
MC/DC0%0/1
(($$dev{"services"} || {})->{$$d{"by"} // ""} || {})->{"user"} // "root"
$$dev{'services'}
MC/DC0%0/1
$$d{"by"} // ""
$$d{"by"}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
Truth table50%1/2
A
A= $$d{"by"}
Aresult
11
00
5787 push @l, sprintf( '%-9s %5d %-6s %4s %4s %6s %12d %5d %7d %s (deleted)', substr( $d->{by} // '?', 0, 9 ), $pid++, $u,
5788 1 ▶ '3w', 'REG', '254,1', _bytes( $d->{size} ), 0, 4242, $d->{path} );
Condition50%1/2
$$d{"by"} // "?"
l!l
10
MC/DC0%0/1
$$d{"by"} // "?"
$$d{"by"}
Truth table50%1/2
A
A= $$d{"by"}
Aresult
11
00
5789 }
5790 1 ▶ if ( !grep { /\+L1|-a|deleted/ } @$av ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {/\+L1|-a|deleted/;} @$av) 0 1 1
5791 0 ▶ for my $p ( sort keys %{ $dev->{files} || {} } ) {
Condition0%0/2
$$dev{'files'} || {}
l!l
00
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table0%0/2
A
A= $$dev{'files'}
Aresult
11
00
5792 0 my $e = _file_entry( $dev, $p );
5793 0 ▶ next unless defined $e->{open_by};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$e{"open_by"} 0 0 0
5794 0 ▶ my $u = ( ( $dev->{services} || {} )->{ $e->{open_by} } || {} )->{user} // 'root';
Condition0%0/6
(($$dev{"services"} || {})->{$$e{"open_by"}} || {})->{"user"} // "root"
l!l
00
($$dev{'services'} || {})->{$$e{'open_by'}} || {}
l!l
00
$$dev{'services'} || {}
l!l
00
MC/DC0%0/1
(($$dev{"services"} || {})->{$$e{"open_by"}} || {})->{"user"} // "root"
$$dev{'services'}
Truth table0%0/2
A
A= $$dev{'services'}
Aresult
11
00
5795 0 push @l, sprintf( '%-9s %5d %-6s %4s %4s %6s %12d %5d %7d %s', substr( $e->{open_by}, 0, 9 ), $pid++, $u, '3w', 'REG', '254,1',
5796 _file_size($e), 1, 4243, $p );
5797 }
5798 }
5799 1 return ( join( "\n", @l ), 1 );
5800 }
5801  
5802 # Datenbank-Programme gibt es nur, wo die Datenbank laeuft
5803 164 our %NEEDS = ( ( map { $_ => 'redis' } qw( redis-cli redis-server ) ),
5804 82 ( map { $_ => 'mariadb' } qw( mysql mariadb mysqld mariadbd mysqladmin mariadb-admin mysqldump ) ) );
5805  
5806 # Zeitangabe fuer date -d: @EPOCHE, now/today/tomorrow/yesterday, [JJJJ-MM-TT][ |T][HH:MM[:SS]] [ZONE|+HH:MM],
5807 # [now] + N hours|minutes|days; $now ist die Uhr des Geraets
5808 17 ▶sub _date_parse {
Subroutine _date_parse: called CC=29 SCAR=36.9
5809 17 my ( $s, $tz, $C, $now ) = @_;
5810 17 $s =~ s/\A\s+|\s+\z//g;
5811 17 ▶ return $1 if $s =~ /\A\@(-?\d+)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ /\A\@(-?\d+)\z/ 1 16 17
5812 16 ▶ return $now + $1 * { h => 3600, m => 60, d => 86400 }->{ lc substr( $2, 0, 1 ) } if $s =~ /\A(?:now\s*)?\+\s*(\d+)\s*(hours?|minutes?|days?)\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ /\A(?:now\s*)?\+\s*(\d+)\s*(hours?|minutes?|days?)\z/i 0 16 16
5813 # "20 days ago", "-3 days", "2 hours ago" (Monate/Jahre wie GNU als Kalenderschritt genaehert)
5814 16 ▶ if ( $s =~ /\A(?:(\d+)\s*(\w+?)\s+ago|-\s*(\d+)\s*(\w+))\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\A(?:(\d+)\s*(\w+?)\s+ago|-\s*(\d+)\s*(\w+))\z/i) 3 13 16
5815 3 ▶ my ( $n, $u ) = defined $1 ? ( $1, lc $2 ) : ( $3, lc $4 );
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 3 0 3
5816 3 my %f = ( sec => 1, second => 1, seconds => 1, secs => 1, min => 60, mins => 60, minute => 60, minutes => 60, hour => 3600, hours => 3600,
5817 day => 86400, days => 86400, week => 604800, weeks => 604800, month => 2592000, months => 2592000, year => 31536000, years => 31536000 );
5818 3 ▶ return defined $f{$u} ? $now - $n * $f{$u} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $f{$u} ? : 3 0 3
5819 }
5820 13 my $fixed; # +02:00 am Ende: fester Versatz
5821 0 ▶ if ( $s =~ s/\s*([+-])(\d\d):?(\d\d)\z// ) { $fixed = ( $1 eq '-' ? -1 : 1 ) * ( $2 * 3600 + $3 * 60 ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($s =~ s/\s*([+-])(\d\d):?(\d\d)\z//) 0 13 13
$1 eq '-' ? : 0 0 0
5822 13 my $zone = $tz;
5823 13 ▶ if ( $s =~ s/\s*\b(UTC|GMT|Z|CEST|CET|[A-Z][a-z]+\/[A-Za-z_]+)\z//i ) { my $z = $1; $zone = uc($z) eq 'Z' ? 'UTC' : $z =~ m{/} ? $z : uc $z }
Branch: 3 branches
BranchTrueFalseTotal
if ($s =~ s[\s*\b(UTC|GMT|Z|CEST|CET|[A-Z][a-z]+/[A-Za-z_]+)\z][]i) 3 10 13
uc $z eq 'Z' ? : 0 3 3
$z =~ m[/] ? : 0 3 3
5824 13 ▶ return undef unless $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$zone};
Branch: 1 branch
BranchTrueFalseTotal
unless $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$zone} 0 13 13
5825 13 my @l = gmtime( $now + $C->can('offset')->( $now, $zone ) );
5826 13 my ( $y, $m, $d, $H, $M, $S ) = ( $l[5] + 1900, $l[4] + 1, $l[3], 0, 0, 0 );
5827 13 my $day = 0;
5828 0 ▶ if ( $s eq '' || $s eq 'now' ) { return $now }
Branch: 3 branches
BranchTrueFalseTotal
if ($s eq '' or $s eq 'now') { } 0 13 13
elsif ($s =~ s/\A(today|tomorrow|yesterday)\b\s*//i) { } 3 10 13
elsif ($s =~ s/\A(\d{4})-(\d{1,2})-(\d{1,2})(?:[ T]+|\z)//) { } 8 2 10
Condition33%1/3
$s eq "" or $s eq "now"
l!l&&r!l&&!r
0013
MC/DC0%0/2
$s eq "" or $s eq "now"
$s eq "" $s eq "now"
Truth table33%1/3
A or B
A= $s eq ""B= $s eq "now"
ABresult
1X1
011
000
5829 elsif ( $s =~ s/\A(today|tomorrow|yesterday)\b\s*//i ) {
5830 3 $day = { today => 0, tomorrow => 1, yesterday => -1 }->{ lc $1 };
5831 3 ▶ ( $H, $M, $S ) = @l[ 2, 1, 0 ] unless length $s; # ohne Uhrzeit: die von jetzt (wie GNU)
Branch: 1 branch
BranchTrueFalseTotal
unless length $s 2 1 3
5832 }
5833 8 elsif ( $s =~ s/\A(\d{4})-(\d{1,2})-(\d{1,2})(?:[ T]+|\z)// ) { ( $y, $m, $d ) = ( $1, $2, $3 ) }
5834 13 ▶ if ( $s =~ s/\A(\d{1,2}):(\d{2})(?::(\d{2}))?\z// ) { ( $H, $M, $S ) = ( $1, $2, $3 // 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ s/\A(\d{1,2}):(\d{2})(?::(\d{2}))?\z//) 9 4 13
Condition100%2/2
$3 // 0
l!l
45
MC/DC100%1/1
$3 // 0
$3
Truth table100%2/2
A
A= $3
Aresult
11
00
5835 13 ▶ return undef if length $s || $m < 1 || $m > 12 || $d < 1 || $d > 31 || $H > 23 || $M > 59 || $S > 59;
Branch: 1 branch
BranchTrueFalseTotal
if length $s or $m < 1 or $m > 12 or $d < 1 or $d > 31 or $H > 23 or $M > 59 or $S > 59 2 11 13
Condition66%14/21
length $s or $m < 1 or $m > 12 or $d < 1 or $d > 31 or $H > 23 or $M > 59 or $S > 59
l!l&&r!l&&!r
2011
length $s or $m < 1 or $m > 12 or $d < 1 or $d > 31 or $H > 23 or $M > 59
l!l&&r!l&&!r
2011
length $s or $m < 1 or $m > 12 or $d < 1 or $d > 31 or $H > 23
l!l&&r!l&&!r
2011
length $s or $m < 1 or $m > 12 or $d < 1 or $d > 31
l!l&&r!l&&!r
2011
length $s or $m < 1 or $m > 12 or $d < 1
l!l&&r!l&&!r
2011
length $s or $m < 1 or $m > 12
l!l&&r!l&&!r
2011
length $s or $m < 1
l!l&&r!l&&!r
2011
MC/DC12%1/8
length $s or $m < 1 or $m > 12 or $d < 1 or $d > 31 or $H > 23 or $M > 59 or $S > 59
length $s $m < 1 $m > 12 $d < 1 $d > 31 $H > 23 $M > 59 $S > 59
Truth table22%2/9
A or B or C or D or E or F or G or H
A= length $sB= $m < 1C= $m > 12D= $d < 1E= $d > 31F= $H > 23G= $M > 59H= $S > 59
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
00001XXX1
000001XX1
0000001X1
000000011
000000000
5836 11 require Time::Local;
5837 11 ▶ my $u = eval { Time::Local::timegm( $S, $M, $H, $d, $m - 1, $y ) } // return undef;
Condition50%1/2
eval { do { Time::Local::timegm($S, $M, $H, $d, $m - 1, $y) } } // (return undef)
l!l
110
MC/DC0%0/1
eval { do { Time::Local::timegm($S, $M, $H, $d, $m - 1, $y) } } // (return undef)
eval { do { Time::Local::timegm($S, $M, $H, $d, $m - 1, $y) } }
Truth table50%1/2
A
A= eval { do { Time::Local::timegm($S, $M, $H, $d, $m - 1, $y) } }
Aresult
11
00
5838 11 $u += 86400 * $day;
5839 11 ▶ return $u - $fixed if defined $fixed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fixed 0 11 11
5840 11 my $off = $C->can('offset')->( $u - $C->can('offset')->( $u, $zone ), $zone );
5841 11 return $u - $off;
5842 }
5843  
5844 # redis-cli (ohne Redis-Zustand)/redis-server: nur mit einem Dienst redis-server (Langertha::Holmgang::Sim::Linux::RedisService)
5845 14 ▶sub _redis_cmd {
Subroutine _redis_cmd: called CC=6 SCAR=17.9
5846 14 my ( $how, $dev, $av, $ctx ) = @_;
5847 14 _part('RedisService');
5848 14 ▶ my $n = $how eq 'cli' ? 'redis-cli' : 'redis-server';
Branch: 1 branch
BranchTrueFalseTotal
$how eq 'cli' ? : 12 2 14
5849 14 ▶ if ( !Langertha::Holmgang::Sim::Linux::RedisService::installed($dev) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Langertha::Holmgang::Sim::Linux::RedisService::installed($dev)) 1 13 14
5850 1 ▶ return ( "bash: $n: command not found", 0 ) unless _prog_file( $dev, $n );
Branch: 1 branch
BranchTrueFalseTotal
unless _prog_file($dev, $n) 0 1 1
5851 1 push @GAPS, join( ' ', $n, @$av );
5852 1 return ( '', 0 );
5853 }
5854 13 ▶ my ( $o, $k, $gap ) = $how eq 'cli' ? Langertha::Holmgang::Sim::Linux::RedisService::cli( $dev, $av, $ctx->{host} ) : Langertha::Holmgang::Sim::Linux::RedisService::server( $dev, $av );
Branch: 1 branch
BranchTrueFalseTotal
$how eq 'cli' ? : 11 2 13
5855 13 ▶ push @GAPS, $gap if defined $gap;
Branch: 1 branch
BranchTrueFalseTotal
if defined $gap 1 12 13
5856 13 return ( $o, $k );
5857 }
5858  
5859 # Dateiargumente eines Filters (head -n 3 DATEI, awk PROG DATEI …): ohne Optionen und
5860 # ihre Werte, ohne das Programm von awk und ohne die Ausgabedatei von uniq; tr liest nur stdin
5861 82 my %FILTER_VALUE = (
5862 head => qr/\A(?:-[nc]|--lines|--bytes)\z/, tail => qr/\A(?:-[ncs]|--lines|--bytes|--pid|--sleep-interval)\z/,
5863 sort => qr/\A(?:-[ktoTS]|--key|--field-separator|--output|--buffer-size)\z/, uniq => qr/\A-[fsw]\z/,
5864 cut => qr/\A-[dfcb]\z/, awk => qr/\A-[Fvf]\z/, fold => qr/\A-w\z/, wc => qr/\A(?!)/,
5865 );
5866 31 ▶sub _filter_files {
Subroutine _filter_files: called CC=12 SCAR=26.2
5867 31 my ( $cmd, @a ) = @_;
5868 31 ▶ my $val = $FILTER_VALUE{$cmd} or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $val = $FILTER_VALUE{$cmd} or return () 31 0 31
5869 31 my ( @ops, $prog_f );
5870 31 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 62 31 93
5871 62 my $x = shift @a;
5872 0 ▶ if ( $x eq '--' ) { push @ops, @a; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "--") 0 62 62
5873 62 ▶ if ( $x =~ $val ) { $prog_f = 1 if $cmd eq 'awk' && $x eq '-f'; shift @a; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($x =~ /$val/) 8 54 62
if $cmd eq "awk" and $x eq "-f" 0 8 8
Condition33%1/3
$cmd eq "awk" and $x eq "-f"
!ll&&!rl&&r
800
MC/DC0%0/2
$cmd eq "awk" and $x eq "-f"
$cmd eq "awk" $x eq "-f"
Truth table33%1/3
A and B
A= $cmd eq "awk"B= $x eq "-f"
ABresult
0X0
100
111
5874 54 ▶ next if $x =~ /\A-./;
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /\A-./ 21 33 54
5875 33 push @ops, $x;
5876 }
5877 31 ▶ if ( $cmd eq 'awk' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "awk") 3 28 31
5878 3 ▶ shift @ops unless $prog_f; # das Programm
Branch: 1 branch
BranchTrueFalseTotal
unless $prog_f 3 0 3
5879 3 @ops = grep { !/\A[A-Za-z_]\w*=/ } @ops; # var=wert ist eine Zuweisung
5880 }
5881 31 ▶ @ops = @ops[ 0 .. 0 ] if $cmd eq 'uniq' && @ops > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "uniq" and @ops > 1 0 31 31
Condition66%2/3
$cmd eq "uniq" and @ops > 1
!ll&&!rl&&r
3010
MC/DC0%0/2
$cmd eq "uniq" and @ops > 1
$cmd eq "uniq" @ops > 1
Truth table66%2/3
A and B
A= $cmd eq "uniq"B= @ops > 1
ABresult
0X0
100
111
5882 31 return @ops;
5883 }
5884  
5885 # od -c | -An | -t c [DATEI…]: Bytes als Zeichen wie GNU od (je Zeile 16, Breite 4,
5886 # \n \t … als Escapes, sonst oktal), Versatz oktal; anderes ist eine Luecke
5887 6 ▶sub _od {
Subroutine _od: called CC=40 SCAR=44.6
5888 6 my ( $dev, $av, $ctx, $stdin ) = @_;
5889 6 my ( $chars, $hex, $noaddr, @files );
5890 6 my @a = @$av;
5891 6 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 9 6 15
5892 9 my $x = shift @a;
5893 9 ▶ if ( $x eq '-c' || $x eq '-tc' ) { $chars = 1 }
Branch: 6 branches
BranchTrueFalseTotal
if ($x eq '-c' or $x eq '-tc') { } 4 5 9
elsif ($x eq '-t' and ($a[0] // '') eq 'c') { } 0 5 5
elsif ($x eq '-tx1' or $x eq '-t' and ($a[0] // '') eq 'x1') { } 2 3 5
elsif ($x eq '-An' or $x eq '-A' and ($a[0] // '') eq 'n') { } 2 1 3
elsif ($x =~ /\A-(?:An)?c\z|\A-cAn\z/) { } 0 1 1
elsif ($x =~ /\A-/) { } 0 1 1
Condition66%2/3
$x eq "-c" or $x eq "-tc"
l!l&&r!l&&!r
405
MC/DC50%1/2
$x eq "-c" or $x eq "-tc"
$x eq "-c" $x eq "-tc"
Truth table66%2/3
A or B
A= $x eq "-c"B= $x eq "-tc"
ABresult
1X1
011
000
5894 0 ▶ elsif ( $x eq '-t' && ( $a[0] // '' ) eq 'c' ) { shift @a; $chars = 1 }
Condition60%3/5
$x eq "-t" and ($a[0] // "") eq "c"
!ll&&!rl&&r
410
$a[0] // ""
l!l
10
MC/DC50%1/2
$x eq "-t" and ($a[0] // "") eq "c"
$x eq "-t" $a[0]
Truth table66%2/3
A and B
A= $x eq "-t"B= $a[0]
ABresult
0X0
100
111
5895 2 ▶ elsif ( $x eq '-tx1' || $x eq '-t' && ( $a[0] // '' ) eq 'x1' ) { shift @a if $x eq '-t'; $hex = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "-t" 1 1 2
Condition75%6/8
$x eq "-tx1" or $x eq "-t" and ($a[0] // "") eq "x1"
l!l&&r!l&&!r
113
$x eq "-t" and ($a[0] // "") eq "x1"
!ll&&!rl&&r
301
$a[0] // ""
l!l
10
MC/DC66%2/3
$x eq "-tx1" or $x eq "-t" and ($a[0] // "") eq "x1"
$x eq "-tx1" $x eq "-t" $a[0]
Truth table75%3/4
A or B and C
A= $x eq "-tx1"B= $x eq "-t"C= $a[0]
ABCresult
1XX1
0111
00X0
0100
5896 2 ▶ elsif ( $x eq '-An' || $x eq '-A' && ( $a[0] // '' ) eq 'n' ) { shift @a if $x eq '-A'; $noaddr = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "-A" 0 2 2
Condition37%3/8
$x eq "-An" or $x eq "-A" and ($a[0] // "") eq "n"
l!l&&r!l&&!r
201
$x eq "-A" and ($a[0] // "") eq "n"
!ll&&!rl&&r
100
$a[0] // ""
l!l
00
MC/DC33%1/3
$x eq "-An" or $x eq "-A" and ($a[0] // "") eq "n"
$x eq "-An" $x eq "-A" $a[0]
Truth table50%2/4
A or B and C
A= $x eq "-An"B= $x eq "-A"C= $a[0]
ABCresult
1XX1
0111
00X0
0100
5897 0 ▶ elsif ( $x =~ /\A-(?:An)?c\z|\A-cAn\z/ ) { $chars = 1; $noaddr = 1 if $x =~ /An/ }
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /An/ 0 0 0
5898 0 elsif ( $x =~ /\A-/ ) { push @GAPS, join( ' ', 'od', @$av ); return ( '', 0 ) }
5899 1 else { push @files, $x }
5900 }
5901 0 ▶ unless ( $chars xor $hex ) { push @GAPS, join( ' ', 'od', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($chars xor $hex) 0 6 6
Condition50%2/4
$chars xor $hex
l&&rl&&!r!l&&r!l&&!r
0420
MC/DC0%0/2
$chars xor $hex
$chars $hex
Truth table50%2/4
A xor B
A= $charsB= $hex
ABresult
110
101
011
000
5902 6 my $in = '';
5903 6 ▶ if (@files) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) { } 1 5 6
5904 1 for my $f (@files) {
5905 1 my $p = _absp($f);
5906 1 ▶ return ( "od: $f: Permission denied", 0 ) unless _read_ok( $dev, $p );
Branch: 1 branch
BranchTrueFalseTotal
unless _read_ok($dev, $p) 0 1 1
5907 1 ▶ my $t = _file_text( $dev, $p ) // return ( "od: $f: No such file or directory", 0 );
Condition50%1/2
_file_text($dev, $p) // (return "od: ${f}: No such file or directory", 0)
l!l
10
MC/DC0%0/1
_file_text($dev, $p) // (return "od: ${f}: No such file or directory", 0)
_file_text($dev, $p)
Truth table50%1/2
A
A= _file_text($dev, $p)
Aresult
11
00
5908 1 $in .= $t;
5909 }
5910 }
5911 5 ▶ else { $in = ( $stdin // '' ) . ( defined $stdin && length $stdin && $STDIN_NL ? "\n" : '' ) }
Branch: 1 branch
BranchTrueFalseTotal
defined $stdin && length $stdin && $Langertha::Holmgang::Sim::Linux::STDIN_NL ? : 2 3 5
Condition50%4/8
$stdin // ""
l!l
50
defined $stdin and length $stdin and $Langertha::Holmgang::Sim::Linux::STDIN_NL
!ll&&!rl&&r
032
defined $stdin and length $stdin
!ll&&!rl&&r
005
MC/DC0%0/1
$stdin // ""
$stdin
MC/DC33%1/3
defined $stdin and length $stdin and $Langertha::Holmgang::Sim::Linux::STDIN_NL
defined $stdin length $stdin $Langertha::Holmgang::Sim::Linux::STDIN_NL
Truth table50%1/2
A
A= $stdin
Aresult
11
00
Truth table50%2/4
A and B and C
A= defined $stdinB= length $stdinC= $Langertha::Holmgang::Sim::Linux::STDIN_NL
ABCresult
0XX0
10X0
1100
1111
5912 6 utf8::encode( my $b = $in );
5913 6 my %esc = ( 0 => '\0', 7 => '\a', 8 => '\b', 9 => '\t', 10 => '\n', 11 => '\v', 12 => '\f', 13 => '\r' );
5914 6 my ( @l, $prev, $star );
5915 6 ▶ for ( my $o = 0; $o < length $b; $o += 16 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o < length $b) 7 6 13
5916 7 my $chunk = substr( $b, $o, 16 );
5917 7 ▶ my $row = join '', map { my $c = ord; $hex ? sprintf( ' %02x', $c ) : sprintf '%4s', $esc{$c} // ( $c >= 32 && $c < 127 ? chr $c : sprintf '%03o', $c ) } split //, $chunk;
Branch: 2 branches
BranchTrueFalseTotal
$hex ? : 20 12 32
$c >= 32 && $c < 127 ? : 7 2 9
Condition80%4/5
$esc{$c} // ($c >= 32 && $c < 127 ? chr $c : sprintf("%03o", $c))
l!l
39
$c >= 32 and $c < 127
!ll&&!rl&&r
027
MC/DC100%1/1
$esc{$c} // ($c >= 32 && $c < 127 ? chr $c : sprintf("%03o", $c))
$esc{$c}
Truth table100%2/2
A
A= $esc{$c}
Aresult
11
00
5918 0 ▶ if ( defined $prev && $chunk eq $prev ) { push @l, '*' unless $star; $star = 1; next }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $prev and $chunk eq $prev) 0 7 7
unless $star 0 0 0
Condition66%2/3
defined $prev and $chunk eq $prev
!ll&&!rl&&r
610
MC/DC0%0/2
defined $prev and $chunk eq $prev
defined $prev $chunk eq $prev
Truth table66%2/3
A and B
A= defined $prevB= $chunk eq $prev
ABresult
0X0
100
111
5919 7 ( $prev, $star ) = ( $chunk, 0 );
5920 7 ▶ push @l, $noaddr ? $row : sprintf( '%07o', $o ) . $row;
Branch: 1 branch
BranchTrueFalseTotal
$noaddr ? : 2 5 7
5921 }
5922 6 ▶ push @l, sprintf '%07o', length $b unless $noaddr;
Branch: 1 branch
BranchTrueFalseTotal
unless $noaddr 4 2 6
5923 6 return ( join( "\n", @l ), 1 );
5924 }
5925  
5926 # flock [-n|-x|-s|-w N|-E N] FD | DATEI [-c BEFEHL | BEFEHL …]: gelingt (die Simulation
5927 # kennt keine nebenlaeufigen Laeufe, es haelt niemand die Sperre); die Sperrdatei wird
5928 # angelegt, ein Befehl laeuft
5929 3 ▶sub _flock {
Subroutine _flock: called CC=21 SCAR=35.6
5930 3 my ( $dev, $av, $ctx, $stdin ) = @_;
5931 3 my @a = @$av;
5932 3 my $c;
5933 3 ▶ while ( @a && $a[0] =~ /\A-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-/) 3 3 6
Condition66%2/3
@a and $a[0] =~ /\A-/
!ll&&!rl&&r
033
MC/DC50%1/2
@a and $a[0] =~ /\A-/
@a $a[0] =~ /\A-/
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A-/
ABresult
0X0
100
111
5934 3 my $x = shift @a;
5935 0 ▶ if ( $x =~ /\A-[wE]\z/ || $x =~ /\A--(?:timeout|conflict-exit-code)\z/ ) { shift @a }
Branch: 3 branches
BranchTrueFalseTotal
if ($x =~ /\A-[wE]\z/ or $x =~ /\A--(?:timeout|conflict-exit-code)\z/) { } 0 3 3
elsif ($x eq '-c' or $x eq '--command') { } 0 3 3
elsif ($x =~ /\A-[nxseuo]+\z|\A--(?:nonblock|exclusive|shared|unlock|close)\z/) { } 3 0 3
Condition33%1/3
$x =~ /\A-[wE]\z/ or $x =~ /\A--(?:timeout|conflict-exit-code)\z/
l!l&&r!l&&!r
003
MC/DC0%0/2
$x =~ /\A-[wE]\z/ or $x =~ /\A--(?:timeout|conflict-exit-code)\z/
$x =~ /\A-[wE]\z/ $x =~ /\A--(?:timeout|conflict-exit-code)\z/
Truth table33%1/3
A or B
A= $x =~ /\A-[wE]\z/B= $x =~ /\A--(?:timeout|conflict-exit-code)\z/
ABresult
1X1
011
000
5936 0 ▶ elsif ( $x eq '-c' || $x eq '--command' ) { $c = shift @a }
Condition33%1/3
$x eq "-c" or $x eq "--command"
l!l&&r!l&&!r
003
MC/DC0%0/2
$x eq "-c" or $x eq "--command"
$x eq "-c" $x eq "--command"
Truth table33%1/3
A or B
A= $x eq "-c"B= $x eq "--command"
ABresult
1X1
011
000
5937 elsif ( $x =~ /\A-[nxseuo]+\z|\A--(?:nonblock|exclusive|shared|unlock|close)\z/ ) { }
5938 0 else { return ( "flock: unrecognized option '$x'", 0 ) }
5939 }
5940 3 ▶ my $t = shift(@a) // return ( "flock: not enough arguments\nTry 'flock --help' for more information.", 0 );
Condition50%1/2
shift @a // (return "flock: not enough arguments\nTry 'flock --help' for more information.", 0)
l!l
30
MC/DC0%0/1
shift @a // (return "flock: not enough arguments\nTry 'flock --help' for more information.", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
5941 3 ▶ if ( @a && ( $a[0] eq '-c' || $a[0] eq '--command' ) ) { shift @a; $c = shift @a } # flock DATEI -c BEFEHL
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] eq "-c" || $a[0] eq "--command") 1 2 3
Condition83%5/6
@a and $a[0] eq "-c" || $a[0] eq "--command"
!ll&&!rl&&r
111
$a[0] eq "-c" or $a[0] eq "--command"
l!l&&r!l&&!r
101
MC/DC66%2/3
@a and $a[0] eq "-c" || $a[0] eq "--command"
@a $a[0] eq "-c" $a[0] eq "--command"
Truth table75%3/4
A and B or C
A= @aB= $a[0] eq "-c"C= $a[0] eq "--command"
ABCresult
0XX0
1000
11X1
1011
5942 3 ▶ return ( '', 1 ) if $t =~ /\A\d+\z/ && !@a && !defined $c; # flock FD
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /\A\d+\z/ and not @a and not defined $c 1 2 3
Condition66%4/6
$t =~ /\A\d+\z/ and not @a and not defined $c
!ll&&!rl&&r
201
$t =~ /\A\d+\z/ and not @a
!ll&&!rl&&r
201
MC/DC33%1/3
$t =~ /\A\d+\z/ and not @a and not defined $c
$t =~ /\A\d+\z/ not @a not defined $c
Truth table50%2/4
A and not(B) and not(C)
A= $t =~ /\A\d+\z/B= not @aC= not defined $c
ABCresult
0XX0
10X0
1100
1111
5943 2 my $p = _absp($t);
5944 2 ▶ if ( !_file_entry( $dev, $p ) && !_is_dir( $dev, $p ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_file_entry($dev, $p) or _is_dir($dev, $p)) 2 0 2
Condition33%1/3
_file_entry($dev, $p) or _is_dir($dev, $p)
l!l&&r!l&&!r
002
MC/DC0%0/2
_file_entry($dev, $p) or _is_dir($dev, $p)
_file_entry($dev, $p) _is_dir($dev, $p)
Truth table33%1/3
A or B
A= _file_entry($dev, $p)B= _is_dir($dev, $p)
ABresult
1X1
011
000
5945 2 my ( $e, $wok ) = _write_path( $dev, $p, '', 0, $ctx );
5946 2 ▶ return ( "flock: cannot open lock file $t: " . ( $e =~ /: ([^:]+)\z/ ? $1 : 'No such file or directory' ), 0 ) unless $wok;
Branch: 2 branches
BranchTrueFalseTotal
unless $wok 0 2 2
$e =~ /: ([^:]+)\z/ ? : 0 0 0
5947 }
5948 2 ▶ return __PACKAGE__->_run_inner( $dev, $c, $ctx ) if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 1 1 2
5949 1 ▶ return ( '', 1 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 1 1
5950 1 return __PACKAGE__->_command( $dev, \@a, $ctx, $stdin );
5951 }
5952  
5953 # Pruefsumme wie coreutils (md5, sha1, sha256) ueber die Bytes (UTF-8); hier fuer sha256sum
5954 # ohne Datei (stdin) — Dateien rechnet Sim::Backup, md5sum hat _md5sum; -c ist eine Luecke
5955 2 ▶sub _digest {
Subroutine _digest: called CC=17 SCAR=49.9
5956 2 my ( $alg, $dev, $av, $ctx, $stdin ) = @_;
5957 0 my @f = grep { !/\A-/ } @$av;
5958 0 ▶ if ( grep { /\A-(?:c|-check)\z/ } @$av ) { push @GAPS, join( ' ', "${alg}sum", @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {/\A-(?:c|-check)\z/;} @$av) 0 2 2
5959 2 require Digest::MD5;
5960 2 require Digest::SHA;
5961 2 ▶ my $h = sub { my $b = shift; utf8::encode($b); $alg eq 'md5' ? Digest::MD5::md5_hex($b) : $alg eq 'sha1' ? Digest::SHA::sha1_hex($b) : Digest::SHA::sha256_hex($b) };
Subroutine __ANON__: called CC=3 SCAR=11.4
Branch: 2 branches
BranchTrueFalseTotal
$alg eq 'md5' ? : 0 2 2
$alg eq 'sha1' ? : 0 2 2
5962 2 ▶ return ( $h->( ( $stdin // '' ) . ( defined $stdin && length $stdin && $STDIN_NL ? "\n" : '' ) ) . ' -', 1 ) unless @f;
Branch: 2 branches
BranchTrueFalseTotal
unless @f 2 0 2
defined $stdin && length $stdin && $Langertha::Holmgang::Sim::Linux::STDIN_NL ? : 2 0 2
Condition37%3/8
$stdin // ""
l!l
20
defined $stdin and length $stdin and $Langertha::Holmgang::Sim::Linux::STDIN_NL
!ll&&!rl&&r
002
defined $stdin and length $stdin
!ll&&!rl&&r
002
MC/DC0%0/1
$stdin // ""
$stdin
MC/DC0%0/3
defined $stdin and length $stdin and $Langertha::Holmgang::Sim::Linux::STDIN_NL
defined $stdin length $stdin $Langertha::Holmgang::Sim::Linux::STDIN_NL
Truth table50%1/2
A
A= $stdin
Aresult
11
00
Truth table25%1/4
A and B and C
A= defined $stdinB= length $stdinC= $Langertha::Holmgang::Sim::Linux::STDIN_NL
ABCresult
0XX0
10X0
1100
1111
5963 0 my ( @out, $ok ) = ();
5964 0 $ok = 1;
5965 0 for my $f (@f) {
5966 0 my $p = _absp($f);
5967 0 ▶ if ( _is_dir( $dev, $p ) && !_file_entry( $dev, $p ) ) { push @out, "${alg}sum: $f: Is a directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if (_is_dir($dev, $p) and not _file_entry($dev, $p)) 0 0 0
Condition0%0/3
_is_dir($dev, $p) and not _file_entry($dev, $p)
!ll&&!rl&&r
000
MC/DC0%0/2
_is_dir($dev, $p) and not _file_entry($dev, $p)
_is_dir($dev, $p) not _file_entry($dev, $p)
Truth table0%0/3
A and not(B)
A= _is_dir($dev, $p)B= not _file_entry($dev, $p)
ABresult
0X0
100
111
5968 0 ▶ if ( _file_entry( $dev, $p ) && !_read_ok( $dev, $p ) ) { push @out, "${alg}sum: $f: Permission denied"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if (_file_entry($dev, $p) and not _read_ok($dev, $p)) 0 0 0
Condition0%0/3
_file_entry($dev, $p) and not _read_ok($dev, $p)
!ll&&!rl&&r
000
MC/DC0%0/2
_file_entry($dev, $p) and not _read_ok($dev, $p)
_file_entry($dev, $p) not _read_ok($dev, $p)
Truth table0%0/3
A and not(B)
A= _file_entry($dev, $p)B= not _read_ok($dev, $p)
ABresult
0X0
100
111
5969 0 my $t = _file_text( $dev, $p );
5970 0 ▶ if ( !defined $t ) { push @out, "${alg}sum: $f: No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 0 0 0
5971 0 my $e = _file_entry( $dev, $p );
5972 0 ▶ if ( ref $e eq 'HASH' && defined $e->{size} && !length( $e->{content} // '' ) ) { push @GAPS, join( ' ', "${alg}sum", @$av ); return ( '', 0 ) } # nur Groesse bekannt
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e eq "HASH" and defined $$e{"size"} and not length($$e{"content"} // "")) 0 0 0
Condition0%0/8
ref $e eq "HASH" and defined $$e{"size"} and not length($$e{"content"} // "")
!ll&&!rl&&r
000
ref $e eq "HASH" and defined $$e{"size"}
!ll&&!rl&&r
000
$$e{"content"} // ""
l!l
00
MC/DC0%0/3
ref $e eq "HASH" and defined $$e{"size"} and not length($$e{"content"} // "")
ref $e eq "HASH" defined $$e{"size"} $$e{"content"}
Truth table0%0/4
A and B and not(C)
A= ref $e eq "HASH"B= defined $$e{"size"}C= $$e{"content"}
ABCresult
0XX0
10X0
1110
1101
5973 0 push @out, $h->($t) . " $f";
5974 }
5975 0 return ( join( "\n", @out ), $ok );
5976 }
5977  
5978 # lsblk-Optionen: -o|--output LISTE (+LISTE ergaenzt die Vorgabe), -b, -n, -l, -p, -a, -f, -m,
5979 # Geraete als Argumente. Rueckgabe \%o; ( undef, Text ) bei Fehler wie lsblk; () bei Luecke
5980 82 our %LSBLK_COL = map { $_ => 1 } qw( NAME KNAME PATH MAJ:MIN RM SIZE RO TYPE MOUNTPOINT MOUNTPOINTS FSTYPE LABEL UUID FSAVAIL FSUSE% );
5981  
5982 7 ▶sub _lsblk_opts {
Subroutine _lsblk_opts: called CC=23 SCAR=34.3
5983 7 my ($av) = @_;
5984 7 my %o = ( dev => [] );
5985 7 my %long = ( all => 'a', bytes => 'b', noheadings => 'n', list => 'l', paths => 'p', fs => 'f', perms => 'm' );
5986 7 my @a = @$av;
5987 7 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 9 7 16
5988 9 my $x = shift @a;
5989 0 ▶ if ( $x =~ /\A--output=(.*)\z/ ) { $o{cols} = $1 }
Branch: 5 branches
BranchTrueFalseTotal
if ($x =~ /\A--output=(.*)\z/) { } 0 9 9
elsif ($x eq '--output') { } 0 9 9
elsif ($x =~ /\A--(\w+)\z/ and $long{$1}) { } 0 9 9
elsif ($x =~ /\A-([abnlpfm]*)(?:(o)(.*))?\z/ and length $1 . ($2 // '')) { } 8 1 9
elsif ($x =~ /\A-/) { } 0 1 1
5990 0 ▶ elsif ( $x eq '--output' ) { $o{cols} = shift(@a) // return }
Condition0%0/2
shift @a // (return)
l!l
00
MC/DC0%0/1
shift @a // (return)
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
5991 0 ▶ elsif ( $x =~ /\A--(\w+)\z/ && $long{$1} ) { $o{ $long{$1} } = 1 }
Condition33%1/3
$x =~ /\A--(\w+)\z/ and $long{$1}
!ll&&!rl&&r
900
MC/DC0%0/2
$x =~ /\A--(\w+)\z/ and $long{$1}
$x =~ /\A--(\w+)\z/ $long{$1}
Truth table33%1/3
A and B
A= $x =~ /\A--(\w+)\z/B= $long{$1}
ABresult
0X0
100
111
5992 ▶ elsif ( $x =~ /\A-([abnlpfm]*)(?:(o)(.*))?\z/ && length( $1 . ( $2 // '' ) ) ) {
Condition80%4/5
$x =~ /\A-([abnlpfm]*)(?:(o)(.*))?\z/ and length $1 . ($2 // "")
!ll&&!rl&&r
108
$2 // ""
l!l
44
MC/DC50%1/2
$x =~ /\A-([abnlpfm]*)(?:(o)(.*))?\z/ and length $1 . ($2 // "")
$x =~ /\A-([abnlpfm]*)(?:(o)(.*))?\z/ length $1 . ($2 // "")
MC/DC100%1/1
$2 // ""
$2
Truth table66%2/3
A and B
A= $x =~ /\A-([abnlpfm]*)(?:(o)(.*))?\z/B= length $1 . ($2 // "")
ABresult
0X0
100
111
Truth table100%2/2
A
A= $2
Aresult
11
00
5993 8 my ( $fl, $oo, $rest ) = ( $1, $2, $3 );
5994 8 $o{$_} = 1 for split //, $fl;
5995 8 ▶ $o{cols} = length $rest ? $rest : shift(@a) // return if $oo;
Branch: 2 branches
BranchTrueFalseTotal
if $oo 4 4 8
length $rest ? : 0 4 4
Condition50%1/2
shift @a // (return)
l!l
40
MC/DC0%0/1
shift @a // (return)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
5996 }
5997 0 elsif ( $x =~ /\A-/ ) { return }
5998 1 else { push @{ $o{dev} }, $x }
5999 }
6000 7 ▶ return if $o{m};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"m"} 0 7 7
6001 7 ▶ my @def = $o{f} ? qw( NAME FSTYPE LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS ) : qw( NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS );
Branch: 1 branch
BranchTrueFalseTotal
$o{'f'} ? : 2 5 7
6002 7 ▶ if ( defined $o{cols} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o{'cols'}) { } 4 3 7
6003 4 my $plus = $o{cols} =~ s/\A\+//;
6004 4 my @c = map {uc} grep {length} split /,/, $o{cols};
6005 4 ▶ for (@c) { return ( undef, "lsblk: unknown column: $_" ) unless $LSBLK_COL{$_} }
Branch: 1 branch
BranchTrueFalseTotal
unless $Langertha::Holmgang::Sim::Linux::LSBLK_COL{$_} 1 9 10
6006 3 ▶ $o{list} = [ $plus ? ( @def, @c ) : @c ];
Branch: 1 branch
BranchTrueFalseTotal
$plus ? : 0 3 3
6007 }
6008 3 else { $o{list} = \@def }
6009 6 ▶ $o{table} = 1 if defined $o{cols} || grep { $o{$_} } qw( b n l p );
Branch: 1 branch
BranchTrueFalseTotal
if defined $o{"cols"} or grep {$o{$_};} "b", "n", "l", "p" 3 3 6
Condition66%2/3
defined $o{"cols"} or grep {$o{$_};} "b", "n", "l", "p"
l!l&&r!l&&!r
303
MC/DC50%1/2
defined $o{"cols"} or grep {$o{$_};} "b", "n", "l", "p"
defined $o{"cols"} grep {$o{$_};} "b", "n", "l", "p"
Truth table66%2/3
A or B
A= defined $o{"cols"}B= grep {$o{$_};} "b", "n", "l", "p"
ABresult
1X1
011
000
6010 6 return \%o;
6011 }
6012  
6013 # Zeilen -> Tabelle wie lsblk: Zeile { name, path, tree, majmin, size (Bytes), type, mps => [], fstype,
6014 # label, uuid, fsavail (Bytes), fsuse }; Zahlenspalten rechtsbuendig, eine Leerstelle dazwischen
6015 3 ▶sub _lsblk_table {
Subroutine _lsblk_table: called CC=5 SCAR=16.9
6016 3 my ( $rows, $o ) = @_;
6017 3 my %right = map { $_ => 1 } qw( RM SIZE RO FSAVAIL FSUSE% );
6018 3 ▶ my $sz = sub { my $b = shift; return '' unless defined $b; $o->{b} ? $b : _human($b) };
Subroutine __ANON__: called CC=3 SCAR=11.4
Branch: 2 branches
BranchTrueFalseTotal
unless defined $b 0 2 2
$$o{'b'} ? : 2 0 2
6019 my %val = (
6020 5 ▶ NAME => sub { ( $o->{l} ? '' : $_[0]{tree} // '' ) . ( $o->{p} ? $_[0]{path} : $_[0]{name} ) },
Subroutine __ANON__: called CC=4 SCAR=14.0
Branch: 2 branches
BranchTrueFalseTotal
$$o{'l'} ? : 2 3 5
$$o{'p'} ? : 2 3 5
Condition50%1/2
$_[0]{"tree"} // ""
l!l
30
MC/DC0%0/1
$_[0]{"tree"} // ""
$_[0]{"tree"}
Truth table50%1/2
A
A= $_[0]{"tree"}
Aresult
11
00
6021 0 ▶ KNAME => sub { $o->{p} ? $_[0]{path} : $_[0]{name} },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$$o{'p'} ? : 0 0 0
6022 0 ▶ PATH => sub { $_[0]{path} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
6023 0 ▶ 'MAJ:MIN' => sub { $_[0]{majmin} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
6024 0 ▶ RM => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
6025 0 ▶ RO => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
6026 2 ▶ SIZE => sub { $sz->( $_[0]{size} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
6027 2 ▶ TYPE => sub { $_[0]{type} },
Subroutine __ANON__: called CC=1 SCAR=0.0
6028 2 ▶ MOUNTPOINT => sub { $_[0]{mps}[0] // '' },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]{"mps"}[0] // ""
l!l
11
MC/DC100%1/1
$_[0]{"mps"}[0] // ""
$_[0]{"mps"}[0]
Truth table100%2/2
A
A= $_[0]{"mps"}[0]
Aresult
11
00
6029 0 ▶ MOUNTPOINTS => sub { join ' ', @{ $_[0]{mps} } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
6030 2 ▶ FSTYPE => sub { $_[0]{fstype} // '' },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]{"fstype"} // ""
l!l
11
MC/DC100%1/1
$_[0]{"fstype"} // ""
$_[0]{"fstype"}
Truth table100%2/2
A
A= $_[0]{"fstype"}
Aresult
11
00
6031 1 ▶ LABEL => sub { $_[0]{label} // '' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]{"label"} // ""
l!l
10
MC/DC0%0/1
$_[0]{"label"} // ""
$_[0]{"label"}
Truth table50%1/2
A
A= $_[0]{"label"}
Aresult
11
00
6032 1 ▶ UUID => sub { $_[0]{uuid} // '' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]{"uuid"} // ""
l!l
10
MC/DC0%0/1
$_[0]{"uuid"} // ""
$_[0]{"uuid"}
Truth table50%1/2
A
A= $_[0]{"uuid"}
Aresult
11
00
6033 0 ▶ FSAVAIL => sub { $sz->( $_[0]{fsavail} ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
6034 0 ▶ 'FSUSE%' => sub { defined $_[0]{fsuse} ? "$_[0]{fsuse}%" : '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'fsuse'} ? : 0 0 0
6035 3 );
6036 3 my @c = @{ $o->{list} };
6037 3 ▶ my @t = ( $o->{n} ? () : [@c], map { my $r = $_; [ map { $val{$_}->($r) } @c ] } @$rows );
Branch: 1 branch
BranchTrueFalseTotal
$$o{'n'} ? : 2 1 3
6038 3 ▶ my @w = map { my $i = $_; my $m = 0; for (@t) { my $l = length $_->[$i]; $m = $l if $l > $m } $m } 0 .. $#c;
Branch: 1 branch
BranchTrueFalseTotal
if $l > $m 12 6 18
6039 return join "\n", map {
6040 3 my $r = $_;
6041 6 ▶ join( ' ', map { $right{ $c[$_] } ? sprintf( '%*s', $w[$_], $r->[$_] ) : sprintf( '%-*s', $w[$_], $r->[$_] ) } 0 .. $#c ) =~ s/\s+\z//r
Branch: 1 branch
BranchTrueFalseTotal
$right{$c[$_]} ? : 3 15 18
6042 } @t;
6043 }
6044  
6045 # lsblk ohne Platten im Zustand: die Geraete der Einhaengepunkte (vda1 -> Platte vda);
6046 # LABEL, UUID und -f/-m kennt der Zustand hier nicht (Luecke)
6047 5 ▶sub _lsblk_basic {
Subroutine _lsblk_basic: called CC=28 SCAR=34.1
6048 5 my ( $dev, $av ) = @_;
6049 5 my ( $o, $err ) = _lsblk_opts($av);
6050 5 ▶ return ( $err, 0 ) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 1 4 5
6051 4 ▶ if ( !$o || $o->{f} || @{ $o->{dev} } || grep { /\A(?:LABEL|UUID)\z/ } @{ $o->{list} } ) { push @GAPS, join( ' ', 'lsblk', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (not $o or $$o{"f"} or @{$$o{"dev"};} or grep {/\A(?:LABEL|UUID)\z/;} @{$$o{"list"};}) 1 3 4
Condition66%6/9
not $o or $$o{"f"} or @{$$o{"dev"};} or grep {/\A(?:LABEL|UUID)\z/;} @{$$o{"list"};}
l!l&&r!l&&!r
103
not $o or $$o{"f"} or @{$$o{"dev"};}
l!l&&r!l&&!r
103
not $o or $$o{"f"}
l!l&&r!l&&!r
013
MC/DC25%1/4
not $o or $$o{"f"} or @{$$o{"dev"};} or grep {/\A(?:LABEL|UUID)\z/;} @{$$o{"list"};}
not $o $$o{"f"} @{$$o{"dev"};} grep {/\A(?:LABEL|UUID)\z/;} @{$$o{"list"};}
Truth table40%2/5
not(A) or B or C or D
A= not $oB= $$o{"f"}C= @{$$o{"dev"};}D= grep {/\A(?:LABEL|UUID)\z/;} @{$$o{"list"};}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
6052 3 my $m = _mounts($dev);
6053 3 my ( %disk, @order );
6054 3 my $minor = 0;
6055 3 for my $mp ( sort keys %$m ) {
6056 3 ▶ my $d = $m->{$mp}{dev} // '/dev/vda1';
Condition50%1/2
$$m{$mp}{"dev"} // "/dev/vda1"
l!l
30
MC/DC0%0/1
$$m{$mp}{"dev"} // "/dev/vda1"
$$m{$mp}{"dev"}
Truth table50%1/2
A
A= $$m{$mp}{"dev"}
Aresult
11
00
6057 3 ▶ next unless $d =~ m{\A/dev/((?:[sv]d[a-z]|nvme\d+n\d+)(?:p?\d+)?)\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $d =~ m[\A/dev/((?:[sv]d[a-z]|nvme\d+n\d+)(?:p?\d+)?)\z] 0 3 3
6058 3 my $part = $1;
6059 3 ▶ ( my $disk = $part ) =~ s/(?:p?\d+)\z// unless $part =~ /\Anvme\d+n\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $part =~ /\Anvme\d+n\d+\z/ 3 0 3
6060 3 ▶ $disk //= $part;
Condition33%1/3
$disk //= $part
l!l&&r!l&&!r
300
MC/DC0%0/2
$disk //= $part
$disk $part
Truth table33%1/3
A //= B
A= $diskB= $part
ABresult
1X1
011
000
6061 3 ▶ push @order, $disk unless $disk{$disk};
Branch: 1 branch
BranchTrueFalseTotal
unless $disk{$disk} 3 0 3
6062 3 ▶ push @{ $disk{$disk} }, [ $part, $m->{$mp}{size} // '40G', $mp, $m->{$mp}{fstype} ];
Condition50%1/2
$$m{$mp}{"size"} // "40G"
l!l
30
MC/DC0%0/1
$$m{$mp}{"size"} // "40G"
$$m{$mp}{"size"}
Truth table50%1/2
A
A= $$m{$mp}{"size"}
Aresult
11
00
6063 }
6064 3 my %df = map { $_->{mount} => $_ } _df_rows($dev);
6065 3 my @rows;
6066 3 my $maj = 254;
6067 3 for my $dk (@order) {
6068 3 my $base = $minor;
6069 3 my @parts = grep { $_->[0] ne $dk } @{ $disk{$dk} };
6070 3 my ($whole) = grep { $_->[0] eq $dk } @{ $disk{$dk} };
6071 3 ▶ my $size = $whole ? $whole->[1] : $parts[0][1];
Branch: 1 branch
BranchTrueFalseTotal
$whole ? : 0 3 3
6072 3 my @r = ( [ $dk, "$maj:$base", $size, 'disk', $whole, '' ] );
6073 3 my $i = 0;
6074 3 for my $pt (@parts) {
6075 3 $i++;
6076 3 ▶ push @r, [ $pt->[0], "$maj:" . ( $base + $i ), $pt->[1], 'part', $pt, $i == @parts ? "\x{2514}\x{2500}" : "\x{251c}\x{2500}" ];
Branch: 1 branch
BranchTrueFalseTotal
$i == @parts ? : 3 0 3
6077 }
6078 3 for (@r) {
6079 6 my ( $n, $mm, $sz, $type, $src, $tree ) = @$_;
6080 6 ▶ my $mp = $src ? $src->[2] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$src ? : 3 3 6
6081 6 ▶ my $df = defined $mp ? $df{$mp} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $mp ? : 3 3 6
6082 push @rows, { name => $n, path => "/dev/$n", tree => $tree, majmin => $mm, size => $sz, type => $type, mps => [ $mp // () ],
6083 6 ▶ fstype => $src ? $src->[3] // 'ext4' : undef, fsavail => $df ? $df->{avail} : undef, fsuse => $df ? $df->{pct} : undef };
Branch: 3 branches
BranchTrueFalseTotal
$src ? : 3 3 6
$df ? : 3 3 6
$df ? : 3 3 6
Condition60%3/5
$mp // ()
l!l&&r!l&&!r
330
$$src[3] // "ext4"
l!l
03
MC/DC0%0/2
$mp // ()
$mp ()
MC/DC0%0/1
$$src[3] // "ext4"
$$src[3]
Truth table66%2/3
A // B
A= $mpB= ()
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$src[3]
Aresult
11
00
6084 }
6085 3 $minor += 16;
6086 }
6087 3 ▶ if ( $o->{table} ) { $_->{size} = _bytes( $_->{size} ) for @rows; return ( _lsblk_table( \@rows, $o ), 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($$o{"table"}) 2 1 3
6088 1 my @l = ( sprintf '%-8s %-7s %2s %5s %2s %-4s %s', 'NAME', 'MAJ:MIN', 'RM', 'SIZE', 'RO', 'TYPE', 'MOUNTPOINTS' );
6089 1 push @l, sprintf( '%-8s %-7s %2d %5s %2d %-4s %s', $_->{tree} . $_->{name}, $_->{majmin}, 0, $_->{size}, 0, $_->{type}, join( ' ', @{ $_->{mps} } ) ) =~ s/\s+\z//r for @rows;
6090 1 return ( join( "\n", @l ), 1 );
6091 }
6092  
6093 # Programm, das als ausfuehrbare Datei im Zustand liegt (z. B. /usr/bin/redis-cli)
6094 2416 ▶sub _prog_file {
Subroutine _prog_file: called CC=5 SCAR=16.3
6095 2416 my ( $dev, $n ) = @_;
6096 2416 ▶ return undef if $n =~ m{/};
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ m[/] 0 2416 2416
6097 2416 for my $d (qw( /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin )) {
6098 14466 ▶ my $e = _file_entry( $dev, "$d/$n" ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $e = _file_entry($dev, "$d/$n") or next 14 14452 14466
6099 14 ▶ return "$d/$n" if _mode_of($e) & 0111;
Branch: 1 branch
BranchTrueFalseTotal
if _mode_of($e) & 73 14 0 14
6100 }
6101 2402 return undef;
6102 }
6103  
6104 # Shell-Skript im Zustand: Text mit sh/bash/dash-Shebang oder ohne Shebang (leer = Programm)
6105 17 ▶sub _shell_script {
Subroutine _shell_script: called CC=5 SCAR=16.1
6106 17 my ( $dev, $p ) = @_;
6107 17 ▶ return 0 unless _file_entry( $dev, $p );
Branch: 1 branch
BranchTrueFalseTotal
unless _file_entry($dev, $p) 7 10 17
6108 10 ▶ my $t = _file_text( $dev, $p ) // '';
Condition50%1/2
_file_text($dev, $p) // ""
l!l
100
MC/DC0%0/1
_file_text($dev, $p) // ""
_file_text($dev, $p)
Truth table50%1/2
A
A= _file_text($dev, $p)
Aresult
11
00
6109 10 ▶ return $t =~ /\S/ && $t !~ m{\A#!(?!\s*(?:\S*/env\s+(?:-S\s+)?)?\S*\b(?:ba|da)?sh\b)} ? 1 : 0; # auch #!/usr/bin/env bash
Branch: 1 branch
BranchTrueFalseTotal
$t =~ /\S/ && !($t =~ m[\A#!(?!\s*(?:\S*/env\s+(?:-S\s+)?)?\S*\b(?:ba|da)?sh\b)]) ? : 8 2 10
Condition100%3/3
$t =~ /\S/ and not $t =~ m[\A#!(?!\s*(?:\S*/env\s+(?:-S\s+)?)?\S*\b(?:ba|da)?sh\b)]
!ll&&!rl&&r
118
MC/DC100%2/2
$t =~ /\S/ and not $t =~ m[\A#!(?!\s*(?:\S*/env\s+(?:-S\s+)?)?\S*\b(?:ba|da)?sh\b)]
$t =~ /\S/ not $t =~ m[\A#!(?!\s*(?:\S*/env\s+(?:-S\s+)?)?\S*\b(?:ba|da)?sh\b)]
Truth table100%3/3
A and not(B)
A= $t =~ /\S/B= not $t =~ m[\A#!(?!\s*(?:\S*/env\s+(?:-S\s+)?)?\S*\b(?:ba|da)?sh\b)]
ABresult
0X0
100
111
6110 }
6111  
6112 # which/whereis/type/command -v: Pfad eines Programms, das es auf dem System gibt
6113 2365 ▶sub _which {
Subroutine _which: called CC=38 SCAR=36.6
6114 2365 my ( $how, $dev, $av, $ctx, $stdin ) = @_;
6115 2365 my @a = @$av;
6116 2365 ▶ if ( $how eq 'command' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($how eq "command") 2 2363 2365
6117 2 ▶ return __PACKAGE__->_command( $dev, \@a, $ctx, $stdin ) unless @a && $a[0] =~ /\A-[vV]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless @a and $a[0] =~ /\A-[vV]\z/ 1 1 2
Condition66%2/3
@a and $a[0] =~ /\A-[vV]\z/
!ll&&!rl&&r
011
MC/DC50%1/2
@a and $a[0] =~ /\A-[vV]\z/
@a $a[0] =~ /\A-[vV]\z/
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A-[vV]\z/
ABresult
0X0
100
111
6118 1 shift @a;
6119 }
6120 2364 @a = grep { !/\A-/ } @a;
6121 2364 ▶ return ( '', 1 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 2364 2364
6122 2364 my ( @out, $ok );
6123 2364 $ok = 1;
6124 # Dienstprogramme aus ExecStart (exec); eine Datei des Falls gilt vor der Vorgabe
6125 2364 ▶ my %exec = map { ( $_->{exec} // '' ) => 1 } grep { ref eq 'HASH' } values %{ $dev->{services} || {} };
Condition100%4/4
$$_{"exec"} // ""
l!l
62533
$$dev{'services'} || {}
l!l
2098266
MC/DC100%1/1
$$_{"exec"} // ""
$$_{"exec"}
MC/DC100%1/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table100%2/2
A
A= $$_{"exec"}
Aresult
11
00
Truth table100%2/2
A
A= $$dev{'services'}
Aresult
11
00
6126 2364 for my $n (@a) {
6127 2372 my ($file) = grep { _file_entry( $dev, $_ ) } map {"$_/$n"} qw( /usr/local/bin /usr/bin /usr/sbin /bin );
6128 2372 ▶ my $have = $NEEDS{$n} ? $dev->{ $NEEDS{$n} } : $CMD{$n} || $REAL{$n} || $FILTER{$n} || $INTERACTIVE{$n} || $exec{$n}
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::NEEDS{$n} ? : 66 2306 2372
Condition86%13/15
$CMD{$n} or $Langertha::Holmgang::Sim::Linux::REAL{$n} or $Langertha::Holmgang::Sim::Linux::FILTER{$n} or $Langertha::Holmgang::Sim::Linux::INTERACTIVE{$n} or $exec{$n} or $n =~ /\A(?:ls|bash|sh|cat|cp|mv|rm|mkdir|tail|head|grep|sed|awk|find)\z/
l!l&&r!l&&!r
230006
$CMD{$n} or $Langertha::Holmgang::Sim::Linux::REAL{$n} or $Langertha::Holmgang::Sim::Linux::FILTER{$n} or $Langertha::Holmgang::Sim::Linux::INTERACTIVE{$n} or $exec{$n}
l!l&&r!l&&!r
2284166
$CMD{$n} or $Langertha::Holmgang::Sim::Linux::REAL{$n} or $Langertha::Holmgang::Sim::Linux::FILTER{$n} or $Langertha::Holmgang::Sim::Linux::INTERACTIVE{$n}
l!l&&r!l&&!r
2284022
$CMD{$n} or $Langertha::Holmgang::Sim::Linux::REAL{$n} or $Langertha::Holmgang::Sim::Linux::FILTER{$n}
l!l&&r!l&&!r
22028222
$CMD{$n} or $Langertha::Holmgang::Sim::Linux::REAL{$n}
l!l&&r!l&&!r
1714488104
MC/DC66%4/6
$CMD{$n} or $Langertha::Holmgang::Sim::Linux::REAL{$n} or $Langertha::Holmgang::Sim::Linux::FILTER{$n} or $Langertha::Holmgang::Sim::Linux::INTERACTIVE{$n} or $exec{$n} or $n =~ /\A(?:ls|bash|sh|cat|cp|mv|rm|mkdir|tail|head|grep|sed|awk|find)\z/
$CMD{$n} $Langertha::Holmgang::Sim::Linux::REAL{$n} $Langertha::Holmgang::Sim::Linux::FILTER{$n} $Langertha::Holmgang::Sim::Linux::INTERACTIVE{$n} $exec{$n} $n =~ /\A(?:ls|bash|sh|cat|cp|mv|rm|mkdir|tail|head|grep|sed|awk|find)\z/
Truth table71%5/7
A or B or C or D or E or F
A= $CMD{$n}B= $Langertha::Holmgang::Sim::Linux::REAL{$n}C= $Langertha::Holmgang::Sim::Linux::FILTER{$n}D= $Langertha::Holmgang::Sim::Linux::INTERACTIVE{$n}E= $exec{$n}F= $n =~ /\A(?:ls|bash|sh|cat|cp|mv|rm|mkdir|tail|head|grep|sed|awk|find)\z/
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
6129 || $n =~ /\A(?:ls|bash|sh|cat|cp|mv|rm|mkdir|tail|head|grep|sed|awk|find)\z/;
6130 2372 ▶ $have = 0 if $NOT_INSTALLED{$n};
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::NOT_INSTALLED{$n} 61 2311 2372
6131 2372 ▶ $have = 1 if _web_cmd( $dev, $n );
Branch: 1 branch
BranchTrueFalseTotal
if _web_cmd($dev, $n) 1 2371 2372
6132 # Zusatz-Simulatoren (BIND, Postfix, Platten, …) nur, wo ihr Paket im Zustand steht
6133 2372 ▶ if ( $have && $CMD{$n} && ( my $need = $EXT_NEED{ $CMD{$n} } ) ) { $have = 0 if @$need && !grep { $dev->{$_} } @$need }
Branch: 2 branches
BranchTrueFalseTotal
if ($have and $CMD{$n} and my $need = $Langertha::Holmgang::Sim::Linux::EXT_NEED{$CMD{$n}}) 477 1895 2372
if @$need and not grep({$$dev{$_};} @$need) 117 360 477
Condition88%8/9
$have and $CMD{$n} and my $need = $Langertha::Holmgang::Sim::Linux::EXT_NEED{$CMD{$n}}
!ll&&!rl&&r
7141181477
$have and $CMD{$n}
!ll&&!rl&&r
1285861658
@$need and not grep({$$dev{$_};} @$need)
!ll&&!rl&&r
3600117
MC/DC100%3/3
$have and $CMD{$n} and my $need = $Langertha::Holmgang::Sim::Linux::EXT_NEED{$CMD{$n}}
$have $CMD{$n} my $need = $Langertha::Holmgang::Sim::Linux::EXT_NEED{$CMD{$n}}
MC/DC50%1/2
@$need and not grep({$$dev{$_};} @$need)
@$need not grep({$$dev{$_};} @$need)
Truth table100%4/4
A and B and C
A= $haveB= $CMD{$n}C= my $need = $Langertha::Holmgang::Sim::Linux::EXT_NEED{$CMD{$n}}
ABCresult
0XX0
10X0
1100
1111
Truth table66%2/3
A and not(B)
A= @$needB= not grep({$$dev{$_};} @$need)
ABresult
0X0
100
111
6134 2372 ▶ $have = 1 if $file;
Branch: 1 branch
BranchTrueFalseTotal
if $file 2 2370 2372
6135 2372 ▶ my $path = $file // ( $n =~ /\A(?:kubectl|helm)\z/ ? '/usr/local/bin/' : $SBIN{$n} || $n =~ /\A(?:mkfs.*|fsck.*|pv\w+|vg\w+|lv\w+|named-check\w+)\z/ ? '/usr/sbin/' : '/usr/bin/' ) . $n;
Branch: 2 branches
BranchTrueFalseTotal
$n =~ /\A(?:kubectl|helm)\z/ ? : 20 2350 2370
$Langertha::Holmgang::Sim::Linux::SBIN{$n} || $n =~ /\A(?:mkfs.*|fsck.*|pv\w+|vg\w+|lv\w+|named-check\w+)\z/ ? : 615 1735 2350
Condition100%5/5
$file // ($n =~ /\A(?:kubectl|helm)\z/ ? "/usr/local/bin/" : ($Langertha::Holmgang::Sim::Linux::SBIN{$n} || $n =~ /\A(?:mkfs.*|fsck.*|pv\w+|vg\w+|lv\w+|named-check\w+)\z/ ? "/usr/sbin/" : "/usr/bin/")) . $n
l!l
22370
$Langertha::Holmgang::Sim::Linux::SBIN{$n} or $n =~ /\A(?:mkfs.*|fsck.*|pv\w+|vg\w+|lv\w+|named-check\w+)\z/
l!l&&r!l&&!r
4441711735
MC/DC100%1/1
$file // ($n =~ /\A(?:kubectl|helm)\z/ ? "/usr/local/bin/" : ($Langertha::Holmgang::Sim::Linux::SBIN{$n} || $n =~ /\A(?:mkfs.*|fsck.*|pv\w+|vg\w+|lv\w+|named-check\w+)\z/ ? "/usr/sbin/" : "/usr/bin/")) . $n
$file
MC/DC100%2/2
$Langertha::Holmgang::Sim::Linux::SBIN{$n} or $n =~ /\A(?:mkfs.*|fsck.*|pv\w+|vg\w+|lv\w+|named-check\w+)\z/
$Langertha::Holmgang::Sim::Linux::SBIN{$n} $n =~ /\A(?:mkfs.*|fsck.*|pv\w+|vg\w+|lv\w+|named-check\w+)\z/
Truth table100%2/2
A
A= $file
Aresult
11
00
Truth table100%3/3
A or B
A= $Langertha::Holmgang::Sim::Linux::SBIN{$n}B= $n =~ /\A(?:mkfs.*|fsck.*|pv\w+|vg\w+|lv\w+|named-check\w+)\z/
ABresult
1X1
011
000
6136 2372 ▶ if ( my $prog = _prog_file( $dev, $n ) ) { ( $have, $path ) = ( 1, $prog ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $prog = _prog_file($dev, $n)) 2 2370 2372
6137 2372 ▶ if ( $how eq 'whereis' ) { push @out, $have && !$BUILTIN{$n} ? "$n: $path" : "$n:"; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($how eq "whereis") 1 2371 2372
$have && !$Langertha::Holmgang::Sim::Linux::BUILTIN{$n} ? : 0 1 1
Condition33%1/3
$have and not $Langertha::Holmgang::Sim::Linux::BUILTIN{$n}
!ll&&!rl&&r
100
MC/DC0%0/2
$have and not $Langertha::Holmgang::Sim::Linux::BUILTIN{$n}
$have not $Langertha::Holmgang::Sim::Linux::BUILTIN{$n}
Truth table33%1/3
A and not(B)
A= $haveB= not $Langertha::Holmgang::Sim::Linux::BUILTIN{$n}
ABresult
0X0
100
111
6138 2371 ▶ if ( $BUILTIN{$n} && $how ne 'which' ) { push @out, $how eq 'type' ? "$n is a shell builtin" : $n; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($Langertha::Holmgang::Sim::Linux::BUILTIN{$n} and $how ne "which") 1 2370 2371
$how eq 'type' ? : 1 0 1
Condition100%3/3
$Langertha::Holmgang::Sim::Linux::BUILTIN{$n} and $how ne "which"
!ll&&!rl&&r
2279911
MC/DC100%2/2
$Langertha::Holmgang::Sim::Linux::BUILTIN{$n} and $how ne "which"
$Langertha::Holmgang::Sim::Linux::BUILTIN{$n} $how ne "which"
Truth table100%3/3
A and B
A= $Langertha::Holmgang::Sim::Linux::BUILTIN{$n}B= $how ne "which"
ABresult
0X0
100
111
6139 2370 ▶ if ( !$have || $BUILTIN{$n} && $n !~ /\A(?:echo|printf|true|false|test|\[)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $have or $Langertha::Holmgang::Sim::Linux::BUILTIN{$n} and not $n =~ /\A(?:echo|printf|true|false|test|\[)\z/) 278 2092 2370
Condition100%6/6
not $have or $Langertha::Holmgang::Sim::Linux::BUILTIN{$n} and not $n =~ /\A(?:echo|printf|true|false|test|\[)\z/
l!l&&r!l&&!r
242362092
$Langertha::Holmgang::Sim::Linux::BUILTIN{$n} and not $n =~ /\A(?:echo|printf|true|false|test|\[)\z/
!ll&&!rl&&r
20375536
MC/DC100%3/3
not $have or $Langertha::Holmgang::Sim::Linux::BUILTIN{$n} and not $n =~ /\A(?:echo|printf|true|false|test|\[)\z/
not $have $Langertha::Holmgang::Sim::Linux::BUILTIN{$n} not $n =~ /\A(?:echo|printf|true|false|test|\[)\z/
Truth table100%4/4
not(A) or B and not(C)
A= not $haveB= $Langertha::Holmgang::Sim::Linux::BUILTIN{$n}C= not $n =~ /\A(?:echo|printf|true|false|test|\[)\z/
ABCresult
1XX1
0111
00X0
0100
6140 278 ▶ push @out, "bash: type: $n: not found" if $how eq 'type';
Branch: 1 branch
BranchTrueFalseTotal
if $how eq "type" 0 278 278
6141 278 $ok = 0;
6142 278 next;
6143 }
6144 2092 ▶ push @out, $how eq 'type' ? "$n is $path" : $path;
Branch: 1 branch
BranchTrueFalseTotal
$how eq 'type' ? : 1 2091 2092
6145 }
6146 2364 return ( join( "\n", @out ), $ok );
6147 }
6148  
6149 # --- Benutzer und Gruppen ------------------------------------------------------------
6150  
6151 7 ▶sub _id {
Subroutine _id: called CC=6 SCAR=19.2
6152 7 my ( $dev, $av ) = @_;
6153 7 my ($u) = grep { !/\A-/ } @$av;
6154 7 ▶ $u //= _who();
Condition33%1/3
$u //= _who()
l!l&&r!l&&!r
700
MC/DC0%0/2
$u //= _who()
$u _who()
Truth table33%1/3
A //= B
A= $uB= _who()
ABresult
1X1
011
000
6155 7 ▶ return ( 'uid=0(root) gid=0(root) groups=0(root)', 1 ) if $u eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $u eq "root" 0 7 7
6156 7 ▶ my $e = ( $dev->{users} || {} )->{$u} or return ( "id: '$u': no such user", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $e = ($$dev{"users"} || {})->{$u} or return "id: '${u}': no such user", 0 7 0 7
Condition50%1/2
$$dev{'users'} || {}
l!l
70
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
6157 7 ▶ my @g = @{ $e->{groups} || [$u] };
Condition50%1/2
$$e{'groups'} || [$u]
l!l
70
MC/DC0%0/1
$$e{'groups'} || [$u]
$$e{'groups'}
Truth table50%1/2
A
A= $$e{'groups'}
Aresult
11
00
6158 7 return ( "uid=$e->{uid}($u) gid=" . _gid( $dev, $g[0] ) . "($g[0]) groups=" . join( ',', map { _gid( $dev, $_ ) . "($_)" } @g ), 1 );
6159 }
6160  
6161 0 ▶sub _groups_cmd {
Subroutine _groups_cmd: not called CC=6 SCAR=37.4
6162 0 my ( $dev, $av ) = @_;
6163 0 my ($u) = @$av;
6164 0 ▶ $u //= 'root';
Condition0%0/2
$u //= "root"
l!l
00
MC/DC0%0/1
$u //= "root"
$u
Truth table0%0/2
A
A= $u
Aresult
11
00
6165 0 ▶ return ( 'root', 1 ) if $u eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $u eq "root" 0 0 0
6166 0 ▶ my $e = ( $dev->{users} || {} )->{$u} or return ( "groups: '$u': no such user", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $e = ($$dev{"users"} || {})->{$u} or return "groups: '${u}': no such user", 0 0 0 0
Condition0%0/2
$$dev{'users'} || {}
l!l
00
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
Truth table0%0/2
A
A= $$dev{'users'}
Aresult
11
00
6167 0 ▶ return ( "$u : " . join( ' ', @{ $e->{groups} || [] } ), 1 );
Condition0%0/2
$$e{'groups'} || []
l!l
00
MC/DC0%0/1
$$e{'groups'} || []
$$e{'groups'}
Truth table0%0/2
A
A= $$e{'groups'}
Aresult
11
00
6168 }
6169  
6170 7 ▶sub _usermod {
Subroutine _usermod: called CC=66 SCAR=53.1
6171 7 my ( $dev, $av ) = @_;
6172 7 my @a = @$av;
6173 7 my ( $add, $grps, $del, %set );
6174 7 ▶ while ( @a > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a > 1) 11 7 18
6175 11 my $x = shift @a;
6176 11 ▶ if ( $x eq '-aG' || $x eq '-a' ) { $add = 1; $grps = shift @a if $x eq '-aG' }
Branch: 12 branches
BranchTrueFalseTotal
if ($x eq '-aG' or $x eq '-a') { } 3 8 11
elsif ($x eq '-rG' or $x eq '-r' or $x eq '--remove') { } 1 7 8
elsif ($x eq '-G' or $x eq '--groups') { } 1 6 7
elsif ($x eq '-L' or $x eq '--lock') { } 1 5 6
elsif ($x eq '-U' or $x eq '--unlock') { } 0 5 5
elsif ($x eq '-s' or $x eq '--shell') { } 2 3 5
elsif ($x eq '-e' or $x eq '--expiredate') { } 1 2 3
elsif ($x =~ /\A-[LU]+\z/) { } 0 2 2
elsif ($x eq '-c' or $x eq '--comment') { } 0 2 2
elsif ($x eq '-d' or $x eq '--home') { } 1 1 2
elsif ($x eq '-m' or $x eq '--move-home') { } 1 0 1
if $x eq "-aG" 3 0 3
Condition66%2/3
$x eq "-aG" or $x eq "-a"
l!l&&r!l&&!r
308
MC/DC50%1/2
$x eq "-aG" or $x eq "-a"
$x eq "-aG" $x eq "-a"
Truth table66%2/3
A or B
A= $x eq "-aG"B= $x eq "-a"
ABresult
1X1
011
000
6177 1 ▶ elsif ( $x eq '-rG' || $x eq '-r' || $x eq '--remove' ) { $del = 1; $grps = shift @a if $x eq '-rG' }
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "-rG" 0 1 1
Condition66%4/6
$x eq "-rG" or $x eq "-r" or $x eq "--remove"
l!l&&r!l&&!r
107
$x eq "-rG" or $x eq "-r"
l!l&&r!l&&!r
017
MC/DC33%1/3
$x eq "-rG" or $x eq "-r" or $x eq "--remove"
$x eq "-rG" $x eq "-r" $x eq "--remove"
Truth table50%2/4
A or B or C
A= $x eq "-rG"B= $x eq "-r"C= $x eq "--remove"
ABCresult
1XX1
01X1
0011
0000
6178 1 ▶ elsif ( $x eq '-G' || $x eq '--groups' ) { $grps = shift @a }
Condition66%2/3
$x eq "-G" or $x eq "--groups"
l!l&&r!l&&!r
106
MC/DC50%1/2
$x eq "-G" or $x eq "--groups"
$x eq "-G" $x eq "--groups"
Truth table66%2/3
A or B
A= $x eq "-G"B= $x eq "--groups"
ABresult
1X1
011
000
6179 1 ▶ elsif ( $x eq '-L' || $x eq '--lock' ) { $set{locked} = 1 }
Condition66%2/3
$x eq "-L" or $x eq "--lock"
l!l&&r!l&&!r
105
MC/DC50%1/2
$x eq "-L" or $x eq "--lock"
$x eq "-L" $x eq "--lock"
Truth table66%2/3
A or B
A= $x eq "-L"B= $x eq "--lock"
ABresult
1X1
011
000
6180 0 ▶ elsif ( $x eq '-U' || $x eq '--unlock' ) { $set{locked} = 0 }
Condition33%1/3
$x eq "-U" or $x eq "--unlock"
l!l&&r!l&&!r
005
MC/DC0%0/2
$x eq "-U" or $x eq "--unlock"
$x eq "-U" $x eq "--unlock"
Truth table33%1/3
A or B
A= $x eq "-U"B= $x eq "--unlock"
ABresult
1X1
011
000
6181 2 ▶ elsif ( $x eq '-s' || $x eq '--shell' ) { $set{shell} = shift @a }
Condition66%2/3
$x eq "-s" or $x eq "--shell"
l!l&&r!l&&!r
203
MC/DC50%1/2
$x eq "-s" or $x eq "--shell"
$x eq "-s" $x eq "--shell"
Truth table66%2/3
A or B
A= $x eq "-s"B= $x eq "--shell"
ABresult
1X1
011
000
6182 1 ▶ elsif ( $x eq '-e' || $x eq '--expiredate' ) { $set{expire} = shift @a }
Condition66%2/3
$x eq "-e" or $x eq "--expiredate"
l!l&&r!l&&!r
102
MC/DC50%1/2
$x eq "-e" or $x eq "--expiredate"
$x eq "-e" $x eq "--expiredate"
Truth table66%2/3
A or B
A= $x eq "-e"B= $x eq "--expiredate"
ABresult
1X1
011
000
6183 0 ▶ elsif ( $x =~ /\A-[LU]+\z/ ) { $set{locked} = $x =~ /L/ ? 1 : 0 }
Branch: 1 branch
BranchTrueFalseTotal
$x =~ /L/ ? : 0 0 0
6184 0 ▶ elsif ( $x eq '-c' || $x eq '--comment' ) { shift @a }
Condition33%1/3
$x eq "-c" or $x eq "--comment"
l!l&&r!l&&!r
002
MC/DC0%0/2
$x eq "-c" or $x eq "--comment"
$x eq "-c" $x eq "--comment"
Truth table33%1/3
A or B
A= $x eq "-c"B= $x eq "--comment"
ABresult
1X1
011
000
6185 1 ▶ elsif ( $x eq '-d' || $x eq '--home' ) { $set{home} = shift @a }
Condition66%2/3
$x eq "-d" or $x eq "--home"
l!l&&r!l&&!r
101
MC/DC50%1/2
$x eq "-d" or $x eq "--home"
$x eq "-d" $x eq "--home"
Truth table66%2/3
A or B
A= $x eq "-d"B= $x eq "--home"
ABresult
1X1
011
000
6186 1 ▶ elsif ( $x eq '-m' || $x eq '--move-home' ) { $set{move} = 1 }
Condition33%1/3
$x eq "-m" or $x eq "--move-home"
l!l&&r!l&&!r
100
MC/DC0%0/2
$x eq "-m" or $x eq "--move-home"
$x eq "-m" $x eq "--move-home"
Truth table33%1/3
A or B
A= $x eq "-m"B= $x eq "--move-home"
ABresult
1X1
011
000
6187 0 else { return ( "usermod: invalid option -- '$x'", 0 ) }
6188 }
6189 7 my $u = shift @a;
6190 7 ▶ my $e = ( $dev->{users} || {} )->{ $u // '' } or return ( "usermod: user '" . ( $u // '' ) . "' does not exist", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $e = ($$dev{"users"} || {})->{$u // ""} or return q[usermod: user '] . ($u // "") . q[' does not exist], 0 7 0 7
Condition33%2/6
$$dev{'users'} || {}
l!l
70
$u // ""
l!l
70
$u // ""
l!l
00
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
MC/DC0%0/1
$u // ""
$u
MC/DC0%0/1
$u // ""
$u
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
Truth table50%1/2
A
A= $u
Aresult
11
00
Truth table0%0/2
A
A= $u
Aresult
11
00
6191 7 ▶ if ( defined $set{home} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set{"home"}) 1 6 7
6192 1 ▶ my $old = $e->{home} // "/home/$u";
Condition50%1/2
$$e{"home"} // "/home/$u"
l!l
10
MC/DC0%0/1
$$e{"home"} // "/home/$u"
$$e{"home"}
Truth table50%1/2
A
A= $$e{"home"}
Aresult
11
00
6193 1 my $new = delete $set{home};
6194 1 ▶ return ( "usermod: no changes", 1 ) if $old eq $new && !%set;
Branch: 1 branch
BranchTrueFalseTotal
if $old eq $new and not %set 0 1 1
Condition33%1/3
$old eq $new and not %set
!ll&&!rl&&r
100
MC/DC0%0/2
$old eq $new and not %set
$old eq $new not %set
Truth table33%1/3
A and not(B)
A= $old eq $newB= not %set
ABresult
0X0
100
111
6195 1 ▶ _tree( $dev, $old, $new, 'move' ) if delete $set{move} && _is_dir( $dev, $old ) && !_is_dir( $dev, $new );
Branch: 1 branch
BranchTrueFalseTotal
if delete $set{"move"} and _is_dir($dev, $old) and not _is_dir($dev, $new) 1 0 1
Condition33%2/6
delete $set{"move"} and _is_dir($dev, $old) and not _is_dir($dev, $new)
!ll&&!rl&&r
001
delete $set{"move"} and _is_dir($dev, $old)
!ll&&!rl&&r
001
MC/DC0%0/3
delete $set{"move"} and _is_dir($dev, $old) and not _is_dir($dev, $new)
delete $set{"move"} _is_dir($dev, $old) not _is_dir($dev, $new)
Truth table25%1/4
A and B and not(C)
A= delete $set{"move"}B= _is_dir($dev, $old)C= not _is_dir($dev, $new)
ABCresult
0XX0
10X0
1100
1111
6196 1 $e->{home} = $new;
6197 1 ▶ return ( '', 1 ) unless %set || defined $grps;
Branch: 1 branch
BranchTrueFalseTotal
unless %set or defined $grps 1 0 1
Condition33%1/3
%set or defined $grps
l!l&&r!l&&!r
001
MC/DC0%0/2
%set or defined $grps
%set defined $grps
Truth table33%1/3
A or B
A= %setB= defined $grps
ABresult
1X1
011
000
6198 }
6199 6 delete $set{move};
6200 6 ▶ if ( exists $set{expire} ) { my $err = _acc()->can('set_expire')->( $dev, $e, $set{expire} ); return ( "usermod: $err", 0 ) if $err }
Branch: 2 branches
BranchTrueFalseTotal
if (exists $set{"expire"}) 1 5 6
if $err 0 1 1
6201 6 ▶ if ( exists $set{locked} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $set{"locked"}) 1 5 6
6202 1 ▶ my $want = $set{locked} ? JSON::MaybeXS::true() : JSON::MaybeXS::false();
Branch: 1 branch
BranchTrueFalseTotal
$set{'locked'} ? : 1 0 1
6203 1 ▶ $e->{locked} = $want if ( $e->{locked} ? 1 : 0 ) != $set{locked};
Branch: 2 branches
BranchTrueFalseTotal
if ($$e{"locked"} ? 1 : 0) != $set{"locked"} 1 0 1
$$e{'locked'} ? : 0 1 1
6204 }
6205 6 ▶ if ( defined $set{shell} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set{"shell"}) 2 4 6
6206 2 ▶ return ( "usermod: invalid shell '$set{shell}'", 0 ) unless $set{shell} =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
unless $set{"shell"} =~ m[\A/] 0 2 2
6207 2 ▶ $e->{shell} = $set{shell} unless ( $e->{shell} // '' ) eq $set{shell};
Branch: 1 branch
BranchTrueFalseTotal
unless ($$e{"shell"} // "") eq $set{"shell"} 2 0 2
Condition50%1/2
$$e{"shell"} // ""
l!l
20
MC/DC0%0/1
$$e{"shell"} // ""
$$e{"shell"}
Truth table50%1/2
A
A= $$e{"shell"}
Aresult
11
00
6208 }
6209 6 ▶ if ( $del && defined $grps ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($del and defined $grps) 1 5 6
Condition66%2/3
$del and defined $grps
!ll&&!rl&&r
501
MC/DC50%1/2
$del and defined $grps
$del defined $grps
Truth table66%2/3
A and B
A= $delB= defined $grps
ABresult
0X0
100
111
6210 1 my %rm = map { $_ => 1 } split /,/, $grps;
6211 1 ▶ my @g = grep { !$rm{$_} } @{ $e->{groups} || [] };
Condition50%1/2
$$e{'groups'} || []
l!l
10
MC/DC0%0/1
$$e{'groups'} || []
$$e{'groups'}
Truth table50%1/2
A
A= $$e{'groups'}
Aresult
11
00
6212 1 ▶ $e->{groups} = \@g unless @g == @{ $e->{groups} || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless @g == @{$$e{"groups"} or [];} 1 0 1
Condition50%1/2
$$e{'groups'} || []
l!l
10
MC/DC0%0/1
$$e{'groups'} || []
$$e{'groups'}
Truth table50%1/2
A
A= $$e{'groups'}
Aresult
11
00
6213 1 return ( '', 1 );
6214 }
6215 5 ▶ return ( %set ? '' : "usermod: no changes", 1 ) unless defined $grps;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $grps 2 3 5
%set ? : 2 0 2
6216 3 ▶ my %known = ( map { $_ => 1 } keys %{ $dev->{groups} || {} }, map { @{ $_->{groups} || [] } } values %{ $dev->{users} } );
Condition50%2/4
$$dev{'groups'} || {}
l!l
30
$$_{'groups'} || []
l!l
70
MC/DC0%0/1
$$dev{'groups'} || {}
$$dev{'groups'}
MC/DC0%0/1
$$_{'groups'} || []
$$_{'groups'}
Truth table50%1/2
A
A= $$dev{'groups'}
Aresult
11
00
Truth table50%1/2
A
A= $$_{'groups'}
Aresult
11
00
6217 3 my @new = split /,/, $grps;
6218 3 ▶ for (@new) { return ( "usermod: group '$_' does not exist", 0 ) unless $known{$_} }
Branch: 1 branch
BranchTrueFalseTotal
unless $known{$_} 1 2 3
6219 2 ▶ my @cur = @{ $e->{groups} || [] };
Condition50%1/2
$$e{'groups'} || []
l!l
20
MC/DC0%0/1
$$e{'groups'} || []
$$e{'groups'}
Truth table50%1/2
A
A= $$e{'groups'}
Aresult
11
00
6220 0 ▶ my @g = $add ? ( @cur, grep { my $x = $_; !grep { $_ eq $x } @cur } @new ) : ( $cur[0] // $u, grep { $_ ne ( $cur[0] // $u ) } @new );
Branch: 1 branch
BranchTrueFalseTotal
$add ? : 2 0 2
Condition0%0/6
$cur[0] // $u
l!l&&r!l&&!r
000
$cur[0] // $u
l!l&&r!l&&!r
000
MC/DC0%0/2
$cur[0] // $u
$cur[0] $u
MC/DC0%0/2
$cur[0] // $u
$cur[0] $u
Truth table0%0/3
A // B
A= $cur[0]B= $u
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $cur[0]B= $u
ABresult
1X1
011
000
6221 2 ▶ $e->{groups} = \@g unless join( ',', @g ) eq join( ',', @cur );
Branch: 1 branch
BranchTrueFalseTotal
unless join(",", @g) eq join(",", @cur) 2 0 2
6222 2 return ( '', 1 );
6223 }
6224  
6225 # Naechste freie Nummer: Konten ab 1000 nach der hoechsten vergebenen, Systemkonten von 999
6226 # abwaerts (useradd/groupadd -r), adduser/addgroup --system ab 100 aufwaerts; $want zuerst
6227 9 ▶sub _free_id {
Subroutine _free_id: called CC=11 SCAR=24.7
6228 9 my ( $used, $sys, $want, $up ) = @_;
6229 9 ▶ return $want if defined $want && !$used->{$want};
Branch: 1 branch
BranchTrueFalseTotal
if defined $want and not $$used{$want} 2 7 9
Condition66%2/3
defined $want and not $$used{$want}
!ll&&!rl&&r
702
MC/DC50%1/2
defined $want and not $$used{$want}
defined $want not $$used{$want}
Truth table66%2/3
A and not(B)
A= defined $wantB= not $$used{$want}
ABresult
0X0
100
111
6230 7 ▶ if ($sys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sys) 4 3 7
6231 4 ▶ if ($up) { for my $i ( 100 .. 999 ) { return $i unless $used->{$i} } }
Branch: 2 branches
BranchTrueFalseTotal
if ($up) 2 2 4
unless $$used{$i} 2 0 2
6232 2 ▶ for ( my $i = 999; $i >= 100; $i-- ) { return $i unless $used->{$i} }
Branch: 2 branches
BranchTrueFalseTotal
if ($i >= 100) 2 0 2
unless $$used{$i} 2 0 2
6233 }
6234 3 ▶ my ($max) = sort { $b <=> $a } grep { $_ >= 1000 && $_ < 60000 } keys %$used;
Condition66%2/3
$_ >= 1000 && $_ < 60000
!ll&&!rl&&r
4012
MC/DC50%1/2
$_ >= 1000 && $_ < 60000
$_ >= 1000 $_ < 60000
Truth table66%2/3
A && B
A= $_ >= 1000B= $_ < 60000
ABresult
0X0
100
111
6235 3 ▶ return defined $max ? $max + 1 : 1000;
Branch: 1 branch
BranchTrueFalseTotal
defined $max ? : 3 0 3
6236 }
6237  
6238 5 ▶sub _gids { my ($dev) = @_; return { map { ( $_->{gid} // -1 ) => 1 } values %{ $dev->{groups} || {} } } }
Subroutine _gids: called CC=3 SCAR=11.4
Condition50%2/4
$$_{"gid"} // -1
l!l
400
$$dev{'groups'} || {}
l!l
50
MC/DC0%0/1
$$_{"gid"} // -1
$$_{"gid"}
MC/DC0%0/1
$$dev{'groups'} || {}
$$dev{'groups'}
Truth table50%1/2
A
A= $$_{"gid"}
Aresult
11
00
Truth table50%1/2
A
A= $$dev{'groups'}
Aresult
11
00
6239  
6240 # groupadd [-r] [-g GID] name | addgroup [--system] [--gid GID] name
6241 4 ▶sub _groupadd {
Subroutine _groupadd: called CC=19 SCAR=36.1
6242 4 my ( $prog, $dev, $av ) = @_;
6243 4 my @a = @$av;
6244 4 my ( $sys, $gid, @n );
6245 4 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 6 4 10
6246 6 my $x = shift @a;
6247 6 ▶ if ( $x eq '-r' || $x eq '--system' ) { $sys = 1 }
Branch: 4 branches
BranchTrueFalseTotal
if ($x eq '-r' or $x eq '--system') { } 2 4 6
elsif ($x eq '-g' or $x eq '--gid') { } 0 4 4
elsif ($x eq '-f' or $x eq '--force' or $x eq '--quiet' or $x eq '-q') { } 0 4 4
elsif ($x =~ /\A-/) { } 0 4 4
Condition100%3/3
$x eq "-r" or $x eq "--system"
l!l&&r!l&&!r
114
MC/DC100%2/2
$x eq "-r" or $x eq "--system"
$x eq "-r" $x eq "--system"
Truth table100%3/3
A or B
A= $x eq "-r"B= $x eq "--system"
ABresult
1X1
011
000
6248 0 ▶ elsif ( $x eq '-g' || $x eq '--gid' ) { $gid = shift @a }
Condition33%1/3
$x eq "-g" or $x eq "--gid"
l!l&&r!l&&!r
004
MC/DC0%0/2
$x eq "-g" or $x eq "--gid"
$x eq "-g" $x eq "--gid"
Truth table33%1/3
A or B
A= $x eq "-g"B= $x eq "--gid"
ABresult
1X1
011
000
6249 ▶ elsif ( $x eq '-f' || $x eq '--force' || $x eq '--quiet' || $x eq '-q' ) { }
Condition33%3/9
$x eq "-f" or $x eq "--force" or $x eq "--quiet" or $x eq "-q"
l!l&&r!l&&!r
004
$x eq "-f" or $x eq "--force" or $x eq "--quiet"
l!l&&r!l&&!r
004
$x eq "-f" or $x eq "--force"
l!l&&r!l&&!r
004
MC/DC0%0/4
$x eq "-f" or $x eq "--force" or $x eq "--quiet" or $x eq "-q"
$x eq "-f" $x eq "--force" $x eq "--quiet" $x eq "-q"
Truth table20%1/5
A or B or C or D
A= $x eq "-f"B= $x eq "--force"C= $x eq "--quiet"D= $x eq "-q"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
6250 0 elsif ( $x =~ /\A-/ ) { return ( "$prog: unrecognized option '$x'", 0 ) }
6251 4 else { push @n, $x }
6252 }
6253 4 ▶ return ( $prog eq 'addgroup' ? 'fatal: Only one or two names allowed.' : "Usage: groupadd [options] GROUP", 0 ) unless @n == 1;
Branch: 2 branches
BranchTrueFalseTotal
unless @n == 1 0 4 4
$prog eq 'addgroup' ? : 0 0 0
6254 4 my $g = $n[0];
6255 4 ▶ return ( $prog eq 'addgroup' ? "fatal: The group `$g' already exists." : "groupadd: group '$g' already exists", 0 ) if ( $dev->{groups} || {} )->{$g};
Branch: 2 branches
BranchTrueFalseTotal
if ($$dev{"groups"} || {})->{$g} 1 3 4
$prog eq 'addgroup' ? : 0 1 1
Condition50%1/2
$$dev{'groups'} || {}
l!l
40
MC/DC0%0/1
$$dev{'groups'} || {}
$$dev{'groups'}
Truth table50%1/2
A
A= $$dev{'groups'}
Aresult
11
00
6256 3 ▶ return ( "$prog: '$g' is not a valid group name", 0 ) unless $g =~ /\A[a-z_][a-z0-9_-]*\$?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $g =~ /\A[a-z_][a-z0-9_-]*\$?\z/ 0 3 3
6257 3 my $used = _gids($dev);
6258 3 ▶ return ( "groupadd: GID '$gid' already exists", 0 ) if defined $gid && $used->{$gid};
Branch: 1 branch
BranchTrueFalseTotal
if defined $gid and $$used{$gid} 0 3 3
Condition33%1/3
defined $gid and $$used{$gid}
!ll&&!rl&&r
300
MC/DC0%0/2
defined $gid and $$used{$gid}
defined $gid $$used{$gid}
Truth table33%1/3
A and B
A= defined $gidB= $$used{$gid}
ABresult
0X0
100
111
6259 3 $dev->{groups}{$g} = { gid => 0 + _free_id( $used, $sys, $gid, $prog eq 'addgroup' ) };
6260 3 return ( '', 1 );
6261 }
6262  
6263 # useradd [-m|-M] [-r] [-s S] [-d D] [-g G] [-G a,b] [-u UID] name;
6264 # adduser --system [--group|--ingroup G] [--no-create-home] [--home D] [--shell S] name;
6265 # adduser BENUTZER GRUPPE. Interaktives adduser (Passwort): Luecke der Simulation.
6266 8 ▶sub _useradd {
Subroutine _useradd: called CC=81 SCAR=55.4
6267 8 my ( $prog, $dev, $av ) = @_;
6268 8 my @a = @$av;
6269 8 my ( %o, @n );
6270 8 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 22 8 30
6271 22 my $x = shift @a;
6272 22 ▶ if ( $x eq '-m' || $x eq '--create-home' ) { $o{home_make} = 1 }
Branch: 13 branches
BranchTrueFalseTotal
if ($x eq '-m' or $x eq '--create-home') { } 1 21 22
elsif ($x eq '-M' or $x eq '--no-create-home') { } 2 19 21
elsif ($x eq '-r' or $x eq '--system') { } 2 17 19
elsif ($x eq '-s' or $x eq '--shell') { } 2 15 17
elsif ($x eq '-d' or $x eq '--home-dir' or $x eq '--home') { } 2 13 15
elsif ($x eq '-g' or $x eq '--gid' or $x eq '--ingroup') { } 2 11 13
elsif ($x eq '-G' or $x eq '--groups') { } 2 9 11
elsif ($x eq '-u' or $x eq '--uid') { } 0 9 9
elsif ($x eq '-c' or $x eq '--comment' or $x eq '--gecos') { } 0 9 9
elsif ($x eq '-U' or $x eq '--user-group' or $x eq '--group') { } 0 9 9
elsif ($x eq '-N' or $x eq '--no-user-group') { } 0 9 9
elsif ($x =~ /\A--(?:disabled-password|disabled-login|quiet|no-log-init)\z/ or $x eq '-q') { } 0 9 9
elsif ($x =~ /\A-/) { } 0 9 9
Condition66%2/3
$x eq "-m" or $x eq "--create-home"
l!l&&r!l&&!r
1021
MC/DC50%1/2
$x eq "-m" or $x eq "--create-home"
$x eq "-m" $x eq "--create-home"
Truth table66%2/3
A or B
A= $x eq "-m"B= $x eq "--create-home"
ABresult
1X1
011
000
6273 2 ▶ elsif ( $x eq '-M' || $x eq '--no-create-home' ) { $o{home_make} = 0 }
Condition66%2/3
$x eq "-M" or $x eq "--no-create-home"
l!l&&r!l&&!r
0219
MC/DC50%1/2
$x eq "-M" or $x eq "--no-create-home"
$x eq "-M" $x eq "--no-create-home"
Truth table66%2/3
A or B
A= $x eq "-M"B= $x eq "--no-create-home"
ABresult
1X1
011
000
6274 2 ▶ elsif ( $x eq '-r' || $x eq '--system' ) { $o{sys} = 1 }
Condition66%2/3
$x eq "-r" or $x eq "--system"
l!l&&r!l&&!r
0217
MC/DC50%1/2
$x eq "-r" or $x eq "--system"
$x eq "-r" $x eq "--system"
Truth table66%2/3
A or B
A= $x eq "-r"B= $x eq "--system"
ABresult
1X1
011
000
6275 2 ▶ elsif ( $x eq '-s' || $x eq '--shell' ) { $o{shell} = shift @a }
Condition100%3/3
$x eq "-s" or $x eq "--shell"
l!l&&r!l&&!r
1115
MC/DC100%2/2
$x eq "-s" or $x eq "--shell"
$x eq "-s" $x eq "--shell"
Truth table100%3/3
A or B
A= $x eq "-s"B= $x eq "--shell"
ABresult
1X1
011
000
6276 2 ▶ elsif ( $x eq '-d' || $x eq '--home-dir' || $x eq '--home' ) { $o{home} = shift @a }
Condition83%5/6
$x eq "-d" or $x eq "--home-dir" or $x eq "--home"
l!l&&r!l&&!r
1113
$x eq "-d" or $x eq "--home-dir"
l!l&&r!l&&!r
0114
MC/DC66%2/3
$x eq "-d" or $x eq "--home-dir" or $x eq "--home"
$x eq "-d" $x eq "--home-dir" $x eq "--home"
Truth table75%3/4
A or B or C
A= $x eq "-d"B= $x eq "--home-dir"C= $x eq "--home"
ABCresult
1XX1
01X1
0011
0000
6277 2 ▶ elsif ( $x eq '-g' || $x eq '--gid' || $x eq '--ingroup' ) { $o{group} = shift @a }
Condition83%5/6
$x eq "-g" or $x eq "--gid" or $x eq "--ingroup"
l!l&&r!l&&!r
1111
$x eq "-g" or $x eq "--gid"
l!l&&r!l&&!r
1012
MC/DC66%2/3
$x eq "-g" or $x eq "--gid" or $x eq "--ingroup"
$x eq "-g" $x eq "--gid" $x eq "--ingroup"
Truth table75%3/4
A or B or C
A= $x eq "-g"B= $x eq "--gid"C= $x eq "--ingroup"
ABCresult
1XX1
01X1
0011
0000
6278 2 ▶ elsif ( $x eq '-G' || $x eq '--groups' ) { $o{groups} = shift @a }
Condition66%2/3
$x eq "-G" or $x eq "--groups"
l!l&&r!l&&!r
209
MC/DC50%1/2
$x eq "-G" or $x eq "--groups"
$x eq "-G" $x eq "--groups"
Truth table66%2/3
A or B
A= $x eq "-G"B= $x eq "--groups"
ABresult
1X1
011
000
6279 0 ▶ elsif ( $x eq '-u' || $x eq '--uid' ) { $o{uid} = shift @a }
Condition33%1/3
$x eq "-u" or $x eq "--uid"
l!l&&r!l&&!r
009
MC/DC0%0/2
$x eq "-u" or $x eq "--uid"
$x eq "-u" $x eq "--uid"
Truth table33%1/3
A or B
A= $x eq "-u"B= $x eq "--uid"
ABresult
1X1
011
000
6280 0 ▶ elsif ( $x eq '-c' || $x eq '--comment' || $x eq '--gecos' ) { shift @a }
Condition33%2/6
$x eq "-c" or $x eq "--comment" or $x eq "--gecos"
l!l&&r!l&&!r
009
$x eq "-c" or $x eq "--comment"
l!l&&r!l&&!r
009
MC/DC0%0/3
$x eq "-c" or $x eq "--comment" or $x eq "--gecos"
$x eq "-c" $x eq "--comment" $x eq "--gecos"
Truth table25%1/4
A or B or C
A= $x eq "-c"B= $x eq "--comment"C= $x eq "--gecos"
ABCresult
1XX1
01X1
0011
0000
6281 0 ▶ elsif ( $x eq '-U' || $x eq '--user-group' || $x eq '--group' ) { $o{usergroup} = 1 }
Condition33%2/6
$x eq "-U" or $x eq "--user-group" or $x eq "--group"
l!l&&r!l&&!r
009
$x eq "-U" or $x eq "--user-group"
l!l&&r!l&&!r
009
MC/DC0%0/3
$x eq "-U" or $x eq "--user-group" or $x eq "--group"
$x eq "-U" $x eq "--user-group" $x eq "--group"
Truth table25%1/4
A or B or C
A= $x eq "-U"B= $x eq "--user-group"C= $x eq "--group"
ABCresult
1XX1
01X1
0011
0000
6282 0 ▶ elsif ( $x eq '-N' || $x eq '--no-user-group' ) { $o{usergroup} = 0 }
Condition33%1/3
$x eq "-N" or $x eq "--no-user-group"
l!l&&r!l&&!r
009
MC/DC0%0/2
$x eq "-N" or $x eq "--no-user-group"
$x eq "-N" $x eq "--no-user-group"
Truth table33%1/3
A or B
A= $x eq "-N"B= $x eq "--no-user-group"
ABresult
1X1
011
000
6283 ▶ elsif ( $x =~ /\A--(?:disabled-password|disabled-login|quiet|no-log-init)\z/ || $x eq '-q' ) { }
Condition33%1/3
$x =~ /\A--(?:disabled-password|disabled-login|quiet|no-log-init)\z/ or $x eq "-q"
l!l&&r!l&&!r
009
MC/DC0%0/2
$x =~ /\A--(?:disabled-password|disabled-login|quiet|no-log-init)\z/ or $x eq "-q"
$x =~ /\A--(?:disabled-password|disabled-login|quiet|no-log-init)\z/ $x eq "-q"
Truth table33%1/3
A or B
A= $x =~ /\A--(?:disabled-password|disabled-login|quiet|no-log-init)\z/B= $x eq "-q"
ABresult
1X1
011
000
6284 0 ▶ elsif ( $x =~ /\A-/ ) { return ( $prog eq 'adduser' ? "Unknown option: " . ( $x =~ s/\A-+//r ) : "$prog: unrecognized option '$x'", 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
$prog eq 'adduser' ? : 0 0 0
6285 9 else { push @n, $x }
6286 }
6287 8 ▶ my $users = $dev->{users} ||= {};
Condition50%1/2
$$dev{"users"} ||= {}
l!l
80
MC/DC0%0/1
$$dev{"users"} ||= {}
$$dev{"users"}
Truth table50%1/2
A
A= $$dev{"users"}
Aresult
11
00
6288 8 ▶ if ( $prog eq 'adduser' && @n == 2 && !%o ) { # adduser BENUTZER GRUPPE
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "adduser" and @n == 2 and not %o) 1 7 8
Condition83%5/6
$prog eq "adduser" and @n == 2 and not %o
!ll&&!rl&&r
701
$prog eq "adduser" and @n == 2
!ll&&!rl&&r
521
MC/DC66%2/3
$prog eq "adduser" and @n == 2 and not %o
$prog eq "adduser" @n == 2 not %o
Truth table75%3/4
A and B and not(C)
A= $prog eq "adduser"B= @n == 2C= not %o
ABCresult
0XX0
10X0
1100
1111
6289 1 my ( $u, $g ) = @n;
6290 1 ▶ my $e = $users->{$u} or return ( "fatal: The user `$u' does not exist.", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $e = $$users{$u} or return "fatal: The user `${u}' does not exist.", 0 1 0 1
6291 1 ▶ return ( "fatal: The group `$g' does not exist.", 0 ) unless ( $dev->{groups} || {} )->{$g};
Branch: 1 branch
BranchTrueFalseTotal
unless ($$dev{"groups"} || {})->{$g} 0 1 1
Condition50%1/2
$$dev{'groups'} || {}
l!l
10
MC/DC0%0/1
$$dev{'groups'} || {}
$$dev{'groups'}
Truth table50%1/2
A
A= $$dev{'groups'}
Aresult
11
00
6292 1 ▶ return ( "info: The user `$u' is already a member of `$g'.", 1 ) if grep { $_ eq $g } @{ $e->{groups} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $g;} @{$$e{"groups"} or [];} 0 1 1
Condition50%1/2
$$e{'groups'} || []
l!l
10
MC/DC0%0/1
$$e{'groups'} || []
$$e{'groups'}
Truth table50%1/2
A
A= $$e{'groups'}
Aresult
11
00
6293 1 ▶ $e->{groups} = [ @{ $e->{groups} || [$u] }, $g ];
Condition50%1/2
$$e{'groups'} || [$u]
l!l
10
MC/DC0%0/1
$$e{'groups'} || [$u]
$$e{'groups'}
Truth table50%1/2
A
A= $$e{'groups'}
Aresult
11
00
6294 1 return ( "Adding user `$u' to group `$g' ...\nDone.", 1 );
6295 }
6296 7 ▶ if ( $prog eq 'adduser' && !$o{sys} ) { push @GAPS, join( ' ', 'adduser', @$av ); return ( '', 0 ) } # fragt nach Passwort und Namen
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "adduser" and not $o{"sys"}) 1 6 7
Condition100%3/3
$prog eq "adduser" and not $o{"sys"}
!ll&&!rl&&r
511
MC/DC100%2/2
$prog eq "adduser" and not $o{"sys"}
$prog eq "adduser" not $o{"sys"}
Truth table100%3/3
A and not(B)
A= $prog eq "adduser"B= not $o{"sys"}
ABresult
0X0
100
111
6297 6 ▶ return ( $prog eq 'adduser' ? 'fatal: Only one or two names allowed.' : "Usage: useradd [options] LOGIN", 0 ) unless @n == 1;
Branch: 2 branches
BranchTrueFalseTotal
unless @n == 1 0 6 6
$prog eq 'adduser' ? : 0 0 0
6298 6 my $u = $n[0];
6299 6 ▶ return ( $prog eq 'adduser' ? "fatal: The user `$u' already exists." : "useradd: user '$u' already exists", 0 ) if $users->{$u};
Branch: 2 branches
BranchTrueFalseTotal
if $$users{$u} 1 5 6
$prog eq 'adduser' ? : 0 1 1
6300 5 ▶ return ( "$prog: invalid user name '$u'", 0 ) unless $u =~ /\A[a-z_][a-z0-9_-]*\$?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $u =~ /\A[a-z_][a-z0-9_-]*\$?\z/ 0 5 5
6301 5 ▶ my $groups = $dev->{groups} ||= {};
Condition50%1/2
$$dev{"groups"} ||= {}
l!l
50
MC/DC0%0/1
$$dev{"groups"} ||= {}
$$dev{"groups"}
Truth table50%1/2
A
A= $$dev{"groups"}
Aresult
11
00
6302 5 ▶ my @extra = defined $o{groups} ? split /,/, $o{groups} : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $o{'groups'} ? : 2 3 5
6303 5 ▶ for ( ( defined $o{group} ? $o{group} : () ), @extra ) {
Branch: 1 branch
BranchTrueFalseTotal
defined $o{'group'} ? : 2 3 5
6304 4 ▶ return ( $prog eq 'adduser' ? "fatal: The group `$_' does not exist." : "useradd: group '$_' does not exist", 0 ) unless $groups->{$_};
Branch: 2 branches
BranchTrueFalseTotal
unless $$groups{$_} 1 3 4
$prog eq 'adduser' ? : 0 1 1
6305 }
6306 4 ▶ my $usergroup = !defined $o{group} && ( $o{usergroup} // ( $prog eq 'useradd' ? 1 : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
$prog eq 'useradd' ? : 2 0 2
Condition60%3/5
!defined($o{'group'}) && ($o{'usergroup'} // ($prog eq 'useradd' ? 1 : 0))
!ll&&!rl&&r
202
$o{"usergroup"} // ($prog eq "useradd" ? 1 : 0)
l!l
02
MC/DC0%0/2
!defined($o{'group'}) && ($o{'usergroup'} // ($prog eq 'useradd' ? 1 : 0))
!defined($o{'group'}) $o{"usergroup"}
Truth table66%2/3
not(A) && B
A= !defined($o{'group'})B= $o{"usergroup"}
ABresult
0X0
100
111
6307 4 ▶ return ( "useradd: group $u exists - if you want to add this user to that group, use -g.", 0 ) if $usergroup && $groups->{$u};
Branch: 1 branch
BranchTrueFalseTotal
if $usergroup and $$groups{$u} 0 4 4
Condition66%2/3
$usergroup and $$groups{$u}
!ll&&!rl&&r
220
MC/DC0%0/2
$usergroup and $$groups{$u}
$usergroup $$groups{$u}
Truth table66%2/3
A and B
A= $usergroupB= $$groups{$u}
ABresult
0X0
100
111
6308 4 ▶ my %uids = map { ( $_->{uid} // -1 ) => 1 } values %$users;
Condition50%1/2
$$_{"uid"} // -1
l!l
220
MC/DC0%0/1
$$_{"uid"} // -1
$$_{"uid"}
Truth table50%1/2
A
A= $$_{"uid"}
Aresult
11
00
6309 4 my $uid = _free_id( \%uids, $o{sys}, $o{uid}, $prog eq 'adduser' );
6310 4 ▶ my $primary = defined $o{group} ? $o{group} : $usergroup ? $u : $prog eq 'adduser' ? 'nogroup' : 'users';
Branch: 3 branches
BranchTrueFalseTotal
defined $o{'group'} ? : 2 2 4
$usergroup ? : 2 0 2
$prog eq 'adduser' ? : 0 0 0
6311 4 ▶ if ($usergroup) { $groups->{$u} = { gid => 0 + _free_id( _gids($dev), $o{sys}, $uid, $prog eq 'adduser' ) } }
Branch: 1 branch
BranchTrueFalseTotal
if ($usergroup) 2 2 4
6312 4 ▶ $groups->{nogroup} //= { gid => 65534 } if $primary eq 'nogroup';
Branch: 1 branch
BranchTrueFalseTotal
if $primary eq "nogroup" 0 4 4
Condition0%0/2
$$groups{"nogroup"} //= {"gid", 65534}
l!l
00
MC/DC0%0/1
$$groups{"nogroup"} //= {"gid", 65534}
$$groups{"nogroup"}
Truth table0%0/2
A
A= $$groups{"nogroup"}
Aresult
11
00
6313 4 ▶ $groups->{users} //= { gid => 100 } if $primary eq 'users';
Branch: 1 branch
BranchTrueFalseTotal
if $primary eq "users" 0 4 4
Condition0%0/2
$$groups{"users"} //= {"gid", 100}
l!l
00
MC/DC0%0/1
$$groups{"users"} //= {"gid", 100}
$$groups{"users"}
Truth table0%0/2
A
A= $$groups{"users"}
Aresult
11
00
6314 4 ▶ my $home = $o{home} // ( $prog eq 'adduser' && $o{sys} ? '/nonexistent' : "/home/$u" );
Branch: 1 branch
BranchTrueFalseTotal
$prog eq 'adduser' && $o{'sys'} ? : 0 2 2
Condition60%3/5
$o{"home"} // ($prog eq "adduser" && $o{"sys"} ? "/nonexistent" : "/home/$u")
l!l
22
$prog eq "adduser" and $o{"sys"}
!ll&&!rl&&r
200
MC/DC100%1/1
$o{"home"} // ($prog eq "adduser" && $o{"sys"} ? "/nonexistent" : "/home/$u")
$o{"home"}
Truth table100%2/2
A
A= $o{"home"}
Aresult
11
00
6315 4 ▶ my $shell = $o{shell} // ( $prog eq 'adduser' ? '/usr/sbin/nologin' : '/bin/sh' );
Branch: 1 branch
BranchTrueFalseTotal
$prog eq 'adduser' ? : 1 1 2
Condition100%2/2
$o{"shell"} // ($prog eq "adduser" ? "/usr/sbin/nologin" : "/bin/sh")
l!l
22
MC/DC100%1/1
$o{"shell"} // ($prog eq "adduser" ? "/usr/sbin/nologin" : "/bin/sh")
$o{"shell"}
Truth table100%2/2
A
A= $o{"shell"}
Aresult
11
00
6316 4 ▶ $users->{$u} = { uid => 0 + $uid, groups => [ $primary, grep { $_ ne $primary } @extra ], shell => $shell,
Branch: 1 branch
BranchTrueFalseTotal
$home ne "/home/$u" ? : 2 2 4
6317 ( $home ne "/home/$u" ? ( home => $home ) : () ) };
6318 4 ▶ my $make = $o{home_make} // ( $prog eq 'adduser' && $o{sys} && $home ne '/nonexistent' ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$prog eq 'adduser' && $o{'sys'} && $home ne '/nonexistent' ? : 0 1 1
Condition50%4/8
$o{"home_make"} // ($prog eq "adduser" && $o{"sys"} && $home ne "/nonexistent" ? 1 : 0)
l!l
31
$prog eq "adduser" and $o{"sys"} and $home ne "/nonexistent"
!ll&&!rl&&r
100
$prog eq "adduser" and $o{"sys"}
!ll&&!rl&&r
100
MC/DC100%1/1
$o{"home_make"} // ($prog eq "adduser" && $o{"sys"} && $home ne "/nonexistent" ? 1 : 0)
$o{"home_make"}
Truth table100%2/2
A
A= $o{"home_make"}
Aresult
11
00
6319 4 ▶ $dev->{dirs}{$home} = { owner => $u, group => $primary, mode => '0755' } if $make && !_is_dir( $dev, $home );
Branch: 1 branch
BranchTrueFalseTotal
if $make and not _is_dir($dev, $home) 1 3 4
Condition66%2/3
$make and not _is_dir($dev, $home)
!ll&&!rl&&r
301
MC/DC50%1/2
$make and not _is_dir($dev, $home)
$make not _is_dir($dev, $home)
Truth table66%2/3
A and not(B)
A= $makeB= not _is_dir($dev, $home)
ABresult
0X0
100
111
6320 4 return ( '', 1 );
6321 }
6322  
6323 # install [-m MODUS] [-o BENUTZER] [-g GRUPPE] [-D] QUELLE… ZIEL | install -d [-m …] DIR…
6324 9 ▶sub _install {
Subroutine _install: called CC=52 SCAR=45.5
6325 9 my ( $dev, $av ) = @_;
6326 9 my @a = @$av;
6327 9 my ( %o, @p );
6328 9 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 35 9 44
6329 35 my $x = shift @a;
6330 35 ▶ if ( $x eq '-m' || $x eq '--mode' ) { $o{mode} = shift @a }
Branch: 9 branches
BranchTrueFalseTotal
if ($x eq '-m' or $x eq '--mode') { } 5 30 35
elsif ($x eq '-o' or $x eq '--owner') { } 5 25 30
elsif ($x eq '-g' or $x eq '--group') { } 5 20 25
elsif ($x =~ /\A--(mode|owner|group)=(.*)\z/) { } 0 20 20
elsif ($x eq '-d' or $x eq '--directory') { } 2 18 20
elsif ($x eq '-D') { } 1 17 18
elsif ($x =~ /\A-([dDvpCcsb]+)\z/) { } 0 17 17
elsif ($x =~ /\A-([dDvpC]*)([mog])\z/) { } 0 17 17
elsif ($x =~ /\A-/) { } 0 17 17
Condition66%2/3
$x eq "-m" or $x eq "--mode"
l!l&&r!l&&!r
5030
MC/DC50%1/2
$x eq "-m" or $x eq "--mode"
$x eq "-m" $x eq "--mode"
Truth table66%2/3
A or B
A= $x eq "-m"B= $x eq "--mode"
ABresult
1X1
011
000
6331 5 ▶ elsif ( $x eq '-o' || $x eq '--owner' ) { $o{owner} = shift @a }
Condition66%2/3
$x eq "-o" or $x eq "--owner"
l!l&&r!l&&!r
5025
MC/DC50%1/2
$x eq "-o" or $x eq "--owner"
$x eq "-o" $x eq "--owner"
Truth table66%2/3
A or B
A= $x eq "-o"B= $x eq "--owner"
ABresult
1X1
011
000
6332 5 ▶ elsif ( $x eq '-g' || $x eq '--group' ) { $o{group} = shift @a }
Condition66%2/3
$x eq "-g" or $x eq "--group"
l!l&&r!l&&!r
5020
MC/DC50%1/2
$x eq "-g" or $x eq "--group"
$x eq "-g" $x eq "--group"
Truth table66%2/3
A or B
A= $x eq "-g"B= $x eq "--group"
ABresult
1X1
011
000
6333 0 elsif ( $x =~ /\A--(mode|owner|group)=(.*)\z/ ) { $o{$1} = $2 }
6334 2 ▶ elsif ( $x eq '-d' || $x eq '--directory' ) { $o{dir} = 1 }
Condition66%2/3
$x eq "-d" or $x eq "--directory"
l!l&&r!l&&!r
2018
MC/DC50%1/2
$x eq "-d" or $x eq "--directory"
$x eq "-d" $x eq "--directory"
Truth table66%2/3
A or B
A= $x eq "-d"B= $x eq "--directory"
ABresult
1X1
011
000
6335 1 elsif ( $x eq '-D' ) { $o{parents} = 1 }
6336 0 ▶ elsif ( $x =~ /\A-([dDvpCcsb]+)\z/ ) { my $f = $1; $o{dir} = 1 if $f =~ /d/; $o{parents} = 1 if $f =~ /D/ }
Branch: 2 branches
BranchTrueFalseTotal
if $f =~ /d/ 0 0 0
if $f =~ /D/ 0 0 0
6337 0 ▶ elsif ( $x =~ /\A-([dDvpC]*)([mog])\z/ ) { my ( $f, $k ) = ( $1, $2 ); $o{dir} = 1 if $f =~ /d/; $o{parents} = 1 if $f =~ /D/; $o{ { m => 'mode', o => 'owner', g => 'group' }->{$k} } = shift @a }
Branch: 2 branches
BranchTrueFalseTotal
if $f =~ /d/ 0 0 0
if $f =~ /D/ 0 0 0
6338 0 elsif ( $x =~ /\A-/ ) { return ( "install: invalid option -- '" . substr( $x, 1, 1 ) . "'\nTry 'install --help' for more information.", 0 ) }
6339 17 else { push @p, $x }
6340 }
6341 9 ▶ return ( "install: invalid mode '$o{mode}'", 0 ) if defined $o{mode} && $o{mode} !~ /\A[0-7]{1,4}\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $o{"mode"} and not $o{"mode"} =~ /\A[0-7]{1,4}\z/ 0 9 9
Condition66%2/3
defined $o{"mode"} and not $o{"mode"} =~ /\A[0-7]{1,4}\z/
!ll&&!rl&&r
450
MC/DC0%0/2
defined $o{"mode"} and not $o{"mode"} =~ /\A[0-7]{1,4}\z/
defined $o{"mode"} not $o{"mode"} =~ /\A[0-7]{1,4}\z/
Truth table66%2/3
A and not(B)
A= defined $o{"mode"}B= not $o{"mode"} =~ /\A[0-7]{1,4}\z/
ABresult
0X0
100
111
6342 9 ▶ return ( "install: invalid user '$o{owner}'", 0 ) if defined $o{owner} && $o{owner} ne 'root' && !( $dev->{users} || {} )->{ $o{owner} };
Branch: 1 branch
BranchTrueFalseTotal
if defined $o{"owner"} and $o{"owner"} ne "root" and not +($$dev{"users"} || {})->{$o{"owner"}} 1 8 9
Condition87%7/8
defined $o{"owner"} and $o{"owner"} ne "root" and not +($$dev{"users"} || {})->{$o{"owner"}}
!ll&&!rl&&r
531
defined $o{"owner"} and $o{"owner"} ne "root"
!ll&&!rl&&r
414
$$dev{'users'} || {}
l!l
40
MC/DC0%0/3
defined $o{"owner"} and $o{"owner"} ne "root" and not +($$dev{"users"} || {})->{$o{"owner"}}
defined $o{"owner"} $o{"owner"} ne "root" $$dev{'users'}
Truth table75%3/4
A and B and not(C)
A= defined $o{"owner"}B= $o{"owner"} ne "root"C= $$dev{'users'}
ABCresult
0XX0
10X0
1110
1101
6343 return ( "install: invalid group '$o{group}'", 0 )
6344 8 ▶ if defined $o{group} && $o{group} ne 'root' && !( $dev->{groups} || {} )->{ $o{group} } && !grep { grep { $_ eq $o{group} } @{ $_->{groups} || [] } } values %{ $dev->{users} || {} };
Branch: 1 branch
BranchTrueFalseTotal
if defined $o{"group"} and $o{"group"} ne "root" and not +($$dev{"groups"} || {})->{$o{"group"}} and not grep({grep {$_ eq $o{"group"};} @{$$_{"groups"} or [];};} values %{$$dev{"users"} or {};}) 1 7 8
Condition86%13/15
defined $o{"group"} and $o{"group"} ne "root" and not +($$dev{"groups"} || {})->{$o{"group"}} and not grep({grep {$_ eq $o{"group"};} @{$$_{"groups"} or [];};} values %{$$dev{"users"} or {};})
!ll&&!rl&&r
521
defined $o{"group"} and $o{"group"} ne "root" and not +($$dev{"groups"} || {})->{$o{"group"}}
!ll&&!rl&&r
413
defined $o{"group"} and $o{"group"} ne "root"
!ll&&!rl&&r
314
$$dev{'groups'} || {}
l!l
22
$$_{'groups'} || []
l!l
80
$$dev{'users'} || {}
l!l
30
MC/DC0%0/4
defined $o{"group"} and $o{"group"} ne "root" and not +($$dev{"groups"} || {})->{$o{"group"}} and not grep({grep {$_ eq $o{"group"};} @{$$_{"groups"} or [];};} values %{$$dev{"users"} or {};})
defined $o{"group"} $o{"group"} ne "root" $$dev{'groups'} not grep({grep {$_ eq $o{"group"};} @{$$_{"groups"} or [];};} values %{$$dev{"users"} or {};})
MC/DC0%0/1
$$_{'groups'} || []
$$_{'groups'}
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
Truth table80%4/5
A and B and not(C) and not(D)
A= defined $o{"group"}B= $o{"group"} ne "root"C= $$dev{'groups'}D= not grep({grep {$_ eq $o{"group"};} @{$$_{"groups"} or [];};} values %{$$dev{"users"} or {};})
ABCDresult
0XXX0
10XX0
111X0
11000
11011
Truth table50%1/2
A
A= $$_{'groups'}
Aresult
11
00
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
6345 7 ▶ my %meta = ( owner => $o{owner} // 'root', group => $o{group} // 'root', mode => sprintf( '%04o', oct( $o{mode} // '0755' ) ) );
Condition100%6/6
$o{"owner"} // "root"
l!l
43
$o{"group"} // "root"
l!l
43
$o{"mode"} // "0755"
l!l
52
MC/DC100%1/1
$o{"owner"} // "root"
$o{"owner"}
MC/DC100%1/1
$o{"group"} // "root"
$o{"group"}
MC/DC100%1/1
$o{"mode"} // "0755"
$o{"mode"}
Truth table100%2/2
A
A= $o{"owner"}
Aresult
11
00
Truth table100%2/2
A
A= $o{"group"}
Aresult
11
00
Truth table100%2/2
A
A= $o{"mode"}
Aresult
11
00
6346 3 ▶ my $mkdirs = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
6347 3 my ($d) = @_;
6348 3 my @seg = split m{/}, $d;
6349 3 ▶ for my $t ( map { join '/', @seg[ 0 .. $_ ] } 1 .. $#seg ) { $dev->{dirs}{$t} //= {} unless _is_dir( $dev, $t ) }
Branch: 1 branch
BranchTrueFalseTotal
unless _is_dir($dev, $t) 5 4 9
Condition50%1/2
$$dev{"dirs"}{$t} //= {}
l!l
05
MC/DC0%0/1
$$dev{"dirs"}{$t} //= {}
$$dev{"dirs"}{$t}
Truth table50%1/2
A
A= $$dev{"dirs"}{$t}
Aresult
11
00
6350 7 };
6351 7 ▶ if ( $o{dir} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"dir"}) 2 5 7
6352 2 ▶ return ( "install: missing file operand\nTry 'install --help' for more information.", 0 ) unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 2 2
6353 2 for my $d ( map { _absp($_) =~ s{(?<=.)/+\z}{}r } @p ) { $mkdirs->($d); $dev->{dirs}{$d} = {%meta} }
6354 2 return ( '', 1 );
6355 }
6356 5 ▶ return ( "install: missing destination file operand after '" . ( $p[0] // '' ) . "'\nTry 'install --help' for more information.", 0 ) unless @p >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @p >= 2 0 5 5
Condition0%0/2
$p[0] // ""
l!l
00
MC/DC0%0/1
$p[0] // ""
$p[0]
Truth table0%0/2
A
A= $p[0]
Aresult
11
00
6357 5 my $to = _absp( pop @p ) =~ s{(?<=.)/+\z}{}r;
6358 5 ▶ if ( $o{parents} ) { ( my $d = @p > 1 ? "$to/x" : $to ) =~ s{/[^/]+\z}{}; $mkdirs->($d) if length $d }
Branch: 3 branches
BranchTrueFalseTotal
if ($o{"parents"}) 1 4 5
@p > 1 ? : 0 1 1
if length $d 1 0 1
6359 5 ▶ return ( "install: target '$to' is not a directory", 0 ) if @p > 1 && !_is_dir( $dev, $to );
Branch: 1 branch
BranchTrueFalseTotal
if @p > 1 and not _is_dir($dev, $to) 0 5 5
Condition66%2/3
@p > 1 and not _is_dir($dev, $to)
!ll&&!rl&&r
410
MC/DC0%0/2
@p > 1 and not _is_dir($dev, $to)
@p > 1 not _is_dir($dev, $to)
Truth table66%2/3
A and not(B)
A= @p > 1B= not _is_dir($dev, $to)
ABresult
0X0
100
111
6360 5 for my $src (@p) {
6361 6 ▶ my $e = ( $src eq '/dev/null' ? { content => '' } : _file_entry( $dev, _absp($src) ) ) or return ( "install: cannot stat '$src': No such file or directory", 0 );
Branch: 2 branches
BranchTrueFalseTotal
my $e = $src eq "/dev/null" ? {"content", ""} : _file_entry($dev, _absp($src)) or return "install: cannot stat '${src}': No such file or directory", 0 5 1 6
$src eq '/dev/null' ? : 0 6 6
6362 5 ( my $base = $src ) =~ s{.*/}{};
6363 5 ▶ my $dst = _is_dir( $dev, $to ) ? ( $to eq '/' ? '' : $to ) . "/$base" : $to;
Branch: 2 branches
BranchTrueFalseTotal
_is_dir($dev, $to) ? : 2 3 5
$to eq '/' ? : 0 2 2
6364 5 ( my $dd = $dst ) =~ s{/[^/]+\z}{};
6365 5 ▶ return ( "install: cannot create regular file '$dst': No such file or directory", 0 ) unless _is_dir( $dev, length $dd ? $dd : '/' );
Branch: 2 branches
BranchTrueFalseTotal
unless _is_dir($dev, length $dd ? $dd : "/") 0 5 5
length $dd ? : 5 0 5
6366 5 my %n = %$e;
6367 5 delete @n{qw( open_by link tar )};
6368 5 $dev->{files}{$dst} = { %n, %meta, mtime => 'Oct 20 12:00' };
6369 }
6370 4 return ( '', 1 );
6371 }
6372  
6373 2 ▶sub _gpasswd {
Subroutine _gpasswd: called CC=9 SCAR=37.4
6374 2 my ( $dev, $av ) = @_;
6375 2 my ( $o, $u, $g ) = @$av;
6376 2 ▶ return _acc()->can('remove_group')->( $dev, $u, $g, 'gpasswd' ) if defined $o && ( $o eq '-d' || $o eq '--delete' ) && defined $g;
Branch: 1 branch
BranchTrueFalseTotal
if defined $o and $o eq "-d" || $o eq "--delete" and defined $g 2 0 2
Condition33%3/9
defined $o and $o eq "-d" || $o eq "--delete" and defined $g
!ll&&!rl&&r
002
defined $o and $o eq "-d" || $o eq "--delete"
!ll&&!rl&&r
002
$o eq "-d" or $o eq "--delete"
l!l&&r!l&&!r
200
MC/DC0%0/4
defined $o and $o eq "-d" || $o eq "--delete" and defined $g
defined $o $o eq "-d" $o eq "--delete" defined $g
Truth table16%1/6
A and B or C and D
A= defined $oB= $o eq "-d"C= $o eq "--delete"D= defined $g
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
6377 0 ▶ return ( 'Usage: gpasswd [option] GROUP', 0 ) unless defined $o && $o eq '-a' && defined $g;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o and $o eq "-a" and defined $g 0 0 0
Condition0%0/6
defined $o and $o eq "-a" and defined $g
!ll&&!rl&&r
000
defined $o and $o eq "-a"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $o and $o eq "-a" and defined $g
defined $o $o eq "-a" defined $g
Truth table0%0/4
A and B and C
A= defined $oB= $o eq "-a"C= defined $g
ABCresult
0XX0
10X0
1100
1111
6378 0 my ( $out, $ok ) = _usermod( $dev, [ '-aG', $g, $u ] );
6379 0 ▶ return ( $ok ? "Adding user $u to group $g" : $out, $ok );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 0 0
6380 }
6381  
6382 14 ▶sub _getent {
Subroutine _getent: called CC=33 SCAR=41.5
6383 14 my ( $dev, $av ) = @_;
6384 14 my ( $db, @keys ) = @$av;
6385 14 ▶ $db //= '';
Condition50%1/2
$db //= ""
l!l
140
MC/DC0%0/1
$db //= ""
$db
Truth table50%1/2
A
A= $db
Aresult
11
00
6386 14 ▶ if ( $db eq 'passwd' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db eq "passwd") 3 11 14
6387 3 my @l;
6388 0 ▶ for my $u ( @keys ? @keys : ( 'root', sort keys %{ $dev->{users} || {} } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
@keys ? : 3 0 3
Condition0%0/2
$$dev{'users'} || {}
l!l
00
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
Truth table0%0/2
A
A= $$dev{'users'}
Aresult
11
00
6389 0 ▶ if ( $u eq 'root' ) { push @l, 'root:x:0:0:root:/root:/bin/bash'; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($u eq "root") 0 3 3
6390 3 ▶ my $e = ( $dev->{users} || {} )->{$u} or return ( join( "\n", @l ), 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $e = ($$dev{"users"} || {})->{$u} or return join("\n", @l), 0 3 0 3
Condition50%1/2
$$dev{'users'} || {}
l!l
30
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
6391 3 ▶ push @l, "$u:x:$e->{uid}:" . _gid( $dev, ( $e->{groups} || [$u] )->[0] ) . ':' . ( $e->{gecos} // '' ) . ':' . ( $e->{home} // "/home/$u" ) . ':' . ( $e->{shell} // '/usr/sbin/nologin' );
Condition62%5/8
$$e{'groups'} || [$u]
l!l
30
$$e{"gecos"} // ""
l!l
03
$$e{"home"} // "/home/$u"
l!l
12
$$e{"shell"} // "/usr/sbin/nologin"
l!l
30
MC/DC0%0/1
$$e{'groups'} || [$u]
$$e{'groups'}
MC/DC0%0/1
$$e{"gecos"} // ""
$$e{"gecos"}
MC/DC100%1/1
$$e{"home"} // "/home/$u"
$$e{"home"}
MC/DC0%0/1
$$e{"shell"} // "/usr/sbin/nologin"
$$e{"shell"}
Truth table50%1/2
A
A= $$e{'groups'}
Aresult
11
00
Truth table50%1/2
A
A= $$e{"gecos"}
Aresult
11
00
Truth table100%2/2
A
A= $$e{"home"}
Aresult
11
00
Truth table50%1/2
A
A= $$e{"shell"}
Aresult
11
00
6392 }
6393 3 return ( join( "\n", @l ), 1 );
6394 }
6395 11 ▶ if ( $db eq 'shadow' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db eq "shadow") 1 10 11
6396 1 my @l;
6397 0 ▶ for my $u ( @keys ? @keys : ( 'root', sort keys %{ $dev->{users} || {} } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
@keys ? : 1 0 1
Condition0%0/2
$$dev{'users'} || {}
l!l
00
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
Truth table0%0/2
A
A= $$dev{'users'}
Aresult
11
00
6398 0 ▶ if ( $u eq 'root' ) { push @l, 'root:*:20332:0:99999:7:::'; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($u eq "root") 0 1 1
6399 1 ▶ my $e = ( $dev->{users} || {} )->{$u} or return ( join( "\n", @l ), 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $e = ($$dev{"users"} || {})->{$u} or return join("\n", @l), 0 1 0 1
Condition50%1/2
$$dev{'users'} || {}
l!l
10
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
6400 1 push @l, _acc()->can('shadow_line')->( $u, $e );
6401 }
6402 1 return ( join( "\n", @l ), 1 );
6403 }
6404 10 ▶ if ( $db eq 'group' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db eq "group") 4 6 10
6405 4 my %m;
6406 4 ▶ for my $u ( keys %{ $dev->{users} || {} } ) { push @{ $m{$_} }, $u for @{ $dev->{users}{$u}{groups} || [] } }
Condition50%2/4
$$dev{'users'} || {}
l!l
40
$$dev{'users'}{$u}{'groups'} || []
l!l
160
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
MC/DC0%0/1
$$dev{'users'}{$u}{'groups'} || []
$$dev{'users'}{$u}{'groups'}
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
Truth table50%1/2
A
A= $$dev{'users'}{$u}{'groups'}
Aresult
11
00
6407 4 ▶ my %known = ( %m, map { $_ => 1 } keys %{ $dev->{groups} || {} } );
Condition50%1/2
$$dev{'groups'} || {}
l!l
40
MC/DC0%0/1
$$dev{'groups'} || {}
$$dev{'groups'}
Truth table50%1/2
A
A= $$dev{'groups'}
Aresult
11
00
6408 4 ▶ my @l = map { "$_:x:" . _gid( $dev, $_ ) . ':' . join( ',', sort @{ $m{$_} || [] } ) } grep { $known{$_} } @keys ? @keys : sort keys %m;
Branch: 1 branch
BranchTrueFalseTotal
@keys ? : 4 0 4
Condition50%1/2
$m{$_} || []
l!l
03
MC/DC0%0/1
$m{$_} || []
$m{$_}
Truth table50%1/2
A
A= $m{$_}
Aresult
11
00
6409 4 ▶ return ( join( "\n", @l ), ( grep { !$known{$_} } @keys ) ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
grep({not $known{$_};} @keys) ? : 1 3 4
6410 }
6411 6 ▶ if ( $db eq 'hosts' || $db eq 'ahosts' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db eq "hosts" or $db eq "ahosts") 6 0 6
Condition33%1/3
$db eq "hosts" or $db eq "ahosts"
l!l&&r!l&&!r
600
MC/DC0%0/2
$db eq "hosts" or $db eq "ahosts"
$db eq "hosts" $db eq "ahosts"
Truth table33%1/3
A or B
A= $db eq "hosts"B= $db eq "ahosts"
ABresult
1X1
011
000
6412 6 my @l;
6413 6 for my $n (@keys) {
6414 6 my ($ip) = _resolve( $dev, $n );
6415 6 ▶ return ( join( "\n", @l ), 0 ) unless defined $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip 3 3 6
6416 3 push @l, sprintf( '%-15s %s', $ip, $n );
6417 }
6418 3 return ( join( "\n", @l ), 1 );
6419 }
6420 0 return ( "Unknown database: $db\nTry `getent --help' or `getent --usage' for more information.", 0 );
6421 }
6422  
6423 # --- Resolver ---------------------------------------------------------------------
6424  
6425 # Nameserver aus /etc/resolv.conf (bzw. dem Stub von systemd-resolved)
6426 21 ▶sub _nameservers {
Subroutine _nameservers: called CC=8 SCAR=21.0
6427 21 my ($dev) = @_;
6428 21 ▶ my $rc = _file_text( $dev, '/etc/resolv.conf' ) // '';
Condition100%2/2
_file_text($dev, "/etc/resolv.conf") // ""
l!l
165
MC/DC100%1/1
_file_text($dev, "/etc/resolv.conf") // ""
_file_text($dev, "/etc/resolv.conf")
Truth table100%2/2
A
A= _file_text($dev, "/etc/resolv.conf")
Aresult
11
00
6429 21 my @ns = $rc =~ /^\s*nameserver\s+(\S+)/mg;
6430 21 ▶ if ( @ns == 1 && $ns[0] eq '127.0.0.53' && $dev->{resolved} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ns == 1 and $ns[0] eq "127.0.0.53" and $$dev{"resolved"}) 2 19 21
Condition83%5/6
@ns == 1 and $ns[0] eq "127.0.0.53" and $$dev{"resolved"}
!ll&&!rl&&r
1902
@ns == 1 and $ns[0] eq "127.0.0.53"
!ll&&!rl&&r
5142
MC/DC66%2/3
@ns == 1 and $ns[0] eq "127.0.0.53" and $$dev{"resolved"}
@ns == 1 $ns[0] eq "127.0.0.53" $$dev{"resolved"}
Truth table75%3/4
A and B and C
A= @ns == 1B= $ns[0] eq "127.0.0.53"C= $$dev{"resolved"}
ABCresult
0XX0
10X0
1100
1111
6431 2 my $r = $dev->{resolved};
6432 2 ▶ @ns = ( ( map { @{ $_->{dns} || [] } } map { $r->{links}{$_} } sort keys %{ $r->{links} || {} } ), @{ $r->{global}{dns} || [] } );
Condition50%3/6
$$_{'dns'} || []
l!l
20
$$r{'links'} || {}
l!l
20
$$r{'global'}{'dns'} || []
l!l
20
MC/DC0%0/1
$$_{'dns'} || []
$$_{'dns'}
MC/DC0%0/1
$$r{'links'} || {}
$$r{'links'}
MC/DC0%0/1
$$r{'global'}{'dns'} || []
$$r{'global'}{'dns'}
Truth table50%1/2
A
A= $$_{'dns'}
Aresult
11
00
Truth table50%1/2
A
A= $$r{'links'}
Aresult
11
00
Truth table50%1/2
A
A= $$r{'global'}{'dns'}
Aresult
11
00
6433 }
6434 21 return @ns;
6435 }
6436  
6437 # Name -> Adresse: /etc/hosts, dann die Nameserver der Reihe nach (dns_servers:
6438 # { <adresse>: { <name>: <ip> } }; ein Server, der fehlt, antwortet nicht).
6439 136 ▶sub _resolve {
Subroutine _resolve: called CC=12 SCAR=24.9
6440 136 my ( $dev, $name ) = @_;
6441 136 ▶ for my $l ( split /\n/, _file_text( $dev, '/etc/hosts' ) // '' ) {
Condition100%2/2
_file_text($dev, "/etc/hosts") // ""
l!l
1297
MC/DC100%1/1
_file_text($dev, "/etc/hosts") // ""
_file_text($dev, "/etc/hosts")
Truth table100%2/2
A
A= _file_text($dev, "/etc/hosts")
Aresult
11
00
6442 211 $l =~ s/#.*//;
6443 211 my ( $ip, @n ) = split ' ', $l;
6444 211 ▶ return ( $ip, 'hosts' ) if defined $ip && grep { $_ eq $name } @n;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ip and grep {$_ eq $name;} @n 124 87 211
Condition66%2/3
defined $ip and grep {$_ eq $name;} @n
!ll&&!rl&&r
087124
MC/DC50%1/2
defined $ip and grep {$_ eq $name;} @n
defined $ip grep {$_ eq $name;} @n
Truth table66%2/3
A and B
A= defined $ipB= grep {$_ eq $name;} @n
ABresult
0X0
100
111
6445 }
6446 12 ▶ my $rc = _file_text( $dev, '/etc/resolv.conf' ) // '';
Condition100%2/2
_file_text($dev, "/etc/resolv.conf") // ""
l!l
75
MC/DC100%1/1
_file_text($dev, "/etc/resolv.conf") // ""
_file_text($dev, "/etc/resolv.conf")
Truth table100%2/2
A
A= _file_text($dev, "/etc/resolv.conf")
Aresult
11
00
6447 12 my @search = map { split ' ' } $rc =~ /^\s*(?:search|domain)\s+(.+)$/mg;
6448 12 for my $ns ( _nameservers($dev) ) {
6449 7 ▶ my $zone = ( $dev->{dns_servers} || {} )->{$ns} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $zone = ($$dev{"dns_servers"} || {})->{$ns} or next 7 0 7
Condition50%1/2
$$dev{'dns_servers'} || {}
l!l
70
MC/DC0%0/1
$$dev{'dns_servers'} || {}
$$dev{'dns_servers'}
Truth table50%1/2
A
A= $$dev{'dns_servers'}
Aresult
11
00
6450 7 ▶ for my $q ( $name, ( $name =~ /\./ ? () : map {"$name.$_"} @search ) ) {
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /\./ ? : 5 2 7
6451 9 ▶ return ( $zone->{$q}, $ns ) if defined $zone->{$q};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$zone{$q} 4 5 9
6452 }
6453 3 return ( undef, $ns ); # Server antwortet: NXDOMAIN
6454 }
6455 5 return ();
6456 }
6457  
6458 2 ▶sub _resolvectl {
Subroutine _resolvectl: called CC=46 SCAR=62.8
6459 2 my ( $dev, $av ) = @_;
6460 2 ▶ my $r = $dev->{resolved} or return ( 'Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found.', 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $r = $$dev{"resolved"} or return "Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found.", 0 2 0 2
6461 2 my @a = @$av;
6462 2 ▶ my $verb = shift(@a) // 'status';
Condition50%1/2
shift @a // "status"
l!l
20
MC/DC0%0/1
shift @a // "status"
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
6463 2 ▶ if ( $verb eq 'status' || $verb eq 'dns' && !@a || $verb eq 'domain' && !@a ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "status" or $verb eq "dns" and not @a or $verb eq "domain" and not @a) 1 1 2
Condition50%6/12
$verb eq "status" or $verb eq "dns" and not @a or $verb eq "domain" and not @a
l!l&&r!l&&!r
101
$verb eq "status" or $verb eq "dns" and not @a
l!l&&r!l&&!r
101
$verb eq "dns" and not @a
!ll&&!rl&&r
010
$verb eq "domain" and not @a
!ll&&!rl&&r
100
MC/DC20%1/5
$verb eq "status" or $verb eq "dns" and not @a or $verb eq "domain" and not @a
$verb eq "status" $verb eq "dns" not @a $verb eq "domain" not @a
Truth table25%2/8
A or B and not(C) or D and not(E)
A= $verb eq "status"B= $verb eq "dns"C= not @aD= $verb eq "domain"E= not @a
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
6464 1 my @l;
6465 1 ▶ if ( $verb eq 'status' && !@a ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "status" and not @a) 0 1 1
Condition33%1/3
$verb eq "status" and not @a
!ll&&!rl&&r
010
MC/DC0%0/2
$verb eq "status" and not @a
$verb eq "status" not @a
Truth table33%1/3
A and not(B)
A= $verb eq "status"B= not @a
ABresult
0X0
100
111
6466 0 push @l, 'Global', ' Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported', 'resolv.conf mode: stub';
6467 0 ▶ push @l, 'Current DNS Server: ' . $r->{global}{dns}[0] if @{ $r->{global}{dns} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$r{"global"}{"dns"} or [];} 0 0 0
Condition0%0/2
$$r{'global'}{'dns'} || []
l!l
00
MC/DC0%0/1
$$r{'global'}{'dns'} || []
$$r{'global'}{'dns'}
Truth table0%0/2
A
A= $$r{'global'}{'dns'}
Aresult
11
00
6468 0 ▶ push @l, ' DNS Servers: ' . join( ' ', @{ $r->{global}{dns} || [] } ) if @{ $r->{global}{dns} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$r{"global"}{"dns"} or [];} 0 0 0
Condition0%0/4
$$r{'global'}{'dns'} || []
l!l
00
$$r{'global'}{'dns'} || []
l!l
00
MC/DC0%0/1
$$r{'global'}{'dns'} || []
$$r{'global'}{'dns'}
MC/DC0%0/1
$$r{'global'}{'dns'} || []
$$r{'global'}{'dns'}
Truth table0%0/2
A
A= $$r{'global'}{'dns'}
Aresult
11
00
Truth table0%0/2
A
A= $$r{'global'}{'dns'}
Aresult
11
00
6469 }
6470 1 my $i = 1;
6471 1 ▶ for my $n ( sort keys %{ $r->{links} || {} } ) {
Condition50%1/2
$$r{'links'} || {}
l!l
10
MC/DC0%0/1
$$r{'links'} || {}
$$r{'links'}
Truth table50%1/2
A
A= $$r{'links'}
Aresult
11
00
6472 1 $i++;
6473 1 ▶ next if @a && $a[0] ne $n;
Branch: 1 branch
BranchTrueFalseTotal
if @a and $a[0] ne $n 0 1 1
Condition33%1/3
@a and $a[0] ne $n
!ll&&!rl&&r
010
MC/DC0%0/2
@a and $a[0] ne $n
@a $a[0] ne $n
Truth table33%1/3
A and B
A= @aB= $a[0] ne $n
ABresult
0X0
100
111
6474 1 my $k = $r->{links}{$n};
6475 0 ▶ if ( $verb eq 'dns' ) { push @l, "Link $i ($n): " . join( ' ', @{ $k->{dns} || [] } ); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "dns") 0 1 1
Condition0%0/2
$$k{'dns'} || []
l!l
00
MC/DC0%0/1
$$k{'dns'} || []
$$k{'dns'}
Truth table0%0/2
A
A= $$k{'dns'}
Aresult
11
00
6476 0 ▶ if ( $verb eq 'domain' ) { push @l, "Link $i ($n): " . join( ' ', @{ $k->{domains} || [] } ); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "domain") 0 1 1
Condition0%0/2
$$k{'domains'} || []
l!l
00
MC/DC0%0/1
$$k{'domains'} || []
$$k{'domains'}
Truth table0%0/2
A
A= $$k{'domains'}
Aresult
11
00
6477 1 push @l, '', "Link $i ($n)", ' Current Scopes: DNS', ' Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS';
6478 1 ▶ push @l, 'Current DNS Server: ' . $k->{dns}[0] if @{ $k->{dns} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$k{"dns"} or [];} 1 0 1
Condition50%1/2
$$k{'dns'} || []
l!l
10
MC/DC0%0/1
$$k{'dns'} || []
$$k{'dns'}
Truth table50%1/2
A
A= $$k{'dns'}
Aresult
11
00
6479 1 ▶ push @l, ' DNS Servers: ' . join( ' ', @{ $k->{dns} || [] } ) if @{ $k->{dns} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$k{"dns"} or [];} 1 0 1
Condition50%2/4
$$k{'dns'} || []
l!l
10
$$k{'dns'} || []
l!l
10
MC/DC0%0/1
$$k{'dns'} || []
$$k{'dns'}
MC/DC0%0/1
$$k{'dns'} || []
$$k{'dns'}
Truth table50%1/2
A
A= $$k{'dns'}
Aresult
11
00
Truth table50%1/2
A
A= $$k{'dns'}
Aresult
11
00
6480 0 ▶ push @l, ' DNS Domain: ' . join( ' ', @{ $k->{domains} || [] } ) if @{ $k->{domains} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$k{"domains"} or [];} 0 1 1
Condition25%1/4
$$k{'domains'} || []
l!l
10
$$k{'domains'} || []
l!l
00
MC/DC0%0/1
$$k{'domains'} || []
$$k{'domains'}
MC/DC0%0/1
$$k{'domains'} || []
$$k{'domains'}
Truth table50%1/2
A
A= $$k{'domains'}
Aresult
11
00
Truth table0%0/2
A
A= $$k{'domains'}
Aresult
11
00
6481 }
6482 1 return ( join( "\n", @l ), 1 );
6483 }
6484 1 ▶ if ( $verb eq 'dns' || $verb eq 'domain' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "dns" or $verb eq "domain") 1 0 1
Condition33%1/3
$verb eq "dns" or $verb eq "domain"
l!l&&r!l&&!r
100
MC/DC0%0/2
$verb eq "dns" or $verb eq "domain"
$verb eq "dns" $verb eq "domain"
Truth table33%1/3
A or B
A= $verb eq "dns"B= $verb eq "domain"
ABresult
1X1
011
000
6485 1 my $if = shift @a;
6486 1 ▶ my $k = ( $r->{links} || {} )->{$if} or return ( "Failed to resolve interface \"$if\": No such device", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $k = ($$r{"links"} || {})->{$if} or return qq[Failed to resolve interface "$if": No such device], 0 1 0 1
Condition50%1/2
$$r{'links'} || {}
l!l
10
MC/DC0%0/1
$$r{'links'} || {}
$$r{'links'}
Truth table50%1/2
A
A= $$r{'links'}
Aresult
11
00
6487 1 ▶ $k->{ $verb eq 'dns' ? 'dns' : 'domains' } = [@a];
Branch: 1 branch
BranchTrueFalseTotal
$verb eq 'dns' ? : 1 0 1
6488 1 return ( '', 1 );
6489 }
6490 0 ▶ if ( $verb eq 'query' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "query") 0 0 0
6491 0 my @l;
6492 0 for my $n (@a) {
6493 0 my ( $ip, $src ) = _resolve( $dev, $n );
6494 0 ▶ return ( "$n: resolve call failed: " . ( defined $src ? "'$n' not found" : 'All attempts to contact name servers or networks failed' ), 0 )
Branch: 2 branches
BranchTrueFalseTotal
unless defined $ip 0 0 0
defined $src ? : 0 0 0
6495 unless defined $ip;
6496 0 push @l, "$n: $ip", '', '-- Information acquired via protocol DNS in 1.2ms.';
6497 }
6498 0 return ( join( "\n", @l ), 1 );
6499 }
6500 0 ▶ return ( '', 1 ) if $verb eq 'flush-caches' || $verb eq 'reset-statistics';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "flush-caches" or $verb eq "reset-statistics" 0 0 0
Condition0%0/3
$verb eq "flush-caches" or $verb eq "reset-statistics"
l!l&&r!l&&!r
000
MC/DC0%0/2
$verb eq "flush-caches" or $verb eq "reset-statistics"
$verb eq "flush-caches" $verb eq "reset-statistics"
Truth table0%0/3
A or B
A= $verb eq "flush-caches"B= $verb eq "reset-statistics"
ABresult
1X1
011
000
6501 0 ▶ if ( $verb eq 'revert' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "revert") 0 0 0
6502 0 ▶ my $k = ( $r->{links} || {} )->{ $a[0] // '' } or return ( 'Failed to resolve interface', 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $k = ($$r{"links"} || {})->{$a[0] // ""} or return "Failed to resolve interface", 0 0 0 0
Condition0%0/4
$$r{'links'} || {}
l!l
00
$a[0] // ""
l!l
00
MC/DC0%0/1
$$r{'links'} || {}
$$r{'links'}
MC/DC0%0/1
$a[0] // ""
$a[0]
Truth table0%0/2
A
A= $$r{'links'}
Aresult
11
00
Truth table0%0/2
A
A= $a[0]
Aresult
11
00
6503 0 delete @{$k}{qw( dns domains )};
6504 0 return ( '', 1 );
6505 }
6506 0 return ( "Unknown command verb '$verb'.", 0 );
6507 }
6508  
6509 8 ▶sub _ln {
Subroutine _ln: called CC=18 SCAR=30.0
6510 8 my ( $dev, $av ) = @_;
6511 8 my @a = grep { !/\A-/ } @$av;
6512 8 my $sym = grep {/s/} grep {/\A-/} @$av;
6513 8 ▶ return ( "ln: missing file operand", 0 ) unless @a == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @a == 2 0 8 8
6514 8 ▶ return ( "ln: failed to create hard link: Operation not permitted", 0 ) unless $sym;
Branch: 1 branch
BranchTrueFalseTotal
unless $sym 0 8 8
6515 8 my ( $target, $link ) = @a;
6516 8 ▶ my $flags = join '', map { /\A-(\w+)\z/ ? $1 : /\A--no-(?:target-directory|dereference)\z/ ? 'n' : /\A--force\z/ ? 'f' : '' } @$av;
Branch: 3 branches
BranchTrueFalseTotal
/\A-(\w+)\z/ ? : 8 16 24
/\A--no-(?:target-directory|dereference)\z/ ? : 0 16 16
/\A--force\z/ ? : 0 16 16
6517 8 $link =~ s{(?<=.)/+\z}{};
6518 8 $link = _absp($link); # der Name gilt im aktuellen Verzeichnis, das Ziel bleibt Text (relativ zum Link)
6519 # Ein Verzeichnis (auch ein Symlink darauf, ohne -n/-T) als Ziel: der Link entsteht darin
6520 8 ▶ if ( _is_dir( $dev, $link ) && $flags !~ /[nT]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_dir($dev, $link) and not $flags =~ /[nT]/) 3 5 8
Condition100%3/3
_is_dir($dev, $link) and not $flags =~ /[nT]/
!ll&&!rl&&r
413
MC/DC100%2/2
_is_dir($dev, $link) and not $flags =~ /[nT]/
_is_dir($dev, $link) not $flags =~ /[nT]/
Truth table100%3/3
A and not(B)
A= _is_dir($dev, $link)B= not $flags =~ /[nT]/
ABresult
0X0
100
111
6521 3 ▶ my $e = ref $dev->{files} eq 'HASH' ? $dev->{files}{$link} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'} eq 'HASH' ? : 3 0 3
6522 3 ▶ my $d = ref $e eq 'HASH' && defined $e->{link} ? _link_target( $link, $e->{link} ) : $link;
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' && defined $$e{'link'} ? : 1 2 3
Condition66%2/3
ref $e eq "HASH" and defined $$e{"link"}
!ll&&!rl&&r
201
MC/DC50%1/2
ref $e eq "HASH" and defined $$e{"link"}
ref $e eq "HASH" defined $$e{"link"}
Truth table66%2/3
A and B
A= ref $e eq "HASH"B= defined $$e{"link"}
ABresult
0X0
100
111
6523 3 ( my $base = $target ) =~ s{/+\z}{};
6524 3 $base =~ s{.*/}{};
6525 3 $link = "$d/$base";
6526 }
6527 return ( "ln: failed to create symbolic link '$link': File exists", 0 )
6528 8 ▶ if ( ( ref $dev->{files} eq 'HASH' && exists $dev->{files}{$link} ) || _is_dir( $dev, $link ) ) && $flags !~ /f/;
Branch: 1 branch
BranchTrueFalseTotal
if ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$link} || _is_dir($dev, $link) and not $flags =~ /f/ 2 6 8
Condition77%7/9
ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$link} || _is_dir($dev, $link) and not $flags =~ /f/
!ll&&!rl&&r
512
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{$link} or _is_dir($dev, $link)
l!l&&r!l&&!r
305
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{$link}
!ll&&!rl&&r
053
MC/DC50%2/4
ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$link} || _is_dir($dev, $link) and not $flags =~ /f/
ref $$dev{"files"} eq "HASH" exists $$dev{"files"}{$link} _is_dir($dev, $link) not $flags =~ /f/
Truth table37%3/8
A and B or C and not(D)
A= ref $$dev{"files"} eq "HASH"B= exists $$dev{"files"}{$link}C= _is_dir($dev, $link)D= not $flags =~ /f/
ABCDresult
0X0X0
100X0
11X00
0X100
10100
11X11
0X111
10111
6529 6 ▶ return ( "ln: cannot overwrite directory '$link'", 0 ) if _is_dir( $dev, $link ) && !( ref $dev->{files}{$link} eq 'HASH' && defined $dev->{files}{$link}{link} );
Branch: 1 branch
BranchTrueFalseTotal
if _is_dir($dev, $link) and not ref $$dev{"files"}{$link} eq "HASH" && defined $$dev{"files"}{$link}{"link"} 0 6 6
Condition50%3/6
_is_dir($dev, $link) and not ref $$dev{"files"}{$link} eq "HASH" && defined $$dev{"files"}{$link}{"link"}
!ll&&!rl&&r
510
ref $$dev{'files'}{$link} eq 'HASH' && defined $$dev{'files'}{$link}{'link'}
!ll&&!rl&&r
001
MC/DC0%0/3
_is_dir($dev, $link) and not ref $$dev{"files"}{$link} eq "HASH" && defined $$dev{"files"}{$link}{"link"}
_is_dir($dev, $link) ref $$dev{'files'}{$link} eq 'HASH' defined $$dev{'files'}{$link}{'link'}
Truth table50%2/4
A and not(B && C)
A= _is_dir($dev, $link)B= ref $$dev{'files'}{$link} eq 'HASH'C= defined $$dev{'files'}{$link}{'link'}
ABCresult
0XX0
1110
10X1
1101
6530 6 $dev->{files}{$link} = { link => $target };
6531 6 return ( '', 1 );
6532 }
6533  
6534 # ssh [-o …] [user@]ziel befehl: der Befehl laeuft auf dem Geraet mit diesem Namen oder
6535 # dieser Adresse (als root, Schluessel hinterlegt); ohne Befehl keine Sitzung; andere Ziele
6536 # sind eine Luecke
6537 13 ▶sub _ssh {
Subroutine _ssh: called CC=30 SCAR=37.1
6538 13 my ( $dev, $av, $ctx ) = @_;
6539 13 my @a = @$av;
6540 13 my $host;
6541 13 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 18 0 18
6542 18 my $x = shift @a;
6543 18 ▶ if ( $x =~ /\A-[oipFlJ]\z/ ) { shift @a }
Branch: 2 branches
BranchTrueFalseTotal
if ($x =~ /\A-[oipFlJ]\z/) { } 4 14 18
elsif ($x =~ /\A-/) { } 1 13 14
6544 elsif ( $x =~ /\A-/ ) { }
6545 13 else { $host = $x; last }
6546 }
6547 13 ▶ return ( 'usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] destination [command [argument ...]]', 0 ) unless defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 13 13
6548 13 my ($login) = $host =~ /\A([^@]+)@/;
6549 13 $host =~ s/\A[^@]*@//;
6550 13 ▶ if ( ( $login // '' ) eq 'git' && ( my $git = ( $dev->{git} || {} )->{hosts} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($login // "") eq "git" and my $git = ($$dev{"git"} || {})->{"hosts"}) 2 11 13
Condition71%5/7
($login // "") eq "git" and my $git = ($$dev{"git"} || {})->{"hosts"}
!ll&&!rl&&r
1102
$login // ""
l!l
76
$$dev{'git'} || {}
l!l
20
MC/DC50%1/2
($login // "") eq "git" and my $git = ($$dev{"git"} || {})->{"hosts"}
$login $$dev{'git'}
Truth table66%2/3
A and B
A= $loginB= $$dev{'git'}
ABresult
0X0
100
111
6551 2 _part('Git');
6552 2 ▶ my $srv = ( ( $ctx || {} )->{state} || {} )->{ $git->{$host} // '' } // Langertha::Holmgang::Sim::Linux::Git::_by_hosts_file( $ctx, $host );
Condition44%4/9
(($ctx || {})->{"state"} || {})->{$$git{$host} // ""} // Langertha::Holmgang::Sim::Linux::Git::_by_hosts_file($ctx, $host)
l!l&&r!l&&!r
200
($ctx || {})->{'state'} || {}
l!l
20
$ctx || {}
l!l
20
$$git{$host} // ""
l!l
20
MC/DC0%0/2
(($ctx || {})->{"state"} || {})->{$$git{$host} // ""} // Langertha::Holmgang::Sim::Linux::Git::_by_hosts_file($ctx, $host)
$ctx Langertha::Holmgang::Sim::Linux::Git::_by_hosts_file($ctx, $host)
MC/DC0%0/1
$$git{$host} // ""
$$git{$host}
Truth table33%1/3
A // B
A= $ctxB= Langertha::Holmgang::Sim::Linux::Git::_by_hosts_file($ctx, $host)
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$git{$host}
Aresult
11
00
6553 2 ▶ if ( $srv && $srv->{forgejo} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($srv and $$srv{"forgejo"}) 2 0 2
Condition33%1/3
$srv and $$srv{"forgejo"}
!ll&&!rl&&r
002
MC/DC0%0/2
$srv and $$srv{"forgejo"}
$srv $$srv{"forgejo"}
Truth table33%1/3
A and B
A= $srvB= $$srv{"forgejo"}
ABresult
0X0
100
111
6554 2 ▶ return ( "Hi there, dev! You've successfully authenticated with the key named dev\@dev1, but Forgejo does not provide shell access.\nIf this is unexpected, please log in with password and setup Forgejo under another user.", 1 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 1 1 2
6555 1 push @GAPS, join( ' ', 'ssh', @$av );
6556 1 return ( '', 0 );
6557 }
6558 }
6559 # auf sich selbst (localhost, eigene Adresse, eigener Name): Anmeldung gegen die geladene
6560 # sshd-Konfiguration, wie sshd selbst sie prueft
6561 11 ▶ my %own = map { $_ => 1 } _own_addrs($dev), 'localhost', ( $ctx || {} )->{host} // ();
Condition40%2/5
($ctx || {})->{"host"} // ()
l!l&&r!l&&!r
1100
$ctx || {}
l!l
110
MC/DC0%0/2
($ctx || {})->{"host"} // ()
$ctx ()
Truth table33%1/3
A // B
A= $ctxB= ()
ABresult
1X1
011
000
6562 11 ▶ return _ssh_client( $dev, $av, $ctx ) if $own{$host} && ref $dev->{files} eq 'HASH' && exists $dev->{files}{'/etc/ssh/sshd_config'};
Branch: 1 branch
BranchTrueFalseTotal
if $own{$host} and ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"} 3 8 11
Condition66%4/6
$own{$host} and ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"}
!ll&&!rl&&r
803
$own{$host} and ref $$dev{"files"} eq "HASH"
!ll&&!rl&&r
803
MC/DC33%1/3
$own{$host} and ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"}
$own{$host} ref $$dev{"files"} eq "HASH" exists $$dev{"files"}{"/etc/ssh/sshd_config"}
Truth table50%2/4
A and B and C
A= $own{$host}B= ref $$dev{"files"} eq "HASH"C= exists $$dev{"files"}{"/etc/ssh/sshd_config"}
ABCresult
0XX0
10X0
1100
1111
6563 8 ▶ my $state = $CTX ? $CTX->{state} : {};
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 8 0 8
6564 my $other = ref $state->{$host} eq 'HASH' ? $state->{$host}
6565 8 ▶ : ( grep { ref $_ eq 'HASH' && ( ( $_->{hostname} // '' ) eq $host || grep { $_ eq $host } _own_addrs($_) ) } values %$state )[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $$state{$host} eq 'HASH' ? : 2 6 8
Condition75%6/8
ref $_ eq 'HASH' && (($$_{'hostname'} // '') eq $host || grep({$_ eq $host;} _own_addrs($_)))
!ll&&!rl&&r
091
($$_{"hostname"} // "") eq $host or grep {$_ eq $host;} _own_addrs($_)
l!l&&r!l&&!r
019
$$_{"hostname"} // ""
l!l
46
MC/DC33%1/3
ref $_ eq 'HASH' && (($$_{'hostname'} // '') eq $host || grep({$_ eq $host;} _own_addrs($_)))
ref $_ eq 'HASH' $$_{"hostname"} grep {$_ eq $host;} _own_addrs($_)
Truth table50%2/4
A && B or C
A= ref $_ eq 'HASH'B= $$_{"hostname"}C= grep {$_ eq $host;} _own_addrs($_)
ABCresult
0XX0
1000
11X1
1011
6566 # ein Geraet, das der Fall nicht nachbildet: Luecke (es kann es geben)
6567 8 ▶ if ( !$other ) { push @GAPS, join( ' ', 'ssh', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($other) 5 3 8
6568 3 ▶ return ( 'Pseudo-terminal will not be allocated because stdin is not a terminal.', 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 3 3
6569 3 ▶ return ( "ssh: connect to host $host port 22: Connection refused", 0 ) if ( $other->{type} // '' ) ne 'linux';
Branch: 1 branch
BranchTrueFalseTotal
if ($$other{"type"} // "") ne "linux" 0 3 3
Condition50%1/2
$$other{"type"} // ""
l!l
30
MC/DC0%0/1
$$other{"type"} // ""
$$other{"type"}
Truth table50%1/2
A
A= $$other{"type"}
Aresult
11
00
6570 # wie echtes ssh: die Woerter mit Leerzeichen verbunden, drueben neu gelesen (im Heimatverzeichnis)
6571 3 local $CWD_DIR;
6572 3 my ( $o, $k ) = __PACKAGE__->_run_inner( $other, join( ' ', @a ), $ctx );
6573 3 return ( $o, $k );
6574 }
6575  
6576 # nginx als Webserver fuer statische Dateien: ( text, status, typ ) fuer GET auf PORT/PFAD
6577 # mit Host-Kopf, oder () wenn nicht nachgebildet (proxy_pass, kein passender server-Block).
6578 # Der server-Block nach Port und server_name (sonst der erste mit dem Port), root + Pfad,
6579 # index.html fuer ein Verzeichnis; 403, wenn der Arbeiter (user, Vorgabe www-data) ein
6580 # Verzeichnis auf dem Weg nicht betreten oder die Datei nicht lesen darf, 404, wenn es sie
6581 # nicht gibt. Status 0: nginx laeuft nicht oder lauscht nicht auf dem Port.
6582 9 ▶sub _nginx_http {
Subroutine _nginx_http: called CC=32 SCAR=35.7
6583 9 my ( $dev, $port, $vhost, $path ) = @_;
6584 9 ▶ my ( $name, $svc ) = map { ( $_, $dev->{services}{$_} ) } grep { ( $dev->{services}{$_}{exec} // $_ ) eq 'nginx' } sort keys %{ $dev->{services} || {} };
Condition40%2/5
$$dev{"services"}{$_}{"exec"} // $_
l!l&&r!l&&!r
900
$$dev{'services'} || {}
l!l
90
MC/DC0%0/2
$$dev{"services"}{$_}{"exec"} // $_
$$dev{"services"}{$_}{"exec"} $_
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table33%1/3
A // B
A= $$dev{"services"}{$_}{"exec"}B= $_
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
6585 9 ▶ return ( '', 0 ) unless $svc && $svc->{active} && grep { /:\Q$port\E\z/ } _svc_listen( $dev, $name, $svc );
Branch: 1 branch
BranchTrueFalseTotal
unless $svc and $$svc{"active"} and grep {/:\Q$port\E\z/;} _svc_listen($dev, $name, $svc) 1 8 9
Condition66%4/6
$svc and $$svc{"active"} and grep {/:\Q$port\E\z/;} _svc_listen($dev, $name, $svc)
!ll&&!rl&&r
108
$svc and $$svc{"active"}
!ll&&!rl&&r
018
MC/DC33%1/3
$svc and $$svc{"active"} and grep {/:\Q$port\E\z/;} _svc_listen($dev, $name, $svc)
$svc $$svc{"active"} grep {/:\Q$port\E\z/;} _svc_listen($dev, $name, $svc)
Truth table50%2/4
A and B and C
A= $svcB= $$svc{"active"}C= grep {/:\Q$port\E\z/;} _svc_listen($dev, $name, $svc)
ABCresult
0XX0
10X0
1100
1111
6586 8 ▶ my $run = ref $svc->{running} eq 'HASH' ? $svc->{running} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'running'} eq 'HASH' ? : 0 8 8
6587 8 ▶ my $text = sub { $run->{ $_[0] } // _file_text( $dev, $_[0] ) // '' };
Subroutine __ANON__: called CC=3 SCAR=11.1
Condition80%4/5
($$run{$_[0]} // _file_text($dev, $_[0])) // ""
l!l
88
$$run{$_[0]} // _file_text($dev, $_[0])
l!l&&r!l&&!r
088
MC/DC50%1/2
($$run{$_[0]} // _file_text($dev, $_[0])) // ""
$$run{$_[0]} _file_text($dev, $_[0])
Truth table66%2/3
A // B
A= $$run{$_[0]}B= _file_text($dev, $_[0])
ABresult
1X1
011
000
6588 8 my ($user) = $text->('/etc/nginx/nginx.conf') =~ /^\s*user\s+([^\s;]+)/m;
6589 8 ▶ $user //= 'www-data';
Condition50%1/2
$user //= "www-data"
l!l
08
MC/DC0%0/1
$user //= "www-data"
$user
Truth table50%1/2
A
A= $user
Aresult
11
00
6590 8 my @blocks;
6591 8 ▶ for my $p ( sort grep { m{\A/etc/nginx/(?:nginx\.conf|conf\.d/[^/]+\.conf|sites-enabled/[^/]+)\z} } keys %{ $dev->{files} || {} } ) {
Condition50%1/2
$$dev{'files'} || {}
l!l
80
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
6592 8 ( my $t = $text->($p) ) =~ s/#[^\n]*//g;
6593 8 ▶ while ( $t =~ /\bserver\s*\{/g ) { # Block mit ausgeglichenen Klammern
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /\bserver\s*\{/g) 8 8 16
6594 8 my ( $start, $depth, $i ) = ( pos($t), 1, pos($t) );
6595 8 ▶ while ( $depth && $i < length $t ) { my $c = substr( $t, $i++, 1 ); $depth++ if $c eq '{'; $depth-- if $c eq '}' }
Branch: 3 branches
BranchTrueFalseTotal
if ($depth and $i < length $t) 1088 8 1096
if $c eq "{" 8 1080 1088
if $c eq "}" 16 1072 1088
Condition66%2/3
$depth and $i < length $t
!ll&&!rl&&r
801088
MC/DC50%1/2
$depth and $i < length $t
$depth $i < length $t
Truth table66%2/3
A and B
A= $depthB= $i < length $t
ABresult
0X0
100
111
6596 8 my $body = substr( $t, $start, $i - $start - 1 );
6597 8 pos($t) = $i;
6598 8 ( my $top = $body ) =~ s/\blocation\b[^{]*\{(?:[^{}]|\{[^{}]*\})*\}//g;
6599 8 ▶ push @blocks, { body => $body, top => $top, ports => [ map { /(\d+)\z/ ? $1 : () } $top =~ /^\s*listen\s+([^;\s]+)/mg ],
Branch: 1 branch
BranchTrueFalseTotal
/(\d+)\z/ ? : 8 0 8
6600 8 names => [ map { split ' ' } $top =~ /^\s*server_name\s+([^;]+);/mg ] };
6601 }
6602 }
6603 8 ▶ ( $vhost //= '' ) =~ s/:\d+\z//;
Condition50%1/2
$vhost //= ""
l!l
80
MC/DC0%0/1
$vhost //= ""
$vhost
Truth table50%1/2
A
A= $vhost
Aresult
11
00
6604 8 my @on = grep { grep { $_ == $port } @{ $_->{ports} } } @blocks;
6605 8 my ($blk) = ( ( grep { my $x = $_; grep { $_ eq $vhost } @{ $x->{names} } } @on ), @on );
6606 8 ▶ return () unless $blk;
Branch: 1 branch
BranchTrueFalseTotal
unless $blk 0 8 8
6607 8 $path =~ s/[?#].*//s;
6608 # eine location mit proxy_pass, die den Pfad betrifft: nicht nachgebildet
6609 8 ▶ for my $loc ( $blk->{body} =~ /\blocation\s+([^\s{]+)\s*\{[^{}]*\bproxy_pass\b/g ) { return () if index( $path, $loc ) == 0 }
Branch: 1 branch
BranchTrueFalseTotal
if index($path, $loc) == 0 1 7 8
6610 7 my ($root) = $blk->{top} =~ /^\s*root\s+([^;\s]+)\s*;/m;
6611 7 ▶ return () unless defined $root;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root 0 7 7
6612 7 my $f = $root =~ s{/+\z}{}r . $path;
6613 7 ▶ $f .= 'index.html' if $f =~ m{/\z};
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ m[/\z] 1 6 7
6614 7 my @parts = split m{/}, $f;
6615 7 for my $i ( 1 .. $#parts - 1 ) {
6616 25 my $d = join '/', @parts[ 0 .. $i ];
6617 25 ▶ next unless length $d;
Branch: 1 branch
BranchTrueFalseTotal
unless length $d 0 25 25
6618 25 ▶ return ( "<html>\n<head><title>404 Not Found</title></head>\n<body>\n<center><h1>404 Not Found</h1></center>\n<hr><center>nginx/1.22.1</center>\n</body>\n</html>", 404, 'text/html' )
Branch: 1 branch
BranchTrueFalseTotal
unless _is_dir($dev, $d) 0 25 25
6619 unless _is_dir( $dev, $d );
6620 25 ▶ next unless ( $dev->{dirs} || {} )->{$d}; # ohne Eintrag: root, 0755
Branch: 1 branch
BranchTrueFalseTotal
unless ($$dev{"dirs"} || {})->{$d} 14 11 25
Condition50%1/2
$$dev{'dirs'} || {}
l!l
250
MC/DC0%0/1
$$dev{'dirs'} || {}
$$dev{'dirs'}
Truth table50%1/2
A
A= $$dev{'dirs'}
Aresult
11
00
6621 11 ▶ return ( "<html>\n<head><title>403 Forbidden</title></head>\n<body>\n<center><h1>403 Forbidden</h1></center>\n<hr><center>nginx/1.22.1</center>\n</body>\n</html>", 403, 'text/html' )
Branch: 1 branch
BranchTrueFalseTotal
unless _can($dev, $user, $d, "x") 1 10 11
6622 unless _can( $dev, $user, $d, 'x' );
6623 }
6624 6 my $body = _file_text( $dev, $f );
6625 6 ▶ return ( "<html>\n<head><title>404 Not Found</title></head>\n<body>\n<center><h1>404 Not Found</h1></center>\n<hr><center>nginx/1.22.1</center>\n</body>\n</html>", 404, 'text/html' )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 1 5 6
6626 unless defined $body;
6627 5 ▶ return ( "<html>\n<head><title>403 Forbidden</title></head>\n<body>\n<center><h1>403 Forbidden</h1></center>\n<hr><center>nginx/1.22.1</center>\n</body>\n</html>", 403, 'text/html' )
Branch: 1 branch
BranchTrueFalseTotal
unless _can($dev, $user, $f, "r") 1 4 5
6628 unless _can( $dev, $user, $f, 'r' );
6629 4 my %type = ( css => 'text/css', js => 'application/javascript', html => 'text/html', svg => 'image/svg+xml', json => 'application/json', txt => 'text/plain' );
6630 4 my ($ext) = $f =~ /\.(\w+)\z/;
6631 4 ▶ return ( $body, 200, $type{ lc( $ext // '' ) } // 'application/octet-stream' );
Condition50%2/4
$type{lc($ext // "")} // "application/octet-stream"
l!l
40
$ext // ""
l!l
40
MC/DC0%0/1
$type{lc($ext // "")} // "application/octet-stream"
$type{lc($ext // "")}
MC/DC0%0/1
$ext // ""
$ext
Truth table50%1/2
A
A= $type{lc($ext // "")}
Aresult
11
00
Truth table50%1/2
A
A= $ext
Aresult
11
00
6632 }
6633  
6634 # /dev/tcp/HOST/PORT der bash: Verbindung wie _tcp_probe; UDP und Unbekanntes sind eine Luecke
6635 9 ▶sub _dev_tcp {
Subroutine _dev_tcp: called CC=9 SCAR=22.3
6636 9 my ( $dev, $path, $dir ) = @_;
6637 9 my ( $proto, $h, $p ) = $path =~ m{\A/dev/(tcp|udp)/([^/]+)/(\d+)\z};
6638 9 ▶ my $st = defined $p && $proto eq 'tcp' ? _tcp_probe( $dev, $h, $p ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $p && $proto eq 'tcp' ? : 9 0 9
Condition33%1/3
defined $p and $proto eq "tcp"
!ll&&!rl&&r
009
MC/DC0%0/2
defined $p and $proto eq "tcp"
defined $p $proto eq "tcp"
Truth table33%1/3
A and B
A= defined $pB= $proto eq "tcp"
ABresult
0X0
100
111
6639 9 ▶ if ( !defined $st ) { push @GAPS, "$dir $path"; return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 2 7 9
6640 7 ▶ return ( '', 1 ) if $st eq 'open';
Branch: 1 branch
BranchTrueFalseTotal
if $st eq "open" 3 4 7
6641 4 ▶ return ( "bash: $h: Name or service not known\nbash: $path: Invalid argument", 0 ) if $st eq 'noname';
Branch: 1 branch
BranchTrueFalseTotal
if $st eq "noname" 1 3 4
6642 3 ▶ if ( $st eq 'timeout' && $IN_TIMEOUT ) { $SH->{code} = 124 if $SH; return ( '', 0 ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($st eq "timeout" and $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT) 1 2 3
if $Langertha::Holmgang::Sim::Linux::SH 1 0 1
Condition66%2/3
$st eq "timeout" and $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT
!ll&&!rl&&r
201
MC/DC50%1/2
$st eq "timeout" and $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT
$st eq "timeout" $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT
Truth table66%2/3
A and B
A= $st eq "timeout"B= $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT
ABresult
0X0
100
111
6643 2 my $m = { refused => 'Connection refused', timeout => 'Connection timed out', unreach => 'Network is unreachable' }->{$st};
6644 2 return ( "bash: connect: $m\nbash: $path: $m", 0 );
6645 }
6646  
6647 # --- Anmeldungen (wtmp) ------------------------------------------------------------------
6648 # Laufender Start des Geraets (Epoche): der frueheste since eines Dienstes, sonst die Vorgabe
6649 43 ▶sub _boot_epoch {
Subroutine _boot_epoch: called CC=6 SCAR=19.1
6650 43 my ($dev) = @_;
6651 30 ▶ my ($t) = sort { $a <=> $b } grep {defined} map { _parse_stamp( $_->{since} // $BOOT_STAMP ) }
Condition66%2/3
$$_{"since"} // $Langertha::Holmgang::Sim::Linux::BOOT_STAMP
l!l&&r!l&&!r
10210
MC/DC0%0/2
$$_{"since"} // $Langertha::Holmgang::Sim::Linux::BOOT_STAMP
$$_{"since"} $Langertha::Holmgang::Sim::Linux::BOOT_STAMP
Truth table66%2/3
A // B
A= $$_{"since"}B= $Langertha::Holmgang::Sim::Linux::BOOT_STAMP
ABresult
1X1
011
000
6652 43 ▶ grep { ref eq 'HASH' && ( $_->{active} || defined $_->{since} ) } values %{ $dev->{services} || {} };
Condition50%4/8
ref $_ eq 'HASH' && ($$_{'active'} || defined $$_{'since'})
!ll&&!rl&&r
0031
$$_{"active"} or defined $$_{"since"}
l!l&&r!l&&!r
3100
$$dev{'services'} || {}
l!l
1132
MC/DC0%0/3
ref $_ eq 'HASH' && ($$_{'active'} || defined $$_{'since'})
ref $_ eq 'HASH' $$_{"active"} defined $$_{"since"}
MC/DC100%1/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table25%1/4
A && B or C
A= ref $_ eq 'HASH'B= $$_{"active"}C= defined $$_{"since"}
ABCresult
0XX0
1000
11X1
1011
Truth table100%2/2
A
A= $$dev{'services'}
Aresult
11
00
6653 43 ▶ return $t // _parse_stamp($BOOT_STAMP);
Condition66%2/3
$t // _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
l!l&&r!l&&!r
11320
MC/DC0%0/2
$t // _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
$t _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
Truth table66%2/3
A // B
A= $tB= _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
ABresult
1X1
011
000
6654 }
6655  
6656 # Anmeldungen aus dem Zustand (logins: [ { user, tty, from, start: "Mon Oct 19 16:02",
6657 # end: "16:40"|"still logged in", duration } ]) und der laufende Start: [ epoche, zeile, -a-zeile, user, tty ]
6658 7 ▶sub _wtmp {
Subroutine _wtmp: called CC=17 SCAR=31.2
6659 7 my ($dev) = @_;
6660 7 require POSIX;
6661 7 require Time::Local;
6662 7 my @r;
6663 7 my $boot = _boot_epoch($dev);
6664 7 my $bs = POSIX::strftime( '%a %b %e %H:%M', _local_tm($boot) );
6665 7 my $kern = '6.1.0-26-amd64';
6666 7 push @r, [ $boot, sprintf( '%-8s %-12s %-16s %-16s still running', 'reboot', 'system boot', $kern, $bs ),
6667 sprintf( '%-8s %-12s %-37s %s', 'reboot', 'system boot', "$bs still running", $kern ), 'reboot', 'system boot' ];
6668 7 ▶ for my $l ( grep { ref eq 'HASH' } @{ $dev->{logins} || [] } ) {
Condition100%2/2
$$dev{'logins'} || []
l!l
52
MC/DC100%1/1
$$dev{'logins'} || []
$$dev{'logins'}
Truth table100%2/2
A
A= $$dev{'logins'}
Aresult
11
00
6669 5 ▶ my ( $mon, $d, $h, $mi ) = ( $l->{start} // '' ) =~ /\A\w{3}\s+(\w{3})\s+(\d+)\s+(\d\d):(\d\d)\z/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = ($$l{"start"} // "") =~ /\A\w{3}\s+(\w{3})\s+(\d+)\s+(\d\d):(\d\d)\z/ or next 5 0 5
Condition50%1/2
$$l{"start"} // ""
l!l
50
MC/DC0%0/1
$$l{"start"} // ""
$$l{"start"}
Truth table50%1/2
A
A= $$l{"start"}
Aresult
11
00
6670 5 ▶ my $t = Time::Local::timegm( 0, $mi, $h, $d, $MON{$mon} // 9, 2026 );
Condition50%1/2
$MON{$mon} // 9
l!l
50
MC/DC0%0/1
$MON{$mon} // 9
$MON{$mon}
Truth table50%1/2
A
A= $MON{$mon}
Aresult
11
00
6671 5 $t -= Langertha::Holmgang::Sim::Linux::Calendar::offset( $t - 3600 );
6672 5 ▶ my $end = $l->{end} // 'still logged in';
Condition50%1/2
$$l{"end"} // "still logged in"
l!l
50
MC/DC0%0/1
$$l{"end"} // "still logged in"
$$l{"end"}
Truth table50%1/2
A
A= $$l{"end"}
Aresult
11
00
6673 5 my $dur = $l->{duration};
6674 5 ▶ if ( !defined $dur && $end =~ /\A(\d\d):(\d\d)\z/ ) { my $m = ( $1 * 60 + $2 ) - ( $h * 60 + $mi ); $m += 1440 if $m < 0; $dur = sprintf '(%02d:%02d)', int( $m / 60 ), $m % 60 }
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $dur and $end =~ /\A(\d\d):(\d\d)\z/) 5 0 5
if $m < 0 0 5 5
Condition33%1/3
not defined $dur and $end =~ /\A(\d\d):(\d\d)\z/
!ll&&!rl&&r
005
MC/DC0%0/2
not defined $dur and $end =~ /\A(\d\d):(\d\d)\z/
not defined $dur $end =~ /\A(\d\d):(\d\d)\z/
Truth table33%1/3
not(A) and B
A= not defined $durB= $end =~ /\A(\d\d):(\d\d)\z/
ABresult
0X0
100
111
6675 5 ▶ my $rest = $end =~ /\A\d\d:\d\d\z/ ? "- $end " . ( $dur // '' ) : " $end";
Branch: 1 branch
BranchTrueFalseTotal
$end =~ /\A\d\d:\d\d\z/ ? : 5 0 5
Condition50%1/2
$dur // ""
l!l
50
MC/DC0%0/1
$dur // ""
$dur
Truth table50%1/2
A
A= $dur
Aresult
11
00
6676 5 my $start = sprintf '%-16s', $l->{start};
6677 push @r, [ $t, sprintf( '%-8s %-12s %-16s %s %s', $l->{user}, $l->{tty} // 'pts/0', $l->{from} // '', $start, $rest ),
6678 5 ▶ sprintf( '%-8s %-12s %-37s %s', $l->{user}, $l->{tty} // 'pts/0', "$start $rest", $l->{from} // '' ), $l->{user}, $l->{tty} // 'pts/0' ];
Condition50%5/10
$$l{"tty"} // "pts/0"
l!l
50
$$l{"from"} // ""
l!l
50
$$l{"tty"} // "pts/0"
l!l
50
$$l{"from"} // ""
l!l
50
$$l{"tty"} // "pts/0"
l!l
50
MC/DC0%0/1
$$l{"tty"} // "pts/0"
$$l{"tty"}
MC/DC0%0/1
$$l{"from"} // ""
$$l{"from"}
MC/DC0%0/1
$$l{"tty"} // "pts/0"
$$l{"tty"}
MC/DC0%0/1
$$l{"from"} // ""
$$l{"from"}
MC/DC0%0/1
$$l{"tty"} // "pts/0"
$$l{"tty"}
Truth table50%1/2
A
A= $$l{"tty"}
Aresult
11
00
Truth table50%1/2
A
A= $$l{"from"}
Aresult
11
00
Truth table50%1/2
A
A= $$l{"tty"}
Aresult
11
00
Truth table50%1/2
A
A= $$l{"from"}
Aresult
11
00
Truth table50%1/2
A
A= $$l{"tty"}
Aresult
11
00
6679 }
6680 7 return sort { $b->[0] <=> $a->[0] } @r;
6681 }
6682  
6683 # uptime [-p|-s]: seit dem laufenden Start (_boot_epoch) an der Uhr des Geraets; ein
6684 # Benutzer (die Sitzung des Modells), ruhige Last
6685 36 ▶sub _uptime {
Subroutine _uptime: called CC=16 SCAR=32.4
6686 36 my ( $dev, $av ) = @_;
6687 36 require POSIX;
6688 36 my ( $boot, $now ) = ( _boot_epoch($dev), _dev_now($dev) );
6689 36 my $up = $now - $boot;
6690 36 ▶ $up = 60 if $up < 60;
Branch: 1 branch
BranchTrueFalseTotal
if $up < 60 0 36 36
6691 36 my ( $d, $h, $m ) = ( int( $up / 86400 ), int( $up % 86400 / 3600 ), int( $up % 3600 / 60 ) );
6692 36 ▶ my $opt = $av->[0] // '';
Condition100%2/2
$$av[0] // ""
l!l
234
MC/DC100%1/1
$$av[0] // ""
$$av[0]
Truth table100%2/2
A
A= $$av[0]
Aresult
11
00
6693 36 ▶ return ( POSIX::strftime( '%Y-%m-%d %H:%M:%S', _local_tm($boot) ), 1 ) if $opt eq '-s' || $opt eq '--since';
Branch: 1 branch
BranchTrueFalseTotal
if $opt eq "-s" or $opt eq "--since" 1 35 36
Condition66%2/3
$opt eq "-s" or $opt eq "--since"
l!l&&r!l&&!r
1035
MC/DC50%1/2
$opt eq "-s" or $opt eq "--since"
$opt eq "-s" $opt eq "--since"
Truth table66%2/3
A or B
A= $opt eq "-s"B= $opt eq "--since"
ABresult
1X1
011
000
6694 35 ▶ if ( $opt eq '-p' || $opt eq '--pretty' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt eq "-p" or $opt eq "--pretty") 1 34 35
Condition66%2/3
$opt eq "-p" or $opt eq "--pretty"
l!l&&r!l&&!r
1034
MC/DC50%1/2
$opt eq "-p" or $opt eq "--pretty"
$opt eq "-p" $opt eq "--pretty"
Truth table66%2/3
A or B
A= $opt eq "-p"B= $opt eq "--pretty"
ABresult
1X1
011
000
6695 1 my @p;
6696 1 ▶ push @p, $d == 1 ? '1 day' : "$d days" if $d;
Branch: 2 branches
BranchTrueFalseTotal
if $d 0 1 1
$d == 1 ? : 0 0 0
6697 1 ▶ push @p, $h == 1 ? '1 hour' : "$h hours" if $h;
Branch: 2 branches
BranchTrueFalseTotal
if $h 1 0 1
$h == 1 ? : 0 1 1
6698 1 ▶ push @p, $m == 1 ? '1 minute' : "$m minutes" if $m;
Branch: 2 branches
BranchTrueFalseTotal
if $m 0 1 1
$m == 1 ? : 0 0 0
6699 1 return ( 'up ' . join( ', ', @p ), 1 );
6700 }
6701 0 ▶ if ( length $opt ) { push @GAPS, join( ' ', 'uptime', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (length $opt) 0 34 34
6702 34 ▶ my $t = ( $d ? ( $d == 1 ? '1 day, ' : "$d days, " ) : '' ) . sprintf( '%2d:%02d', $h, $m );
Branch: 2 branches
BranchTrueFalseTotal
$d ? : 0 34 34
$d == 1 ? : 0 0 0
6703 34 return ( POSIX::strftime( ' %H:%M:%S', _local_tm($now) ) . " up $t, 1 user, load average: 0.08, 0.03, 0.01", 1 );
6704 }
6705  
6706 # last [-a] [-n N] [-F] [-x] [BENUTZER|reboot|TTY …]
6707 6 ▶sub _last {
Subroutine _last: called CC=15 SCAR=31.1
6708 6 my ( $dev, $av ) = @_;
6709 6 my ( $a, $n, @who );
6710 6 my @x = @$av;
6711 6 ▶ while (@x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@x) 4 6 10
6712 4 my $o = shift @x;
6713 0 ▶ if ( $o eq '-n' || $o eq '--limit' ) { $n = shift @x }
Branch: 4 branches
BranchTrueFalseTotal
if ($o eq '-n' or $o eq '--limit') { } 0 4 4
elsif ($o =~ /\A-(\d+)\z/ or $o =~ /\A-n(\d+)\z/) { } 0 4 4
elsif ($o =~ /\A-([aFxwiR]+)\z/) { } 1 3 4
elsif ($o =~ /\A-/) { } 0 3 3
Condition33%1/3
$o eq "-n" or $o eq "--limit"
l!l&&r!l&&!r
004
MC/DC0%0/2
$o eq "-n" or $o eq "--limit"
$o eq "-n" $o eq "--limit"
Truth table33%1/3
A or B
A= $o eq "-n"B= $o eq "--limit"
ABresult
1X1
011
000
6714 0 ▶ elsif ( $o =~ /\A-(\d+)\z/ || $o =~ /\A-n(\d+)\z/ ) { $n = $1 }
Condition33%1/3
$o =~ /\A-(\d+)\z/ or $o =~ /\A-n(\d+)\z/
l!l&&r!l&&!r
004
MC/DC0%0/2
$o =~ /\A-(\d+)\z/ or $o =~ /\A-n(\d+)\z/
$o =~ /\A-(\d+)\z/ $o =~ /\A-n(\d+)\z/
Truth table33%1/3
A or B
A= $o =~ /\A-(\d+)\z/B= $o =~ /\A-n(\d+)\z/
ABresult
1X1
011
000
6715 1 ▶ elsif ( $o =~ /\A-([aFxwiR]+)\z/ ) { $a = 1 if $1 =~ /a/ }
Branch: 1 branch
BranchTrueFalseTotal
if $1 =~ /a/ 1 0 1
6716 0 elsif ( $o =~ /\A-/ ) { push @GAPS, join( ' ', 'last', @$av ); return ( '', 0 ) }
6717 3 else { push @who, $o }
6718 }
6719 6 my @r = _wtmp($dev);
6720 6 my $first = $r[-1][0];
6721 6 ▶ @r = grep { my $r = $_; grep { $r->[3] eq $_ || $r->[4] eq $_ } @who } @r if @who;
Branch: 1 branch
BranchTrueFalseTotal
if @who 3 3 6
Condition66%2/3
$$r[3] eq $_ || $$r[4] eq $_
l!l&&r!l&&!r
302
MC/DC50%1/2
$$r[3] eq $_ || $$r[4] eq $_
$$r[3] eq $_ $$r[4] eq $_
Truth table66%2/3
A || B
A= $$r[3] eq $_B= $$r[4] eq $_
ABresult
1X1
011
000
6722 6 ▶ @r = @r[ 0 .. $n - 1 ] if defined $n && $n =~ /\A\d+\z/ && @r > $n;
Branch: 1 branch
BranchTrueFalseTotal
if defined $n and $n =~ /\A\d+\z/ and @r > $n 0 6 6
Condition33%2/6
defined $n and $n =~ /\A\d+\z/ and @r > $n
!ll&&!rl&&r
600
defined $n and $n =~ /\A\d+\z/
!ll&&!rl&&r
600
MC/DC0%0/3
defined $n and $n =~ /\A\d+\z/ and @r > $n
defined $n $n =~ /\A\d+\z/ @r > $n
Truth table25%1/4
A and B and C
A= defined $nB= $n =~ /\A\d+\z/C= @r > $n
ABCresult
0XX0
10X0
1100
1111
6723 6 require POSIX;
6724 6 ▶ my @l = map { ( $a ? $_->[2] : $_->[1] ) =~ s/\s+\z//r } @r;
Branch: 1 branch
BranchTrueFalseTotal
$a ? : 2 6 8
6725 6 return ( join( "\n", @l, '', 'wtmp begins ' . POSIX::strftime( '%a %b %e %H:%M:%S %Y', _local_tm($first) ) ), 1 );
6726 }
6727  
6728 # lastlog [-u BENUTZER]: letzte Anmeldung je Konto (root und die Konten im Zustand)
6729 1 ▶sub _lastlog {
Subroutine _lastlog: called CC=16 SCAR=34.0
6730 1 my ( $dev, $av ) = @_;
6731 1 my @a = @$av;
6732 1 my $only;
6733 0 ▶ while (@a) { my $o = shift @a; if ( $o eq '-u' ) { $only = shift @a } elsif ( $o =~ /\A-/ ) { push @GAPS, join( ' ', 'lastlog', @$av ); return ( '', 0 ) } }
Branch: 3 branches
BranchTrueFalseTotal
if (@a) 0 1 1
if ($o eq '-u') { } 0 0 0
elsif ($o =~ /\A-/) { } 0 0 0
6734 1 my %last;
6735 1 ▶ for my $r ( reverse _wtmp($dev) ) { $last{ $r->[3] } = $r if $r->[3] ne 'reboot' }
Branch: 1 branch
BranchTrueFalseTotal
if $$r[3] ne "reboot" 1 1 2
6736 1 ▶ my %login = map { $_->{user} => $_ } grep { ref eq 'HASH' } @{ $dev->{logins} || [] };
Condition50%1/2
$$dev{'logins'} || []
l!l
10
MC/DC0%0/1
$$dev{'logins'} || []
$$dev{'logins'}
Truth table50%1/2
A
A= $$dev{'logins'}
Aresult
11
00
6737 1 require POSIX;
6738 1 my @l = ( sprintf '%-16s %-8s %-16s %s', 'Username', 'Port', 'From', 'Latest' );
6739 0 ▶ for my $u ( 'root', sort { ( $dev->{users}{$a}{uid} // 0 ) <=> ( $dev->{users}{$b}{uid} // 0 ) } keys %{ $dev->{users} || {} } ) {
Condition16%1/6
$$dev{"users"}{$a}{"uid"} // 0
l!l
00
$$dev{"users"}{$b}{"uid"} // 0
l!l
00
$$dev{'users'} || {}
l!l
10
MC/DC0%0/1
$$dev{"users"}{$a}{"uid"} // 0
$$dev{"users"}{$a}{"uid"}
MC/DC0%0/1
$$dev{"users"}{$b}{"uid"} // 0
$$dev{"users"}{$b}{"uid"}
MC/DC0%0/1
$$dev{'users'} || {}
$$dev{'users'}
Truth table0%0/2
A
A= $$dev{"users"}{$a}{"uid"}
Aresult
11
00
Truth table0%0/2
A
A= $$dev{"users"}{$b}{"uid"}
Aresult
11
00
Truth table50%1/2
A
A= $$dev{'users'}
Aresult
11
00
6740 2 ▶ next if defined $only && $u ne $only;
Branch: 1 branch
BranchTrueFalseTotal
if defined $only and $u ne $only 0 2 2
Condition33%1/3
defined $only and $u ne $only
!ll&&!rl&&r
200
MC/DC0%0/2
defined $only and $u ne $only
defined $only $u ne $only
Truth table33%1/3
A and B
A= defined $onlyB= $u ne $only
ABresult
0X0
100
111
6741 2 my $r = $last{$u};
6742 2 ▶ if ( !$r ) { push @l, sprintf '%-43s%s', $u, '**Never logged in**'; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 1 1 2
6743 1 my $lg = $login{$u};
6744 1 my $t = $r->[0];
6745 1 my $off = Langertha::Holmgang::Sim::Linux::Calendar::offset($t);
6746 1 ▶ push @l, sprintf '%-16s %-8s %-16s %s', $u, $lg->{tty} // 'pts/0', $lg->{from} // '',
Condition50%2/4
$$lg{"tty"} // "pts/0"
l!l
10
$$lg{"from"} // ""
l!l
10
MC/DC0%0/1
$$lg{"tty"} // "pts/0"
$$lg{"tty"}
MC/DC0%0/1
$$lg{"from"} // ""
$$lg{"from"}
Truth table50%1/2
A
A= $$lg{"tty"}
Aresult
11
00
Truth table50%1/2
A
A= $$lg{"from"}
Aresult
11
00
6747 POSIX::strftime( '%a %b %e %H:%M:%S', gmtime( $t + $off ) ) . sprintf( ' %+03d%02d %d', $off / 3600, 0, ( gmtime( $t + $off ) )[5] + 1900 );
6748 }
6749 1 return ( join( "\n", @l ), 1 );
6750 }
6751  
6752 # --- TCP zwischen Geraeten -------------------------------------------------------------
6753 # Wo laufende Dienste ohne listen im Zustand lauschen (Debian-Vorgaben nach exec bzw. Name);
6754 # Dienste, die nie lauschen. Ein anderer laufender Dienst macht die Ports des Geraets
6755 # unbekannt (dann ist eine geschlossene Antwort nicht sicher: Luecke).
6756 82 our %SVC_PORT = ( sshd => [22], postgres => [5432], 'redis-server' => [6379], mariadbd => [3306], mysqld => [3306],
6757 prometheus => [9090], alertmanager => [9093], 'prometheus-node-exporter' => [9100], node_exporter => [9100],
6758 named => [53], dnsmasq => [53], 'systemd-resolved' => [], unbound => [53], postfix => [25], master => [25],
6759 dovecot => [ 143, 993 ], 'grafana-server' => [3000], apache2 => [80], gunicorn => [8000] );
6760 82 our %NO_LISTEN = map { $_ => 1 } qw( cron rsyslogd rsyslog systemd-journald nftables chronyd chrony unattended-upgrades
6761 systemd-timesyncd systemd-networkd networking auditd logrotate e2scrub_all fstrim apt-daily wg-quick smartd mdmonitor );
6762  
6763 # Lauscher eines Geraets auf PORT: ( [ adresse, … ], vollstaendig? )
6764 15 ▶sub _listeners {
Subroutine _listeners: called CC=29 SCAR=39.9
6765 15 my ( $dev, $port ) = @_;
6766 15 my @addr;
6767 15 for my $line ( split /\n/, ( _ss( $dev, [] ) )[0] ) {
6768 47 ▶ my ($a) = $line =~ /\A\S+\s+LISTEN\s+\S+\s+\S+\s+(\S+):\Q$port\E\s/ or next;
Branch: 1 branch
BranchTrueFalseTotal
my($a) = $line =~ /\A\S+\s+LISTEN\s+\S+\s+\S+\s+(\S+):\Q$port\E\s/ or next 10 37 47
6769 10 push @addr, $a;
6770 }
6771 15 my $complete = 1;
6772 15 ▶ my $s = $dev->{services} || {};
Condition50%1/2
$$dev{'services'} || {}
l!l
150
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
6773 15 for my $n ( sort keys %$s ) {
6774 27 my $v = $s->{$n};
6775 27 ▶ next unless ref $v eq 'HASH' && $v->{active} && $n !~ /\.(?:timer|socket|target|mount|path)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v eq "HASH" and $$v{"active"} and not $n =~ /\.(?:timer|socket|target|mount|path)\z/ 0 27 27
Condition33%2/6
ref $v eq "HASH" and $$v{"active"} and not $n =~ /\.(?:timer|socket|target|mount|path)\z/
!ll&&!rl&&r
0027
ref $v eq "HASH" and $$v{"active"}
!ll&&!rl&&r
0027
MC/DC0%0/3
ref $v eq "HASH" and $$v{"active"} and not $n =~ /\.(?:timer|socket|target|mount|path)\z/
ref $v eq "HASH" $$v{"active"} not $n =~ /\.(?:timer|socket|target|mount|path)\z/
Truth table25%1/4
A and B and not(C)
A= ref $v eq "HASH"B= $$v{"active"}C= not $n =~ /\.(?:timer|socket|target|mount|path)\z/
ABCresult
0XX0
10X0
1100
1111
6776 27 ▶ next if $v->{listen} || ( $v->{exec} // $n ) eq 'nginx' || $n eq 'ssh';
Branch: 1 branch
BranchTrueFalseTotal
if $$v{"listen"} or ($$v{"exec"} // $n) eq "nginx" or $n eq "ssh" 18 9 27
Condition77%7/9
$$v{"listen"} or ($$v{"exec"} // $n) eq "nginx" or $n eq "ssh"
l!l&&r!l&&!r
4149
$$v{"listen"} or ($$v{"exec"} // $n) eq "nginx"
l!l&&r!l&&!r
4023
$$v{"exec"} // $n
l!l&&r!l&&!r
2210
MC/DC0%0/4
$$v{"listen"} or ($$v{"exec"} // $n) eq "nginx" or $n eq "ssh"
$$v{"listen"} $$v{"exec"} $n $n eq "ssh"
Truth table20%1/5
A or B // C or D
A= $$v{"listen"}B= $$v{"exec"}C= $nD= $n eq "ssh"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
6777 9 ▶ next if defined $v->{run} || $NO_LISTEN{ $v->{exec} // $n } || $NO_LISTEN{$n};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$v{"run"} or $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$$v{"exec"} // $n} or $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$n} 0 9 9
Condition44%4/9
defined $$v{"run"} or $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$$v{"exec"} // $n} or $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$n}
l!l&&r!l&&!r
009
defined $$v{"run"} or $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$$v{"exec"} // $n}
l!l&&r!l&&!r
009
$$v{"exec"} // $n
l!l&&r!l&&!r
810
MC/DC0%0/3
defined $$v{"run"} or $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$$v{"exec"} // $n} or $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$n}
defined $$v{"run"} $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$$v{"exec"} // $n} $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$n}
MC/DC0%0/2
$$v{"exec"} // $n
$$v{"exec"} $n
Truth table25%1/4
A or B or C
A= defined $$v{"run"}B= $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$$v{"exec"} // $n}C= $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$n}
ABCresult
1XX1
01X1
0011
0000
Truth table66%2/3
A // B
A= $$v{"exec"}B= $n
ABresult
1X1
011
000
6778 9 ▶ next if $n eq ( ( $dev->{redis} || {} )->{service} // 'redis-server' ) && $dev->{redis};
Branch: 1 branch
BranchTrueFalseTotal
if $n eq (($$dev{"redis"} || {})->{"service"} // "redis-server") and $$dev{"redis"} 0 9 9
Condition42%3/7
$n eq (($$dev{"redis"} || {})->{"service"} // "redis-server") and $$dev{"redis"}
!ll&&!rl&&r
900
($$dev{"redis"} || {})->{"service"} // "redis-server"
l!l
09
$$dev{'redis'} || {}
l!l
09
MC/DC0%0/2
$n eq (($$dev{"redis"} || {})->{"service"} // "redis-server") and $$dev{"redis"}
$n eq (($$dev{"redis"} || {})->{"service"} // "redis-server") $$dev{"redis"}
MC/DC0%0/1
($$dev{"redis"} || {})->{"service"} // "redis-server"
$$dev{'redis'}
Truth table33%1/3
A and B
A= $n eq (($$dev{"redis"} || {})->{"service"} // "redis-server")B= $$dev{"redis"}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$dev{'redis'}
Aresult
11
00
6779 9 ▶ next if $n eq ( ( $dev->{mariadb} || {} )->{service} // 'mariadb' ) && $dev->{mariadb};
Branch: 1 branch
BranchTrueFalseTotal
if $n eq (($$dev{"mariadb"} || {})->{"service"} // "mariadb") and $$dev{"mariadb"} 0 9 9
Condition42%3/7
$n eq (($$dev{"mariadb"} || {})->{"service"} // "mariadb") and $$dev{"mariadb"}
!ll&&!rl&&r
900
($$dev{"mariadb"} || {})->{"service"} // "mariadb"
l!l
09
$$dev{'mariadb'} || {}
l!l
09
MC/DC0%0/2
$n eq (($$dev{"mariadb"} || {})->{"service"} // "mariadb") and $$dev{"mariadb"}
$n eq (($$dev{"mariadb"} || {})->{"service"} // "mariadb") $$dev{"mariadb"}
MC/DC0%0/1
($$dev{"mariadb"} || {})->{"service"} // "mariadb"
$$dev{'mariadb'}
Truth table33%1/3
A and B
A= $n eq (($$dev{"mariadb"} || {})->{"service"} // "mariadb")B= $$dev{"mariadb"}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$dev{'mariadb'}
Aresult
11
00
6780 9 ▶ my $ports = $SVC_PORT{ ( split ' ', $v->{exec} // '' )[0] // '' } // $SVC_PORT{$n};
Condition85%6/7
$Langertha::Holmgang::Sim::Linux::SVC_PORT{(split(' ', $$v{"exec"} // "", 0))[0] // ""} // $Langertha::Holmgang::Sim::Linux::SVC_PORT{$n}
l!l&&r!l&&!r
405
(split(' ', $$v{"exec"} // "", 0))[0] // ""
l!l
81
$$v{"exec"} // ""
l!l
81
MC/DC50%1/2
$Langertha::Holmgang::Sim::Linux::SVC_PORT{(split(' ', $$v{"exec"} // "", 0))[0] // ""} // $Langertha::Holmgang::Sim::Linux::SVC_PORT{$n}
$Langertha::Holmgang::Sim::Linux::SVC_PORT{(split(' ', $$v{"exec"} // "", 0))[0] // ""} $Langertha::Holmgang::Sim::Linux::SVC_PORT{$n}
MC/DC100%1/1
(split(' ', $$v{"exec"} // "", 0))[0] // ""
(split(' ', $$v{"exec"} // "", 0))[0]
MC/DC100%1/1
$$v{"exec"} // ""
$$v{"exec"}
Truth table66%2/3
A // B
A= $Langertha::Holmgang::Sim::Linux::SVC_PORT{(split(' ', $$v{"exec"} // "", 0))[0] // ""}B= $Langertha::Holmgang::Sim::Linux::SVC_PORT{$n}
ABresult
1X1
011
000
Truth table100%2/2
A
A= (split(' ', $$v{"exec"} // "", 0))[0]
Aresult
11
00
Truth table100%2/2
A
A= $$v{"exec"}
Aresult
11
00
6781 9 ▶ if ( !$ports ) { $complete = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ports) 5 4 9
6782 4 ▶ push @addr, '0.0.0.0' if grep { $_ == $port } @$ports;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == $port;} @$ports 0 4 4
6783 }
6784 15 return ( \@addr, $complete );
6785 }
6786  
6787 # Urteil der Firewall (nft, Ketten mit hook input) fuer ein neues TCP-Paket von $src an
6788 # $dst:$port ueber $iif: 'accept', 'drop', 'reject' oder undef (Regel nicht nachgebildet)
6789 16 ▶sub _nft_verdict {
Subroutine _nft_verdict: called CC=16 SCAR=36.3
6790 16 my ( $dev, $src, $dst, $port, $iif ) = @_;
6791 16 ▶ my $T = ref $dev->{nft} eq 'HASH' ? $dev->{nft} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'nft'} eq 'HASH' ? : 7 9 16
6792 16 my @chains;
6793 16 for my $tn ( sort keys %$T ) {
6794 7 ▶ next unless $tn =~ /\A(?:inet|ip) /;
Branch: 1 branch
BranchTrueFalseTotal
unless $tn =~ /\A(?:inet|ip) / 0 7 7
6795 7 ▶ for my $cn ( sort keys %{ $T->{$tn}{chains} || {} } ) {
Condition50%1/2
$$T{$tn}{'chains'} || {}
l!l
70
MC/DC0%0/1
$$T{$tn}{'chains'} || {}
$$T{$tn}{'chains'}
Truth table50%1/2
A
A= $$T{$tn}{'chains'}
Aresult
11
00
6796 7 my $c = $T->{$tn}{chains}{$cn};
6797 7 ▶ push @chains, [ $tn, $c ] if ( $c->{hook} // '' ) eq 'input';
Branch: 1 branch
BranchTrueFalseTotal
if ($$c{"hook"} // "") eq "input" 7 0 7
Condition50%1/2
$$c{"hook"} // ""
l!l
70
MC/DC0%0/1
$$c{"hook"} // ""
$$c{"hook"}
Truth table50%1/2
A
A= $$c{"hook"}
Aresult
11
00
6798 }
6799 }
6800 30 ▶ my $inset = sub { # Wert gegen "X", "{ a, b }", "a-b", "!= X"
Subroutine __ANON__: called CC=13 SCAR=29.0
6801 30 my ( $spec, $v, $kind ) = @_;
6802 30 ▶ my @alt = $spec =~ /\A\{\s*(.*?)\s*\}\z/ ? split( /\s*,\s*/, $1 ) : ($spec);
Branch: 1 branch
BranchTrueFalseTotal
$spec =~ /\A\{\s*(.*?)\s*\}\z/ ? : 4 26 30
6803 30 for my $a (@alt) {
6804 34 $a =~ s/\A"|"\z//g;
6805 34 ▶ if ( $kind eq 'ip' ) { return 1 if $a =~ m{/} ? _in( $v, $a ) : $a eq $v }
Branch: 4 branches
BranchTrueFalseTotal
if ($kind eq 'ip') { } 7 27 34
elsif ($kind eq 'port') { } 20 7 27
if $a =~ m[/] ? _in($v, $a) : $a eq $v 7 0 7
$a =~ m[/] ? : 0 7 7
6806 20 ▶ elsif ( $kind eq 'port' ) { return 1 if $a =~ /\A(\d+)-(\d+)\z/ ? $v >= $1 && $v <= $2 : $a =~ /\A\d+\z/ ? $a == $v : ( { ssh => 22, http => 80, https => 443 }->{$a} // -1 ) == $v }
Branch: 3 branches
BranchTrueFalseTotal
if $a =~ /\A(\d+)-(\d+)\z/ ? $v >= $1 && $v <= $2 : ($a =~ /\A\d+\z/ ? $a == $v : ({"ssh", 22, "http", 80, "https", 443}->{$a} // -1) == $v) 4 16 20
$a =~ /\A(\d+)-(\d+)\z/ ? : 0 20 20
$a =~ /\A\d+\z/ ? : 20 0 20
Condition0%0/5
$v >= $1 and $v <= $2
!ll&&!rl&&r
000
{"ssh", 22, "http", 80, "https", 443}->{$a} // -1
l!l
00
MC/DC0%0/2
$v >= $1 and $v <= $2
$v >= $1 $v <= $2
MC/DC0%0/1
{"ssh", 22, "http", 80, "https", 443}->{$a} // -1
{"ssh", 22, "http", 80, "https", 443}->{$a}
Truth table0%0/3
A and B
A= $v >= $1B= $v <= $2
ABresult
0X0
100
111
Truth table0%0/2
A
A= {"ssh", 22, "http", 80, "https", 443}->{$a}
Aresult
11
00
6807 7 ▶ else { return 1 if $a eq $v }
Branch: 1 branch
BranchTrueFalseTotal
if $a eq $v 0 7 7
6808 }
6809 19 return 0;
6810 16 };
6811 16 my $rule;
6812 7 ▶ $rule = sub {
Subroutine __ANON__: called CC=67 SCAR=63.3
6813 7 my ( $tn, $c, $depth ) = @_;
6814 7 ▶ return undef if $depth > 5;
Branch: 1 branch
BranchTrueFalseTotal
if $depth > 5 0 7 7
6815 7 ▶ RULE: for my $r ( @{ $c->{rules} || [] } ) {
Condition50%1/2
$$c{'rules'} || []
l!l
70
MC/DC0%0/1
$$c{'rules'} || []
$$c{'rules'}
Truth table50%1/2
A
A= $$c{'rules'}
Aresult
11
00
6816 33 ▶ my $t = ref $r eq 'HASH' ? $r->{rule} // '' : $r;
Branch: 1 branch
BranchTrueFalseTotal
ref $r eq 'HASH' ? : 0 33 33
Condition0%0/2
$$r{"rule"} // ""
l!l
00
MC/DC0%0/1
$$r{"rule"} // ""
$$r{"rule"}
Truth table0%0/2
A
A= $$r{"rule"}
Aresult
11
00
6817 33 $t =~ s/\s+comment\s+"[^"]*"//g;
6818 33 $t =~ s/\blog(?:\s+(?:prefix\s+"[^"]*"|level\s+\S+|flags\s+\S+))*//g;
6819 33 $t =~ s/\bcounter(?:\s+packets\s+\d+\s+bytes\s+\d+)?//g;
6820 33 $t =~ s/\blimit rate\s+\S+(?:\s+burst\s+\d+\s+packets)?//g; # Grenze: ein einzelnes Paket liegt darunter
6821 33 my @w = $t =~ /(\{[^}]*\}|"[^"]*"|\S+)/g;
6822 33 my $verdict;
6823 33 ▶ while (@w) {
Branch: 1 branch
BranchTrueFalseTotal
if (@w) 44 0 44
6824 44 my $x = shift @w;
6825 44 ▶ if ( $x eq 'ct' && ( $w[0] // '' ) eq 'state' ) { shift @w; my $neg = ( $w[0] // '' ) eq '!=' ? shift @w : 0; my $s = shift(@w) // '';
Branch: 2 branches
BranchTrueFalseTotal
if ($x eq "ct" and ($w[0] // "") eq "state") 7 37 44
($w[0] // '') eq '!=' ? : 0 7 7
Condition55%5/9
$x eq "ct" and ($w[0] // "") eq "state"
!ll&&!rl&&r
3707
$w[0] // ""
l!l
70
$w[0] // ""
l!l
70
shift @w // ""
l!l
70
MC/DC50%1/2
$x eq "ct" and ($w[0] // "") eq "state"
$x eq "ct" $w[0]
MC/DC0%0/1
shift @w // ""
shift @w
Truth table66%2/3
A and B
A= $x eq "ct"B= $w[0]
ABresult
0X0
100
111
Truth table50%1/2
A
A= shift @w
Aresult
11
00
6826 0 ▶ my $m = grep { $_ eq 'new' } map { s/[{}\s]//gr } split /,/, $s =~ s/\A\{|\}\z//gr; next RULE if $neg ? $m : !$m; next }
Branch: 2 branches
BranchTrueFalseTotal
if $neg ? $m : !$m 7 0 7
$neg ? : 0 7 7
6827 0 ▶ if ( $x eq 'iif' || $x eq 'iifname' ) { my $neg = ( $w[0] // '' ) eq '!=' ? shift @w : 0; my $m = $inset->( shift(@w) // '', $iif, 's' ); next RULE if $neg ? $m : !$m; next }
Branch: 4 branches
BranchTrueFalseTotal
if ($x eq "iif" or $x eq "iifname") 7 30 37
($w[0] // '') eq '!=' ? : 0 7 7
if $neg ? $m : !$m 7 0 7
$neg ? : 0 7 7
Condition57%4/7
$x eq "iif" or $x eq "iifname"
l!l&&r!l&&!r
7030
$w[0] // ""
l!l
70
shift @w // ""
l!l
70
MC/DC50%1/2
$x eq "iif" or $x eq "iifname"
$x eq "iif" $x eq "iifname"
MC/DC0%0/1
$w[0] // ""
$w[0]
MC/DC0%0/1
shift @w // ""
shift @w
Truth table66%2/3
A or B
A= $x eq "iif"B= $x eq "iifname"
ABresult
1X1
011
000
Truth table50%1/2
A
A= $w[0]
Aresult
11
00
Truth table50%1/2
A
A= shift @w
Aresult
11
00
6828 30 ▶ if ( $x eq 'ip' && ( $w[0] // '' ) =~ /\A[sd]addr\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "ip" and ($w[0] // "") =~ /\A[sd]addr\z/) 7 23 30
Condition60%3/5
$x eq "ip" and ($w[0] // "") =~ /\A[sd]addr\z/
!ll&&!rl&&r
2307
$w[0] // ""
l!l
70
MC/DC50%1/2
$x eq "ip" and ($w[0] // "") =~ /\A[sd]addr\z/
$x eq "ip" $w[0]
Truth table66%2/3
A and B
A= $x eq "ip"B= $w[0]
ABresult
0X0
100
111
6829 7 my $which = shift @w;
6830 7 ▶ my $neg = ( $w[0] // '' ) eq '!=' ? shift @w : 0;
Branch: 1 branch
BranchTrueFalseTotal
($w[0] // '') eq '!=' ? : 0 7 7
Condition50%1/2
$w[0] // ""
l!l
70
MC/DC0%0/1
$w[0] // ""
$w[0]
Truth table50%1/2
A
A= $w[0]
Aresult
11
00
6831 7 ▶ my $m = $inset->( shift(@w) // '', $which eq 'saddr' ? $src : $dst, 'ip' );
Branch: 1 branch
BranchTrueFalseTotal
$which eq 'saddr' ? : 7 0 7
Condition50%1/2
shift @w // ""
l!l
70
MC/DC0%0/1
shift @w // ""
shift @w
Truth table50%1/2
A
A= shift @w
Aresult
11
00
6832 7 ▶ next RULE if $neg ? $m : !$m;
Branch: 2 branches
BranchTrueFalseTotal
if $neg ? $m : !$m 0 7 7
$neg ? : 0 7 7
6833 7 next;
6834 }
6835 23 ▶ if ( ( $x eq 'tcp' || $x eq 'th' ) && ( $w[0] // '' ) =~ /\A[sd]port\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "tcp" || $x eq "th" and ($w[0] // "") =~ /\A[sd]port\z/) 16 7 23
Condition62%5/8
$x eq "tcp" || $x eq "th" and ($w[0] // "") =~ /\A[sd]port\z/
!ll&&!rl&&r
7016
$x eq "tcp" or $x eq "th"
l!l&&r!l&&!r
1607
$w[0] // ""
l!l
160
MC/DC33%1/3
$x eq "tcp" || $x eq "th" and ($w[0] // "") =~ /\A[sd]port\z/
$x eq "tcp" $x eq "th" $w[0]
Truth table40%2/5
A or B and C
A= $x eq "tcp"B= $x eq "th"C= $w[0]
ABCresult
00X0
1X00
0100
1X11
0111
6836 16 my $which = shift @w;
6837 16 ▶ my $neg = ( $w[0] // '' ) eq '!=' ? shift @w : 0;
Branch: 1 branch
BranchTrueFalseTotal
($w[0] // '') eq '!=' ? : 0 16 16
Condition50%1/2
$w[0] // ""
l!l
160
MC/DC0%0/1
$w[0] // ""
$w[0]
Truth table50%1/2
A
A= $w[0]
Aresult
11
00
6838 16 ▶ my $spec = shift(@w) // '';
Condition50%1/2
shift @w // ""
l!l
160
MC/DC0%0/1
shift @w // ""
shift @w
Truth table50%1/2
A
A= shift @w
Aresult
11
00
6839 16 ▶ my $m = $which eq 'dport' ? $inset->( $spec, $port, 'port' ) : 1; # sport: ein beliebiger hoher Port
Branch: 1 branch
BranchTrueFalseTotal
$which eq 'dport' ? : 16 0 16
6840 16 ▶ next RULE if $neg ? $m : !$m;
Branch: 2 branches
BranchTrueFalseTotal
if $neg ? $m : !$m 12 4 16
$neg ? : 0 16 16
6841 4 next;
6842 }
6843 0 ▶ if ( $x eq 'udp' || $x eq 'icmp' || $x eq 'icmpv6' || $x eq 'ip6' ) { next RULE } # passt nie auf TCP/IPv4
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "udp" or $x eq "icmp" or $x eq "icmpv6" or $x eq "ip6") 0 7 7
Condition33%3/9
$x eq "udp" or $x eq "icmp" or $x eq "icmpv6" or $x eq "ip6"
l!l&&r!l&&!r
007
$x eq "udp" or $x eq "icmp" or $x eq "icmpv6"
l!l&&r!l&&!r
007
$x eq "udp" or $x eq "icmp"
l!l&&r!l&&!r
007
MC/DC0%0/4
$x eq "udp" or $x eq "icmp" or $x eq "icmpv6" or $x eq "ip6"
$x eq "udp" $x eq "icmp" $x eq "icmpv6" $x eq "ip6"
Truth table20%1/5
A or B or C or D
A= $x eq "udp"B= $x eq "icmp"C= $x eq "icmpv6"D= $x eq "ip6"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
6844 0 ▶ if ( $x eq 'meta' && ( $w[0] // '' ) eq 'l4proto' ) { shift @w; my $m = $inset->( shift(@w) // '', 'tcp', 's' ); next RULE unless $m; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($x eq "meta" and ($w[0] // "") eq "l4proto") 0 7 7
unless $m 0 0 0
Condition14%1/7
$x eq "meta" and ($w[0] // "") eq "l4proto"
!ll&&!rl&&r
700
$w[0] // ""
l!l
00
shift @w // ""
l!l
00
MC/DC0%0/2
$x eq "meta" and ($w[0] // "") eq "l4proto"
$x eq "meta" $w[0]
MC/DC0%0/1
shift @w // ""
shift @w
Truth table33%1/3
A and B
A= $x eq "meta"B= $w[0]
ABresult
0X0
100
111
Truth table0%0/2
A
A= shift @w
Aresult
11
00
6845 0 ▶ if ( $x eq 'ip' && ( $w[0] // '' ) eq 'protocol' ) { shift @w; my $m = $inset->( shift(@w) // '', 'tcp', 's' ); next RULE unless $m; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($x eq "ip" and ($w[0] // "") eq "protocol") 0 7 7
unless $m 0 0 0
Condition14%1/7
$x eq "ip" and ($w[0] // "") eq "protocol"
!ll&&!rl&&r
700
$w[0] // ""
l!l
00
shift @w // ""
l!l
00
MC/DC0%0/2
$x eq "ip" and ($w[0] // "") eq "protocol"
$x eq "ip" $w[0]
MC/DC0%0/1
shift @w // ""
shift @w
Truth table33%1/3
A and B
A= $x eq "ip"B= $w[0]
ABresult
0X0
100
111
Truth table0%0/2
A
A= shift @w
Aresult
11
00
6846 7 ▶ if ( $x eq 'accept' || $x eq 'drop' ) { $verdict = $x; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "accept" or $x eq "drop") 6 1 7
Condition100%3/3
$x eq "accept" or $x eq "drop"
l!l&&r!l&&!r
331
MC/DC100%2/2
$x eq "accept" or $x eq "drop"
$x eq "accept" $x eq "drop"
Truth table100%3/3
A or B
A= $x eq "accept"B= $x eq "drop"
ABresult
1X1
011
000
6847 1 ▶ if ( $x eq 'reject' ) { $verdict = 'reject'; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "reject") 1 0 1
6848 0 ▶ if ( $x eq 'return' ) { return 'return' }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "return") 0 0 0
6849 0 ▶ if ( ( $x eq 'jump' || $x eq 'goto' ) && @w ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "jump" || $x eq "goto" and @w) 0 0 0
Condition0%0/6
$x eq "jump" || $x eq "goto" and @w
!ll&&!rl&&r
000
$x eq "jump" or $x eq "goto"
l!l&&r!l&&!r
000
MC/DC0%0/3
$x eq "jump" || $x eq "goto" and @w
$x eq "jump" $x eq "goto" @w
Truth table0%0/5
A or B and C
A= $x eq "jump"B= $x eq "goto"C= @w
ABCresult
00X0
1X00
0100
1X11
0111
6850 0 ▶ my $sub = $T->{$tn}{chains}{ shift @w } or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $$T{$tn}{"chains"}{shift @w} or return undef 0 0 0
6851 0 my $v = $rule->( $tn, $sub, $depth + 1 );
6852 0 ▶ return undef unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6853 0 ▶ next RULE if $v eq 'return' || $v eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "return" or $v eq "none" 0 0 0
Condition0%0/3
$v eq "return" or $v eq "none"
l!l&&r!l&&!r
000
MC/DC0%0/2
$v eq "return" or $v eq "none"
$v eq "return" $v eq "none"
Truth table0%0/3
A or B
A= $v eq "return"B= $v eq "none"
ABresult
1X1
011
000
6854 0 return $v;
6855 }
6856 0 return undef; # anderes: nicht nachgebildet
6857 }
6858 7 ▶ return $verdict if $verdict;
Branch: 1 branch
BranchTrueFalseTotal
if $verdict 7 0 7
6859 }
6860 0 return 'none';
6861 16 };
6862 0 ▶ for my $ch ( sort { ( $a->[1]{priority} // 0 ) <=> ( $b->[1]{priority} // 0 ) } @chains ) {
Condition0%0/4
$$a[1]{"priority"} // 0
l!l
00
$$b[1]{"priority"} // 0
l!l
00
MC/DC0%0/1
$$a[1]{"priority"} // 0
$$a[1]{"priority"}
MC/DC0%0/1
$$b[1]{"priority"} // 0
$$b[1]{"priority"}
Truth table0%0/2
A
A= $$a[1]{"priority"}
Aresult
11
00
Truth table0%0/2
A
A= $$b[1]{"priority"}
Aresult
11
00
6863 7 my $v = $rule->( $ch->[0], $ch->[1], 0 );
6864 7 ▶ return undef unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 7 7
6865 7 ▶ $v = $ch->[1]{policy} // 'accept' if $v eq 'none' || $v eq 'return';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "none" or $v eq "return" 0 7 7
Condition20%1/5
$v eq "none" or $v eq "return"
l!l&&r!l&&!r
007
$$ch[1]{"policy"} // "accept"
l!l
00
MC/DC0%0/2
$v eq "none" or $v eq "return"
$v eq "none" $v eq "return"
MC/DC0%0/1
$$ch[1]{"policy"} // "accept"
$$ch[1]{"policy"}
Truth table33%1/3
A or B
A= $v eq "none"B= $v eq "return"
ABresult
1X1
011
000
Truth table0%0/2
A
A= $$ch[1]{"policy"}
Aresult
11
00
6866 7 ▶ return $v unless $v eq 'accept';
Branch: 1 branch
BranchTrueFalseTotal
unless $v eq "accept" 4 3 7
6867 }
6868 12 return 'accept';
6869 }
6870  
6871 # Neue TCP-Verbindung von diesem Geraet zu HOST:PORT (beide im Zustand): 'open', 'refused',
6872 # 'timeout', 'unreach' oder undef (Ziel oder Regel nicht nachgebildet)
6873 26 ▶sub _tcp_probe {
Subroutine _tcp_probe: called CC=37 SCAR=42.9
6874 26 my ( $dev, $host, $port ) = @_;
6875 26 ▶ my $state = $CTX ? $CTX->{state} || {} : {};
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 26 0 26
Condition50%1/2
$$Langertha::Holmgang::Sim::Linux::CTX{"state"} or {}
l!l
260
MC/DC0%0/1
$$Langertha::Holmgang::Sim::Linux::CTX{"state"} or {}
$$Langertha::Holmgang::Sim::Linux::CTX{"state"}
Truth table50%1/2
A
A= $$Langertha::Holmgang::Sim::Linux::CTX{"state"}
Aresult
11
00
6876 26 my @own = _own_addrs($dev);
6877 26 ▶ if ( $host =~ /\A(?:localhost|127\.\d+\.\d+\.\d+)\z/ || grep { $_ eq $host } @own, $dev->{hostname} // (), ( $CTX || {} )->{host} // () ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /\A(?:localhost|127\.\d+\.\d+\.\d+)\z/ or grep {$_ eq $host;} @own, $$dev{"hostname"} // (), ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"} // ()) 3 23 26
Condition54%6/11
$host =~ /\A(?:localhost|127\.\d+\.\d+\.\d+)\z/ or grep {$_ eq $host;} @own, $$dev{"hostname"} // (), ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"} // ()
l!l&&r!l&&!r
3023
$$dev{"hostname"} // ()
l!l&&r!l&&!r
0212
($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"} // ()
l!l&&r!l&&!r
2300
$Langertha::Holmgang::Sim::Linux::CTX || {}
l!l
230
MC/DC50%1/2
$host =~ /\A(?:localhost|127\.\d+\.\d+\.\d+)\z/ or grep {$_ eq $host;} @own, $$dev{"hostname"} // (), ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"} // ()
$host =~ /\A(?:localhost|127\.\d+\.\d+\.\d+)\z/ grep {$_ eq $host;} @own, $$dev{"hostname"} // (), ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"} // ()
MC/DC50%1/2
$$dev{"hostname"} // ()
$$dev{"hostname"} ()
MC/DC0%0/2
($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"} // ()
$Langertha::Holmgang::Sim::Linux::CTX ()
Truth table66%2/3
A or B
A= $host =~ /\A(?:localhost|127\.\d+\.\d+\.\d+)\z/B= grep {$_ eq $host;} @own, $$dev{"hostname"} // (), ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"} // ()
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $$dev{"hostname"}B= ()
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $Langertha::Holmgang::Sim::Linux::CTXB= ()
ABresult
1X1
011
000
6878 3 my ( $addr, $complete ) = _listeners( $dev, $port );
6879 3 ▶ my $ip = _ip2n($host) ? $host : '127.0.0.1';
Branch: 1 branch
BranchTrueFalseTotal
_ip2n($host) ? : 3 0 3
6880 3 ▶ return 'open' if grep { $_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ || $_ eq $ip || ( $ip =~ /\A127\./ && $_ =~ /\A127\./ ) } @$addr;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ or $_ eq $ip or $ip =~ /\A127\./ and $_ =~ /\A127\./;} @$addr 2 1 3
Condition33%3/9
$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ || $_ eq $ip || $ip =~ /\A127\./ && $_ =~ /\A127\./
l!l&&r!l&&!r
300
$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ or $_ eq $ip
l!l&&r!l&&!r
210
$ip =~ /\A127\./ and $_ =~ /\A127\./
!ll&&!rl&&r
000
MC/DC0%0/4
$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ || $_ eq $ip || $ip =~ /\A127\./ && $_ =~ /\A127\./
$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ $_ eq $ip $ip =~ /\A127\./ $_ =~ /\A127\./
Truth table40%2/5
A or B || C and D
A= $_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/B= $_ eq $ipC= $ip =~ /\A127\./D= $_ =~ /\A127\./
ABCDresult
1XXX1
01XX1
00111
000X0
00100
6881 1 ▶ return $complete ? 'refused' : undef;
Branch: 1 branch
BranchTrueFalseTotal
$complete ? : 0 1 1
6882 }
6883 23 ▶ my $find = sub {
Subroutine __ANON__: called CC=8 SCAR=23.1
6884 23 my ($h) = @_;
6885 16 ▶ my ($t) = grep { ref $_ eq 'HASH' && ( $_->{type} // '' ) eq 'linux' && $_ != $dev }
Branch: 1 branch
BranchTrueFalseTotal
ref $$state{$h} eq 'HASH' ? : 1 22 23
Condition37%3/8
ref $_ eq 'HASH' && ($$_{'type'} // '') eq 'linux' && $_ != $dev
!ll&&!rl&&r
0016
ref $_ eq "HASH" and ($$_{"type"} // "") eq "linux"
!ll&&!rl&&r
0016
$$_{"type"} // ""
l!l
160
MC/DC0%0/3
ref $_ eq 'HASH' && ($$_{'type'} // '') eq 'linux' && $_ != $dev
ref $_ eq "HASH" $$_{"type"} $_ != $dev
Truth table25%1/4
A and B && C
A= ref $_ eq "HASH"B= $$_{"type"}C= $_ != $dev
ABCresult
0XX0
10X0
1100
1111
6886 ( ref $state->{$h} eq 'HASH' ? $state->{$h} : () ),
6887 23 ▶ map { $state->{$_} } grep { ref $state->{$_} eq 'HASH' && ( ( $state->{$_}{hostname} // '' ) eq $h || grep { $_ eq $h } _own_addrs( $state->{$_} ) ) } sort keys %$state;
Condition62%5/8
ref $$state{$_} eq 'HASH' && (($$state{$_}{'hostname'} // '') eq $h || grep({$_ eq $h;} _own_addrs($$state{$_})))
!ll&&!rl&&r
06415
($$state{$_}{"hostname"} // "") eq $h or grep {$_ eq $h;} _own_addrs($$state{$_})
l!l&&r!l&&!r
01564
$$state{$_}{"hostname"} // ""
l!l
079
MC/DC33%1/3
ref $$state{$_} eq 'HASH' && (($$state{$_}{'hostname'} // '') eq $h || grep({$_ eq $h;} _own_addrs($$state{$_})))
ref $$state{$_} eq 'HASH' $$state{$_}{"hostname"} grep {$_ eq $h;} _own_addrs($$state{$_})
Truth table50%2/4
A && B or C
A= ref $$state{$_} eq 'HASH'B= $$state{$_}{"hostname"}C= grep {$_ eq $h;} _own_addrs($$state{$_})
ABCresult
0XX0
1000
11X1
1011
6888 23 return $t;
6889 23 };
6890 23 my $tgt = $find->($host);
6891 23 my $ip;
6892 23 ▶ if ( !$tgt && !_ip2n($host) ) { # Name: wie getent hosts (/etc/hosts, Nameserver); unbekannt: nicht aufloesbar
Branch: 1 branch
BranchTrueFalseTotal
unless ($tgt or _ip2n($host)) 3 20 23
Condition100%3/3
$tgt or _ip2n($host)
l!l&&r!l&&!r
1643
MC/DC100%2/2
$tgt or _ip2n($host)
$tgt _ip2n($host)
Truth table100%3/3
A or B
A= $tgtB= _ip2n($host)
ABresult
1X1
011
000
6893 3 my ($r) = _resolve( $dev, $host );
6894 3 ▶ return 'noname' unless defined $r;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r 3 0 3
6895 0 ▶ $tgt = $find->($r) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$tgt = &$find($r) or return undef 0 0 0
6896 0 $ip = $r;
6897 }
6898 20 ▶ return undef unless $tgt;
Branch: 1 branch
BranchTrueFalseTotal
unless $tgt 4 16 20
6899 16 ▶ $ip //= _ip2n($host) ? $host : ( _own_addrs($tgt) )[0] // return undef;
Branch: 1 branch
BranchTrueFalseTotal
_ip2n($host) ? : 15 1 16
Condition40%2/5
$ip //= _ip2n($host) ? $host : (_own_addrs($tgt))[0] // (return undef)
l!l&&r!l&&!r
0160
(_own_addrs($tgt))[0] // (return undef)
l!l
10
MC/DC0%0/2
$ip //= _ip2n($host) ? $host : (_own_addrs($tgt))[0] // (return undef)
$ip _ip2n($host) ? $host : (_own_addrs($tgt))[0] // (return undef)
MC/DC0%0/1
(_own_addrs($tgt))[0] // (return undef)
(_own_addrs($tgt))[0]
Truth table33%1/3
A //= B
A= $ipB= _ip2n($host) ? $host : (_own_addrs($tgt))[0] // (return undef)
ABresult
1X1
011
000
Truth table50%1/2
A
A= (_own_addrs($tgt))[0]
Aresult
11
00
6900 16 ▶ return 'unreach' unless _lookup( $dev, $ip );
Branch: 1 branch
BranchTrueFalseTotal
unless _lookup($dev, $ip) 0 16 16
6901 16 ▶ my ($src) = grep { my $s = $_; grep { _in( $s, $_ ) } map { @{ $_->{addr} || [] } } values %{ $tgt->{interfaces} || {} } } @own;
Condition50%2/4
$$_{'addr'} || []
l!l
160
$$tgt{'interfaces'} || {}
l!l
160
MC/DC0%0/1
$$_{'addr'} || []
$$_{'addr'}
MC/DC0%0/1
$$tgt{'interfaces'} || {}
$$tgt{'interfaces'}
Truth table50%1/2
A
A= $$_{'addr'}
Aresult
11
00
Truth table50%1/2
A
A= $$tgt{'interfaces'}
Aresult
11
00
6902 16 ▶ $src //= $own[0] // return undef;
Condition25%1/4
$src //= $own[0] // (return undef)
l!l
160
$own[0] // (return undef)
l!l
00
MC/DC0%0/1
$src //= $own[0] // (return undef)
$src
Truth table50%1/2
A
A= $src
Aresult
11
00
6903 16 ▶ my ($iif) = grep { grep { m{/} && _in( $src, $_ ) } @{ $tgt->{interfaces}{$_}{addr} || [] } } sort keys %{ $tgt->{interfaces} || {} };
Condition42%3/7
m[/] && _in($src, $_)
!ll&&!rl&&r
0016
$$tgt{'interfaces'}{$_}{'addr'} || []
l!l
160
$$tgt{'interfaces'} || {}
l!l
160
MC/DC0%0/2
m[/] && _in($src, $_)
m[/] _in($src, $_)
MC/DC0%0/1
$$tgt{'interfaces'}{$_}{'addr'} || []
$$tgt{'interfaces'}{$_}{'addr'}
MC/DC0%0/1
$$tgt{'interfaces'} || {}
$$tgt{'interfaces'}
Truth table33%1/3
A && B
A= m[/]B= _in($src, $_)
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$tgt{'interfaces'}{$_}{'addr'}
Aresult
11
00
Truth table50%1/2
A
A= $$tgt{'interfaces'}
Aresult
11
00
6904 16 ▶ my $v = _nft_verdict( $tgt, $src, $ip, $port, $iif // 'eth0' ) // return undef;
Condition50%2/4
_nft_verdict($tgt, $src, $ip, $port, $iif // "eth0") // (return undef)
l!l
160
$iif // "eth0"
l!l
160
MC/DC0%0/1
_nft_verdict($tgt, $src, $ip, $port, $iif // "eth0") // (return undef)
_nft_verdict($tgt, $src, $ip, $port, $iif // "eth0")
MC/DC0%0/1
$iif // "eth0"
$iif
Truth table50%1/2
A
A= _nft_verdict($tgt, $src, $ip, $port, $iif // "eth0")
Aresult
11
00
Truth table50%1/2
A
A= $iif
Aresult
11
00
6905 16 ▶ return 'timeout' if $v eq 'drop';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "drop" 3 13 16
6906 13 ▶ return 'refused' if $v eq 'reject';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "reject" 1 12 13
6907 12 my ( $addr, $complete ) = _listeners( $tgt, $port );
6908 12 ▶ return 'open' if grep { $_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ || $_ eq $ip } @$addr;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ or $_ eq $ip;} @$addr 3 9 12
Condition66%2/3
$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ || $_ eq $ip
l!l&&r!l&&!r
601
MC/DC50%1/2
$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ || $_ eq $ip
$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ $_ eq $ip
Truth table66%2/3
A || B
A= $_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/B= $_ eq $ip
ABresult
1X1
011
000
6909 9 ▶ return $complete ? 'refused' : undef;
Branch: 1 branch
BranchTrueFalseTotal
$complete ? : 8 1 9
6910 }
6911  
6912 # nc [-z] [-v] [-w N] [-n] HOST PORT[-PORT]…: Verbindungsprobe (netcat-openbsd), nur wenn
6913 # installiert (Programmdatei im Zustand); Daten senden (ohne -z) und UDP sind eine Luecke
6914 10 ▶sub _nc {
Subroutine _nc: called CC=20 SCAR=31.1
6915 10 my ( $dev, $av, $ctx ) = @_;
6916 10 my ($me) = grep { _prog_file( $dev, $_ ) } qw( nc netcat ncat );
6917 10 ▶ return ( 'bash: nc: command not found', 0 ) unless $me;
Branch: 1 branch
BranchTrueFalseTotal
unless $me 1 9 10
6918 9 my ( $z, $v, @pos );
6919 9 my @a = @$av;
6920 9 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 28 9 37
6921 28 my $x = shift @a;
6922 28 ▶ if ( $x =~ /\A-[wWiqpsTX]\z/ ) { shift @a }
Branch: 3 branches
BranchTrueFalseTotal
if ($x =~ /\A-[wWiqpsTX]\z/) { } 1 27 28
elsif ($x =~ /\A-([zvnNw0-9]+)\z/) { } 9 18 27
elsif ($x =~ /\A-/) { } 0 18 18
6923 9 ▶ elsif ( $x =~ /\A-([zvnNw0-9]+)\z/ ) { my $f = $1; $z = 1 if $f =~ /z/; $v = 1 if $f =~ /v/; shift @a if $f =~ /w\z/ }
Branch: 3 branches
BranchTrueFalseTotal
if $f =~ /z/ 9 0 9
if $f =~ /v/ 8 1 9
if $f =~ /w\z/ 0 9 9
6924 0 elsif ( $x =~ /\A-/ ) { push @GAPS, join( ' ', 'nc', @$av ); return ( '', 0 ) } # -u, -l, …
6925 18 else { push @pos, $x }
6926 }
6927 9 my ( $host, @ports ) = @pos;
6928 0 ▶ if ( !$z || !defined $host || !@ports ) { push @GAPS, join( ' ', 'nc', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($z and defined $host and @ports) 0 9 9
Condition33%2/6
$z and defined $host and @ports
!ll&&!rl&&r
009
$z and defined $host
!ll&&!rl&&r
009
MC/DC0%0/3
$z and defined $host and @ports
$z defined $host @ports
Truth table25%1/4
A and B and C
A= $zB= defined $hostC= @ports
ABCresult
0XX0
10X0
1100
1111
6929 9 my %svc = ( 22 => 'ssh', 25 => 'smtp', 53 => 'domain', 80 => 'http', 443 => 'https', 3306 => 'mysql', 5432 => 'postgresql', 6379 => '*' );
6930 9 my ( @out, $any );
6931 9 ▶ for my $p ( map { /\A(\d+)-(\d+)\z/ ? ( $1 .. $2 ) : $_ } @ports ) {
Branch: 1 branch
BranchTrueFalseTotal
/\A(\d+)-(\d+)\z/ ? : 0 9 9
6932 9 my $st = _tcp_probe( $dev, $host, $p );
6933 9 ▶ if ( !defined $st ) { push @GAPS, join( ' ', 'nc', @$av ); return ( join( "\n", @out ), 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 2 7 9
6934 7 ▶ if ( $st eq 'open' ) { $any = 1; push @out, "Connection to $host $p port [tcp/" . ( $svc{$p} // '*' ) . '] succeeded!' if $v; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($st eq "open") 2 5 7
if $v 1 1 2
Condition50%1/2
$svc{$p} // "*"
l!l
10
MC/DC0%0/1
$svc{$p} // "*"
$svc{$p}
Truth table50%1/2
A
A= $svc{$p}
Aresult
11
00
6935 5 ▶ if ( $st eq 'noname' ) { push @out, qq{nc: getaddrinfo for host "$host" port $p: Name or service not known}; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($st eq "noname") 1 4 5
6936 push @out, "nc: connect to $host port $p (tcp) "
6937 4 . { refused => 'failed: Connection refused', timeout => 'timed out: Operation now in progress', unreach => 'failed: Network is unreachable' }->{$st};
6938 }
6939 7 ▶ return ( join( "\n", @out ), $any ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$any ? : 2 5 7
6940 }
6941  
6942 # curl (nur wenn installiert): eigene Maschine mit nginx wie wget; andere Geraete: nur das
6943 # Scheitern der Verbindung (7 refused, 28 timeout); eine gelungene Verbindung zu einem
6944 # anderen Geraet ist eine Luecke (dort antwortet kein nachgebildeter Dienst)
6945 3 ▶sub _curl {
Subroutine _curl: called CC=52 SCAR=67.3
6946 3 my ( $dev, $av, $ctx ) = @_;
6947 3 ▶ return ( 'bash: curl: command not found', 0 ) unless _prog_file( $dev, 'curl' );
Branch: 1 branch
BranchTrueFalseTotal
unless _prog_file($dev, "curl") 1 2 3
6948 2 my ( $url, $silent, $show, $head, $out, $wfmt, $vhost );
6949 2 my @a = @$av;
6950 2 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 4 2 6
6951 4 my $x = shift @a;
6952 4 ▶ if ( $x =~ /\A-([sSIfLkv]+)\z/ ) { my $f = $1; $silent = 1 if $f =~ /s/; $show = 1 if $f =~ /S/; $head = 1 if $f =~ /I/ }
Branch: 10 branches
BranchTrueFalseTotal
if ($x =~ /\A-([sSIfLkv]+)\z/) { } 2 2 4
elsif ($x eq '-o' or $x eq '--output') { } 0 2 2
elsif ($x eq '-w' or $x eq '--write-out') { } 0 2 2
elsif ($x eq '-H' or $x eq '--header') { } 0 2 2
elsif ($x =~ /\A(?:-m|--max-time|--connect-timeout)\z/) { } 0 2 2
elsif ($x =~ /\A--(?:silent|show-error|head|fail|location|insecure)\z/) { } 0 2 2
elsif ($x =~ /\A-/) { } 0 2 2
if $f =~ /s/ 2 0 2
if $f =~ /S/ 1 1 2
if $f =~ /I/ 0 2 2
6953 0 ▶ elsif ( $x eq '-o' || $x eq '--output' ) { $out = shift @a }
Condition33%1/3
$x eq "-o" or $x eq "--output"
l!l&&r!l&&!r
002
MC/DC0%0/2
$x eq "-o" or $x eq "--output"
$x eq "-o" $x eq "--output"
Truth table33%1/3
A or B
A= $x eq "-o"B= $x eq "--output"
ABresult
1X1
011
000
6954 0 ▶ elsif ( $x eq '-w' || $x eq '--write-out' ) { $wfmt = shift @a }
Condition33%1/3
$x eq "-w" or $x eq "--write-out"
l!l&&r!l&&!r
002
MC/DC0%0/2
$x eq "-w" or $x eq "--write-out"
$x eq "-w" $x eq "--write-out"
Truth table33%1/3
A or B
A= $x eq "-w"B= $x eq "--write-out"
ABresult
1X1
011
000
6955 0 ▶ elsif ( $x eq '-H' || $x eq '--header' ) { my $h = shift(@a) // ''; $vhost = $1 if $h =~ /\AHost:\s*(\S+)/i }
Branch: 1 branch
BranchTrueFalseTotal
if $h =~ /\AHost:\s*(\S+)/i 0 0 0
Condition20%1/5
$x eq "-H" or $x eq "--header"
l!l&&r!l&&!r
002
shift @a // ""
l!l
00
MC/DC0%0/2
$x eq "-H" or $x eq "--header"
$x eq "-H" $x eq "--header"
MC/DC0%0/1
shift @a // ""
shift @a
Truth table33%1/3
A or B
A= $x eq "-H"B= $x eq "--header"
ABresult
1X1
011
000
Truth table0%0/2
A
A= shift @a
Aresult
11
00
6956 0 elsif ( $x =~ /\A(?:-m|--max-time|--connect-timeout)\z/ ) { shift @a }
6957 0 ▶ elsif ( $x =~ /\A--(?:silent|show-error|head|fail|location|insecure)\z/ ) { $silent = 1 if $x eq '--silent'; $show = 1 if $x eq '--show-error'; $head = 1 if $x eq '--head' }
Branch: 3 branches
BranchTrueFalseTotal
if $x eq "--silent" 0 0 0
if $x eq "--show-error" 0 0 0
if $x eq "--head" 0 0 0
6958 0 elsif ( $x =~ /\A-/ ) { push @GAPS, join( ' ', 'curl', @$av ); return ( '', 0 ) }
6959 2 else { $url = $x }
6960 }
6961 0 ▶ my ( $scheme, $h, $port, $path ) = ( $url // '' ) =~ m{\A(?:(https?)://)?([^/:]+)(?::(\d+))?(/.*)?\z} or do { push @GAPS, join( ' ', 'curl', @$av ); return ( '', 0 ) };
Branch: 1 branch
BranchTrueFalseTotal
() = ($url // "") =~ m[\A(?:(https?)://)?([^/:]+)(?::(\d+))?(/.*)?\z] or do { push @Langertha::Holmgang::Sim::Linux::GAPS, join(" ", "curl", @$av); return "", 0 } 2 0 2
Condition50%1/2
$url // ""
l!l
20
MC/DC0%0/1
$url // ""
$url
Truth table50%1/2
A
A= $url
Aresult
11
00
6962 2 ▶ $port //= ( $scheme // 'http' ) eq 'https' ? 443 : 80;
Branch: 1 branch
BranchTrueFalseTotal
($scheme // 'http') eq 'https' ? : 0 0 0
Condition25%1/4
$port //= ($scheme // "http") eq "https" ? 443 : 80
l!l
20
$scheme // "http"
l!l
00
MC/DC0%0/1
$port //= ($scheme // "http") eq "https" ? 443 : 80
$port
Truth table50%1/2
A
A= $port
Aresult
11
00
6963 2 my $st = _tcp_probe( $dev, $h, $port );
6964 0 ▶ if ( !defined $st ) { push @GAPS, join( ' ', 'curl', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 0 2 2
6965 2 ▶ if ( $st ne 'open' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($st ne "open") 2 0 2
6966 2 ▶ my ( $code, $msg ) = $st eq 'noname' ? ( 6, "Could not resolve host: $h" ) : $st eq 'timeout' ? ( 28, "Failed to connect to $h port $port after 130000 ms: Couldn't connect to server" )
Branch: 3 branches
BranchTrueFalseTotal
$st eq 'noname' ? : 0 2 2
$st eq 'timeout' ? : 0 2 2
$st eq 'unreach' ? : 0 2 2
6967 : $st eq 'unreach' ? ( 7, "Failed to connect to $h port $port after 0 ms: Couldn't connect to server" )
6968 : ( 7, "Failed to connect to $h port $port after 0 ms: Couldn't connect to server" );
6969 2 ▶ $SH->{code} = $code if $SH;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH 2 0 2
6970 2 my @o;
6971 2 ▶ push @o, $wfmt =~ s/%\{http_code\}/000/gr =~ s/\\n/\n/gr if defined $wfmt;
Branch: 1 branch
BranchTrueFalseTotal
if defined $wfmt 0 2 2
6972 2 ▶ push @o, "curl: ($code) $msg" if !$silent || $show;
Branch: 1 branch
BranchTrueFalseTotal
if not $silent or $show 1 1 2
Condition66%2/3
not $silent or $show
l!l&&r!l&&!r
011
MC/DC50%1/2
not $silent or $show
not $silent $show
Truth table66%2/3
not(A) or B
A= not $silentB= $show
ABresult
1X1
011
000
6973 2 return ( join( "\n", @o ), 0 );
6974 }
6975 0 ▶ my $self = $h =~ /\A(?:localhost|127\.)/ || grep { $_ eq $h } _own_addrs($dev), $dev->{hostname} // (), ( $ctx || {} )->{host} // ();
Condition0%0/11
$h =~ /\A(?:localhost|127\.)/ || grep({$_ eq $h;} _own_addrs($dev), $$dev{'hostname'} // (), ($ctx || {})->{'host'} // ())
l!l&&r!l&&!r
000
$$dev{"hostname"} // ()
l!l&&r!l&&!r
000
($ctx || {})->{"host"} // ()
l!l&&r!l&&!r
000
$ctx || {}
l!l
00
MC/DC0%0/2
$h =~ /\A(?:localhost|127\.)/ || grep({$_ eq $h;} _own_addrs($dev), $$dev{'hostname'} // (), ($ctx || {})->{'host'} // ())
$h =~ /\A(?:localhost|127\.)/ grep({$_ eq $h;} _own_addrs($dev), $$dev{'hostname'} // (), ($ctx || {})->{'host'} // ())
MC/DC0%0/2
$$dev{"hostname"} // ()
$$dev{"hostname"} ()
MC/DC0%0/2
($ctx || {})->{"host"} // ()
$ctx ()
Truth table0%0/3
A || B
A= $h =~ /\A(?:localhost|127\.)/B= grep({$_ eq $h;} _own_addrs($dev), $$dev{'hostname'} // (), ($ctx || {})->{'host'} // ())
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $$dev{"hostname"}B= ()
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $ctxB= ()
ABresult
1X1
011
000
6976 0 ▶ my ( $body, $code, $type ) = $self && ( $scheme // 'http' ) eq 'http' ? _nginx_http( $dev, $port, $vhost // $h, $path // '/' ) : ();
Branch: 1 branch
BranchTrueFalseTotal
$self && ($scheme // 'http') eq 'http' ? : 0 0 0
Condition0%0/10
$self and ($scheme // "http") eq "http"
!ll&&!rl&&r
000
$scheme // "http"
l!l
00
$vhost // $h
l!l&&r!l&&!r
000
$path // "/"
l!l
00
MC/DC0%0/2
$self and ($scheme // "http") eq "http"
$self $scheme
MC/DC0%0/2
$vhost // $h
$vhost $h
MC/DC0%0/1
$path // "/"
$path
Truth table0%0/3
A and B
A= $selfB= $scheme
ABresult
0X0
100
111
Truth table0%0/3
A // B
A= $vhostB= $h
ABresult
1X1
011
000
Truth table0%0/2
A
A= $path
Aresult
11
00
6977 0 ▶ if ( !defined $code || !$code ) { push @GAPS, join( ' ', 'curl', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code and $code) 0 0 0
Condition0%0/3
defined $code and $code
!ll&&!rl&&r
000
MC/DC0%0/2
defined $code and $code
defined $code $code
Truth table0%0/3
A and B
A= defined $codeB= $code
ABresult
0X0
100
111
6978 0 my %reason = ( 200 => 'OK', 403 => 'Forbidden', 404 => 'Not Found' );
6979 0 my @o;
6980 0 ▶ if ($head) { push @o, "HTTP/1.1 $code $reason{$code}", 'Server: nginx/1.22.1', "Content-Type: $type", 'Content-Length: ' . length($body), 'Connection: keep-alive' }
Branch: 2 branches
BranchTrueFalseTotal
if ($head) { } 0 0 0
elsif (defined $out and $out ne '-') { } 0 0 0
6981 ▶ elsif ( defined $out && $out ne '-' ) {
Condition0%0/3
defined $out and $out ne "-"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $out and $out ne "-"
defined $out $out ne "-"
Truth table0%0/3
A and B
A= defined $outB= $out ne "-"
ABresult
0X0
100
111
6982 0 ▶ if ( $out ne '/dev/null' ) { my ( $e, $wok ) = _write_path( $dev, $out, $body, 0, $ctx ); return ( $e, 0 ) unless $wok }
Branch: 2 branches
BranchTrueFalseTotal
if ($out ne "/dev/null") 0 0 0
unless $wok 0 0 0
6983 }
6984 0 else { push @o, $body =~ s/\n\z//r }
6985 0 ▶ push @o, $wfmt =~ s/%\{http_code\}/$code/gr =~ s/\\n/\n/gr =~ s/\n\z//r if defined $wfmt;
Branch: 1 branch
BranchTrueFalseTotal
if defined $wfmt 0 0 0
6986 0 return ( join( "\n", @o ), 1 );
6987 }
6988  
6989 # env [NAME=wert …] [befehl …]: ohne Befehl die Umgebung der Shell (exportierte Variablen,
6990 # Vorgaben der Anmeldung), sonst den Befehl mit diesen Variablen
6991 8 ▶sub _env {
Subroutine _env: called CC=16 SCAR=29.3
6992 8 my ( $dev, $av, $ctx, $stdin ) = @_;
6993 8 my @a = @$av;
6994 8 my %set;
6995 8 ▶ while ( @a && $a[0] =~ /\A([A-Za-z_]\w*)=(.*)\z/s ) { $set{$1} = $2; shift @a }
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A([A-Za-z_]\w*)=(.*)\z/s) 1 8 9
Condition100%3/3
@a and $a[0] =~ /\A([A-Za-z_]\w*)=(.*)\z/s
!ll&&!rl&&r
711
MC/DC100%2/2
@a and $a[0] =~ /\A([A-Za-z_]\w*)=(.*)\z/s
@a $a[0] =~ /\A([A-Za-z_]\w*)=(.*)\z/s
Truth table100%3/3
A and B
A= @aB= $a[0] =~ /\A([A-Za-z_]\w*)=(.*)\z/s
ABresult
0X0
100
111
6996 0 ▶ if ( @a && $a[0] =~ /\A-/ ) { push @GAPS, join( ' ', 'env', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-/) 0 8 8
Condition66%2/3
@a and $a[0] =~ /\A-/
!ll&&!rl&&r
710
MC/DC0%0/2
@a and $a[0] =~ /\A-/
@a $a[0] =~ /\A-/
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A-/
ABresult
0X0
100
111
6997 8 ▶ if (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 1 7 8
6998 1 ▶ local $SHENV = { %{ $SHENV || {} }, %set };
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::SHENV || {}
l!l
10
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::SHENV || {}
$Langertha::Holmgang::Sim::Linux::SHENV
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::SHENV
Aresult
11
00
6999 1 return __PACKAGE__->_command( $dev, \@a, $ctx, $stdin );
7000 }
7001 7 my $u = _who();
7002 my %e = ( PATH => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', HOME => $u eq 'root' ? '/root' : "/home/$u",
7003 USER => $u, LOGNAME => $u, SHELL => '/bin/bash', PWD => $CWD_DIR // ( $u eq 'root' ? '/root' : "/home/$u" ), LANG => 'C.UTF-8', SHLVL => 1,
7004 1 ( $dev->{ssh_login} ? ( SSH_CONNECTION => ( $dev->{ssh_login}{from} // '10.1.0.50' ) . ' 50122 ' . ( ( grep { !/\A(?:127\.|::1)/ } _own_addrs($dev) )[0] // '127.0.0.1' ) . ' 22' ) : () ),
7005 7 ▶ ( map { $_ => $SH->{vars}{$_} } grep { defined $SH->{vars}{$_} } keys %{ ( $SH || {} )->{exported} || {} } ), %{ $SHENV || {} }, %set );
Branch: 3 branches
BranchTrueFalseTotal
$u eq 'root' ? : 7 0 7
$u eq 'root' ? : 7 0 7
$$dev{'ssh_login'} ? : 1 6 7
Condition58%7/12
$Langertha::Holmgang::Sim::Linux::CWD_DIR // ($u eq "root" ? "/root" : "/home/$u")
l!l
07
$$dev{"ssh_login"}{"from"} // "10.1.0.50"
l!l
10
(grep {not /\A(?:127\.|::1)/;} _own_addrs($dev))[0] // "127.0.0.1"
l!l
10
($Langertha::Holmgang::Sim::Linux::SH || {})->{'exported'} || {}
l!l
25
$Langertha::Holmgang::Sim::Linux::SH || {}
l!l
70
$Langertha::Holmgang::Sim::Linux::SHENV || {}
l!l
70
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::CWD_DIR // ($u eq "root" ? "/root" : "/home/$u")
$Langertha::Holmgang::Sim::Linux::CWD_DIR
MC/DC0%0/1
$$dev{"ssh_login"}{"from"} // "10.1.0.50"
$$dev{"ssh_login"}{"from"}
MC/DC0%0/1
(grep {not /\A(?:127\.|::1)/;} _own_addrs($dev))[0] // "127.0.0.1"
(grep {not /\A(?:127\.|::1)/;} _own_addrs($dev))[0]
MC/DC0%0/1
($Langertha::Holmgang::Sim::Linux::SH || {})->{'exported'} || {}
$Langertha::Holmgang::Sim::Linux::SH
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::SHENV || {}
$Langertha::Holmgang::Sim::Linux::SHENV
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::CWD_DIR
Aresult
11
00
Truth table50%1/2
A
A= $$dev{"ssh_login"}{"from"}
Aresult
11
00
Truth table50%1/2
A
A= (grep {not /\A(?:127\.|::1)/;} _own_addrs($dev))[0]
Aresult
11
00
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::SH
Aresult
11
00
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::SHENV
Aresult
11
00
7006 7 return ( join( "\n", ( map {"$_=$e{$_}"} sort keys %e ), '_=/usr/bin/env' ), 1 );
7007 }
7008  
7009 # wget gegen die eigene Maschine: Prometheus/Alertmanager (Sim::Monitoring), auf dem Port
7010 # von nginx dessen statische Dateien (_nginx_http): -O -|DATEI, -q, -S, --spider,
7011 # --header='Host: …'; anderes ist eine Luecke
7012 25 ▶sub _wget {
Subroutine _wget: called CC=93 SCAR=54.2
7013 25 my ( $dev, $av, $ctx ) = @_;
7014 25 my ( $url, $out, $post, $quiet, $show, $spider, $vhost );
7015 25 my @a = @$av;
7016 25 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 62 25 87
7017 62 my $x = shift @a;
7018 62 ▶ if ( $x =~ /\A-([qS]*)O\z/ || $x eq '--output-document' ) {
Branch: 10 branches
BranchTrueFalseTotal
if ($x =~ /\A-([qS]*)O\z/ or $x eq '--output-document') { } 10 52 62
elsif ($x =~ /\A-([qS]*)O(.+)\z/) { } 14 38 52
elsif ($x =~ /\A--output-document=(.*)\z/) { } 0 38 38
elsif ($x =~ /\A--post-data=/ or $x =~ /\A--method=POST\z/i) { } 2 36 38
elsif ($x eq '--post-data') { } 0 36 36
elsif ($x eq '--header') { } 0 36 36
elsif ($x =~ /\A--header=Host:\s*(\S+)\z/i) { } 1 35 36
elsif ($x eq '--spider') { } 1 34 35
elsif ($x =~ /\A-([qSv]+)\z/ or $x eq '--quiet' or $x eq '--server-response') { } 9 25 34
elsif ($x =~ /\A-/) { } 0 25 25
Condition66%2/3
$x =~ /\A-([qS]*)O\z/ or $x eq "--output-document"
l!l&&r!l&&!r
10052
MC/DC50%1/2
$x =~ /\A-([qS]*)O\z/ or $x eq "--output-document"
$x =~ /\A-([qS]*)O\z/ $x eq "--output-document"
Truth table66%2/3
A or B
A= $x =~ /\A-([qS]*)O\z/B= $x eq "--output-document"
ABresult
1X1
011
000
7019 10 ▶ my $f = $x =~ /\A-([qS]*)O\z/ ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$x =~ /\A-([qS]*)O\z/ ? : 10 0 10
7020 10 $out = shift @a;
7021 10 ▶ $quiet = 1 if $f =~ /q/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /q/ 1 9 10
7022 10 ▶ $show = 1 if $f =~ /S/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /S/ 0 10 10
7023 }
7024 14 ▶ elsif ( $x =~ /\A-([qS]*)O(.+)\z/ ) { my $f = $1; $out = $2; $quiet = 1 if $f =~ /q/; $show = 1 if $f =~ /S/ }
Branch: 2 branches
BranchTrueFalseTotal
if $f =~ /q/ 9 5 14
if $f =~ /S/ 0 14 14
7025 0 elsif ( $x =~ /\A--output-document=(.*)\z/ ) { $out = $1 }
7026 2 ▶ elsif ( $x =~ /\A--post-data=/ || $x =~ /\A--method=POST\z/i ) { $post = 1 }
Condition66%2/3
$x =~ /\A--post-data=/ or $x =~ /\A--method=POST\z/i
l!l&&r!l&&!r
2036
MC/DC50%1/2
$x =~ /\A--post-data=/ or $x =~ /\A--method=POST\z/i
$x =~ /\A--post-data=/ $x =~ /\A--method=POST\z/i
Truth table66%2/3
A or B
A= $x =~ /\A--post-data=/B= $x =~ /\A--method=POST\z/i
ABresult
1X1
011
000
7027 0 elsif ( $x eq '--post-data' ) { shift @a; $post = 1 }
7028 0 ▶ elsif ( $x eq '--header' ) { my $h = shift(@a) // ''; $vhost = $1 if $h =~ /\AHost:\s*(\S+)/i }
Branch: 1 branch
BranchTrueFalseTotal
if $h =~ /\AHost:\s*(\S+)/i 0 0 0
Condition0%0/2
shift @a // ""
l!l
00
MC/DC0%0/1
shift @a // ""
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
7029 1 elsif ( $x =~ /\A--header=Host:\s*(\S+)\z/i ) { $vhost = $1 }
7030 1 elsif ( $x eq '--spider' ) { $spider = 1 }
7031 ▶ elsif ( $x =~ /\A-([qSv]+)\z/ || $x eq '--quiet' || $x eq '--server-response' ) {
Condition66%4/6
$x =~ /\A-([qSv]+)\z/ or $x eq "--quiet" or $x eq "--server-response"
l!l&&r!l&&!r
9025
$x =~ /\A-([qSv]+)\z/ or $x eq "--quiet"
l!l&&r!l&&!r
9025
MC/DC33%1/3
$x =~ /\A-([qSv]+)\z/ or $x eq "--quiet" or $x eq "--server-response"
$x =~ /\A-([qSv]+)\z/ $x eq "--quiet" $x eq "--server-response"
Truth table50%2/4
A or B or C
A= $x =~ /\A-([qSv]+)\z/B= $x eq "--quiet"C= $x eq "--server-response"
ABCresult
1XX1
01X1
0011
0000
7032 9 ▶ my $f = $1 // ( $x eq '--quiet' ? 'q' : 'S' );
Branch: 1 branch
BranchTrueFalseTotal
$x eq '--quiet' ? : 0 0 0
Condition50%1/2
$1 // ($x eq "--quiet" ? "q" : "S")
l!l
90
MC/DC0%0/1
$1 // ($x eq "--quiet" ? "q" : "S")
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
7033 9 ▶ $quiet = 1 if $f =~ /q/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /q/ 8 1 9
7034 9 ▶ $show = 1 if $f =~ /S/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /S/ 1 8 9
7035 }
7036 elsif ( $x =~ /\A-/ ) { }
7037 25 else { $url = $x }
7038 }
7039 25 ▶ my ( $h80, $port80, $path80 ) = ( $url // '' ) =~ m{\A(?:http://)?([^/:]+)(?::(\d+))?(/.*)?\z};
Condition50%1/2
$url // ""
l!l
250
MC/DC0%0/1
$url // ""
$url
Truth table50%1/2
A
A= $url
Aresult
11
00
7040 25 ▶ my $self80 = defined $h80 && ( $h80 =~ /\A(?:localhost|127\.0\.0\.1)\z/ || grep { $_ eq $h80 } _own_addrs($dev), $dev->{hostname} // (), $ctx->{host} // () );
Condition58%7/12
defined $h80 && ($h80 =~ /\A(?:localhost|127\.0\.0\.1)\z/ || grep({$_ eq $h80;} _own_addrs($dev), $$dev{'hostname'} // (), $$ctx{'host'} // ()))
!ll&&!rl&&r
0619
$h80 =~ /\A(?:localhost|127\.0\.0\.1)\z/ or grep {$_ eq $h80;} _own_addrs($dev), $$dev{"hostname"} // (), $$ctx{"host"} // ()
l!l&&r!l&&!r
1906
$$dev{"hostname"} // ()
l!l&&r!l&&!r
042
$$ctx{"host"} // ()
l!l&&r!l&&!r
600
MC/DC33%1/3
defined $h80 && ($h80 =~ /\A(?:localhost|127\.0\.0\.1)\z/ || grep({$_ eq $h80;} _own_addrs($dev), $$dev{'hostname'} // (), $$ctx{'host'} // ()))
defined $h80 $h80 =~ /\A(?:localhost|127\.0\.0\.1)\z/ grep {$_ eq $h80;} _own_addrs($dev), $$dev{"hostname"} // (), $$ctx{"host"} // ()
MC/DC50%1/2
$$dev{"hostname"} // ()
$$dev{"hostname"} ()
MC/DC0%0/2
$$ctx{"host"} // ()
$$ctx{"host"} ()
Truth table50%2/4
A && B or C
A= defined $h80B= $h80 =~ /\A(?:localhost|127\.0\.0\.1)\z/C= grep {$_ eq $h80;} _own_addrs($dev), $$dev{"hostname"} // (), $$ctx{"host"} // ()
ABCresult
0XX0
1000
11X1
1011
Truth table66%2/3
A // B
A= $$dev{"hostname"}B= ()
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $$ctx{"host"}B= ()
ABresult
1X1
011
000
7041 25 ▶ if ( $self80 && !$post && ( $port80 // 80 ) !~ /\A(?:9090|9093)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self80 and not $post and not +($port80 // 80) =~ /\A(?:9090|9093)\z/) 9 16 25
Condition100%8/8
$self80 and not $post and not +($port80 // 80) =~ /\A(?:9090|9093)\z/
!ll&&!rl&&r
889
$self80 and not $post
!ll&&!rl&&r
6217
$port80 // 80
l!l
89
MC/DC100%3/3
$self80 and not $post and not +($port80 // 80) =~ /\A(?:9090|9093)\z/
$self80 not $post $port80
Truth table100%4/4
A and not(B) and not(C)
A= $self80B= not $postC= $port80
ABCresult
0XX0
10X0
1110
1101
7042 9 ▶ my ( $body, $st, $type ) = _nginx_http( $dev, $port80 // 80, $vhost // $h80, $path80 // '/' );
Condition57%4/7
$port80 // 80
l!l
09
$vhost // $h80
l!l&&r!l&&!r
180
$path80 // "/"
l!l
90
MC/DC0%0/1
$port80 // 80
$port80
MC/DC0%0/2
$vhost // $h80
$vhost $h80
MC/DC0%0/1
$path80 // "/"
$path80
Truth table50%1/2
A
A= $port80
Aresult
11
00
Truth table66%2/3
A // B
A= $vhostB= $h80
ABresult
1X1
011
000
Truth table50%1/2
A
A= $path80
Aresult
11
00
7043 # nginx lauscht dort nicht, aber ein anderer Dienst: nicht nachgebildet
7044 9 ▶ my $pn = $port80 // 80;
Condition50%1/2
$port80 // 80
l!l
09
MC/DC0%0/1
$port80 // 80
$port80
Truth table50%1/2
A
A= $port80
Aresult
11
00
7045 0 ▶ if ( defined $st && !$st && ( _ss( $dev, [] ) )[0] =~ /:\Q$pn\E\s/ ) { undef $st }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $st and not $st and (_ss($dev, scalar []))[0] =~ /:\Q$pn\E\s/) 0 9 9
Condition83%5/6
defined $st and not $st and (_ss($dev, scalar []))[0] =~ /:\Q$pn\E\s/
!ll&&!rl&&r
810
defined $st and not $st
!ll&&!rl&&r
171
MC/DC0%0/3
defined $st and not $st and (_ss($dev, scalar []))[0] =~ /:\Q$pn\E\s/
defined $st not $st (_ss($dev, scalar []))[0] =~ /:\Q$pn\E\s/
Truth table75%3/4
A and not(B) and C
A= defined $stB= not $stC= (_ss($dev, scalar []))[0] =~ /:\Q$pn\E\s/
ABCresult
0XX0
10X0
1100
1111
7046 9 ▶ if ( !defined $st ) { push @GAPS, join( ' ', 'wget', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 1 8 9
7047 8 require POSIX;
7048 8 my $stamp = POSIX::strftime( '%Y-%m-%d %H:%M:%S', _local_tm( _dev_now($dev) ) );
7049 8 ▶ my $hp = $h80 . ( defined $port80 ? ":$port80" : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $port80 ? : 0 8 8
7050 8 ▶ my $addr = $h80 eq 'localhost' ? '127.0.0.1' : $h80;
Branch: 1 branch
BranchTrueFalseTotal
$h80 eq 'localhost' ? : 2 6 8
7051 8 my @err;
7052 8 ▶ push @err, "--$stamp-- http://$hp" . ( $path80 // '/' ), "Connecting to $hp ($addr:" . ( $port80 // 80 ) . ')... ' . ( $st ? 'connected.' : 'failed: Connection refused.' ) unless $quiet;
Branch: 2 branches
BranchTrueFalseTotal
unless $quiet 3 5 8
$st ? : 2 1 3
Condition50%2/4
$path80 // "/"
l!l
30
$port80 // 80
l!l
03
MC/DC0%0/1
$path80 // "/"
$path80
MC/DC0%0/1
$port80 // 80
$port80
Truth table50%1/2
A
A= $path80
Aresult
11
00
Truth table50%1/2
A
A= $port80
Aresult
11
00
7053 8 ▶ return ( join( "\n", @err ), 0 ) unless $st;
Branch: 1 branch
BranchTrueFalseTotal
unless $st 1 7 8
7054 7 my %reason = ( 200 => 'OK', 403 => 'Forbidden', 404 => 'Not Found' );
7055 7 ▶ push @err, "HTTP request sent, awaiting response... " . ( $show ? '' : "$st $reason{$st}" ) unless $quiet;
Branch: 2 branches
BranchTrueFalseTotal
unless $quiet 2 5 7
$show ? : 1 1 2
7056 7 ▶ push @err, " HTTP/1.1 $st $reason{$st}", ' Server: nginx/1.22.1', " Content-Type: $type", ' Content-Length: ' . length($body), ' Connection: keep-alive' if $show;
Branch: 1 branch
BranchTrueFalseTotal
if $show 1 6 7
7057 7 ▶ if ( $st != 200 ) { push @err, "$stamp ERROR $st: $reason{$st}." unless $quiet; return ( join( "\n", @err ), 0 ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($st != 200) 3 4 7
unless $quiet 1 2 3
7058 4 ▶ if ($spider) { push @err, 'Remote file exists.' unless $quiet; return ( join( "\n", @err ), 1 ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($spider) 1 3 4
unless $quiet 1 0 1
7059 3 ▶ my $file = $out // ( ( ( $path80 // '/' ) =~ m{([^/]+)\z} )[0] // 'index.html' );
Condition16%1/6
$out // ((($path80 // "/") =~ m[([^/]+)\z])[0] // "index.html")
l!l
30
(($path80 // "/") =~ m[([^/]+)\z])[0] // "index.html"
l!l
00
$path80 // "/"
l!l
00
MC/DC0%0/1
$out // ((($path80 // "/") =~ m[([^/]+)\z])[0] // "index.html")
$out
MC/DC0%0/1
$path80 // "/"
$path80
Truth table50%1/2
A
A= $out
Aresult
11
00
Truth table0%0/2
A
A= $path80
Aresult
11
00
7060 3 ▶ return ( join( "\n", @err, $body =~ s/\n\z//r ), 1 ) if $file eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $file eq "-" 2 1 3
7061 1 ▶ if ( $file ne '/dev/null' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file ne "/dev/null") 1 0 1
7062 1 my ( $e, $wok ) = _write_path( $dev, $file, $body, 0, $ctx );
7063 1 ▶ return ( $e, 0 ) unless $wok;
Branch: 1 branch
BranchTrueFalseTotal
unless $wok 0 1 1
7064 }
7065 1 ▶ push @err, "Saving to: '$file'", '', "'$file' saved [" . length($body) . ']' unless $quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet 0 1 1
7066 1 return ( join( "\n", @err ), 1 );
7067 }
7068 # ein anderes Geraet: nur das Scheitern der Verbindung ist nachgebildet
7069 16 ▶ if ( defined $h80 && !$self80 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h80 and not $self80) 6 10 16
Condition66%2/3
defined $h80 and not $self80
!ll&&!rl&&r
0106
MC/DC50%1/2
defined $h80 and not $self80
defined $h80 not $self80
Truth table66%2/3
A and not(B)
A= defined $h80B= not $self80
ABresult
0X0
100
111
7070 6 ▶ my $pn = $port80 // ( ( $url // '' ) =~ m{\Ahttps://} ? 443 : 80 );
Branch: 1 branch
BranchTrueFalseTotal
($url // '') =~ m[\Ahttps://] ? : 0 4 4
Condition75%3/4
$port80 // (($url // "") =~ m[\Ahttps://] ? 443 : 80)
l!l
24
$url // ""
l!l
40
MC/DC100%1/1
$port80 // (($url // "") =~ m[\Ahttps://] ? 443 : 80)
$port80
Truth table100%2/2
A
A= $port80
Aresult
11
00
7071 6 my $st = _tcp_probe( $dev, $h80, $pn );
7072 6 ▶ if ( defined $st && $st ne 'open' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $st and $st ne "open") 4 2 6
Condition66%2/3
defined $st and $st ne "open"
!ll&&!rl&&r
204
MC/DC50%1/2
defined $st and $st ne "open"
defined $st $st ne "open"
Truth table66%2/3
A and B
A= defined $stB= $st ne "open"
ABresult
0X0
100
111
7073 4 require POSIX;
7074 4 my $stamp = POSIX::strftime( '%Y-%m-%d %H:%M:%S', _local_tm( _dev_now($dev) ) );
7075 4 my $why = { refused => 'Connection refused', timeout => 'Connection timed out', unreach => 'Network is unreachable' }->{$st};
7076 4 ▶ $SH->{code} = 4 if $SH;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH 4 0 4
7077 4 ▶ return ( '', 0 ) if $quiet || $st eq 'timeout' && $IN_TIMEOUT;
Branch: 1 branch
BranchTrueFalseTotal
if $quiet or $st eq "timeout" and $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT 1 3 4
Condition66%4/6
$quiet or $st eq "timeout" and $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT
l!l&&r!l&&!r
103
$st eq "timeout" and $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT
!ll&&!rl&&r
210
MC/DC33%1/3
$quiet or $st eq "timeout" and $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT
$quiet $st eq "timeout" $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT
Truth table75%3/4
A or B and C
A= $quietB= $st eq "timeout"C= $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT
ABCresult
1XX1
0111
00X0
0100
7078 3 ▶ return ( "wget: unable to resolve host address '$h80'", 0 ) if $st eq 'noname';
Branch: 1 branch
BranchTrueFalseTotal
if $st eq "noname" 1 2 3
7079 2 ▶ my $ip = _ip2n($h80) ? $h80 : ( _own_addrs( ( $ctx->{state} || {} )->{$h80} || {} ) )[0] // $h80;
Branch: 1 branch
BranchTrueFalseTotal
_ip2n($h80) ? : 2 0 2
Condition0%0/7
(_own_addrs(($$ctx{"state"} || {})->{$h80} || {}))[0] // $h80
l!l&&r!l&&!r
000
($$ctx{'state'} || {})->{$h80} || {}
l!l
00
$$ctx{'state'} || {}
l!l
00
MC/DC0%0/2
(_own_addrs(($$ctx{"state"} || {})->{$h80} || {}))[0] // $h80
(_own_addrs(($$ctx{"state"} || {})->{$h80} || {}))[0] $h80
MC/DC0%0/1
($$ctx{'state'} || {})->{$h80} || {}
$$ctx{'state'}
Truth table0%0/3
A // B
A= (_own_addrs(($$ctx{"state"} || {})->{$h80} || {}))[0]B= $h80
ABresult
1X1
011
000
Truth table0%0/2
A
A= $$ctx{'state'}
Aresult
11
00
7080 2 return ( "--$stamp-- $url\nConnecting to $h80 ($ip:$pn)... failed: $why.", 0 );
7081 }
7082 }
7083 12 ▶ my ( $host, $port, $path ) = ( $url // '' ) =~ m{\A(?:http://)?([^/:]+):(\d+)(/.*)?\z};
Condition50%1/2
$url // ""
l!l
120
MC/DC0%0/1
$url // ""
$url
Truth table50%1/2
A
A= $url
Aresult
11
00
7084 0 ▶ my $local = defined $host && ( $host =~ /\A(?:localhost|127\.0\.0\.1)\z/ || grep { $_ eq $host } _own_addrs($dev) );
Condition83%5/6
defined $host && ($host =~ /\A(?:localhost|127\.0\.0\.1)\z/ || grep({$_ eq $host;} _own_addrs($dev)))
!ll&&!rl&&r
1110
$host =~ /\A(?:localhost|127\.0\.0\.1)\z/ or grep {$_ eq $host;} _own_addrs($dev)
l!l&&r!l&&!r
1001
MC/DC66%2/3
defined $host && ($host =~ /\A(?:localhost|127\.0\.0\.1)\z/ || grep({$_ eq $host;} _own_addrs($dev)))
defined $host $host =~ /\A(?:localhost|127\.0\.0\.1)\z/ grep {$_ eq $host;} _own_addrs($dev)
Truth table75%3/4
A && B or C
A= defined $hostB= $host =~ /\A(?:localhost|127\.0\.0\.1)\z/C= grep {$_ eq $host;} _own_addrs($dev)
ABCresult
0XX0
1000
11X1
1011
7085 12 ▶ if ( !$local || ( $out // '' ) ne '-' ) { push @GAPS, join( ' ', 'wget', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (not $local or ($out // "") ne "-") 2 10 12
Condition60%3/5
not $local or ($out // "") ne "-"
l!l&&r!l&&!r
2010
$out // ""
l!l
100
MC/DC0%0/2
not $local or ($out // "") ne "-"
not $local $out
Truth table66%2/3
not(A) or B
A= not $localB= $out
ABresult
1X1
011
000
7086 10 _part('Monitoring');
7087 my ( $body, $st ) = Langertha::Holmgang::Sim::Linux::Monitoring::http( $dev, $post ? 'POST' : 'GET', $port, $path // '/',
7088 10 ▶ sub { my ( $o, $k ) = __PACKAGE__->_run_inner( $dev, $_[0], $ctx ); return ( $o, $k ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$post ? : 2 8 10
Condition50%1/2
$path // "/"
l!l
100
MC/DC0%0/1
$path // "/"
$path
Truth table50%1/2
A
A= $path
Aresult
11
00
7089 0 ▶ if ( !defined $st ) { push @GAPS, join( ' ', 'wget', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 0 10 10
7090 10 ▶ return ( "failed: Connection refused.", 0 ) if !$st;
Branch: 1 branch
BranchTrueFalseTotal
unless $st 1 9 10
7091 9 ▶ return ( $body, 1 ) if $st == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $st == 200 8 1 9
7092 1 my %reason = ( 403 => 'Forbidden', 405 => 'Method Not Allowed', 500 => 'Internal Server Error' );
7093 1 ▶ return ( "ERROR $st: " . ( $reason{$st} // 'Error' ) . '.', 0 );
Condition50%1/2
$reason{$st} // "Error"
l!l
10
MC/DC0%0/1
$reason{$st} // "Error"
$reason{$st}
Truth table50%1/2
A
A= $reason{$st}
Aresult
11
00
7094 }
7095  
7096 # nginx -t|-T (Klammern und Semikolons je Datei pruefen: nginx.conf, conf.d/*.conf, sites-enabled/*),
7097 # -v|-V, -s reload|stop|quit (wie systemctl); ohne nginx-Dienst nicht installiert
7098 6 ▶sub _nginx {
Subroutine _nginx: called CC=29 SCAR=36.6
7099 6 my ( $dev, $av, $ctx ) = @_;
7100 6 ▶ return ( 'bash: nginx: command not found', 0 ) unless ( $dev->{services} || {} )->{nginx};
Branch: 1 branch
BranchTrueFalseTotal
unless ($$dev{"services"} || {})->{"nginx"} 2 4 6
Condition100%2/2
$$dev{'services'} || {}
l!l
51
MC/DC100%1/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table100%2/2
A
A= $$dev{'services'}
Aresult
11
00
7101 4 my %o;
7102 4 my @a = @$av;
7103 4 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 4 4 8
7104 4 my $x = shift @a;
7105 4 ▶ if ( $x eq '-s' ) { $o{s} = shift(@a) // '' }
Branch: 2 branches
BranchTrueFalseTotal
if ($x eq '-s') { } 1 3 4
elsif ($x =~ /\A-([tTvVq]+)\z/) { } 3 0 3
Condition50%1/2
shift @a // ""
l!l
10
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
7106 3 elsif ( $x =~ /\A-([tTvVq]+)\z/ ) { $o{$_} = 1 for split //, $1 }
7107 0 else { push @GAPS, join( ' ', 'nginx', @$av ); return ( '', 0 ) }
7108 }
7109 4 ▶ return ( 'nginx version: nginx/1.22.1', 1 ) if $o{v} && !$o{V};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"v"} and not $o{"V"} 0 4 4
Condition33%1/3
$o{"v"} and not $o{"V"}
!ll&&!rl&&r
400
MC/DC0%0/2
$o{"v"} and not $o{"V"}
$o{"v"} not $o{"V"}
Truth table33%1/3
A and not(B)
A= $o{"v"}B= not $o{"V"}
ABresult
0X0
100
111
7110 4 ▶ return ( "nginx version: nginx/1.22.1\nbuilt with OpenSSL 3.0.11 19 Sep 2023\nTLS SNI support enabled\nconfigure arguments: --with-cc-opt='-g -O2' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=stderr --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --with-http_ssl_module --with-http_v2_module --with-stream=dynamic", 1 ) if $o{V};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"V"} 0 4 4
7111 4 ▶ if ( defined $o{s} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o{"s"}) 1 3 4
7112 1 my %verb = ( reload => 'reload', stop => 'stop', quit => 'stop', reopen => 'reload' );
7113 1 ▶ my $v = $verb{ $o{s} } // return ( qq{nginx: invalid option: "-s $o{s}"}, 0 );
Condition50%1/2
$verb{$o{"s"}} // (return qq[nginx: invalid option: "-s $o{"s"}"], 0)
l!l
10
MC/DC0%0/1
$verb{$o{"s"}} // (return qq[nginx: invalid option: "-s $o{"s"}"], 0)
$verb{$o{"s"}}
Truth table50%1/2
A
A= $verb{$o{"s"}}
Aresult
11
00
7114 1 ▶ return ( qq{nginx: [error] invalid PID number "" in "/run/nginx.pid"}, 0 ) unless $dev->{services}{nginx}{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{"services"}{"nginx"}{"active"} 0 1 1
7115 1 my ( $out, $k ) = _systemctl( $dev, [ $v, 'nginx' ], $ctx );
7116 1 ▶ return ( $k ? '' : $out, $k );
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 1 0 1
7117 }
7118 3 ▶ if ( $o{t} || $o{T} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"t"} or $o{"T"}) 3 0 3
Condition33%1/3
$o{"t"} or $o{"T"}
l!l&&r!l&&!r
300
MC/DC0%0/2
$o{"t"} or $o{"T"}
$o{"t"} $o{"T"}
Truth table33%1/3
A or B
A= $o{"t"}B= $o{"T"}
ABresult
1X1
011
000
7119 6 my @f = grep { defined _file_text( $dev, $_ ) } '/etc/nginx/nginx.conf',
7120 3 ▶ grep { m{\A/etc/nginx/(?:conf\.d/[^/]+\.conf|sites-enabled/[^/]+)\z} } sort keys %{ $dev->{files} || {} };
Condition50%1/2
$$dev{'files'} || {}
l!l
30
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
7121 3 for my $f (@f) {
7122 6 my $t = _file_text( $dev, $f );
7123 6 ( my $c = $t ) =~ s/#[^\n]*//g;
7124 6 $c =~ s/"[^"\n]*"|'[^'\n]*'//g;
7125 6 my ( $depth, $line ) = ( 0, 0 );
7126 6 for my $l ( split /\n/, $c, -1 ) {
7127 25 $line++;
7128 25 for my $ch ( $l =~ /([{}])/g ) {
7129 18 ▶ $depth += $ch eq '{' ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$ch eq '{' ? : 10 8 18
7130 18 ▶ return ( qq~nginx: [emerg] unexpected "}" in $f:$line\nnginx: configuration file /etc/nginx/nginx.conf test failed~, 0 ) if $depth < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $depth < 0 0 18 18
7131 }
7132 25 ( my $st = $l ) =~ s/\A\s+|\s+\z//g;
7133 25 ▶ next if $st eq '' || $st =~ /[;{}]\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $st eq "" or $st =~ /[;{}]\z/ 24 1 25
Condition100%3/3
$st eq "" or $st =~ /[;{}]\z/
l!l&&r!l&&!r
5191
MC/DC100%2/2
$st eq "" or $st =~ /[;{}]\z/
$st eq "" $st =~ /[;{}]\z/
Truth table100%3/3
A or B
A= $st eq ""B= $st =~ /[;{}]\z/
ABresult
1X1
011
000
7134 1 ▶ my $next = ( split /\n/, $c, -1 )[$line] // '';
Condition50%1/2
(split(/\n/, $c, -1))[$line] // ""
l!l
10
MC/DC0%0/1
(split(/\n/, $c, -1))[$line] // ""
(split(/\n/, $c, -1))[$line]
Truth table50%1/2
A
A= (split(/\n/, $c, -1))[$line]
Aresult
11
00
7135 1 ▶ next if $next =~ /\A\s*[{;]/; # Fortsetzung auf der naechsten Zeile
Branch: 1 branch
BranchTrueFalseTotal
if $next =~ /\A\s*[{;]/ 0 1 1
7136 1 return ( qq~nginx: [emerg] directive "~ . ( split /\s+/, $st )[0] . qq~" is not terminated by ";" in $f:$line\nnginx: configuration file /etc/nginx/nginx.conf test failed~, 0 );
7137 }
7138 5 ▶ return ( qq~nginx: [emerg] unexpected end of file, expecting "}" in $f:$line\nnginx: configuration file /etc/nginx/nginx.conf test failed~, 0 ) if $depth;
Branch: 1 branch
BranchTrueFalseTotal
if $depth 1 4 5
7139 }
7140 1 my @out = ( 'nginx: the configuration file /etc/nginx/nginx.conf syntax is ok', 'nginx: configuration file /etc/nginx/nginx.conf test is successful' );
7141 0 ▶ push @out, map { ( "# configuration file $_:", _file_text( $dev, $_ ) =~ s/\n\z//r, '' ) } @f if $o{T};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"T"} 0 1 1
7142 1 return ( join( "\n", @out ), 1 );
7143 }
7144 0 push @GAPS, join( ' ', 'nginx', @$av );
7145 0 return ( '', 0 );
7146 }
7147  
7148  
7149 # diff a b (Normalformat) und diff -u (vereinheitlicht, 3 Zeilen Kontext);
7150 # gleich: leer und Erfolg, verschieden: Ausgabe und Exit 1
7151 12 ▶sub _diff {
Subroutine _diff: called CC=25 SCAR=34.1
7152 12 my ( $dev, $av ) = @_;
7153 12 my @f = grep { !/\A-/ } @$av;
7154 12 my $u = grep {/\A-[a-zA-Z]*u|\A--unified/} @$av;
7155 12 my $r = grep {/\A-[a-zA-Z]*r|\A--recursive/} @$av;
7156 12 my $q = grep {/\A-[a-zA-Z]*q|\A--brief/} @$av;
7157 12 ▶ return ( 'diff: missing operand', 0 ) if @f < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @f < 2 0 12 12
7158 12 my ( $fa, $fb ) = map { _absp( s{(?<=.)/+\z}{}r ) } @f[ 0, 1 ];
7159 12 ▶ if ( _is_dir( $dev, $fa ) && _is_dir( $dev, $fb ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_dir($dev, $fa) and _is_dir($dev, $fb)) 2 10 12
Condition66%2/3
_is_dir($dev, $fa) and _is_dir($dev, $fb)
!ll&&!rl&&r
1002
MC/DC50%1/2
_is_dir($dev, $fa) and _is_dir($dev, $fb)
_is_dir($dev, $fa) _is_dir($dev, $fb)
Truth table66%2/3
A and B
A= _is_dir($dev, $fa)B= _is_dir($dev, $fb)
ABresult
0X0
100
111
7160 2 my %rel;
7161 2 for my $d ( $fa, $fb ) {
7162 4 ▶ my $real = _via_link( $dev, $d ) // ( ref $dev->{files}{$d} eq 'HASH' && defined $dev->{files}{$d}{link} ? _link_target( $d, $dev->{files}{$d}{link} ) : $d );
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'}{$d} eq 'HASH' && defined $$dev{'files'}{$d}{'link'} ? : 0 4 4
Condition33%2/6
_via_link($dev, $d) // (ref $$dev{"files"}{$d} eq "HASH" && defined $$dev{"files"}{$d}{"link"} ? _link_target($d, $$dev{"files"}{$d}{"link"}) : $d)
l!l&&r!l&&!r
040
ref $$dev{"files"}{$d} eq "HASH" and defined $$dev{"files"}{$d}{"link"}
!ll&&!rl&&r
400
MC/DC0%0/3
_via_link($dev, $d) // (ref $$dev{"files"}{$d} eq "HASH" && defined $$dev{"files"}{$d}{"link"} ? _link_target($d, $$dev{"files"}{$d}{"link"}) : $d)
_via_link($dev, $d) ref $$dev{"files"}{$d} eq "HASH" defined $$dev{"files"}{$d}{"link"}
Truth table25%1/4
A // B and C
A= _via_link($dev, $d)B= ref $$dev{"files"}{$d} eq "HASH"C= defined $$dev{"files"}{$d}{"link"}
ABCresult
1XX1
0111
00X0
0100
7163 4 for my $p ( _under( $dev, $real ) ) {
7164 10 my $x = substr $p, length($real) + 1;
7165 10 ▶ next if !$r && $x =~ m{/};
Branch: 1 branch
BranchTrueFalseTotal
if not $r and $x =~ m[/] 3 7 10
Condition100%3/3
not $r and $x =~ m[/]
!ll&&!rl&&r
523
MC/DC100%2/2
not $r and $x =~ m[/]
not $r $x =~ m[/]
Truth table100%3/3
not(A) and B
A= not $rB= $x =~ m[/]
ABresult
0X0
100
111
7166 7 $rel{$x}{$d} = 1;
7167 }
7168 }
7169 2 my @out;
7170 2 for my $x ( sort keys %rel ) {
7171 4 ▶ if ( !$rel{$x}{$fb} || !$rel{$x}{$fa} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rel{$x}{$fb} and $rel{$x}{$fa}) 1 3 4
Condition66%2/3
$rel{$x}{$fb} and $rel{$x}{$fa}
!ll&&!rl&&r
013
MC/DC50%1/2
$rel{$x}{$fb} and $rel{$x}{$fa}
$rel{$x}{$fb} $rel{$x}{$fa}
Truth table66%2/3
A and B
A= $rel{$x}{$fb}B= $rel{$x}{$fa}
ABresult
0X0
100
111
7172 1 ▶ my $d = $rel{$x}{$fa} ? $fa : $fb;
Branch: 1 branch
BranchTrueFalseTotal
$rel{$x}{$fa} ? : 0 1 1
7173 1 my ( $sub, $n ) = $x =~ m{\A(?:(.*)/)?([^/]+)\z};
7174 1 ▶ push @out, "Only in $d" . ( defined $sub ? "/$sub" : '' ) . ": $n";
Branch: 1 branch
BranchTrueFalseTotal
defined $sub ? : 1 0 1
7175 1 next;
7176 }
7177 3 ▶ my @d = _diff_text( [ split /\n/, _file_text( $dev, "$fa/$x" ) // '' ], [ split /\n/, _file_text( $dev, "$fb/$x" ) // '' ], $u, "$fa/$x", "$fb/$x" );
Condition50%2/4
_file_text($dev, "$fa/$x") // ""
l!l
30
_file_text($dev, "$fb/$x") // ""
l!l
30
MC/DC0%0/1
_file_text($dev, "$fa/$x") // ""
_file_text($dev, "$fa/$x")
MC/DC0%0/1
_file_text($dev, "$fb/$x") // ""
_file_text($dev, "$fb/$x")
Truth table50%1/2
A
A= _file_text($dev, "$fa/$x")
Aresult
11
00
Truth table50%1/2
A
A= _file_text($dev, "$fb/$x")
Aresult
11
00
7178 3 ▶ push @out, $q ? "Files $fa/$x and $fb/$x differ" : ( ( $u ? "diff -ru $fa/$x $fb/$x" : "diff -r $fa/$x $fb/$x" ), @d ) if @d;
Branch: 3 branches
BranchTrueFalseTotal
if @d 2 1 3
$q ? : 0 2 2
$u ? : 0 2 2
7179 }
7180 2 return ( join( "\n", @out ), !@out );
7181 }
7182 10 my @t;
7183 10 for my $p ( $fa, $fb ) {
7184 20 my $x = _file_text( $dev, $p );
7185 20 ▶ return ( "diff: $p: No such file or directory", 0 ) if !defined $x;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x 1 19 20
7186 19 push @t, [ split /\n/, $x ];
7187 }
7188 9 my @out = _diff_text( @t, $u, @f[ 0, 1 ] );
7189 9 ▶ @out = ("Files $f[0] and $f[1] differ") if $q && @out;
Branch: 1 branch
BranchTrueFalseTotal
if $q and @out 0 9 9
Condition33%1/3
$q and @out
!ll&&!rl&&r
900
MC/DC0%0/2
$q and @out
$q @out
Truth table33%1/3
A and B
A= $qB= @out
ABresult
0X0
100
111
7190 9 return ( join( "\n", @out ), !@out );
7191 }
7192  
7193 12 ▶sub _diff_text {
Subroutine _diff_text: called CC=14 SCAR=26.4
7194 12 my ( $a, $b, $u, $fa, $fb ) = @_;
7195 12 my @ops = _lcs_ops( $a, $b );
7196 12 ▶ return () if !grep { $_->[0] ne '=' } @ops;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$$_[0] ne "=";} @ops 4 8 12
7197 8 ▶ return _diff_unified( \@ops, $fa, $fb ) if $u;
Branch: 1 branch
BranchTrueFalseTotal
if $u 2 6 8
7198 6 my @out;
7199 6 my ( $i, $j ) = ( 0, 0 );
7200 6 my $k = 0;
7201 6 ▶ while ( $k < @ops ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k < @ops) 28 6 34
7202 28 ▶ if ( $ops[$k][0] eq '=' ) { $i++; $j++; $k++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($ops[$k][0] eq "=") 20 8 28
7203 8 my ( @d, @a );
7204 8 ▶ while ( $k < @ops && $ops[$k][0] ne '=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k < @ops and $ops[$k][0] ne "=") 13 8 21
Condition100%3/3
$k < @ops and $ops[$k][0] ne "="
!ll&&!rl&&r
6213
MC/DC100%2/2
$k < @ops and $ops[$k][0] ne "="
$k < @ops $ops[$k][0] ne "="
Truth table100%3/3
A and B
A= $k < @opsB= $ops[$k][0] ne "="
ABresult
0X0
100
111
7205 13 ▶ push @d, $ops[$k][1] if $ops[$k][0] eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $ops[$k][0] eq "-" 5 8 13
7206 13 ▶ push @a, $ops[$k][1] if $ops[$k][0] eq '+';
Branch: 1 branch
BranchTrueFalseTotal
if $ops[$k][0] eq "+" 8 5 13
7207 13 $k++;
7208 }
7209 8 ▶ my $r = sub { my ( $s, $n ) = @_; $n > 1 ? "$s," . ( $s + $n - 1 ) : $s };
Subroutine __ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$n > 1 ? : 0 13 13
7210 8 ▶ my $code = @d && @a ? $r->( $i + 1, scalar @d ) . 'c' . $r->( $j + 1, scalar @a )
Branch: 2 branches
BranchTrueFalseTotal
@d && @a ? : 5 3 8
@d ? : 0 3 3
Condition66%2/3
@d and @a
!ll&&!rl&&r
305
MC/DC50%1/2
@d and @a
@d @a
Truth table66%2/3
A and B
A= @dB= @a
ABresult
0X0
100
111
7211 : @d ? $r->( $i + 1, scalar @d ) . 'd' . $j
7212 : $i . 'a' . $r->( $j + 1, scalar @a );
7213 8 ▶ push @out, $code, ( map {"< $_"} @d ), ( @d && @a ? '---' : () ), map {"> $_"} @a;
Branch: 1 branch
BranchTrueFalseTotal
@d && @a ? : 5 3 8
Condition66%2/3
@d and @a
!ll&&!rl&&r
305
MC/DC50%1/2
@d and @a
@d @a
Truth table66%2/3
A and B
A= @dB= @a
ABresult
0X0
100
111
7214 8 $i += @d;
7215 8 $j += @a;
7216 }
7217 6 return @out;
7218 }
7219  
7220 12 ▶sub _lcs_ops {
Subroutine _lcs_ops: called CC=14 SCAR=26.4
7221 12 my ( $a, $b ) = @_;
7222 12 my ( $n, $m ) = ( scalar @$a, scalar @$b );
7223 12 my @L;
7224 12 for my $i ( reverse 0 .. $n ) {
7225 63 for my $j ( reverse 0 .. $m ) {
7226 657 ▶ $L[$i][$j] = $i == $n || $j == $m ? 0
Branch: 2 branches
BranchTrueFalseTotal
$i == $n || $j == $m ? : 118 539 657
$$a[$i] eq $$b[$j] ? : 48 491 539
Condition100%3/3
$i == $n or $j == $m
l!l&&r!l&&!r
6751539
MC/DC100%2/2
$i == $n or $j == $m
$i == $n $j == $m
Truth table100%3/3
A or B
A= $i == $nB= $j == $m
ABresult
1X1
011
000
7227 : $a->[$i] eq $b->[$j] ? $L[ $i + 1 ][ $j + 1 ] + 1
7228 : _max( $L[ $i + 1 ][$j], $L[$i][ $j + 1 ] );
7229 }
7230 }
7231 12 my ( $i, $j, @ops ) = ( 0, 0 );
7232 12 ▶ while ( $i < $n || $j < $m ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n or $j < $m) 62 12 74
Condition100%3/3
$i < $n or $j < $m
l!l&&r!l&&!r
54812
MC/DC100%2/2
$i < $n or $j < $m
$i < $n $j < $m
Truth table100%3/3
A or B
A= $i < $nB= $j < $m
ABresult
1X1
011
000
7233 62 ▶ if ( $i < $n && $j < $m && $a->[$i] eq $b->[$j] ) { push @ops, [ '=', $a->[$i] ]; $i++; $j++ }
Branch: 2 branches
BranchTrueFalseTotal
if ($i < $n and $j < $m and $$a[$i] eq $$b[$j]) { } 44 18 62
elsif ($j < $m and $i == $n || $L[$i][$j + 1] > $L[$i + 1][$j]) { } 11 7 18
Condition83%5/6
$i < $n and $j < $m and $$a[$i] eq $$b[$j]
!ll&&!rl&&r
81044
$i < $n and $j < $m
!ll&&!rl&&r
8054
MC/DC66%2/3
$i < $n and $j < $m and $$a[$i] eq $$b[$j]
$i < $n $j < $m $$a[$i] eq $$b[$j]
Truth table75%3/4
A and B and C
A= $i < $nB= $j < $mC= $$a[$i] eq $$b[$j]
ABCresult
0XX0
10X0
1100
1111
7234 11 ▶ elsif ( $j < $m && ( $i == $n || $L[$i][ $j + 1 ] > $L[ $i + 1 ][$j] ) ) { push @ops, [ '+', $b->[ $j++ ] ] }
Condition83%5/6
$j < $m and $i == $n || $L[$i][$j + 1] > $L[$i + 1][$j]
!ll&&!rl&&r
0711
$i == $n or $L[$i][$j + 1] > $L[$i + 1][$j]
l!l&&r!l&&!r
837
MC/DC66%2/3
$j < $m and $i == $n || $L[$i][$j + 1] > $L[$i + 1][$j]
$j < $m $i == $n $L[$i][$j + 1] > $L[$i + 1][$j]
Truth table75%3/4
A and B or C
A= $j < $mB= $i == $nC= $L[$i][$j + 1] > $L[$i + 1][$j]
ABCresult
0XX0
1000
11X1
1011
7235 7 else { push @ops, [ '-', $a->[ $i++ ] ] }
7236 }
7237 12 return @ops;
7238 }
7239  
7240 493 ▶sub _max { $_[0] > $_[1] ? $_[0] : $_[1] }
Subroutine _max: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] > $_[1] ? : 228 265 493
7241  
7242 2 ▶sub _diff_unified {
Subroutine _diff_unified: called CC=12 SCAR=26.5
7243 2 my ( $ops, $fa, $fb ) = @_;
7244 2 my @out = ( "--- $fa", "+++ $fb" );
7245 2 my @chg = grep { $ops->[$_][0] ne '=' } 0 .. $#$ops;
7246 # Bereiche: Aenderungen, die hoechstens 6 Zeilen auseinander liegen, gehoeren zusammen
7247 2 my @h;
7248 2 for my $c (@chg) {
7249 5 ▶ if ( @h && $c - $h[-1][1] <= 7 ) { $h[-1][1] = $c }
Branch: 1 branch
BranchTrueFalseTotal
if (@h and $c - $h[-1][1] <= 7) { } 3 2 5
Condition66%2/3
@h and $c - $h[-1][1] <= 7
!ll&&!rl&&r
203
MC/DC50%1/2
@h and $c - $h[-1][1] <= 7
@h $c - $h[-1][1] <= 7
Truth table66%2/3
A and B
A= @hB= $c - $h[-1][1] <= 7
ABresult
0X0
100
111
7250 2 else { push @h, [ $c, $c ] }
7251 }
7252 2 for my $h (@h) {
7253 2 my $s = _max( 0, $h->[0] - 3 );
7254 2 ▶ my $e = $h->[1] + 3 > $#$ops ? $#$ops : $h->[1] + 3;
Branch: 1 branch
BranchTrueFalseTotal
$$h[1] + 3 > $ops->$#* ? : 2 0 2
7255 2 my ( $ia, $ib ) = ( 1, 1 );
7256 0 ▶ for my $k ( 0 .. $s - 1 ) { $ia++ if $ops->[$k][0] ne '+'; $ib++ if $ops->[$k][0] ne '-' }
Branch: 2 branches
BranchTrueFalseTotal
if $$ops[$k][0] ne "+" 0 0 0
if $$ops[$k][0] ne "-" 0 0 0
7257 2 ▶ my @l = map { ( $_->[0] eq '=' ? ' ' : $_->[0] ) . $_->[1] } @$ops[ $s .. $e ];
Branch: 1 branch
BranchTrueFalseTotal
$$_[0] eq '=' ? : 3 5 8
7258 2 my $na = grep { !/\A\+/ } @l;
7259 2 my $nb = grep { !/\A-/ } @l;
7260 2 ▶ push @out, sprintf( '@@ -%d,%d +%d,%d @@', $na ? $ia : $ia - 1, $na, $nb ? $ib : $ib - 1, $nb ), @l;
Branch: 2 branches
BranchTrueFalseTotal
$na ? : 2 0 2
$nb ? : 2 0 2
7261 }
7262 2 return @out;
7263 }
7264  
7265 1 ▶sub _cmp {
Subroutine _cmp: called CC=7 SCAR=20.1
7266 1 my ( $dev, $av ) = @_;
7267 1 my @f = grep { !/\A-/ } @$av;
7268 1 my @t = map { _file_text( $dev, $_ ) } @f[ 0, 1 ];
7269 1 ▶ for ( 0, 1 ) { return ( "cmp: $f[$_]: No such file or directory", 0 ) if !defined $t[$_] }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t[$_] 0 2 2
7270 1 ▶ return ( '', 1 ) if $t[0] eq $t[1];
Branch: 1 branch
BranchTrueFalseTotal
if $t[0] eq $t[1] 0 1 1
7271 1 my $i = 0;
7272 1 ▶ $i++ while $i < length $t[0] && $i < length $t[1] && substr( $t[0], $i, 1 ) eq substr( $t[1], $i, 1 );
Branch: 1 branch
BranchTrueFalseTotal
$i < length $t[0] and $i < length $t[1] and substr($t[0], $i, 1) eq substr($t[1], $i, 1) and do { ++$i } 5 1 6
Condition50%3/6
$i < length $t[0] and $i < length $t[1] and substr($t[0], $i, 1) eq substr($t[1], $i, 1)
!ll&&!rl&&r
015
$i < length $t[0] and $i < length $t[1]
!ll&&!rl&&r
006
MC/DC33%1/3
$i < length $t[0] and $i < length $t[1] and substr($t[0], $i, 1) eq substr($t[1], $i, 1)
$i < length $t[0] $i < length $t[1] substr($t[0], $i, 1) eq substr($t[1], $i, 1)
Truth table50%2/4
A and B and C
A= $i < length $t[0]B= $i < length $t[1]C= substr($t[0], $i, 1) eq substr($t[1], $i, 1)
ABCresult
0XX0
10X0
1100
1111
7273 1 my $line = 1 + ( () = substr( $t[0], 0, $i ) =~ /\n/g );
7274 1 return ( "$f[0] $f[1] differ: byte " . ( $i + 1 ) . ", line $line", 0 );
7275 }
7276  
7277 7 ▶sub _readlink {
Subroutine _readlink: called CC=10 SCAR=23.3
7278 7 my ( $dev, $av ) = @_;
7279 7 my $canon = grep {/\A-\w*[fem]/} @$av;
7280 7 my @out;
7281 7 for my $p ( grep { !/\A-/ } @$av ) {
7282 7 ( my $q = $p ) =~ s{(?<=.)/+\z}{};
7283 7 ▶ my $e = ref $dev->{files} eq 'HASH' ? $dev->{files}{$q} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'} eq 'HASH' ? : 7 0 7
7284 7 ▶ if ( !$canon ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($canon) 3 4 7
7285 3 ▶ return ( '', 0 ) unless ref $e eq 'HASH' && defined $e->{link}; # keine Verknuepfung: Exit 1
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" and defined $$e{"link"} 1 2 3
Condition66%2/3
ref $e eq "HASH" and defined $$e{"link"}
!ll&&!rl&&r
102
MC/DC50%1/2
ref $e eq "HASH" and defined $$e{"link"}
ref $e eq "HASH" defined $$e{"link"}
Truth table66%2/3
A and B
A= ref $e eq "HASH"B= defined $$e{"link"}
ABresult
0X0
100
111
7286 2 push @out, $e->{link};
7287 2 next;
7288 }
7289 4 my $t = $q;
7290 4 for ( 1 .. 6 ) {
7291 7 ▶ $t = _via_link( $dev, $t ) // $t;
Condition33%1/3
_via_link($dev, $t) // $t
l!l&&r!l&&!r
070
MC/DC0%0/2
_via_link($dev, $t) // $t
_via_link($dev, $t) $t
Truth table33%1/3
A // B
A= _via_link($dev, $t)B= $t
ABresult
1X1
011
000
7292 7 my $x = $dev->{files}{$t};
7293 7 ▶ last unless ref $x eq 'HASH' && defined $x->{link};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x eq "HASH" and defined $$x{"link"} 4 3 7
Condition66%2/3
ref $x eq "HASH" and defined $$x{"link"}
!ll&&!rl&&r
403
MC/DC50%1/2
ref $x eq "HASH" and defined $$x{"link"}
ref $x eq "HASH" defined $$x{"link"}
Truth table66%2/3
A and B
A= ref $x eq "HASH"B= defined $$x{"link"}
ABresult
0X0
100
111
7294 3 $t = _link_target( $t, $x->{link} );
7295 }
7296 4 push @out, $t;
7297 }
7298 6 return ( join( "\n", @out ), 1 );
7299 }
7300  
7301 # --- systemd ----------------------------------------------------------------------
7302  
7303 # Startbedingungen eines Dienstes (needs): erste nicht erfuellte oder undef.
7304 # { can: { user, read|write|exec: pfad } } Benutzer darf die Datei …
7305 # { free: { mount, min } } mindestens so viel frei
7306 # { state: [pfad im Geraet], <Erwartungen> } Zustand (wie Regeln)
7307 # Jede Bedingung traegt log: [ Zeilen ] fuer das Journal beim Scheitern.
7308 116 ▶sub _failing_need {
Subroutine _failing_need: called CC=25 SCAR=34.3
7309 116 my ( $dev, $svc ) = @_;
7310 # ohne Benutzer in der Bedingung: User= der geladenen Unit, sonst user des Dienstes
7311 116 ▶ my ($uu) = ( $svc->{unit_loaded} // '' ) =~ /^\s*User\s*=\s*(\S+)/m;
Condition100%2/2
$$svc{"unit_loaded"} // ""
l!l
4670
MC/DC100%1/1
$$svc{"unit_loaded"} // ""
$$svc{"unit_loaded"}
Truth table100%2/2
A
A= $$svc{"unit_loaded"}
Aresult
11
00
7312 116 ▶ for my $n ( @{ $svc->{needs} || [] } ) {
Condition100%2/2
$$svc{'needs'} || []
l!l
3581
MC/DC100%1/1
$$svc{'needs'} || []
$$svc{'needs'}
Truth table100%2/2
A
A= $$svc{'needs'}
Aresult
11
00
7313 35 ▶ if ( my $c = $n->{can} ) {
Branch: 4 branches
BranchTrueFalseTotal
if (my $c = $$n{'can'}) { } 6 29 35
elsif (my $f = $$n{'free'}) { } 9 20 29
elsif (my $want = $$n{'env'}) { } 6 14 20
elsif (exists $$n{'state'}) { } 14 0 14
7314 6 my ($what) = grep { exists $c->{$_} } qw( read write exec );
7315 6 ▶ return $n unless _can( $dev, $c->{user} // $uu // $svc->{user} // 'root', $c->{$what}, substr( $what, 0, 1 ) eq 'e' ? 'x' : substr( $what, 0, 1 ) );
Branch: 2 branches
BranchTrueFalseTotal
unless _can($dev, (($$c{"user"} // $uu) // $$svc{"user"}) // "root", $$c{$what}, substr($what, 0, 1) eq "e" ? "x" : substr($what, 0, 1)) 3 3 6
substr($what, 0, 1) eq 'e' ? : 0 6 6
Condition37%3/8
(($$c{"user"} // $uu) // $$svc{"user"}) // "root"
l!l
60
($$c{"user"} // $uu) // $$svc{"user"}
l!l&&r!l&&!r
600
$$c{"user"} // $uu
l!l&&r!l&&!r
600
MC/DC0%0/3
(($$c{"user"} // $uu) // $$svc{"user"}) // "root"
$$c{"user"} $uu $$svc{"user"}
Truth table25%1/4
A // B // C
A= $$c{"user"}B= $uuC= $$svc{"user"}
ABCresult
1XX1
01X1
0011
0000
7316 }
7317 elsif ( my $f = $n->{free} ) {
7318 9 ▶ my $free = _free( $dev, $f->{mount} // '/' ) // 0;
Condition50%2/4
_free($dev, $$f{"mount"} // "/") // 0
l!l
90
$$f{"mount"} // "/"
l!l
90
MC/DC0%0/1
_free($dev, $$f{"mount"} // "/") // 0
_free($dev, $$f{"mount"} // "/")
MC/DC0%0/1
$$f{"mount"} // "/"
$$f{"mount"}
Truth table50%1/2
A
A= _free($dev, $$f{"mount"} // "/")
Aresult
11
00
Truth table50%1/2
A
A= $$f{"mount"}
Aresult
11
00
7319 9 ▶ return $n if $free < _bytes( $f->{min} );
Branch: 1 branch
BranchTrueFalseTotal
if $free < _bytes($$f{"min"}) 3 6 9
7320 }
7321 elsif ( my $want = $n->{env} ) { # Umgebung des Prozesses: VAR => Muster
7322 6 my ( $env, $miss ) = _unit_env( $dev, $svc );
7323 6 ▶ if ( defined $miss ) { # EnvironmentFile ohne - fehlt: systemd startet den Prozess gar nicht
Branch: 1 branch
BranchTrueFalseTotal
if (defined $miss) 2 4 6
7324 2 ▶ my $u = ( $svc->{unit} // 'unit.service' ) =~ s{.*/}{}r;
Condition50%1/2
$$svc{"unit"} // "unit.service"
l!l
20
MC/DC0%0/1
$$svc{"unit"} // "unit.service"
$$svc{"unit"}
Truth table50%1/2
A
A= $$svc{"unit"}
Aresult
11
00
7325 2 ▶ my $h = $dev->{hostname} // ( $CTX || {} )->{host} // 'localhost';
Condition42%3/7
($$dev{"hostname"} // ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"}) // "localhost"
l!l
20
$$dev{"hostname"} // ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"}
l!l&&r!l&&!r
020
$Langertha::Holmgang::Sim::Linux::CTX || {}
l!l
20
MC/DC0%0/2
($$dev{"hostname"} // ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"}) // "localhost"
$$dev{"hostname"} $Langertha::Holmgang::Sim::Linux::CTX
Truth table33%1/3
A // B
A= $$dev{"hostname"}B= $Langertha::Holmgang::Sim::Linux::CTX
ABresult
1X1
011
000
7326 2 my $c = _clock($dev);
7327 2 return { log => [ "$c:03 $h systemd[1]: $u: Failed to load environment files: No such file or directory",
7328 "$c:03 $h systemd[1]: $u: Failed to spawn 'start' task: No such file or directory" ] };
7329 }
7330 4 ▶ for my $k ( sort keys %$want ) { return $n unless defined $env->{$k} && $env->{$k} =~ /$want->{$k}/ }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$env{$k} and $$env{$k} =~ /$$want{$k}/ 2 2 4
Condition66%2/3
defined $$env{$k} and $$env{$k} =~ /$$want{$k}/
!ll&&!rl&&r
202
MC/DC50%1/2
defined $$env{$k} and $$env{$k} =~ /$$want{$k}/
defined $$env{$k} $$env{$k} =~ /$$want{$k}/
Truth table66%2/3
A and B
A= defined $$env{$k}B= $$env{$k} =~ /$$want{$k}/
ABresult
0X0
100
111
7331 }
7332 elsif ( exists $n->{state} ) {
7333 14 my %c = %$n;
7334 14 delete @c{qw( state log )};
7335 14 my ($ok) = _condition( $dev, { %c, path => $n->{state} } );
7336 14 ▶ return $n unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 7 7 14
7337 }
7338 }
7339 99 return undef;
7340 }
7341  
7342 # Umgebung eines Dienstes aus der geladenen Unit: Environment=, dann EnvironmentFile= (in dieser
7343 # Reihenfolge, die Datei gewinnt; Zeilen VAR=wert, Anfuehrungszeichen weg, Kommentare und
7344 # Zeilen ohne VAR= uebergangen; ein vorangestelltes export ist erlaubt). ( \%env, $fehlende_datei )
7345 6 ▶sub _unit_env {
Subroutine _unit_env: called CC=12 SCAR=25.2
7346 6 my ( $dev, $svc ) = @_;
7347 6 ▶ my $p = _unit_props( $svc->{unit_loaded} // '' );
Condition50%1/2
$$svc{"unit_loaded"} // ""
l!l
60
MC/DC0%0/1
$$svc{"unit_loaded"} // ""
$$svc{"unit_loaded"}
Truth table50%1/2
A
A= $$svc{"unit_loaded"}
Aresult
11
00
7348 6 ▶ my %env = %{ $p->{Environment} || {} };
Condition100%2/2
$$p{'Environment'} || {}
l!l
15
MC/DC100%1/1
$$p{'Environment'} || {}
$$p{'Environment'}
Truth table100%2/2
A
A= $$p{'Environment'}
Aresult
11
00
7349 6 ▶ for my $f ( @{ $p->{EnvironmentFile} || [] } ) {
Condition100%2/2
$$p{'EnvironmentFile'} || []
l!l
33
MC/DC100%1/1
$$p{'EnvironmentFile'} || []
$$p{'EnvironmentFile'}
Truth table100%2/2
A
A= $$p{'EnvironmentFile'}
Aresult
11
00
7350 3 my $opt = $f =~ s/\A-//;
7351 3 my $t = _file_text( $dev, $f );
7352 0 ▶ if ( !defined $t ) { return ( \%env, $f ) unless $opt; next }
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $t) 2 1 3
unless $opt 2 0 2
7353 1 for my $l ( split /\n/, $t ) {
7354 3 ▶ next if $l =~ /\A\s*(?:[#;]|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\A\s*(?:[#;]|\z)/ 1 2 3
7355 2 ▶ my ( $k, $v ) = $l =~ /\A\s*(?:export\s+)?([A-Za-z_]\w*)=(.*?)\s*\z/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $l =~ /\A\s*(?:export\s+)?([A-Za-z_]\w*)=(.*?)\s*\z/ or next 2 0 2
7356 2 ▶ $v = $1 if $v =~ /\A"(.*)"\z/ || $v =~ /\A'(.*)'\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /\A"(.*)"\z/ or $v =~ /\A'(.*)'\z/ 1 1 2
Condition66%2/3
$v =~ /\A"(.*)"\z/ or $v =~ /\A'(.*)'\z/
l!l&&r!l&&!r
101
MC/DC50%1/2
$v =~ /\A"(.*)"\z/ or $v =~ /\A'(.*)'\z/
$v =~ /\A"(.*)"\z/ $v =~ /\A'(.*)'\z/
Truth table66%2/3
A or B
A= $v =~ /\A"(.*)"\z/B= $v =~ /\A'(.*)'\z/
ABresult
1X1
011
000
7357 2 $env{$k} = $v;
7358 }
7359 }
7360 4 return ( \%env, undef );
7361 }
7362  
7363 # Konten und Gruppen eines frischen Debian 12 (und gaengiger Pakete), die kein Fall nennen muss
7364 82 our %BASE_USERS = map { $_ => 1 } qw( root daemon bin sys sync games man lp mail news uucp proxy www-data backup list irc _apt
7365 nobody systemd-network systemd-timesync messagebus sshd postgres redis mysql prometheus bind _chrony postfix nginx );
7366 82 our %BASE_GROUPS = map { $_ => 1 } qw( root daemon bin sys adm tty disk lp mail news uucp man proxy kmem dialout fax voice cdrom
7367 floppy tape sudo audio dip www-data backup operator list irc src shadow utmp video sasl plugdev staff games users nogroup
7368 systemd-journal systemd-network systemd-timesync input sgx kvm render crontab messagebus ssl-cert postgres redis mysql
7369 prometheus bind _chrony postfix postdrop nginx );
7370  
7371 # User=/Group= der Unit, die es auf dem Geraet nicht gibt: 'user' bzw. 'group' oder undef. Nur
7372 # auf Geraeten mit check_accounts (der Fall nennt alle Konten); Nummern und Grundkonten zaehlen
7373 # immer als vorhanden.
7374 79 ▶sub _cred_missing {
Subroutine _cred_missing: called CC=13 SCAR=26.3
7375 79 my ( $dev, $u, $g ) = @_;
7376 79 ▶ return undef unless $dev->{check_accounts};
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{"check_accounts"} 67 12 79
7377 12 ▶ return 'user' if defined $u && $u !~ /\A\d+\z/ && !$BASE_USERS{$u} && !$dev->{users}{$u};
Branch: 1 branch
BranchTrueFalseTotal
if defined $u and not $u =~ /\A\d+\z/ and not $Langertha::Holmgang::Sim::Linux::BASE_USERS{$u} and not $$dev{"users"}{$u} 1 11 12
Condition88%8/9
defined $u and not $u =~ /\A\d+\z/ and not $Langertha::Holmgang::Sim::Linux::BASE_USERS{$u} and not $$dev{"users"}{$u}
!ll&&!rl&&r
921
defined $u and not $u =~ /\A\d+\z/ and not $Langertha::Holmgang::Sim::Linux::BASE_USERS{$u}
!ll&&!rl&&r
813
defined $u and not $u =~ /\A\d+\z/
!ll&&!rl&&r
804
MC/DC75%3/4
defined $u and not $u =~ /\A\d+\z/ and not $Langertha::Holmgang::Sim::Linux::BASE_USERS{$u} and not $$dev{"users"}{$u}
defined $u not $u =~ /\A\d+\z/ not $Langertha::Holmgang::Sim::Linux::BASE_USERS{$u} not $$dev{"users"}{$u}
Truth table80%4/5
A and not(B) and not(C) and not(D)
A= defined $uB= not $u =~ /\A\d+\z/C= not $Langertha::Holmgang::Sim::Linux::BASE_USERS{$u}D= not $$dev{"users"}{$u}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
7378 return 'group' if defined $g && $g !~ /\A\d+\z/ && !$BASE_GROUPS{$g} && !( $dev->{groups} || {} )->{$g}
7379 11 ▶ && !grep { grep { $_ eq $g } @{ $_->{groups} || [] } } values %{ $dev->{users} };
Branch: 1 branch
BranchTrueFalseTotal
if defined $g and not $g =~ /\A\d+\z/ and not $Langertha::Holmgang::Sim::Linux::BASE_GROUPS{$g} and not +($$dev{"groups"} || {})->{$g} and not grep({grep {$_ eq $g;} @{$$_{"groups"} or [];};} values %{$$dev{"users"};}) 1 10 11
Condition62%10/16
defined $g and not $g =~ /\A\d+\z/ and not $Langertha::Holmgang::Sim::Linux::BASE_GROUPS{$g} and not +($$dev{"groups"} || {})->{$g} and not grep({grep {$_ eq $g;} @{$$_{"groups"} or [];};} values %{$$dev{"users"};})
!ll&&!rl&&r
1001
defined $g and not $g =~ /\A\d+\z/ and not $Langertha::Holmgang::Sim::Linux::BASE_GROUPS{$g} and not +($$dev{"groups"} || {})->{$g}
!ll&&!rl&&r
1001
defined $g and not $g =~ /\A\d+\z/ and not $Langertha::Holmgang::Sim::Linux::BASE_GROUPS{$g}
!ll&&!rl&&r
1001
defined $g and not $g =~ /\A\d+\z/
!ll&&!rl&&r
1001
$$dev{'groups'} || {}
l!l
10
$$_{'groups'} || []
l!l
40
MC/DC0%0/5
defined $g and not $g =~ /\A\d+\z/ and not $Langertha::Holmgang::Sim::Linux::BASE_GROUPS{$g} and not +($$dev{"groups"} || {})->{$g} and not grep({grep {$_ eq $g;} @{$$_{"groups"} or [];};} values %{$$dev{"users"};})
defined $g not $g =~ /\A\d+\z/ not $Langertha::Holmgang::Sim::Linux::BASE_GROUPS{$g} $$dev{'groups'} not grep({grep {$_ eq $g;} @{$$_{"groups"} or [];};} values %{$$dev{"users"};})
MC/DC0%0/1
$$_{'groups'} || []
$$_{'groups'}
Truth table16%1/6
A and not(B) and not(C) and not(D) and not(E)
A= defined $gB= not $g =~ /\A\d+\z/C= not $Langertha::Holmgang::Sim::Linux::BASE_GROUPS{$g}D= $$dev{'groups'}E= not grep({grep {$_ eq $g;} @{$$_{"groups"} or [];};} values %{$$dev{"users"};})
ABCDEresult
0XXXX0
10XXX0
110XX0
1111X0
111000
111011
Truth table50%1/2
A
A= $$_{'groups'}
Aresult
11
00
7380 10 return undef;
7381 }
7382  
7383 379 ▶sub _unit_file { my ( $n, $svc ) = @_; return $svc->{unit} // '/lib/systemd/system/' . _uname($n) }
Subroutine _unit_file: called CC=2 SCAR=6.9
Condition100%2/2
$$svc{"unit"} // '/lib/systemd/system/' . _uname($n)
l!l
158221
MC/DC100%1/1
$$svc{"unit"} // '/lib/systemd/system/' . _uname($n)
$$svc{"unit"}
Truth table100%2/2
A
A= $$svc{"unit"}
Aresult
11
00
7384  
7385 # Voller Unit-Name: "app" -> "app.service", "backup.timer" bleibt
7386 996 ▶sub _uname { my ($n) = @_; return $n =~ /\.(?:timer|socket|path|target|mount)\z/ ? $n : "$n.service" }
Subroutine _uname: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$n =~ /\.(?:timer|socket|path|target|mount)\z/ ? : 40 956 996
7387  
7388 # Text der Unit, wie systemd sie geladen hat (sonst Datei und Drop-ins)
7389 203 ▶sub _unit_loaded_text {
Subroutine _unit_loaded_text: called CC=2 SCAR=6.9
7390 203 my ( $dev, $n, $svc ) = @_;
7391 203 ▶ return $svc->{unit_loaded} // _unit_text( $dev, $n, $svc );
Condition100%3/3
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
l!l&&r!l&&!r
932585
MC/DC100%2/2
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
$$svc{"unit_loaded"} _unit_text($dev, $n, $svc)
Truth table100%3/3
A // B
A= $$svc{"unit_loaded"}B= _unit_text($dev, $n, $svc)
ABresult
1X1
011
000
7392 }
7393  
7394 # Ganze Unit ohne [Install]: "static", enable/disable wirken nicht
7395 58 ▶sub _static {
Subroutine _static: called CC=4 SCAR=13.9
7396 58 my ( $dev, $n, $svc ) = @_;
7397 58 my $t = _unit_loaded_text( $dev, $n, $svc );
7398 58 ▶ return defined $t && $t =~ /^\[Unit\]/m && $t !~ /^\[Install\]/m ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $t && $t =~ /^\[Unit\]/m && !($t =~ /^\[Install\]/m) ? : 13 45 58
Condition100%6/6
defined $t and $t =~ /^\[Unit\]/m and not $t =~ /^\[Install\]/m
!ll&&!rl&&r
40513
defined $t and $t =~ /^\[Unit\]/m
!ll&&!rl&&r
31918
MC/DC100%3/3
defined $t and $t =~ /^\[Unit\]/m and not $t =~ /^\[Install\]/m
defined $t $t =~ /^\[Unit\]/m not $t =~ /^\[Install\]/m
Truth table100%4/4
A and B and not(C)
A= defined $tB= $t =~ /^\[Unit\]/mC= not $t =~ /^\[Install\]/m
ABCresult
0XX0
10X0
1100
1111
7399 }
7400  
7401 69 ▶sub _oneshot {
Subroutine _oneshot: called CC=4 SCAR=13.9
7402 69 my ( $dev, $n, $svc ) = @_;
7403 69 ▶ my $t = _unit_loaded_text( $dev, $n, $svc ) // '';
Condition100%2/2
_unit_loaded_text($dev, $n, $svc) // ""
l!l
3831
MC/DC100%1/1
_unit_loaded_text($dev, $n, $svc) // ""
_unit_loaded_text($dev, $n, $svc)
Truth table100%2/2
A
A= _unit_loaded_text($dev, $n, $svc)
Aresult
11
00
7404 69 ▶ return $t =~ /^\s*Type\s*=\s*oneshot\s*$/m && $t !~ /^\s*RemainAfterExit\s*=\s*(?:yes|true|1|on)\s*$/m ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$t =~ /^\s*Type\s*=\s*oneshot\s*$/m && !($t =~ /^\s*RemainAfterExit\s*=\s*(?:yes|true|1|on)\s*$/m) ? : 7 62 69
Condition66%2/3
$t =~ /^\s*Type\s*=\s*oneshot\s*$/m and not $t =~ /^\s*RemainAfterExit\s*=\s*(?:yes|true|1|on)\s*$/m
!ll&&!rl&&r
6207
MC/DC50%1/2
$t =~ /^\s*Type\s*=\s*oneshot\s*$/m and not $t =~ /^\s*RemainAfterExit\s*=\s*(?:yes|true|1|on)\s*$/m
$t =~ /^\s*Type\s*=\s*oneshot\s*$/m not $t =~ /^\s*RemainAfterExit\s*=\s*(?:yes|true|1|on)\s*$/m
Truth table66%2/3
A and not(B)
A= $t =~ /^\s*Type\s*=\s*oneshot\s*$/mB= not $t =~ /^\s*RemainAfterExit\s*=\s*(?:yes|true|1|on)\s*$/m
ABresult
0X0
100
111
7405 }
7406  
7407 # Timer aus dem geladenen Text: gueltige und ungueltige OnCalendar=, andere
7408 # Ausloeser, ausgeloeste Unit.
7409 32 ▶sub _timer_info {
Subroutine _timer_info: called CC=9 SCAR=22.0
7410 32 my ( $dev, $n, $svc ) = @_;
7411 32 require Langertha::Holmgang::Sim::Linux::Calendar;
7412 32 ▶ my $t = _unit_loaded_text( $dev, $n, $svc ) // '';
Condition50%1/2
_unit_loaded_text($dev, $n, $svc) // ""
l!l
320
MC/DC0%0/1
_unit_loaded_text($dev, $n, $svc) // ""
_unit_loaded_text($dev, $n, $svc)
Truth table50%1/2
A
A= _unit_loaded_text($dev, $n, $svc)
Aresult
11
00
7413 32 my ( @cal, @bad, $other );
7414 32 my $line = 0;
7415 32 for my $l ( split /\n/, $t ) {
7416 265 $line++;
7417 265 ▶ if ( $l =~ /^\s*OnCalendar\s*=\s*(.*?)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /^\s*OnCalendar\s*=\s*(.*?)\s*$/) 40 225 265
7418 40 my $e = $1;
7419 # leere Zuweisung setzt die Liste zurueck (systemd.timer(5), z. B. im Drop-in)
7420 40 ▶ if ( $e eq '' ) { @cal = (); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq "") 4 36 40
7421 36 my $c = Langertha::Holmgang::Sim::Linux::Calendar::parse($e);
7422 36 ▶ if ($c) { push @cal, $c } else { push @bad, [ $line, $e ] }
Branch: 1 branch
BranchTrueFalseTotal
if ($c) { } 31 5 36
7423 }
7424 261 ▶ $other = 1 if $l =~ /^\s*On(?:Boot|Startup|Active|UnitActive|UnitInactive)Sec\s*=\s*\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /^\s*On(?:Boot|Startup|Active|UnitActive|UnitInactive)Sec\s*=\s*\S/ 0 261 261
7425 }
7426 32 ( my $base = $n ) =~ s/\.timer\z//;
7427 32 my ($unit) = $t =~ /^\s*Unit\s*=\s*(\S+)\s*$/m;
7428 32 ▶ return { cal => \@cal, bad => \@bad, other => $other, activates => $unit // "$base.service",
Branch: 1 branch
BranchTrueFalseTotal
$t =~ /^\s*Persistent\s*=\s*(?:yes|true|1|on)\s*$/m ? : 18 14 32
Condition100%2/2
$unit // "$base.service"
l!l
923
MC/DC100%1/1
$unit // "$base.service"
$unit
Truth table100%2/2
A
A= $unit
Aresult
11
00
7429 persistent => $t =~ /^\s*Persistent\s*=\s*(?:yes|true|1|on)\s*$/m ? 1 : 0 };
7430 }
7431  
7432 # Abgeleitete Felder eines Timers im Zustand (fuer Regeln): Normalformen der
7433 # gueltigen OnCalendar= und die ausgeloeste Unit. Nur wenn sich die geladene
7434 # Unit aendert.
7435 33 ▶sub _timer_derive {
Subroutine _timer_derive: called CC=2 SCAR=6.9
7436 33 my ( $dev, $n, $svc ) = @_;
7437 33 ▶ return unless $n =~ /\.timer\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $n =~ /\.timer\z/ 25 8 33
7438 8 my $i = _timer_info( $dev, $n, $svc );
7439 8 $svc->{triggers} = [ map { $_->{normalized} } @{ $i->{cal} } ];
7440 8 $svc->{activates} = $i->{activates};
7441 8 return;
7442 }
7443  
7444 # Unit aus ihrer Datei laden, wenn systemd sie noch nicht kennt (wie beim ersten
7445 # Zugriff auf eine neue Unit-Datei)
7446 22 ▶sub _load_unit {
Subroutine _load_unit: called CC=5 SCAR=16.1
7447 22 my ( $dev, $n, $peek ) = @_;
7448 22 for my $dir (qw( /etc/systemd/system /lib/systemd/system )) {
7449 28 my $p = "$dir/" . _uname($n);
7450 28 my $t = _file_text( $dev, $p );
7451 28 ▶ next unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 12 16 28
7452 16 my ($desc) = $t =~ /^\s*Description\s*=\s*(.*?)\s*$/m;
7453 16 ▶ my $svc = { unit => $p, unit_loaded => $t, enabled => JSON::MaybeXS::false(), active => JSON::MaybeXS::false(),
Branch: 1 branch
BranchTrueFalseTotal
defined $desc ? : 11 5 16
7454 ( defined $desc ? ( description => $desc ) : () ) };
7455 16 _timer_derive( $dev, $n, $svc );
7456 16 ▶ $dev->{services}{$n} = $svc unless $peek; # Lesen (status, is-*) laedt nur zur Ansicht
Branch: 1 branch
BranchTrueFalseTotal
unless $peek 12 4 16
7457 16 return $svc;
7458 }
7459 6 return undef;
7460 }
7461  
7462 # Drop-ins <unit>.service.d/*.conf: gleichnamige unter /etc ueberdecken /run und /lib,
7463 # gelesen nach Namen sortiert; ein Link auf /dev/null schaltet einen ab
7464 367 ▶sub _dropins {
Subroutine _dropins: called CC=7 SCAR=19.7
7465 367 my ( $dev, $n ) = @_;
7466 367 my $u = _uname($n);
7467 367 my %by;
7468 367 for my $base (qw( /lib/systemd/system /usr/lib/systemd/system /run/systemd/system /etc/systemd/system )) {
7469 1468 for my $p ( _under( $dev, "$base/$u.d" ) ) {
7470 52 ▶ next unless $p =~ m{\A\Q$base/$u.d/\E([^/]+\.conf)\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $p =~ m[\A\Q$base/$u.d/\E([^/]+\.conf)\z] 0 52 52
7471 52 my $e = $dev->{files}{$p};
7472 52 ▶ $by{$1} = ref $e eq 'HASH' && ( $e->{link} // '' ) eq '/dev/null' ? undef : $p;
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' && ($$e{'link'} // '') eq '/dev/null' ? : 3 49 52
Condition60%3/5
ref $e eq "HASH" and ($$e{"link"} // "") eq "/dev/null"
!ll&&!rl&&r
4903
$$e{"link"} // ""
l!l
30
MC/DC50%1/2
ref $e eq "HASH" and ($$e{"link"} // "") eq "/dev/null"
ref $e eq "HASH" $$e{"link"}
Truth table66%2/3
A and B
A= ref $e eq "HASH"B= $$e{"link"}
ABresult
0X0
100
111
7473 }
7474 }
7475 367 return map { $by{$_} } grep { defined $by{$_} } sort keys %by;
7476 }
7477  
7478 # Unit, wie systemd sie liest: Hauptdatei, dann die Drop-ins (mit Kopfzeile); undef ohne beides
7479 325 ▶sub _unit_text {
Subroutine _unit_text: called CC=4 SCAR=14.0
7480 325 my ( $dev, $n, $svc ) = @_;
7481 325 my $main = _file_text( $dev, _unit_file( $n, $svc ) );
7482 325 my @d = _dropins( $dev, $n );
7483 325 ▶ return $main unless @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 296 29 325
7484 29 ▶ return join '', $main // '', map { "\n# $_\n" . ( _file_text( $dev, $_ ) // '' ) } @d;
Condition50%2/4
$main // ""
l!l
290
_file_text($dev, $_) // ""
l!l
410
MC/DC0%0/1
$main // ""
$main
MC/DC0%0/1
_file_text($dev, $_) // ""
_file_text($dev, $_)
Truth table50%1/2
A
A= $main
Aresult
11
00
Truth table50%1/2
A
A= _file_text($dev, $_)
Aresult
11
00
7485 }
7486  
7487 # Wirksame Einstellungen einer Unit-Fassung (nur innerhalb eines Abschnitts, wie systemd;
7488 # ein Drop-in ohne [Service] wirkt nicht): die letzte Zuweisung gilt; ExecStart*,
7489 # EnvironmentFile sind Listen, die eine leere Zuweisung leert; Environment ist { VAR => wert }.
7490 180 ▶sub _unit_props {
Subroutine _unit_props: called CC=21 SCAR=31.2
7491 180 my ($text) = @_;
7492 180 my %p;
7493 my $sec;
7494 180 ▶ for my $l ( split /\n/, $text // '' ) {
Condition100%2/2
$text // ""
l!l
17010
MC/DC100%1/1
$text // ""
$text
Truth table100%2/2
A
A= $text
Aresult
11
00
7495 713 ▶ if ( $l =~ m{\A# /\S+\.conf\z} ) { undef $sec; next } # Kopf eines Drop-ins: neue Datei
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ m[\A# /\S+\.conf\z]) 42 671 713
7496 671 ▶ if ( $l =~ /\A\s*\[(\w+)\]/ ) { $sec = $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A\s*\[(\w+)\]/) 211 460 671
7497 460 ▶ next if $l =~ /\A\s*(?:[#;]|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\A\s*(?:[#;]|\z)/ 101 359 460
7498 359 ▶ next unless defined $sec; # ausserhalb eines Abschnitts: systemd ignoriert die Zeile
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sec 2 357 359
7499 357 ▶ my ( $k, $v ) = $l =~ /\A\s*([A-Za-z]+)\s*=\s*(.*?)\s*\z/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $l =~ /\A\s*([A-Za-z]+)\s*=\s*(.*?)\s*\z/ or next 357 0 357
7500 357 ▶ if ( $k =~ /\A(?:ExecStart|ExecStartPre|ExecStartPost|ExecReload|EnvironmentFile)\z/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($k =~ /\A(?:ExecStart|ExecStartPre|ExecStartPost|ExecReload|EnvironmentFile)\z/) { } 178 179 357
elsif ($k eq 'Environment') { } 17 162 179
7501 178 ▶ $p{$k} = [] if $v eq '' || !$p{$k};
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "" or not $p{$k} 168 10 178
Condition100%3/3
$v eq "" or not $p{$k}
l!l&&r!l&&!r
915910
MC/DC100%2/2
$v eq "" or not $p{$k}
$v eq "" not $p{$k}
Truth table100%3/3
A or not(B)
A= $v eq ""B= not $p{$k}
ABresult
1X1
011
000
7502 178 ▶ push @{ $p{$k} }, $v if $v ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $v ne "" 169 9 178
7503 }
7504 elsif ( $k eq 'Environment' ) {
7505 17 ▶ $p{Environment} = {} if $v eq '' || !$p{Environment};
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "" or not $p{"Environment"} 17 0 17
Condition33%1/3
$v eq "" or not $p{"Environment"}
l!l&&r!l&&!r
0170
MC/DC0%0/2
$v eq "" or not $p{"Environment"}
$v eq "" not $p{"Environment"}
Truth table33%1/3
A or not(B)
A= $v eq ""B= not $p{"Environment"}
ABresult
1X1
011
000
7506 17 ▶ while ( $v =~ /\G\s*(?:"([^"]*)"|'([^']*)'|(\S+))/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /\G\s*(?:"([^"]*)"|'([^']*)'|(\S+))/cg) 31 17 48
7507 31 ▶ my $w = $1 // $2 // $3;
Condition66%4/6
($1 // $2) // $3
l!l&&r!l&&!r
14170
$1 // $2
l!l&&r!l&&!r
14017
MC/DC0%0/3
($1 // $2) // $3
$1 $2 $3
Truth table50%2/4
A // B // C
A= $1B= $2C= $3
ABCresult
1XX1
01X1
0011
0000
7508 31 my ( $a, $b ) = split /=/, $w, 2;
7509 31 ▶ $p{Environment}{$a} = $b // '' if defined $a && length $a;
Branch: 1 branch
BranchTrueFalseTotal
if defined $a and length $a 31 0 31
Condition40%2/5
defined $a and length $a
!ll&&!rl&&r
0031
$b // ""
l!l
310
MC/DC0%0/2
defined $a and length $a
defined $a length $a
MC/DC0%0/1
$b // ""
$b
Truth table33%1/3
A and B
A= defined $aB= length $a
ABresult
0X0
100
111
Truth table50%1/2
A
A= $b
Aresult
11
00
7510 }
7511 }
7512 162 else { $p{$k} = $v }
7513 }
7514 180 return \%p;
7515 }
7516  
7517 # Fehler beim Laden der Unit (bad-setting) oder undef
7518 153 ▶sub _unit_bad {
Subroutine _unit_bad: called CC=7 SCAR=19.5
7519 153 my ( $n, $props ) = @_;
7520 return _uname($n) . ": Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing."
7521 153 ▶ if @{ $props->{ExecStart} || [] } > 1 && ( $props->{Type} // 'simple' ) ne 'oneshot';
Branch: 1 branch
BranchTrueFalseTotal
if @{$$props{"ExecStart"} or [];} > 1 and ($$props{"Type"} // "simple") ne "oneshot" 3 150 153
Condition71%5/7
@{$$props{"ExecStart"} or [];} > 1 and ($$props{"Type"} // "simple") ne "oneshot"
!ll&&!rl&&r
15003
$$props{'ExecStart'} || []
l!l
7875
$$props{"Type"} // "simple"
l!l
03
MC/DC0%0/2
@{$$props{"ExecStart"} or [];} > 1 and ($$props{"Type"} // "simple") ne "oneshot"
@{$$props{"ExecStart"} or [];} > 1 $$props{"Type"}
MC/DC100%1/1
$$props{'ExecStart'} || []
$$props{'ExecStart'}
Truth table66%2/3
A and B
A= @{$$props{"ExecStart"} or [];} > 1B= $$props{"Type"}
ABresult
0X0
100
111
Truth table100%2/2
A
A= $$props{'ExecStart'}
Aresult
11
00
7522 # ExecStart= geleert und nichts mehr gesetzt
7523 return _uname($n) . ": Service has no ExecStart=, ExecStop=, or SuccessAction=. Refusing."
7524 150 ▶ if $props->{ExecStart} && !@{ $props->{ExecStart} };
Branch: 1 branch
BranchTrueFalseTotal
if $$props{"ExecStart"} and not @{$$props{"ExecStart"};} 2 148 150
Condition100%3/3
$$props{"ExecStart"} and not @{$$props{"ExecStart"};}
!ll&&!rl&&r
75732
MC/DC100%2/2
$$props{"ExecStart"} and not @{$$props{"ExecStart"};}
$$props{"ExecStart"} not @{$$props{"ExecStart"};}
Truth table100%3/3
A and not(B)
A= $$props{"ExecStart"}B= not @{$$props{"ExecStart"};}
ABresult
0X0
100
111
7525 148 return undef;
7526 }
7527  
7528 84 ▶sub _systemd_start {
Subroutine _systemd_start: called CC=120 SCAR=61.8
7529 84 my ( $dev, $n, $svc, $verb ) = @_;
7530 84 my $u = _uname($n);
7531 84 ▶ return ( "Failed to $verb $u: Unit $u is masked.", 0 ) if $svc->{masked};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"masked"} 0 84 84
7532 84 my @warn;
7533 84 ▶ if ( defined $svc->{unit_loaded} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$svc{"unit_loaded"}) 34 50 84
7534 34 my $now = _unit_text( $dev, $n, $svc );
7535 push @warn, "Warning: The unit file, source configuration file or drop-ins of $u changed on disk. Run 'systemctl daemon-reload' to reload units."
7536 34 ▶ if defined $now && $now ne $svc->{unit_loaded};
Branch: 1 branch
BranchTrueFalseTotal
if defined $now and $now ne $$svc{"unit_loaded"} 3 31 34
Condition100%3/3
defined $now and $now ne $$svc{"unit_loaded"}
!ll&&!rl&&r
1303
MC/DC100%2/2
defined $now and $now ne $$svc{"unit_loaded"}
defined $now $now ne $$svc{"unit_loaded"}
Truth table100%3/3
A and B
A= defined $nowB= $now ne $$svc{"unit_loaded"}
ABresult
0X0
100
111
7537 }
7538 84 ▶ if ( $n =~ /\.timer\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /\.timer\z/) 6 78 84
7539 6 my $i = _timer_info( $dev, $n, $svc );
7540 return ( join( "\n", @warn, "Failed to $verb $u: Unit $u has a bad unit file setting.",
7541 6 ▶ "See system logs and 'systemctl status $u' for details." ), 0 ) unless @{ $i->{cal} } || $i->{other};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$$i{"cal"};} or $$i{"other"} 2 4 6
Condition66%2/3
@{$$i{"cal"};} or $$i{"other"}
l!l&&r!l&&!r
402
MC/DC50%1/2
@{$$i{"cal"};} or $$i{"other"}
@{$$i{"cal"};} $$i{"other"}
Truth table66%2/3
A or B
A= @{$$i{"cal"};}B= $$i{"other"}
ABresult
1X1
011
000
7542 4 my $act = _unit( $i->{activates} );
7543 return ( join( "\n", @warn, "Failed to $verb $u: Unit $i->{activates} not found." ), 0 )
7544 4 ▶ unless ( $dev->{services} || {} )->{$act} || _load_unit( $dev, $act, 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless ($$dev{"services"} || {})->{$act} or _load_unit($dev, $act, 1) 1 3 4
Condition80%4/5
($$dev{"services"} || {})->{$act} or _load_unit($dev, $act, 1)
l!l&&r!l&&!r
121
$$dev{'services'} || {}
l!l
40
MC/DC0%0/2
($$dev{"services"} || {})->{$act} or _load_unit($dev, $act, 1)
$$dev{'services'} _load_unit($dev, $act, 1)
Truth table33%1/3
A or B
A= $$dev{'services'}B= _load_unit($dev, $act, 1)
ABresult
1X1
011
000
7545 }
7546 # RuntimeDirectory=/StateDirectory=/LogsDirectory= der geladenen Unit legt systemd beim Start an
7547 81 ▶ my $ut = $svc->{unit_loaded} // _unit_text( $dev, $n, $svc ) // '';
Condition100%5/5
($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)) // ""
l!l
4635
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
l!l&&r!l&&!r
311535
MC/DC100%2/2
($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)) // ""
$$svc{"unit_loaded"} _unit_text($dev, $n, $svc)
Truth table100%3/3
A // B
A= $$svc{"unit_loaded"}B= _unit_text($dev, $n, $svc)
ABresult
1X1
011
000
7548 81 my $props = _unit_props($ut);
7549 # bad-setting: systemd nimmt den Auftrag gar nicht an — ein laufender Prozess laeuft weiter
7550 81 ▶ if ( _unit_bad( $n, $props ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_unit_bad($n, $props)) 2 79 81
7551 2 return ( join( "\n", @warn, "Failed to $verb $u: Unit $u has a bad unit file setting.",
7552 "See system logs and 'systemctl status $u' for details." ), 0 );
7553 }
7554 79 my ($uuser) = $ut =~ /^\s*User\s*=\s*(\S+)/m;
7555 79 my ($ugrp) = $ut =~ /^\s*Group\s*=\s*(\S+)/m;
7556 # User=/Group= der Unit, die es nicht gibt (Geraet mit check_accounts): 217/USER bzw. 216/GROUP wie systemd
7557 79 ▶ if ( my $miss = _cred_missing( $dev, $uuser, $ugrp ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $miss = _cred_missing($dev, $uuser, $ugrp)) 2 77 79
7558 2 ▶ ( my $prog = ( $props->{ExecStart} || [''] )->[0] // '' ) =~ s/\A[-@+!:]+//;
Condition50%2/4
($$props{"ExecStart"} || [""])->[0] // ""
l!l
20
$$props{'ExecStart'} || ['']
l!l
20
MC/DC0%0/1
($$props{"ExecStart"} || [""])->[0] // ""
$$props{'ExecStart'}
Truth table50%1/2
A
A= $$props{'ExecStart'}
Aresult
11
00
7559 2 $prog =~ s/\s.*//s;
7560 2 ( my $short = $n ) =~ s/\A(.{1,15}).*/$1/;
7561 2 my $W = uc $miss;
7562 2 _log( $dev, $n, $svc, "($short)[3001]: $u: Failed to determine $miss credentials: No such process",
7563 "($short)[3001]: $u: Failed at step $W spawning $prog: No such process" );
7564 2 ▶ _app_event( $dev, $n, 'stop' ) if $svc->{active} && $verb =~ /restart/;
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} and $verb =~ /restart/ 0 2 2
Condition33%1/3
$$svc{"active"} and $verb =~ /restart/
!ll&&!rl&&r
200
MC/DC0%0/2
$$svc{"active"} and $verb =~ /restart/
$$svc{"active"} $verb =~ /restart/
Truth table33%1/3
A and B
A= $$svc{"active"}B= $verb =~ /restart/
ABresult
0X0
100
111
7565 2 ▶ $svc->{active} = JSON::MaybeXS::false() if $svc->{active} && $verb =~ /restart/;
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} and $verb =~ /restart/ 0 2 2
Condition33%1/3
$$svc{"active"} and $verb =~ /restart/
!ll&&!rl&&r
200
MC/DC0%0/2
$$svc{"active"} and $verb =~ /restart/
$$svc{"active"} $verb =~ /restart/
Truth table33%1/3
A and B
A= $$svc{"active"}B= $verb =~ /restart/
ABresult
0X0
100
111
7566 2 ▶ $svc->{failed} = JSON::MaybeXS::true() unless $svc->{failed} || $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"failed"} or $$svc{"active"} 2 0 2
Condition33%1/3
$$svc{"failed"} or $$svc{"active"}
l!l&&r!l&&!r
002
MC/DC0%0/2
$$svc{"failed"} or $$svc{"active"}
$$svc{"failed"} $$svc{"active"}
Truth table33%1/3
A or B
A= $$svc{"failed"}B= $$svc{"active"}
ABresult
1X1
011
000
7567 return ( join( "\n", @warn, "Job for $u failed because the control process exited with error code.",
7568 2 ▶ "See \"systemctl status $u\" and \"journalctl -xeu $u\" for details." ), 0 ) unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 2 0 2
7569 }
7570 77 for ( [ RuntimeDirectory => '/run' ], [ StateDirectory => '/var/lib' ], [ LogsDirectory => '/var/log' ], [ CacheDirectory => '/var/cache' ] ) {
7571 308 my ( $k, $base ) = @$_;
7572 308 for my $d ( map { split /\s+/ } $ut =~ /^\s*\Q$k\E\s*=\s*(.+?)\s*$/mg ) {
7573 2 my $p = "$base/$d";
7574 2 ▶ next if _is_dir( $dev, $p );
Branch: 1 branch
BranchTrueFalseTotal
if _is_dir($dev, $p) 1 1 2
7575 1 ▶ $dev->{dirs}{$p} = { owner => $uuser // 'root', group => $ugrp // $uuser // 'root', mode => '0755' };
Condition42%3/7
$uuser // "root"
l!l
10
($ugrp // $uuser) // "root"
l!l
10
$ugrp // $uuser
l!l&&r!l&&!r
010
MC/DC0%0/1
$uuser // "root"
$uuser
MC/DC0%0/2
($ugrp // $uuser) // "root"
$ugrp $uuser
Truth table50%1/2
A
A= $uuser
Aresult
11
00
Truth table33%1/3
A // B
A= $ugrpB= $uuser
ABresult
1X1
011
000
7576 }
7577 }
7578 # Neustart gibt geloeschte, noch offene Dateien frei
7579 77 ▶ if ( $dev->{deleted_open} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"deleted_open"}) 1 76 77
7580 1 ▶ my @keep = grep { ( $_->{by} // '' ) ne $n } @{ $dev->{deleted_open} };
Condition50%1/2
$$_{"by"} // ""
l!l
10
MC/DC0%0/1
$$_{"by"} // ""
$$_{"by"}
Truth table50%1/2
A
A= $$_{"by"}
Aresult
11
00
7581 1 ▶ $dev->{deleted_open} = \@keep if @keep != @{ $dev->{deleted_open} };
Branch: 1 branch
BranchTrueFalseTotal
if @keep != @{$$dev{"deleted_open"};} 1 0 1
7582 }
7583 77 my $conf_bad = _app_conf_error( $dev, $n );
7584 77 ▶ if ($conf_bad) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf_bad) 4 73 77
7585 4 ▶ _app_event( $dev, $n, 'stop' ) if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 4 0 4
7586 4 _log( $dev, $n, $svc, @$conf_bad );
7587 }
7588 77 ▶ if ( $conf_bad || ( my $bad = _failing_need( $dev, $svc ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf_bad or my $bad = _failing_need($dev, $svc)) 11 66 77
Condition100%3/3
$conf_bad or my $bad = _failing_need($dev, $svc)
l!l&&r!l&&!r
4766
MC/DC100%2/2
$conf_bad or my $bad = _failing_need($dev, $svc)
$conf_bad my $bad = _failing_need($dev, $svc)
Truth table100%3/3
A or B
A= $conf_badB= my $bad = _failing_need($dev, $svc)
ABresult
1X1
011
000
7589 11 _app_log( $dev, $n, $svc, 'fail' );
7590 11 ▶ $svc->{active} = JSON::MaybeXS::false() if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 5 6 11
7591 11 ▶ $svc->{failed} = JSON::MaybeXS::true() unless $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"failed"} 8 3 11
7592 11 return ( join( "\n", @warn, "Job for $u failed because the control process exited with error code.",
7593 "See \"systemctl status $u\" and \"journalctl -xeu $u\" for details." ), 0 );
7594 }
7595 66 ▶ if ( defined $svc->{run} ) { # Type=oneshot: der Befehl laeuft beim Start, danach ist der Dienst inaktiv
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$svc{"run"}) 0 66 66
7596 0 ▶ $svc->{runs} = ( $svc->{runs} // 0 ) + 1;
Condition0%0/2
$$svc{"runs"} // 0
l!l
00
MC/DC0%0/1
$$svc{"runs"} // 0
$$svc{"runs"}
Truth table0%0/2
A
A= $$svc{"runs"}
Aresult
11
00
7597 0 local $CWD_DIR = '/';
7598 0 ▶ my ( $o, $k ) = __PACKAGE__->_run_inner( $dev, $svc->{run}, $CTX || { state => {} } );
Condition0%0/2
$Langertha::Holmgang::Sim::Linux::CTX || {'state', {}}
l!l
00
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::CTX || {'state', {}}
$Langertha::Holmgang::Sim::Linux::CTX
Truth table0%0/2
A
A= $Langertha::Holmgang::Sim::Linux::CTX
Aresult
11
00
7599 0 ▶ my $h = $dev->{hostname} // 'localhost';
Condition0%0/2
$$dev{"hostname"} // "localhost"
l!l
00
MC/DC0%0/1
$$dev{"hostname"} // "localhost"
$$dev{"hostname"}
Truth table0%0/2
A
A= $$dev{"hostname"}
Aresult
11
00
7600 0 ▶ push @{ $svc->{journal} }, ( map {"Oct 20 12:00:00 $h $n\[3001\]: $_"} grep {length} split /\n/, $o // '' ),
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 0 0 0
Condition0%0/2
$o // ""
l!l
00
MC/DC0%0/1
$o // ""
$o
Truth table0%0/2
A
A= $o
Aresult
11
00
7601 $k ? "Oct 20 12:00:00 $h systemd[1]: $u: Deactivated successfully." : "Oct 20 12:00:00 $h systemd[1]: $u: Main process exited, code=exited, status=1/FAILURE";
7602 0 ▶ $svc->{active} = JSON::MaybeXS::false() if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 0 0 0
7603 0 ▶ if ($k) { $svc->{failed} = JSON::MaybeXS::false() if $svc->{failed}; return ( join( "\n", @warn ), 1 ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($k) 0 0 0
if $$svc{"failed"} 0 0 0
7604 0 ▶ $svc->{failed} = JSON::MaybeXS::true() unless $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"failed"} 0 0 0
7605 0 return ( join( "\n", @warn, "Job for $u failed because the control process exited with error code.",
7606 "See \"systemctl status $u\" and \"journalctl -xeu $u\" for details." ), 0 );
7607 }
7608 # Geraet mit oneshot_scripts: Type=oneshot mit Shell-Skripten als ExecStart (ohne creates)
7609 # fuehrt die Skripte als User= der Unit aus; ihr Exit-Status entscheidet, ihre Ausgabe
7610 # steht im Journal
7611 66 ▶ if ( $dev->{oneshot_scripts} && !$svc->{creates} && _oneshot( $dev, $n, $svc ) && ( my @steps = _script_steps( $dev, $props ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"oneshot_scripts"} and not $$svc{"creates"} and _oneshot($dev, $n, $svc) and my(@steps) = _script_steps($dev, $props)) 4 62 66
Condition77%7/9
$$dev{"oneshot_scripts"} and not $$svc{"creates"} and _oneshot($dev, $n, $svc) and my(@steps) = _script_steps($dev, $props)
!ll&&!rl&&r
6204
$$dev{"oneshot_scripts"} and not $$svc{"creates"} and _oneshot($dev, $n, $svc)
!ll&&!rl&&r
5934
$$dev{"oneshot_scripts"} and not $$svc{"creates"}
!ll&&!rl&&r
5907
MC/DC50%2/4
$$dev{"oneshot_scripts"} and not $$svc{"creates"} and _oneshot($dev, $n, $svc) and my(@steps) = _script_steps($dev, $props)
$$dev{"oneshot_scripts"} not $$svc{"creates"} _oneshot($dev, $n, $svc) my(@steps) = _script_steps($dev, $props)
Truth table60%3/5
A and not(B) and C and D
A= $$dev{"oneshot_scripts"}B= not $$svc{"creates"}C= _oneshot($dev, $n, $svc)D= my(@steps) = _script_steps($dev, $props)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
7612 4 my ( @o, $k );
7613 {
7614 4 local $CWD_DIR = '/';
7615 4 ▶ local $LOGIN_USER = defined $uuser && $uuser ne 'root' ? $uuser : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $uuser && $uuser ne 'root' ? : 1 3 4
Condition66%2/3
defined $uuser and $uuser ne "root"
!ll&&!rl&&r
301
MC/DC50%1/2
defined $uuser and $uuser ne "root"
defined $uuser $uuser ne "root"
Truth table66%2/3
A and B
A= defined $uuserB= $uuser ne "root"
ABresult
0X0
100
111
7616 4 local $AS_USER;
7617 4 for my $st (@steps) {
7618 4 ▶ if ( $st->[0] eq '!noexec' ) { # direkt gestartet ohne Ausfuehrrecht: 203/EXEC wie systemd
Branch: 1 branch
BranchTrueFalseTotal
if ($$st[0] eq "!noexec") 1 3 4
7619 1 push @o, "$u: Failed to execute $st->[1]: Permission denied", "$u: Failed at step EXEC spawning $st->[1]: Permission denied";
7620 1 $k = 0;
7621 1 last;
7622 }
7623 3 ▶ my ( $o, $kk ) = _script( $dev, _file_text( $dev, $st->[0] ), $CTX || { state => {} }, join( ' ', @$st ), @$st );
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::CTX || {'state', {}}
l!l
30
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::CTX || {'state', {}}
$Langertha::Holmgang::Sim::Linux::CTX
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::CTX
Aresult
11
00
7624 3 ▶ push @o, $o if defined $o && length $o;
Branch: 1 branch
BranchTrueFalseTotal
if defined $o and length $o 1 2 3
Condition66%2/3
defined $o and length $o
!ll&&!rl&&r
021
MC/DC50%1/2
defined $o and length $o
defined $o length $o
Truth table66%2/3
A and B
A= defined $oB= length $o
ABresult
0X0
100
111
7625 3 $k = $kk;
7626 3 ▶ last unless $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $k 2 1 3
7627 }
7628 }
7629 4 ▶ my $h = $dev->{hostname} // ( $CTX || {} )->{host} // 'localhost';
Condition42%3/7
($$dev{"hostname"} // ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"}) // "localhost"
l!l
40
$$dev{"hostname"} // ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"}
l!l&&r!l&&!r
040
$Langertha::Holmgang::Sim::Linux::CTX || {}
l!l
40
MC/DC0%0/2
($$dev{"hostname"} // ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"}) // "localhost"
$$dev{"hostname"} $Langertha::Holmgang::Sim::Linux::CTX
Truth table33%1/3
A // B
A= $$dev{"hostname"}B= $Langertha::Holmgang::Sim::Linux::CTX
ABresult
1X1
011
000
7630 4 ▶ push @{ $svc->{journal} }, ( map {"Oct 20 12:00:00 $h $n\[3001\]: $_"} grep {length} map { split /\n/ } @o ),
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 1 3 4
7631 $k ? "Oct 20 12:00:00 $h systemd[1]: $u: Deactivated successfully." : "Oct 20 12:00:00 $h systemd[1]: $u: Main process exited, code=exited, status=1/FAILURE";
7632 4 ▶ $svc->{active} = JSON::MaybeXS::false() if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 0 4 4
7633 4 ▶ if ($k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k) 1 3 4
7634 1 ▶ $svc->{runs} = ( $svc->{runs} // 0 ) + 1;
Condition50%1/2
$$svc{"runs"} // 0
l!l
01
MC/DC0%0/1
$$svc{"runs"} // 0
$$svc{"runs"}
Truth table50%1/2
A
A= $$svc{"runs"}
Aresult
11
00
7635 1 ▶ $svc->{failed} = JSON::MaybeXS::false() if $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"failed"} 0 1 1
7636 1 return ( join( "\n", @warn ), 1 );
7637 }
7638 3 ▶ $svc->{failed} = JSON::MaybeXS::true() unless $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"failed"} 3 0 3
7639 3 return ( join( "\n", @warn, "Job for $u failed because the control process exited with error code.",
7640 "See \"systemctl status $u\" and \"journalctl -xeu $u\" for details." ), 0 );
7641 }
7642 62 ▶ if ( _oneshot( $dev, $n, $svc ) ) { # laeuft einmal durch und ist danach wieder inactive
Branch: 1 branch
BranchTrueFalseTotal
if (_oneshot($dev, $n, $svc)) 3 59 62
7643 3 ▶ $svc->{runs} = ( $svc->{runs} // 0 ) + 1;
Condition50%1/2
$$svc{"runs"} // 0
l!l
03
MC/DC0%0/1
$$svc{"runs"} // 0
$$svc{"runs"}
Truth table50%1/2
A
A= $$svc{"runs"}
Aresult
11
00
7644 # was ein erfolgreicher Lauf anlegt (creates: { pfad => eintrag })
7645 3 ▶ $dev->{files}{$_} = Langertha::Holmgang::Sim::Linux::clone_state( $svc->{creates}{$_} ) for sort keys %{ $svc->{creates} || {} };
Condition100%2/2
$$svc{'creates'} || {}
l!l
12
MC/DC100%1/1
$$svc{'creates'} || {}
$$svc{'creates'}
Truth table100%2/2
A
A= $$svc{'creates'}
Aresult
11
00
7646 3 ▶ $svc->{failed} = JSON::MaybeXS::false() if $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"failed"} 0 3 3
7647 3 ▶ $svc->{active} = JSON::MaybeXS::false() if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 0 3 3
7648 3 return ( join( "\n", @warn ), 1 );
7649 }
7650 59 my $was = $svc->{active};
7651 59 ▶ if ( defined( my $e = _svc_hook( $dev, $n, $verb ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $e = _svc_hook($dev, $n, $verb))) 1 58 59
7652 1 ▶ $svc->{restarts} = ( $svc->{restarts} // 0 ) + 1 if $was && $verb =~ /restart/;
Branch: 1 branch
BranchTrueFalseTotal
if $was and $verb =~ /restart/ 1 0 1
Condition40%2/5
$was and $verb =~ /restart/
!ll&&!rl&&r
001
$$svc{"restarts"} // 0
l!l
01
MC/DC0%0/2
$was and $verb =~ /restart/
$was $verb =~ /restart/
MC/DC0%0/1
$$svc{"restarts"} // 0
$$svc{"restarts"}
Truth table33%1/3
A and B
A= $wasB= $verb =~ /restart/
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$svc{"restarts"}
Aresult
11
00
7653 1 ▶ $svc->{active} = JSON::MaybeXS::false() if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 1 0 1
7654 1 ▶ $svc->{failed} = JSON::MaybeXS::true() unless $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"failed"} 1 0 1
7655 1 $svc->{last_error} = $e;
7656 1 return ( join( "\n", @warn, "Job for $n.service failed because the control process exited with error code.",
7657 "See \"systemctl status $n.service\" and \"journalctl -xeu $n.service\" for details." ), 0 );
7658 }
7659 58 ▶ $svc->{restarts} = ( $svc->{restarts} // 0 ) + 1 if $was && $verb =~ /restart/;
Branch: 1 branch
BranchTrueFalseTotal
if $was and $verb =~ /restart/ 38 20 58
Condition80%4/5
$was and $verb =~ /restart/
!ll&&!rl&&r
20038
$$svc{"restarts"} // 0
l!l
731
MC/DC50%1/2
$was and $verb =~ /restart/
$was $verb =~ /restart/
MC/DC100%1/1
$$svc{"restarts"} // 0
$$svc{"restarts"}
Truth table66%2/3
A and B
A= $wasB= $verb =~ /restart/
ABresult
0X0
100
111
Truth table100%2/2
A
A= $$svc{"restarts"}
Aresult
11
00
7660 58 _restart_effect( $dev, $n, $verb );
7661 55 ▶ _app_event( $dev, $n, $was ? 'restart' : 'start' ) unless $was && $verb !~ /restart/;
Branch: 2 branches
BranchTrueFalseTotal
unless $was and not $verb =~ /restart/ 55 0 55
$was ? : 36 19 55
Condition66%2/3
$was and not $verb =~ /restart/
!ll&&!rl&&r
19360
MC/DC0%0/2
$was and not $verb =~ /restart/
$was not $verb =~ /restart/
Truth table66%2/3
A and not(B)
A= $wasB= not $verb =~ /restart/
ABresult
0X0
100
111
7662 # journal_start: was der Dienst beim (Neu-)Start ins Journal schreibt
7663 0 ▶ push @{ $svc->{journal} }, @{ $svc->{journal_start} } if ref $svc->{journal_start} eq 'ARRAY' && !( $verb eq 'start' && $was );
Branch: 1 branch
BranchTrueFalseTotal
if ref $$svc{"journal_start"} eq "ARRAY" and not $verb eq "start" && $was 0 55 55
Condition16%1/6
ref $$svc{"journal_start"} eq "ARRAY" and not $verb eq "start" && $was
!ll&&!rl&&r
5500
$verb eq 'start' && $was
!ll&&!rl&&r
000
MC/DC0%0/3
ref $$svc{"journal_start"} eq "ARRAY" and not $verb eq "start" && $was
ref $$svc{"journal_start"} eq "ARRAY" $verb eq 'start' $was
Truth table25%1/4
A and not(B && C)
A= ref $$svc{"journal_start"} eq "ARRAY"B= $verb eq 'start'C= $was
ABCresult
0XX0
1110
10X1
1101
7664 55 ▶ $svc->{active} = JSON::MaybeXS::true() unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 19 36 55
7665 55 ▶ $svc->{failed} = JSON::MaybeXS::false() if $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"failed"} 6 49 55
7666 # Laufzeitdateien (Socket, PID-Datei) legt der laufende Dienst an — sofern es das Verzeichnis gibt
7667 55 ▶ for my $rf ( @{ $svc->{runtime_files} || [] } ) {
Condition100%2/2
$$svc{'runtime_files'} || []
l!l
154
MC/DC100%1/1
$$svc{'runtime_files'} || []
$$svc{'runtime_files'}
Truth table100%2/2
A
A= $$svc{'runtime_files'}
Aresult
11
00
7668 1 ( my $d = $rf->{path} ) =~ s{/[^/]+\z}{};
7669 1 ▶ next unless _is_dir( $dev, $d ) && !exists $dev->{files}{ $rf->{path} };
Branch: 1 branch
BranchTrueFalseTotal
unless _is_dir($dev, $d) and not exists $$dev{"files"}{$$rf{"path"}} 0 1 1
Condition33%1/3
_is_dir($dev, $d) and not exists $$dev{"files"}{$$rf{"path"}}
!ll&&!rl&&r
001
MC/DC0%0/2
_is_dir($dev, $d) and not exists $$dev{"files"}{$$rf{"path"}}
_is_dir($dev, $d) not exists $$dev{"files"}{$$rf{"path"}}
Truth table33%1/3
A and not(B)
A= _is_dir($dev, $d)B= not exists $$dev{"files"}{$$rf{"path"}}
ABresult
0X0
100
111
7670 $dev->{files}{ $rf->{path} } = { content => '', owner => $rf->{owner} // $svc->{user} // $uuser // 'root',
7671 group => $rf->{group} // $ugrp // $svc->{user} // $uuser // 'root',
7672 1 ▶ mode => $rf->{mode} // '0660', ( $rf->{type} ? ( type => $rf->{type} ) : () ) };
Branch: 1 branch
BranchTrueFalseTotal
$$rf{'type'} ? : 1 0 1
Condition38%8/21
(($$rf{"owner"} // $$svc{"user"}) // $uuser) // "root"
l!l
10
($$rf{"owner"} // $$svc{"user"}) // $uuser
l!l&&r!l&&!r
010
$$rf{"owner"} // $$svc{"user"}
l!l&&r!l&&!r
001
((($$rf{"group"} // $ugrp) // $$svc{"user"}) // $uuser) // "root"
l!l
10
(($$rf{"group"} // $ugrp) // $$svc{"user"}) // $uuser
l!l&&r!l&&!r
010
($$rf{"group"} // $ugrp) // $$svc{"user"}
l!l&&r!l&&!r
001
$$rf{"group"} // $ugrp
l!l&&r!l&&!r
001
$$rf{"mode"} // "0660"
l!l
01
MC/DC0%0/3
(($$rf{"owner"} // $$svc{"user"}) // $uuser) // "root"
$$rf{"owner"} $$svc{"user"} $uuser
MC/DC0%0/4
((($$rf{"group"} // $ugrp) // $$svc{"user"}) // $uuser) // "root"
$$rf{"group"} $ugrp $$svc{"user"} $uuser
MC/DC0%0/1
$$rf{"mode"} // "0660"
$$rf{"mode"}
Truth table25%1/4
A // B // C
A= $$rf{"owner"}B= $$svc{"user"}C= $uuser
ABCresult
1XX1
01X1
0011
0000
Truth table20%1/5
A // B // C // D
A= $$rf{"group"}B= $ugrpC= $$svc{"user"}D= $uuser
ABCDresult
1XXX1
01XX1
001X1
00011
00000
Truth table50%1/2
A
A= $$rf{"mode"}
Aresult
11
00
7673 }
7674 55 ▶ if ( !$was || $verb =~ /restart/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $was or $verb =~ /restart/) 55 0 55
Condition66%2/3
not $was or $verb =~ /restart/
l!l&&r!l&&!r
19360
MC/DC0%0/2
not $was or $verb =~ /restart/
not $was $verb =~ /restart/
Truth table66%2/3
not(A) or B
A= not $wasB= $verb =~ /restart/
ABresult
1X1
011
000
7675 55 ▶ $svc->{_started} = $props if length $ut; # womit der Prozess laeuft
Branch: 1 branch
BranchTrueFalseTotal
if length $ut 28 27 55
7676 55 ▶ _log( $dev, $n, $svc, $was ? ( "systemd[1]: Stopping $u" . _desc($svc) . '...', "systemd[1]: $u: Deactivated successfully." ) : (),
Branch: 1 branch
BranchTrueFalseTotal
$was ? : 36 19 55
7677 "systemd[1]: Started $u" . _desc($svc) . '.' );
7678 # neuer Prozess: neue Haupt-PID (die der Startmeldungen), Startzeit = Zeit der Zeile "Started"
7679 55 ▶ my $pid = $svc->{_pid} = 50000 + ( $dev->{_tick} // 0 );
Condition50%1/2
$$dev{"_tick"} // 0
l!l
550
MC/DC0%0/1
$$dev{"_tick"} // 0
$$dev{"_tick"}
Truth table50%1/2
A
A= $$dev{"_tick"}
Aresult
11
00
7680 55 require Time::Local;
7681 55 $svc->{_since} = _jtime( $svc->{_log}[-1] );
7682 # wo der neue Prozess lauscht (wie er die Datei gelesen hat), Zeilen in seinem Log
7683 55 ▶ $svc->{_listen} = [ _svc_listen( $dev, $n, $svc ) ] if ref $svc->{listen} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $$svc{"listen"} eq "HASH" 1 54 55
7684 55 _app_log( $dev, $n, $svc, 'start', $svc->{_since} );
7685 # Startmeldungen des Dienstes (Kolon, duerfen vom Zustand abhaengen)
7686 3 ▶ _log( $dev, $n, $svc, map { ( $svc->{exec} // $n ) . "[$pid]: " . _render( $_, $CTX ? $CTX->{state} : {} ) =~ s/\s+\z//r }
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 3 0 3
Condition33%1/3
$$svc{"exec"} // $n
l!l&&r!l&&!r
300
MC/DC0%0/2
$$svc{"exec"} // $n
$$svc{"exec"} $n
Truth table33%1/3
A // B
A= $$svc{"exec"}B= $n
ABresult
1X1
011
000
7687 55 ▶ @{ $svc->{start_log} || [] } );
Condition100%2/2
$$svc{'start_log'} || []
l!l
352
MC/DC100%1/1
$$svc{'start_log'} || []
$$svc{'start_log'}
Truth table100%2/2
A
A= $$svc{'start_log'}
Aresult
11
00
7688 }
7689 55 ▶ _reopen_logs( $dev, $n ) unless $verb eq 'start' && $was;
Branch: 1 branch
BranchTrueFalseTotal
unless $verb eq "start" and $was 55 0 55
Condition66%2/3
$verb eq "start" and $was
!ll&&!rl&&r
38170
MC/DC0%0/2
$verb eq "start" and $was
$verb eq "start" $was
Truth table66%2/3
A and B
A= $verb eq "start"B= $was
ABresult
0X0
100
111
7690 55 ▶ _pg_event( $dev, $n, $verb =~ /restart/ ? 'restart' : $verb ) unless $verb eq 'start' && $was;
Branch: 2 branches
BranchTrueFalseTotal
unless $verb eq "start" and $was 55 0 55
$verb =~ /restart/ ? : 38 17 55
Condition66%2/3
$verb eq "start" and $was
!ll&&!rl&&r
38170
MC/DC0%0/2
$verb eq "start" and $was
$verb eq "start" $was
Truth table66%2/3
A and B
A= $verb eq "start"B= $was
ABresult
0X0
100
111
7691 55 return ( join( "\n", @warn ), 1 );
7692 }
7693  
7694 # ExecStart= einer Unit als Shell-Skripte im Zustand: ( [ skript, argumente … ], … ) —
7695 # leer, wenn eine Zeile kein Skript startet (dann wie bisher ohne Ausfuehrung)
7696 4 ▶sub _script_steps {
Subroutine _script_steps: called CC=11 SCAR=28.6
7697 4 my ( $dev, $props ) = @_;
7698 4 my @steps;
7699 4 ▶ for my $line ( @{ $props->{ExecStart} || [] } ) {
Condition50%1/2
$$props{'ExecStart'} || []
l!l
40
MC/DC0%0/1
$$props{'ExecStart'} || []
$$props{'ExecStart'}
Truth table50%1/2
A
A= $$props{'ExecStart'}
Aresult
11
00
7700 4 my @w = split ' ', $line =~ s/\A[-@+!:]+//r;
7701 4 ▶ my $via = @w > 1 && $w[0] =~ m{\A/(?:usr/)?bin/(?:ba|da)?sh\z} && $w[1] !~ /\A-/ ? shift @w : undef;
Branch: 1 branch
BranchTrueFalseTotal
@w > 1 && $w[0] =~ m[\A/(?:usr/)?bin/(?:ba|da)?sh\z] && !($w[1] =~ /\A-/) ? : 0 4 4
Condition33%2/6
@w > 1 and $w[0] =~ m[\A/(?:usr/)?bin/(?:ba|da)?sh\z] and not $w[1] =~ /\A-/
!ll&&!rl&&r
400
@w > 1 and $w[0] =~ m[\A/(?:usr/)?bin/(?:ba|da)?sh\z]
!ll&&!rl&&r
400
MC/DC0%0/3
@w > 1 and $w[0] =~ m[\A/(?:usr/)?bin/(?:ba|da)?sh\z] and not $w[1] =~ /\A-/
@w > 1 $w[0] =~ m[\A/(?:usr/)?bin/(?:ba|da)?sh\z] not $w[1] =~ /\A-/
Truth table25%1/4
A and B and not(C)
A= @w > 1B= $w[0] =~ m[\A/(?:usr/)?bin/(?:ba|da)?sh\z]C= not $w[1] =~ /\A-/
ABCresult
0XX0
10X0
1100
1111
7702 4 ▶ return () unless @w && $w[0] =~ m{\A/} && _shell_script( $dev, $w[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless @w and $w[0] =~ m[\A/] and _shell_script($dev, $w[0]) 0 4 4
Condition33%2/6
@w and $w[0] =~ m[\A/] and _shell_script($dev, $w[0])
!ll&&!rl&&r
004
@w and $w[0] =~ m[\A/]
!ll&&!rl&&r
004
MC/DC0%0/3
@w and $w[0] =~ m[\A/] and _shell_script($dev, $w[0])
@w $w[0] =~ m[\A/] _shell_script($dev, $w[0])
Truth table25%1/4
A and B and C
A= @wB= $w[0] =~ m[\A/]C= _shell_script($dev, $w[0])
ABCresult
0XX0
10X0
1100
1111
7703 4 ▶ push @steps, !$via && !( _mode_of( _file_entry( $dev, $w[0] ) ) & 0111 ) ? [ '!noexec', $w[0] ] : \@w;
Branch: 1 branch
BranchTrueFalseTotal
!($via || _mode_of(_file_entry($dev, $w[0])) & 73) ? : 1 3 4
Condition66%2/3
$via || _mode_of(_file_entry($dev, $w[0])) & 73
l!l&&r!l&&!r
031
MC/DC50%1/2
$via || _mode_of(_file_entry($dev, $w[0])) & 73
$via _mode_of(_file_entry($dev, $w[0])) & 73
Truth table66%2/3
A || B
A= $viaB= _mode_of(_file_entry($dev, $w[0])) & 73
ABresult
1X1
011
000
7704 }
7705 4 return @steps;
7706 }
7707  
7708 209 ▶sub _desc { my ($svc) = @_; return defined $svc->{description} ? " - $svc->{description}" : '' }
Subroutine _desc: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $$svc{'description'} ? : 65 144 209
7709  
7710 # Uhr der Simulation fuer neue Journalzeilen (clock am Geraet, z. B. "Oct 24 09:12")
7711 285 ▶sub _clock { my ($dev) = @_; return $dev->{clock} // 'Oct 20 09:12' }
Subroutine _clock: called CC=2 SCAR=6.9
Condition100%2/2
$$dev{"clock"} // "Oct 20 09:12"
l!l
92193
MC/DC100%1/1
$$dev{"clock"} // "Oct 20 09:12"
$$dev{"clock"}
Truth table100%2/2
A
A= $$dev{"clock"}
Aresult
11
00
7712  
7713 # Journalzeilen anhaengen (unter _log: Laufzeitspur, „sonst nichts geaendert" sieht sie nicht)
7714 171 ▶sub _log {
Subroutine _log: called CC=6 SCAR=19.3
7715 171 my ( $dev, $n, $svc, @lines ) = @_;
7716 171 ▶ return unless @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 52 119 171
7717 119 ▶ my $host = $CTX && $CTX->{host} ? $CTX->{host} : $dev->{hostname} // 'localhost';
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX && $$Langertha::Holmgang::Sim::Linux::CTX{'host'} ? : 119 0 119
Condition20%1/5
$Langertha::Holmgang::Sim::Linux::CTX and $$Langertha::Holmgang::Sim::Linux::CTX{"host"}
!ll&&!rl&&r
00119
$$dev{"hostname"} // "localhost"
l!l
00
MC/DC0%0/2
$Langertha::Holmgang::Sim::Linux::CTX and $$Langertha::Holmgang::Sim::Linux::CTX{"host"}
$Langertha::Holmgang::Sim::Linux::CTX $$Langertha::Holmgang::Sim::Linux::CTX{"host"}
MC/DC0%0/1
$$dev{"hostname"} // "localhost"
$$dev{"hostname"}
Truth table33%1/3
A and B
A= $Langertha::Holmgang::Sim::Linux::CTXB= $$Langertha::Holmgang::Sim::Linux::CTX{"host"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $$dev{"hostname"}
Aresult
11
00
7718 119 for my $l (@lines) {
7719 265 my $t = ++$dev->{_tick};
7720 265 push @{ $svc->{_log} }, sprintf( '%s:%02d %s %s', _clock($dev), 3 + $t % 57, $host, $l );
7721 }
7722 119 return;
7723 }
7724  
7725 68 ▶sub _journal_lines {
Subroutine _journal_lines: called CC=28 SCAR=35.7
7726 68 my ( $dev, $n, $svc, $host ) = @_;
7727 68 ▶ $host //= $dev->{hostname} // 'localhost';
Condition25%1/4
$host //= $$dev{"hostname"} // "localhost"
l!l
680
$$dev{"hostname"} // "localhost"
l!l
00
MC/DC0%0/1
$host //= $$dev{"hostname"} // "localhost"
$host
Truth table50%1/2
A
A= $host
Aresult
11
00
7728 68 my $u = _uname($n);
7729 68 ▶ my @l = ( @{ $svc->{journal} || [] }, @{ $svc->{_log} || [] } );
Condition100%4/4
$$svc{'journal'} || []
l!l
2246
$$svc{'_log'} || []
l!l
2048
MC/DC100%1/1
$$svc{'journal'} || []
$$svc{'journal'}
MC/DC100%1/1
$$svc{'_log'} || []
$$svc{'_log'}
Truth table100%2/2
A
A= $$svc{'journal'}
Aresult
11
00
Truth table100%2/2
A
A= $$svc{'_log'}
Aresult
11
00
7730 # eigene Simulation (nginx): Meldung des letzten gescheiterten Starts bzw. reload
7731 68 ▶ push @l, map {"Oct 24 09:12:03 $host $n\[2210]: $_"} split /\n/, $svc->{last_error} if defined $svc->{last_error};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$svc{"last_error"} 1 67 68
7732 0 ▶ push @l, @{ $dev->{bind}{log} || [] } if $dev->{bind} && $n eq ( $dev->{bind}{service} // 'named' );
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"bind"} and $n eq ($$dev{"bind"}{"service"} // "named") 0 68 68
Condition14%1/7
$$dev{"bind"} and $n eq ($$dev{"bind"}{"service"} // "named")
!ll&&!rl&&r
6800
$$dev{"bind"}{"service"} // "named"
l!l
00
$$dev{'bind'}{'log'} || []
l!l
00
MC/DC0%0/2
$$dev{"bind"} and $n eq ($$dev{"bind"}{"service"} // "named")
$$dev{"bind"} $n eq ($$dev{"bind"}{"service"} // "named")
MC/DC0%0/1
$$dev{"bind"}{"service"} // "named"
$$dev{"bind"}{"service"}
MC/DC0%0/1
$$dev{'bind'}{'log'} || []
$$dev{'bind'}{'log'}
Truth table33%1/3
A and B
A= $$dev{"bind"}B= $n eq ($$dev{"bind"}{"service"} // "named")
ABresult
0X0
100
111
Truth table0%0/2
A
A= $$dev{"bind"}{"service"}
Aresult
11
00
Truth table0%0/2
A
A= $$dev{'bind'}{'log'}
Aresult
11
00
7733 68 ▶ push @l, _ssh_access()->can('journal')->( $dev, $host ) if ( $n eq 'ssh' || $n eq 'sshd' ) && $dev->{ssh_tries};
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "ssh" || $n eq "sshd" and $$dev{"ssh_tries"} 2 66 68
Condition83%5/6
$n eq "ssh" || $n eq "sshd" and $$dev{"ssh_tries"}
!ll&&!rl&&r
6152
$n eq "ssh" or $n eq "sshd"
l!l&&r!l&&!r
7061
MC/DC66%2/3
$n eq "ssh" || $n eq "sshd" and $$dev{"ssh_tries"}
$n eq "ssh" $n eq "sshd" $$dev{"ssh_tries"}
Truth table60%3/5
A or B and C
A= $n eq "ssh"B= $n eq "sshd"C= $$dev{"ssh_tries"}
ABCresult
00X0
1X00
0100
1X11
0111
7734 68 ▶ if ( $n =~ /\.timer\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /\.timer\z/) 2 66 68
7735 2 my $i = _timer_info( $dev, $n, $svc );
7736 2 push @l, map {"Oct 20 09:00:00 $host systemd[1]: " . _unit_file( $n, $svc ) . ":$_->[0]: Failed to parse calendar specification, ignoring: $_->[1]"} @{ $i->{bad} };
7737 2 ▶ push @l, "Oct 20 09:00:00 $host systemd[1]: $u: Timer unit lacks value setting. Refusing." unless @{ $i->{cal} } || $i->{other};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$$i{"cal"};} or $$i{"other"} 1 1 2
Condition66%2/3
@{$$i{"cal"};} or $$i{"other"}
l!l&&r!l&&!r
101
MC/DC50%1/2
@{$$i{"cal"};} or $$i{"other"}
@{$$i{"cal"};} $$i{"other"}
Truth table66%2/3
A or B
A= @{$$i{"cal"};}B= $$i{"other"}
ABresult
1X1
011
000
7738 }
7739 68 ▶ if ( !$svc->{active} && ( $svc->{failed} || _failing_need( $dev, $svc ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $$svc{"active"} and $$svc{"failed"} || _failing_need($dev, $svc)) 14 54 68
Condition83%5/6
not $$svc{"active"} and $$svc{"failed"} || _failing_need($dev, $svc)
!ll&&!rl&&r
431114
$$svc{"failed"} or _failing_need($dev, $svc)
l!l&&r!l&&!r
14011
MC/DC66%2/3
not $$svc{"active"} and $$svc{"failed"} || _failing_need($dev, $svc)
not $$svc{"active"} $$svc{"failed"} _failing_need($dev, $svc)
Truth table75%3/4
not(A) and B or C
A= not $$svc{"active"}B= $$svc{"failed"}C= _failing_need($dev, $svc)
ABCresult
0XX0
1000
11X1
1011
7740 14 my $bad = _failing_need( $dev, $svc );
7741 14 my $c = _clock($dev);
7742 14 ▶ push @l, @{ $bad->{log} || [] } if $bad;
Branch: 1 branch
BranchTrueFalseTotal
if $bad 5 9 14
Condition50%1/2
$$bad{'log'} || []
l!l
50
MC/DC0%0/1
$$bad{'log'} || []
$$bad{'log'}
Truth table50%1/2
A
A= $$bad{'log'}
Aresult
11
00
7743 push @l, "$c:03 $host systemd[1]: $u: Main process exited, code=exited, status=1/FAILURE",
7744 "$c:03 $host systemd[1]: $u: Failed with result 'exit-code'.",
7745 "$c:03 $host systemd[1]: Failed to start $u" . _desc($svc) . '.'
7746 14 ▶ if $svc->{failed} && !_unit_bad( $n, _unit_props( $svc->{unit_loaded} // _unit_text( $dev, $n, $svc ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"failed"} and not _unit_bad($n, _unit_props($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc))) 14 0 14
Condition50%3/6
$$svc{"failed"} and not _unit_bad($n, _unit_props($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)))
!ll&&!rl&&r
0014
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
l!l&&r!l&&!r
905
MC/DC0%0/2
$$svc{"failed"} and not _unit_bad($n, _unit_props($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)))
$$svc{"failed"} not _unit_bad($n, _unit_props($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)))
MC/DC50%1/2
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
$$svc{"unit_loaded"} _unit_text($dev, $n, $svc)
Truth table33%1/3
A and not(B)
A= $$svc{"failed"}B= not _unit_bad($n, _unit_props($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)))
ABresult
0X0
100
111
Truth table66%2/3
A // B
A= $$svc{"unit_loaded"}B= _unit_text($dev, $n, $svc)
ABresult
1X1
011
000
7747 }
7748 68 ▶ for my $r ( 1 .. ( $svc->{runs} // 0 ) ) {
Condition100%2/2
$$svc{"runs"} // 0
l!l
365
MC/DC100%1/1
$$svc{"runs"} // 0
$$svc{"runs"}
Truth table100%2/2
A
A= $$svc{"runs"}
Aresult
11
00
7749 3 ▶ my $d = defined $svc->{description} ? " - $svc->{description}" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $$svc{'description'} ? : 2 1 3
7750 3 ▶ push @l, sprintf( "Oct 20 14:%02d:00 $host systemd[1]: Starting $u$d...", $r ), map( { sprintf "Oct 20 14:%02d:01 %s", $r, $_ } @{ $svc->{run_journal} || [] } ),
Condition100%2/2
$$svc{'run_journal'} || []
l!l
12
MC/DC100%1/1
$$svc{'run_journal'} || []
$$svc{'run_journal'}
Truth table100%2/2
A
A= $$svc{'run_journal'}
Aresult
11
00
7751 sprintf( "Oct 20 14:%02d:01 $host systemd[1]: $u: Deactivated successfully.", $r ),
7752 sprintf( "Oct 20 14:%02d:01 $host systemd[1]: Finished $u$d.", $r );
7753 }
7754 68 return @l;
7755 }
7756  
7757 50 ▶sub _journalctl {
Subroutine _journalctl: called CC=79 SCAR=60.7
7758 50 my ( $dev, $av, $ctx ) = @_;
7759 50 my $host = $ctx->{host};
7760 50 my @a = @$av;
7761 50 my ( @units, $n, $grep, $since, $until, $out, $reverse, $file, $boots, $all_units, $kernel );
7762 50 ▶ my $val = sub { my ($x) = @_; $x =~ /=(.*)\z/s ? $1 : shift(@a) };
Subroutine __ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$x =~ /=(.*)\z/s ? : 0 9 9
7763 50 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 74 46 120
7764 74 my $x = shift @a;
7765 74 ▶ if ( $x eq '-u' || $x eq '--unit' ) { push @units, _unit( shift(@a) // '' ) }
Branch: 27 branches
BranchTrueFalseTotal
if ($x eq '-u' or $x eq '--unit') { } 38 36 74
elsif ($x =~ /\A--unit=(.+)\z/) { } 0 36 36
elsif ($x eq '-n' or $x eq '--lines') { } 17 19 36
elsif ($x =~ /\A(?:-n|--lines=)(\d+)\z/) { } 0 19 19
elsif ($x eq '-e' or $x eq '--pager-end') { } 0 19 19
elsif ($x eq '-g' or $x eq '--grep') { } 1 18 19
elsif ($x =~ /\A--grep=(.+)\z/) { } 0 18 18
elsif ($x =~ /\A(?:-S|--since)(?:=.*)?\z/) { } 8 10 18
elsif ($x =~ /\A(?:-U|--until)(?:=.*)?\z/) { } 0 10 10
elsif ($x =~ /\A(?:-o|--output)(?:=.*)?\z/) { } 1 9 10
elsif ($x =~ /\A--file(?:=.*)?\z/) { } 0 9 9
elsif ($x eq '-r' or $x eq '--reverse') { } 0 9 9
elsif ($x eq '--list-boots') { } 2 7 9
elsif ($x eq '-k' or $x eq '--dmesg') { } 2 5 7
elsif ($x eq '-p' or $x eq '--priority' or $x eq '-t' or $x eq '--identifier') { } 0 5 5
elsif ($x =~ /\A-(?:b|-boot)\z/) { } 2 3 5
elsif ($x eq '-f' or $x eq '--follow') { } 0 3 3
elsif ($x eq '--flush') { } 1 2 3
elsif ($x =~ /\A--(?:rotate|sync|relinquish-var)\z/) { } 0 2 2
elsif ($x eq '--verify') { } 0 2 2
elsif ($x =~ /\A-\w*u\z/) { } 0 2 2
elsif ($x eq '--disk-usage') { } 1 1 2
elsif ($x =~ /\A--vacuum-(size|time|files)=(.+)\z/) { } 0 1 1
elsif ($x =~ /\A-(?:x|-no-pager|-no-hostname|-quiet|q|-catalog|a|-all|-merge|m|-system|-utc|-no-full|l|-full)\z/) { } 0 1 1
elsif ($x =~ /\A(?:-F|--field|--facility|--cursor|--after-cursor|--cursor-file|-D|--directory|--header|--namespace|-M|--machine|--output-fields|--show-cursor|--user|--user-unit|-I|-N|--fields)(?:=.*)?\z/) { } 0 1 1
elsif ($x =~ /\A--/) { } 1 0 1
elsif ($x =~ /\A-(.)/) { } 0 0 0
Condition60%3/5
$x eq "-u" or $x eq "--unit"
l!l&&r!l&&!r
38036
shift @a // ""
l!l
380
MC/DC50%1/2
$x eq "-u" or $x eq "--unit"
$x eq "-u" $x eq "--unit"
MC/DC0%0/1
shift @a // ""
shift @a
Truth table66%2/3
A or B
A= $x eq "-u"B= $x eq "--unit"
ABresult
1X1
011
000
Truth table50%1/2
A
A= shift @a
Aresult
11
00
7766 0 elsif ( $x =~ /\A--unit=(.+)\z/ ) { push @units, _unit($1) }
7767 17 ▶ elsif ( $x eq '-n' || $x eq '--lines' ) { $n = shift @a }
Condition66%2/3
$x eq "-n" or $x eq "--lines"
l!l&&r!l&&!r
17019
MC/DC50%1/2
$x eq "-n" or $x eq "--lines"
$x eq "-n" $x eq "--lines"
Truth table66%2/3
A or B
A= $x eq "-n"B= $x eq "--lines"
ABresult
1X1
011
000
7768 0 elsif ( $x =~ /\A(?:-n|--lines=)(\d+)\z/ ) { $n = $1 }
7769 0 ▶ elsif ( $x eq '-e' || $x eq '--pager-end' ) { $n //= 1000 }
Condition20%1/5
$x eq "-e" or $x eq "--pager-end"
l!l&&r!l&&!r
0019
$n //= 1000
l!l
00
MC/DC0%0/2
$x eq "-e" or $x eq "--pager-end"
$x eq "-e" $x eq "--pager-end"
MC/DC0%0/1
$n //= 1000
$n
Truth table33%1/3
A or B
A= $x eq "-e"B= $x eq "--pager-end"
ABresult
1X1
011
000
Truth table0%0/2
A
A= $n
Aresult
11
00
7770 1 ▶ elsif ( $x eq '-g' || $x eq '--grep' ) { $grep = shift @a }
Condition66%2/3
$x eq "-g" or $x eq "--grep"
l!l&&r!l&&!r
1018
MC/DC50%1/2
$x eq "-g" or $x eq "--grep"
$x eq "-g" $x eq "--grep"
Truth table66%2/3
A or B
A= $x eq "-g"B= $x eq "--grep"
ABresult
1X1
011
000
7771 0 elsif ( $x =~ /\A--grep=(.+)\z/ ) { $grep = $1 }
7772 8 elsif ( $x =~ /\A(?:-S|--since)(?:=.*)?\z/ ) { $since = $val->($x) }
7773 0 elsif ( $x =~ /\A(?:-U|--until)(?:=.*)?\z/ ) { $until = $val->($x) }
7774 1 elsif ( $x =~ /\A(?:-o|--output)(?:=.*)?\z/ ) { $out = $val->($x) }
7775 0 elsif ( $x =~ /\A--file(?:=.*)?\z/ ) { $file = $val->($x) }
7776 0 ▶ elsif ( $x eq '-r' || $x eq '--reverse' ) { $reverse = 1 }
Condition33%1/3
$x eq "-r" or $x eq "--reverse"
l!l&&r!l&&!r
009
MC/DC0%0/2
$x eq "-r" or $x eq "--reverse"
$x eq "-r" $x eq "--reverse"
Truth table33%1/3
A or B
A= $x eq "-r"B= $x eq "--reverse"
ABresult
1X1
011
000
7777 2 elsif ( $x eq '--list-boots' ) { $boots = 1 }
7778 2 ▶ elsif ( $x eq '-k' || $x eq '--dmesg' ) { $kernel = 1 } # Kernel-Meldungen: der Zustand kennt keine (wie dmesg)
Condition100%3/3
$x eq "-k" or $x eq "--dmesg"
l!l&&r!l&&!r
115
MC/DC100%2/2
$x eq "-k" or $x eq "--dmesg"
$x eq "-k" $x eq "--dmesg"
Truth table100%3/3
A or B
A= $x eq "-k"B= $x eq "--dmesg"
ABresult
1X1
011
000
7779 0 ▶ elsif ( $x eq '-p' || $x eq '--priority' || $x eq '-t' || $x eq '--identifier' ) { shift @a } # Prioritaeten nicht nachgebildet: alles
Condition33%3/9
$x eq "-p" or $x eq "--priority" or $x eq "-t" or $x eq "--identifier"
l!l&&r!l&&!r
005
$x eq "-p" or $x eq "--priority" or $x eq "-t"
l!l&&r!l&&!r
005
$x eq "-p" or $x eq "--priority"
l!l&&r!l&&!r
005
MC/DC0%0/4
$x eq "-p" or $x eq "--priority" or $x eq "-t" or $x eq "--identifier"
$x eq "-p" $x eq "--priority" $x eq "-t" $x eq "--identifier"
Truth table20%1/5
A or B or C or D
A= $x eq "-p"B= $x eq "--priority"C= $x eq "-t"D= $x eq "--identifier"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
7780 elsif ( $x =~ /\A-(?:b|-boot)\z/ ) { # nachgebildet ist nur der laufende Start (--list-boots: einer)
7781 2 ▶ return ( "Data from the specified boot ($a[0]) is not available: No such boot ID in journal.", 0 ) if @a && $a[0] =~ /\A-[1-9]\d*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if @a and $a[0] =~ /\A-[1-9]\d*\z/ 1 1 2
Condition66%2/3
@a and $a[0] =~ /\A-[1-9]\d*\z/
!ll&&!rl&&r
011
MC/DC50%1/2
@a and $a[0] =~ /\A-[1-9]\d*\z/
@a $a[0] =~ /\A-[1-9]\d*\z/
Truth table66%2/3
A and B
A= @aB= $a[0] =~ /\A-[1-9]\d*\z/
ABresult
0X0
100
111
7782 1 ▶ shift @a if @a && $a[0] =~ /\A-?\d+\z|\A[0-9a-f]{32}\z/;
Branch: 1 branch
BranchTrueFalseTotal
if @a and $a[0] =~ /\A-?\d+\z|\A[0-9a-f]{32}\z/ 1 0 1
Condition33%1/3
@a and $a[0] =~ /\A-?\d+\z|\A[0-9a-f]{32}\z/
!ll&&!rl&&r
001
MC/DC0%0/2
@a and $a[0] =~ /\A-?\d+\z|\A[0-9a-f]{32}\z/
@a $a[0] =~ /\A-?\d+\z|\A[0-9a-f]{32}\z/
Truth table33%1/3
A and B
A= @aB= $a[0] =~ /\A-?\d+\z|\A[0-9a-f]{32}\z/
ABresult
0X0
100
111
7783 }
7784 0 ▶ elsif ( $x eq '-f' || $x eq '--follow' ) { push @GAPS, join( ' ', 'journalctl', @$av ); return ( '', 0 ) }
Condition33%1/3
$x eq "-f" or $x eq "--follow"
l!l&&r!l&&!r
003
MC/DC0%0/2
$x eq "-f" or $x eq "--follow"
$x eq "-f" $x eq "--follow"
Truth table33%1/3
A or B
A= $x eq "-f"B= $x eq "--follow"
ABresult
1X1
011
000
7785 1 ▶ elsif ( $x eq '--flush' ) { _journal_flush($dev) if _journal_persistent($dev); return ( '', 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if _journal_persistent($dev) 1 0 1
7786 0 elsif ( $x =~ /\A--(?:rotate|sync|relinquish-var)\z/ ) { return ( '', 1 ) }
7787 elsif ( $x eq '--verify' ) {
7788 0 return ( join( "\n", map {"PASS: $_"} grep {/\.journal~?\z/} _under( $dev, '/var/log/journal' ), _under( $dev, '/run/log/journal' ) ), 1 );
7789 }
7790 0 ▶ elsif ( $x =~ /\A-\w*u\z/ ) { push @units, _unit( shift(@a) // '' ) } # -xeu dienst
Condition0%0/2
shift @a // ""
l!l
00
MC/DC0%0/1
shift @a // ""
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
7791 elsif ( $x eq '--disk-usage' ) {
7792 1 my $t = 0;
7793 1 $t += _file_size( _file_entry( $dev, $_ ) ) for _under( $dev, '/var/log/journal' ), _under( $dev, '/run/log/journal' );
7794 1 return ( 'Archived and active journals take up ' . _human($t) . ' in the file system.', 1 );
7795 }
7796 elsif ( $x =~ /\A--vacuum-(size|time|files)=(.+)\z/ ) {
7797 0 my ( $kind, $v ) = ( $1, $2 );
7798 0 my $freed;
7799 0 ▶ if ( $kind eq 'size' ) { $freed = _journal_vacuum( $dev, size => _bytes($v) ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq 'size') { } 0 0 0
elsif ($kind eq 'time') { } 0 0 0
7800 elsif ( $kind eq 'time' ) {
7801 0 ▶ my $age = _secs($v) // return ( "Failed to parse timespan '$v'.", 0 );
Condition0%0/2
_secs($v) // (return "Failed to parse timespan '${v}'.", 0)
l!l
00
MC/DC0%0/1
_secs($v) // (return "Failed to parse timespan '${v}'.", 0)
_secs($v)
Truth table0%0/2
A
A= _secs($v)
Aresult
11
00
7802 0 $freed = _journal_vacuum( $dev, age => $age );
7803 }
7804 0 else { push @GAPS, "journalctl --vacuum-files=$v"; return ( '', 0 ) }
7805 0 return ( 'Vacuuming done, freed ' . _human($freed) . ' of archived journals from /var/log/journal.', 1 );
7806 }
7807 elsif ( $x =~ /\A-(?:x|-no-pager|-no-hostname|-quiet|q|-catalog|a|-all|-merge|m|-system|-utc|-no-full|l|-full)\z/ ) { }
7808 elsif ( $x =~ /\A(?:-F|--field|--facility|--cursor|--after-cursor|--cursor-file|-D|--directory|--header|--namespace|-M|--machine|--output-fields|--show-cursor|--user|--user-unit|-I|-N|--fields)(?:=.*)?\z/ ) {
7809 0 push @GAPS, join( ' ', 'journalctl', @$av ); # echte Optionen ohne Nachbildung
7810 0 return ( '', 0 );
7811 }
7812 1 elsif ( $x =~ /\A--/ ) { ( my $o = $x ) =~ s/=.*//s; return ( "journalctl: unrecognized option '$o'", 0 ) }
7813 0 elsif ( $x =~ /\A-(.)/ ) { return ( "journalctl: invalid option -- '$1'", 0 ) }
7814 0 else { push @GAPS, join( ' ', 'journalctl', @$av ); return ( '', 0 ) } # Treffer wie _SYSTEMD_UNIT=…
7815 }
7816 46 ▶ return ( '-- No entries --', 1 ) if $kernel;
Branch: 1 branch
BranchTrueFalseTotal
if $kernel 2 44 46
7817 # Zeilen mit Zeitpunkt: [ epoche, text ]
7818 44 my @l;
7819 44 ▶ if ( defined $file ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $file) { } 0 44 44
elsif (@units) { } 38 6 44
7820 0 ▶ return ( "Failed to open journal file $file: No such file or directory", 0 ) unless _file_entry( $dev, $file );
Branch: 1 branch
BranchTrueFalseTotal
unless _file_entry($dev, $file) 0 0 0
7821 0 @l = grep { $_->[2] eq $file } _journal_file_lines( $dev, $host );
7822 }
7823 elsif (@units) {
7824 38 for my $u (@units) {
7825 38 ▶ my $svc = ( $dev->{services} || {} )->{$u} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $svc = ($$dev{"services"} || {})->{$u} or next 38 0 38
Condition50%1/2
$$dev{'services'} || {}
l!l
380
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
7826 38 push @l, map { [ _jtime($_), $_ ] } _journal_lines( $dev, $u, $svc, $host );
7827 }
7828 }
7829 else {
7830 6 ▶ @l = ( ( map { my $s = $_; map { [ _jtime($_), $_ ] } _journal_lines( $dev, $s, $dev->{services}{$s}, $host ) } sort keys %{ $dev->{services} || {} } ),
Condition50%1/2
$$dev{'services'} || {}
l!l
60
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
7831 _journal_file_lines( $dev, $host ) );
7832 }
7833 44 @l = sort { $a->[0] <=> $b->[0] } @l;
7834 44 ▶ if ($boots) {
Branch: 1 branch
BranchTrueFalseTotal
if ($boots) 2 42 44
7835 0 my @all = sort { $a->[0] <=> $b->[0] } ( _journal_file_lines( $dev, $host ),
7836 2 ▶ map { my $s = $_; map { [ _jtime($_), $_ ] } _journal_lines( $dev, $s, $dev->{services}{$s}, $host ) } keys %{ $dev->{services} || {} } );
Condition50%1/2
$$dev{'services'} || {}
l!l
20
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
7837 2 ▶ return ( 'No boots found.', 0 ) unless @all;
Branch: 1 branch
BranchTrueFalseTotal
unless @all 0 2 2
7838 2 my $f = Langertha::Holmgang::Sim::Linux::Calendar::format_local( $all[0][0] );
7839 2 my $t = Langertha::Holmgang::Sim::Linux::Calendar::format_local( _dev_now($dev) );
7840 2 return ( " 0 7f3e9c2b5a1d4e8f9b0c6a2d4e8f1a3c $f\x{2014}$t", 1 );
7841 }
7842 42 for my $b ( [ $since, 1 ], [ $until, 0 ] ) {
7843 83 ▶ next unless defined $b->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$b[0] 75 8 83
7844 8 ▶ my $t = _parse_since( $b->[0], _dev_now($dev) ) // return ( "Failed to parse timestamp: $b->[0]", 0 );
Condition100%2/2
_parse_since($$b[0], _dev_now($dev)) // (return "Failed to parse timestamp: $$b[0]", 0)
l!l
71
MC/DC100%1/1
_parse_since($$b[0], _dev_now($dev)) // (return "Failed to parse timestamp: $$b[0]", 0)
_parse_since($$b[0], _dev_now($dev))
Truth table100%2/2
A
A= _parse_since($$b[0], _dev_now($dev))
Aresult
11
00
7845 7 ▶ @l = grep { $b->[1] ? $_->[0] >= $t : $_->[0] <= $t } @l;
Branch: 1 branch
BranchTrueFalseTotal
$$b[1] ? : 7 0 7
7846 }
7847 41 my @txt = map { $_->[1] } @l;
7848 41 ▶ if ( defined $grep ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grep) 1 40 41
7849 1 ▶ my $re = eval { qr/$grep/i } or return ( "Failed to compile pattern \"$grep\"", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $re = eval { do { qr/$grep/i } } or return qq[Failed to compile pattern "$grep"], 0 1 0 1
7850 0 @txt = grep { $_ =~ $re } @txt;
7851 }
7852 41 ▶ @txt = @txt[ ( @txt > $n ? @txt - $n : 0 ) .. $#txt ] if defined $n && $n =~ /\A\d+\z/;
Branch: 2 branches
BranchTrueFalseTotal
if defined $n and $n =~ /\A\d+\z/ 16 25 41
@txt > $n ? : 9 7 16
Condition66%2/3
defined $n and $n =~ /\A\d+\z/
!ll&&!rl&&r
25016
MC/DC50%1/2
defined $n and $n =~ /\A\d+\z/
defined $n $n =~ /\A\d+\z/
Truth table66%2/3
A and B
A= defined $nB= $n =~ /\A\d+\z/
ABresult
0X0
100
111
7853 41 ▶ @txt = reverse @txt if $reverse;
Branch: 1 branch
BranchTrueFalseTotal
if $reverse 0 41 41
7854 41 ▶ if ( defined $out ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $out) 1 40 41
7855 1 ▶ if ( $out eq 'short-iso' || $out eq 'short-iso-precise' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($out eq 'short-iso' or $out eq 'short-iso-precise') { } 1 0 1
elsif ($out eq 'cat') { } 0 0 0
elsif (not $out =~ /\A(?:short|short-full|short-precise|with-unit)\z/) { } 0 0 0
Condition33%1/3
$out eq "short-iso" or $out eq "short-iso-precise"
l!l&&r!l&&!r
100
MC/DC0%0/2
$out eq "short-iso" or $out eq "short-iso-precise"
$out eq "short-iso" $out eq "short-iso-precise"
Truth table33%1/3
A or B
A= $out eq "short-iso"B= $out eq "short-iso-precise"
ABresult
1X1
011
000
7856 @txt = map {
7857 1 my $l = $_;
7858 1 my $t = _jtime($l);
7859 1 my $off = Langertha::Holmgang::Sim::Linux::Calendar::offset($t);
7860 1 my @g = gmtime( $t + $off );
7861 1 $l =~ s/\A\w{3}\s+\d+ \d\d:\d\d:\d\d/sprintf( '%04d-%02d-%02dT%02d:%02d:%02d%s%02d%02d', $g[5] + 1900, $g[4] + 1, $g[3], $g[2], $g[1], $g[0], '+', $off \/ 3600, 0 )/e;
7862 1 $l
7863 } @txt;
7864 }
7865 0 elsif ( $out eq 'cat' ) { s/\A\w{3}\s+\d+ \d\d:\d\d:\d\d \S+ [^:]+: // for @txt }
7866 0 elsif ( $out !~ /\A(?:short|short-full|short-precise|with-unit)\z/ ) { push @GAPS, "journalctl -o $out"; return ( '', 0 ) }
7867 }
7868 41 ▶ return ( '-- No entries --', 1 ) unless @txt;
Branch: 1 branch
BranchTrueFalseTotal
unless @txt 4 37 41
7869 37 return ( join( "\n", @txt ), 1 );
7870 }
7871  
7872 # "Oct 20 14:00:01 host …" -> Epoche (Ortszeit, Jahr 2026)
7873 229 ▶sub _jtime {
Subroutine _jtime: called CC=4 SCAR=14.9
7874 229 my ($l) = @_;
7875 229 ▶ my ( $mon, $d, $h, $mi, $s ) = ( $l // '' ) =~ /\A(\w{3})\s+(\d+) (\d\d):(\d\d):(\d\d)/ or return _sim_now();
Branch: 1 branch
BranchTrueFalseTotal
() = ($l // "") =~ /\A(\w{3})\s+(\d+) (\d\d):(\d\d):(\d\d)/ or return _sim_now() 229 0 229
Condition50%1/2
$l // ""
l!l
2290
MC/DC0%0/1
$l // ""
$l
Truth table50%1/2
A
A= $l
Aresult
11
00
7876 229 ▶ my $lt = Time::Local::timegm( $s, $mi, $h, $d, $MON{$mon} // 9, 2026 );
Condition50%1/2
$MON{$mon} // 9
l!l
2290
MC/DC0%0/1
$MON{$mon} // 9
$MON{$mon}
Truth table50%1/2
A
A= $MON{$mon}
Aresult
11
00
7877 229 return $lt - Langertha::Holmgang::Sim::Linux::Calendar::offset( $lt - 3600 );
7878 }
7879  
7880 # --since/--until: 2026-10-01[ 12:00[:00]], 06:00[:00] (heute), today, yesterday, now, -2d,
7881 # "2 days ago", "1 hour ago"; $now: die Uhr des Geraets (Vorgabe: die der Simulation)
7882 9 ▶sub _parse_since {
Subroutine _parse_since: called CC=16 SCAR=28.8
7883 9 my ( $v, $now ) = @_;
7884 9 require Time::Local;
7885 9 ▶ $now //= _sim_now();
Condition33%1/3
$now //= _sim_now()
l!l&&r!l&&!r
900
MC/DC0%0/2
$now //= _sim_now()
$now _sim_now()
Truth table33%1/3
A //= B
A= $nowB= _sim_now()
ABresult
1X1
011
000
7886 9 ▶ my $loc = sub { my $lt = Time::Local::timegm(@_); $lt - Langertha::Holmgang::Sim::Linux::Calendar::offset( $lt - 3600 ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
7887 9 my @g = gmtime( $now + Langertha::Holmgang::Sim::Linux::Calendar::offset($now) );
7888 9 ▶ return $now if $v eq 'now';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "now" 0 9 9
7889 9 ▶ return $loc->( 0, 0, 0, $g[3], $g[4], $g[5] + 1900 ) if $v eq 'today';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "today" 1 8 9
7890 8 ▶ return $loc->( 0, 0, 0, $g[3], $g[4], $g[5] + 1900 ) - 86400 if $v eq 'yesterday';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "yesterday" 1 7 8
7891 7 ▶ return $loc->( 0, 0, 0, $g[3], $g[4], $g[5] + 1900 ) + 86400 if $v eq 'tomorrow';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "tomorrow" 0 7 7
7892 7 ▶ if ( $v =~ /\A(\d{4})-(\d\d)-(\d\d)(?:[ T](\d\d):(\d\d)(?::(\d\d))?)?\z/ ) { return $loc->( $6 // 0, $5 // 0, $4 // 0, $3, $2 - 1, $1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /\A(\d{4})-(\d\d)-(\d\d)(?:[ T](\d\d):(\d\d)(?::(\d\d))?)?\z/) 2 5 7
Condition83%5/6
$6 // 0
l!l
02
$5 // 0
l!l
11
$4 // 0
l!l
11
MC/DC0%0/1
$6 // 0
$6
MC/DC100%1/1
$5 // 0
$5
MC/DC100%1/1
$4 // 0
$4
Truth table50%1/2
A
A= $6
Aresult
11
00
Truth table100%2/2
A
A= $5
Aresult
11
00
Truth table100%2/2
A
A= $4
Aresult
11
00
7893 5 ▶ if ( $v =~ /\A(\d\d?):(\d\d)(?::(\d\d))?\z/ ) { return $loc->( $3 // 0, $2, $1, $g[3], $g[4], $g[5] + 1900 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /\A(\d\d?):(\d\d)(?::(\d\d))?\z/) 2 3 5
Condition50%1/2
$3 // 0
l!l
02
MC/DC0%0/1
$3 // 0
$3
Truth table50%1/2
A
A= $3
Aresult
11
00
7894 3 ▶ if ( $v =~ /\A-(\d+)\s*(\w+)\z/ || $v =~ /\A(\d+)\s*(\w+?)\s+ago\z/ ) { my $s = _secs("$1$2") // _secs("$1 $2"); return defined $s ? $now - $s : undef }
Branch: 2 branches
BranchTrueFalseTotal
if ($v =~ /\A-(\d+)\s*(\w+)\z/ or $v =~ /\A(\d+)\s*(\w+?)\s+ago\z/) 2 1 3
defined $s ? : 2 0 2
Condition50%3/6
$v =~ /\A-(\d+)\s*(\w+)\z/ or $v =~ /\A(\d+)\s*(\w+?)\s+ago\z/
l!l&&r!l&&!r
021
_secs("$1$2") // _secs("$1 $2")
l!l&&r!l&&!r
200
MC/DC50%1/2
$v =~ /\A-(\d+)\s*(\w+)\z/ or $v =~ /\A(\d+)\s*(\w+?)\s+ago\z/
$v =~ /\A-(\d+)\s*(\w+)\z/ $v =~ /\A(\d+)\s*(\w+?)\s+ago\z/
MC/DC0%0/2
_secs("$1$2") // _secs("$1 $2")
_secs("$1$2") _secs("$1 $2")
Truth table66%2/3
A or B
A= $v =~ /\A-(\d+)\s*(\w+)\z/B= $v =~ /\A(\d+)\s*(\w+?)\s+ago\z/
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= _secs("$1$2")B= _secs("$1 $2")
ABresult
1X1
011
000
7895 1 return undef;
7896 }
7897  
7898 # Je Journal-Datei eine unauffaellige Zeile zu ihrer Zeit (damit das Journal so weit
7899 # zurueckreicht wie seine Dateien): [ epoche, text, datei ]
7900 8 ▶sub _journal_file_lines {
Subroutine _journal_file_lines: called CC=6 SCAR=18.5
7901 8 my ( $dev, $host ) = @_;
7902 8 ▶ $host //= $dev->{hostname} // 'localhost';
Condition25%1/4
$host //= $$dev{"hostname"} // "localhost"
l!l
80
$$dev{"hostname"} // "localhost"
l!l
00
MC/DC0%0/1
$host //= $$dev{"hostname"} // "localhost"
$host
Truth table50%1/2
A
A= $host
Aresult
11
00
7903 8 my @msg = ( 'CRON[%d]: pam_unix(cron:session): session closed for user root', 'systemd[1]: Starting systemd-tmpfiles-clean.service - Cleanup of Temporary Directories...',
7904 'systemd[1]: logrotate.service: Deactivated successfully.', 'sshd[%d]: Received disconnect from 10.0.0.5 port 52114:11: disconnected by user' );
7905 8 my @r;
7906 8 my $i = 0;
7907 8 for my $p ( grep {/\.journal~?\z/} _under( $dev, '/var/log/journal' ), _under( $dev, '/run/log/journal' ) ) {
7908 6 my $fe = _file_entry( $dev, $p );
7909 6 ▶ my $lt = defined $fe->{mtime} ? _mtime($fe) : _sim_now() + Langertha::Holmgang::Sim::Linux::Calendar::offset( _sim_now() ); # Ortszeit
Branch: 1 branch
BranchTrueFalseTotal
defined $$fe{'mtime'} ? : 0 6 6
7910 6 my @g = gmtime $lt;
7911 6 my $stamp = sprintf '%s %2d %02d:%02d:%02d', (qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ))[ $g[4] ], $g[3], $g[2], $g[1], $g[0];
7912 6 my $m = $msg[ $i++ % @msg ];
7913 6 ▶ $m = sprintf $m, 1000 + 37 * $i if $m =~ /%d/;
Branch: 1 branch
BranchTrueFalseTotal
if $m =~ /%d/ 6 0 6
7914 6 push @r, [ $lt - Langertha::Holmgang::Sim::Linux::Calendar::offset( $lt - 3600 ), "$stamp $host $m", $p ];
7915 }
7916 8 return @r;
7917 }
7918  
7919 # Speichert journald dauerhaft? (Storage=persistent, oder auto mit /var/log/journal)
7920 1 ▶sub _journal_persistent {
Subroutine _journal_persistent: called CC=9 SCAR=26.5
7921 1 my ($dev) = @_;
7922 1 ▶ my $svc = ( $dev->{services} || {} )->{'systemd-journald'} || {};
Condition50%2/4
($$dev{'services'} || {})->{'systemd-journald'} || {}
l!l
10
$$dev{'services'} || {}
l!l
10
MC/DC0%0/1
($$dev{'services'} || {})->{'systemd-journald'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
7923 1 ▶ my $t = $svc->{running} // _file_text( $dev, '/etc/systemd/journald.conf' ) // '';
Condition40%2/5
($$svc{"running"} // _file_text($dev, "/etc/systemd/journald.conf")) // ""
l!l
10
$$svc{"running"} // _file_text($dev, "/etc/systemd/journald.conf")
l!l&&r!l&&!r
100
MC/DC0%0/2
($$svc{"running"} // _file_text($dev, "/etc/systemd/journald.conf")) // ""
$$svc{"running"} _file_text($dev, "/etc/systemd/journald.conf")
Truth table33%1/3
A // B
A= $$svc{"running"}B= _file_text($dev, "/etc/systemd/journald.conf")
ABresult
1X1
011
000
7924 1 my ($st) = $t =~ /^\s*Storage\s*=\s*(\S+)\s*$/m;
7925 1 ▶ $st //= 'auto';
Condition50%1/2
$st //= "auto"
l!l
01
MC/DC0%0/1
$st //= "auto"
$st
Truth table50%1/2
A
A= $st
Aresult
11
00
7926 1 ▶ return 1 if $st eq 'persistent';
Branch: 1 branch
BranchTrueFalseTotal
if $st eq "persistent" 0 1 1
7927 1 ▶ return $st eq 'auto' && _is_dir( $dev, '/var/log/journal' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$st eq 'auto' && _is_dir($dev, '/var/log/journal') ? : 1 0 1
Condition33%1/3
$st eq "auto" and _is_dir($dev, "/var/log/journal")
!ll&&!rl&&r
001
MC/DC0%0/2
$st eq "auto" and _is_dir($dev, "/var/log/journal")
$st eq "auto" _is_dir($dev, "/var/log/journal")
Truth table33%1/3
A and B
A= $st eq "auto"B= _is_dir($dev, "/var/log/journal")
ABresult
0X0
100
111
7928 }
7929  
7930 # Laufzeit-Journal (/run/log/journal/<id>) nach /var/log/journal/<id> uebernehmen
7931 4 ▶sub _journal_flush {
Subroutine _journal_flush: called CC=11 SCAR=24.2
7932 4 my ($dev) = @_;
7933 4 my @run = grep {/\.journal\z/} _under( $dev, '/run/log/journal' );
7934 4 ▶ my ($id) = map { m{\A/run/log/journal/([0-9a-f]{32})/} ? $1 : () } @run;
Branch: 1 branch
BranchTrueFalseTotal
m[\A/run/log/journal/([0-9a-f]{32})/] ? : 2 0 2
7935 4 ▶ ($id) = map { m{\A/var/log/journal/([0-9a-f]{32})/} ? $1 : () } _under( $dev, '/var/log/journal' ) unless defined $id;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $id 2 2 4
m[\A/var/log/journal/([0-9a-f]{32})/] ? : 0 2 2
7936 4 ▶ $id //= '3b1f5c7e9a2d4c6e8f0a1b3d5e7f9a1c';
Condition100%2/2
$id //= "3b1f5c7e9a2d4c6e8f0a1b3d5e7f9a1c"
l!l
22
MC/DC100%1/1
$id //= "3b1f5c7e9a2d4c6e8f0a1b3d5e7f9a1c"
$id
Truth table100%2/2
A
A= $id
Aresult
11
00
7937 4 ▶ $dev->{dirs}{'/var/log/journal'} //= {} unless _is_dir( $dev, '/var/log/journal' );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_dir($dev, "/var/log/journal") 2 2 4
Condition50%1/2
$$dev{"dirs"}{"/var/log/journal"} //= {}
l!l
02
MC/DC0%0/1
$$dev{"dirs"}{"/var/log/journal"} //= {}
$$dev{"dirs"}{"/var/log/journal"}
Truth table50%1/2
A
A= $$dev{"dirs"}{"/var/log/journal"}
Aresult
11
00
7938 4 my $dst = "/var/log/journal/$id/system.journal";
7939 4 ▶ if ( !_file_entry( $dev, $dst ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_file_entry($dev, $dst)) 4 0 4
7940 4 my $size = 0;
7941 4 $size += _file_size( _file_entry( $dev, $_ ) ) for @run;
7942 4 ▶ $dev->{files}{$dst} = { size => _human( $size || 8 * 1024 * 1024 ), owner => 'root', group => 'systemd-journal', mode => '0640',
Condition100%2/2
$size || 8388608
l!l
22
MC/DC100%1/1
$size || 8388608
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
7943 content => '', open_by => 'systemd-journald', mtime => 'Oct 20 14:00' };
7944 }
7945 4 delete $dev->{files}{$_} for @run;
7946 4 return;
7947 }
7948  
7949 42 ▶sub _unit_changed {
Subroutine _unit_changed: called CC=4 SCAR=13.9
7950 42 my ( $dev, $n, $svc ) = @_;
7951 42 ▶ return 0 unless defined $svc->{unit_loaded};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$svc{"unit_loaded"} 30 12 42
7952 12 my $now = _unit_text( $dev, $n, $svc );
7953 12 ▶ return defined $now && $now ne $svc->{unit_loaded} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $now && $now ne $$svc{'unit_loaded'} ? : 3 9 12
Condition66%2/3
defined $now and $now ne $$svc{"unit_loaded"}
!ll&&!rl&&r
093
MC/DC50%1/2
defined $now and $now ne $$svc{"unit_loaded"}
defined $now $now ne $$svc{"unit_loaded"}
Truth table66%2/3
A and B
A= defined $nowB= $now ne $$svc{"unit_loaded"}
ABresult
0X0
100
111
7954 }
7955  
7956 # Naechster Ablauf eines Timers (Epoche) oder undef
7957 7 ▶sub _timer_next {
Subroutine _timer_next: called CC=1 SCAR=0.0
7958 7 my ( $dev, $n, $svc ) = @_;
7959 7 my $i = _timer_info( $dev, $n, $svc );
7960 0 my ($t) = sort { $a <=> $b } grep {defined} map { Langertha::Holmgang::Sim::Linux::Calendar::next_elapse( $_, _sim_now() ) } @{ $i->{cal} };
7961 7 return $t;
7962 }
7963  
7964 # "Tue 2026-10-20 02:00:04 CEST" -> Epoche
7965 139 ▶sub _parse_stamp {
Subroutine _parse_stamp: called CC=3 SCAR=11.0
7966 139 my ($s) = @_;
7967 139 ▶ my ( $y, $m, $d, $h, $mi, $se, $tz ) = ( $s // '' ) =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d) (CEST|CET|UTC)/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = ($s // "") =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d) (CEST|CET|UTC)/ or return undef 86 53 139
Condition100%2/2
$s // ""
l!l
8653
MC/DC100%1/1
$s // ""
$s
Truth table100%2/2
A
A= $s
Aresult
11
00
7968 86 require Time::Local;
7969 86 return Time::Local::timegm( $se, $mi, $h, $d, $m - 1, $y ) - { CEST => 7200, CET => 3600, UTC => 0 }->{$tz};
7970 }
7971  
7972 10 ▶sub _systemctl_status {
Subroutine _systemctl_status: called CC=32 SCAR=36.5
7973 10 my ( $dev, $n, $svc, $host ) = @_;
7974 10 my $u = _uname($n);
7975 10 my $uf = _unit_file( $n, $svc );
7976 10 my $timer = $n =~ /\.timer\z/;
7977 10 ▶ my $en = _static( $dev, $n, $svc ) ? 'static' : ( $svc->{enabled} // 1 ) ? 'enabled' : 'disabled';
Branch: 2 branches
BranchTrueFalseTotal
_static($dev, $n, $svc) ? : 3 7 10
$$svc{'enabled'} // 1 ? : 7 0 7
Condition100%2/2
$$svc{"enabled"} // 1
l!l
16
MC/DC100%1/1
$$svc{"enabled"} // 1
$$svc{"enabled"}
Truth table100%2/2
A
A= $$svc{"enabled"}
Aresult
11
00
7978 10 ▶ my $bad = $timer && do { my $i = _timer_info( $dev, $n, $svc ); !@{ $i->{cal} } && !$i->{other} };
Condition50%3/6
$timer && do { my $i = _timer_info($dev, $n, $svc); not @{$$i{'cal'};} || $$i{'other'} }
!ll&&!rl&&r
910
@{$$i{'cal'};} || $$i{'other'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$timer && do { my $i = _timer_info($dev, $n, $svc); not @{$$i{'cal'};} || $$i{'other'} }
$timer do { my $i = _timer_info($dev, $n, $svc); not @{$$i{'cal'};} || $$i{'other'} }
MC/DC0%0/2
@{$$i{'cal'};} || $$i{'other'}
@{$$i{'cal'};} $$i{'other'}
Truth table66%2/3
A && B
A= $timerB= do { my $i = _timer_info($dev, $n, $svc); not @{$$i{'cal'};} || $$i{'other'} }
ABresult
0X0
100
111
Truth table33%1/3
A || B
A= @{$$i{'cal'};}B= $$i{'other'}
ABresult
1X1
011
000
7979 10 ▶ my $since = _svc_since($svc) // _parse_stamp($BOOT_STAMP);
Condition66%2/3
_svc_since($svc) // _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
l!l&&r!l&&!r
730
MC/DC0%0/2
_svc_since($svc) // _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
_svc_since($svc) _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
Truth table66%2/3
A // B
A= _svc_since($svc)B= _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
ABresult
1X1
011
000
7980 my $act = $svc->{active} ? ( $timer ? 'active (waiting)' : 'active (running)' ) . ' since '
7981 . Langertha::Holmgang::Sim::Linux::Calendar::format_local($since) . '; ' . _ago( $dev, $since )
7982 : $svc->{failed} ? "failed (Result: exit-code) since Tue 2026-10-20 09:12:03 CEST; 4h 47min ago"
7983 10 ▶ : $svc->{runs} ? 'inactive (dead) since Tue 2026-10-20 14:0' . $svc->{runs} . ':01 CEST; 1min ago'
Branch: 4 branches
BranchTrueFalseTotal
$$svc{'active'} ? : 9 1 10
$timer ? : 1 8 9
$$svc{'failed'} ? : 1 0 1
$$svc{'runs'} ? : 0 0 0
7984 : 'inactive (dead)';
7985 10 ▶ my $head = ( $svc->{active} ? '●' : $svc->{failed} ? '×' : '○' ) . " $u" . ( defined $svc->{description} && !$svc->{masked} ? " - $svc->{description}" : '' );
Branch: 3 branches
BranchTrueFalseTotal
$$svc{'active'} ? : 9 1 10
$$svc{'failed'} ? : 1 0 1
defined $$svc{'description'} && !$$svc{'masked'} ? : 7 3 10
Condition66%2/3
defined $$svc{"description"} and not $$svc{"masked"}
!ll&&!rl&&r
307
MC/DC50%1/2
defined $$svc{"description"} and not $$svc{"masked"}
defined $$svc{"description"} not $$svc{"masked"}
Truth table66%2/3
A and not(B)
A= defined $$svc{"description"}B= not $$svc{"masked"}
ABresult
0X0
100
111
7986 10 ▶ $bad ||= _unit_bad( $n, _unit_props( $svc->{unit_loaded} // _unit_text( $dev, $n, $svc ) ) );
Condition66%4/6
$bad ||= _unit_bad($n, _unit_props($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)))
l!l&&r!l&&!r
019
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
l!l&&r!l&&!r
505
MC/DC50%1/2
$bad ||= _unit_bad($n, _unit_props($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)))
$bad _unit_bad($n, _unit_props($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)))
MC/DC50%1/2
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
$$svc{"unit_loaded"} _unit_text($dev, $n, $svc)
Truth table66%2/3
A ||= B
A= $badB= _unit_bad($n, _unit_props($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)))
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $$svc{"unit_loaded"}B= _unit_text($dev, $n, $svc)
ABresult
1X1
011
000
7987 10 ▶ my @l = ( $head, $svc->{masked} ? " Loaded: masked (Reason: Unit $u is masked.)"
Branch: 2 branches
BranchTrueFalseTotal
$$svc{'masked'} ? : 0 10 10
$bad ? : 1 9 10
7988 : $bad ? " Loaded: bad-setting (Reason: Unit $u has a bad unit file setting.)"
7989 : " Loaded: loaded ($uf; $en; preset: enabled)" );
7990 10 my @d = _dropins( $dev, $n );
7991 10 ▶ if (@d) {
Branch: 1 branch
BranchTrueFalseTotal
if (@d) 3 7 10
7992 3 my %dir;
7993 3 for (@d) { my ( $dd, $f ) = m{\A(.*)/([^/]+)\z}; push @{ $dir{$dd} }, $f }
7994 3 my $first = 1;
7995 3 for my $dd ( sort keys %dir ) {
7996 3 ▶ push @l, ( $first ? ' Drop-In: ' : ' ' ) . $dd, ' └─' . join( ', ', @{ $dir{$dd} } );
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 3 0 3
7997 3 $first = 0;
7998 }
7999 }
8000 10 ▶ push @l, " Warning: The unit file, source configuration file or drop-ins of $u changed on disk. Run 'systemctl daemon-reload' to reload units."
Branch: 1 branch
BranchTrueFalseTotal
if _unit_changed($dev, $n, $svc) 1 9 10
8001 if _unit_changed( $dev, $n, $svc );
8002 10 push @l, " Active: $act";
8003 10 ▶ if ($timer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timer) 1 9 10
8004 1 ▶ my $next = $svc->{active} ? _timer_next( $dev, $n, $svc ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$svc{'active'} ? : 1 0 1
8005 1 ▶ push @l, ' Trigger: ' . ( defined $next ? Langertha::Holmgang::Sim::Linux::Calendar::format_local($next) . '; '
Branch: 1 branch
BranchTrueFalseTotal
defined $next ? : 1 0 1
8006 . Langertha::Holmgang::Sim::Linux::Calendar::left( $next - _sim_now() ) . ' left' : 'n/a' );
8007 1 push @l, ' Triggers: ● ' . _timer_info( $dev, $n, $svc )->{activates};
8008 }
8009 10 ▶ push @l, ' Main PID: ' . _main_pid( $dev, $n ) . ' (' . ( $svc->{exec} // $n ) . ')' if $svc->{active} && !$timer;
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} and not $timer 8 2 10
Condition66%4/6
$$svc{"active"} and not $timer
!ll&&!rl&&r
118
$$svc{"exec"} // $n
l!l&&r!l&&!r
800
MC/DC100%2/2
$$svc{"active"} and not $timer
$$svc{"active"} not $timer
MC/DC0%0/2
$$svc{"exec"} // $n
$$svc{"exec"} $n
Truth table100%3/3
A and not(B)
A= $$svc{"active"}B= not $timer
ABresult
0X0
100
111
Truth table33%1/3
A // B
A= $$svc{"exec"}B= $n
ABresult
1X1
011
000
8010 10 my @j = _journal_lines( $dev, $n, $svc, $host );
8011 10 ▶ push @l, '', @j[ ( @j > 10 ? @j - 10 : 0 ) .. $#j ] if @j;
Branch: 2 branches
BranchTrueFalseTotal
if @j 7 3 10
@j > 10 ? : 0 7 7
8012 10 return @l;
8013 }
8014  
8015 # Ein Dienst oeffnet seine Logdateien neu (Neustart, reload): schrieb er nach einer
8016 # Rotation noch in die umbenannte Datei (opened_as), schreibt er jetzt wieder in die
8017 # Originaldatei; fehlt sie, legt er sie an.
8018 93 ▶sub _reopen_logs {
Subroutine _reopen_logs: called CC=11 SCAR=27.1
8019 93 my ( $dev, $n ) = @_;
8020 93 ▶ my $files = $dev->{files} || {};
Condition100%2/2
$$dev{'files'} || {}
l!l
903
MC/DC100%1/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table100%2/2
A
A= $$dev{'files'}
Aresult
11
00
8021 93 ▶ for my $p ( sort grep { ref $files->{$_} eq 'HASH' && ( $files->{$_}{open_by} // '' ) eq $n && defined $files->{$_}{opened_as} } keys %$files ) {
Condition100%8/8
ref $$files{$_} eq 'HASH' && ($$files{$_}{'open_by'} // '') eq $n && defined $$files{$_}{'opened_as'}
!ll&&!rl&&r
54064
ref $$files{$_} eq "HASH" and ($$files{$_}{"open_by"} // "") eq $n
!ll&&!rl&&r
37116910
$$files{$_}{"open_by"} // ""
l!l
41138
MC/DC100%3/3
ref $$files{$_} eq 'HASH' && ($$files{$_}{'open_by'} // '') eq $n && defined $$files{$_}{'opened_as'}
ref $$files{$_} eq "HASH" $$files{$_}{"open_by"} defined $$files{$_}{'opened_as'}
Truth table100%4/4
A and B && C
A= ref $$files{$_} eq "HASH"B= $$files{$_}{"open_by"}C= defined $$files{$_}{'opened_as'}
ABCresult
0XX0
10X0
1100
1111
8022 4 my $e = $files->{$p};
8023 4 my $orig = delete $e->{opened_as};
8024 4 delete $e->{open_by};
8025 4 ▶ if ( ref $files->{$orig} eq 'HASH' ) { $files->{$orig}{open_by} = $n }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $$files{$orig} eq 'HASH') { } 4 0 4
elsif (not exists $$files{$orig}) { } 0 0 0
8026 elsif ( !exists $files->{$orig} ) {
8027 $files->{$orig} = { content => '', size => '0', mode => $e->{mode} // '0644', owner => $e->{owner} // 'root',
8028 0 ▶ group => $e->{group} // 'root', open_by => $n, mtime => 'Oct 20 14:00' };
Condition0%0/6
$$e{"mode"} // "0644"
l!l
00
$$e{"owner"} // "root"
l!l
00
$$e{"group"} // "root"
l!l
00
MC/DC0%0/1
$$e{"mode"} // "0644"
$$e{"mode"}
MC/DC0%0/1
$$e{"owner"} // "root"
$$e{"owner"}
MC/DC0%0/1
$$e{"group"} // "root"
$$e{"group"}
Truth table0%0/2
A
A= $$e{"mode"}
Aresult
11
00
Truth table0%0/2
A
A= $$e{"owner"}
Aresult
11
00
Truth table0%0/2
A
A= $$e{"group"}
Aresult
11
00
8029 }
8030 }
8031 93 return;
8032 }
8033  
8034 # systemctl list-timers [--all]
8035 2 ▶sub _list_timers {
Subroutine _list_timers: called CC=20 SCAR=32.2
8036 2 my ( $dev, $all, $pat ) = @_; # $pat: Muster hinter dem Verb (export*)
8037 2 require Langertha::Holmgang::Sim::Linux::Calendar;
8038 2 ▶ my $svcs = $dev->{services} || {};
Condition50%1/2
$$dev{'services'} || {}
l!l
20
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
8039 2 my @rows;
8040 2 for my $n ( sort grep {/\.timer\z/} keys %$svcs ) {
8041 3 my $svc = $svcs->{$n};
8042 3 ▶ next unless $svc->{active} || $all;
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} or $all 0 3 3
Condition33%1/3
$$svc{"active"} or $all
l!l&&r!l&&!r
300
MC/DC0%0/2
$$svc{"active"} or $all
$$svc{"active"} $all
Truth table33%1/3
A or B
A= $$svc{"active"}B= $all
ABresult
1X1
011
000
8043 3 ▶ next if $pat && @$pat && !grep { $n =~ _unit_glob($_) } @$pat;
Branch: 1 branch
BranchTrueFalseTotal
if $pat and @$pat and not grep({$n =~ _unit_glob($_);} @$pat) 0 3 3
Condition66%4/6
$pat and @$pat and not grep({$n =~ _unit_glob($_);} @$pat)
!ll&&!rl&&r
210
$pat and @$pat
!ll&&!rl&&r
021
MC/DC0%0/3
$pat and @$pat and not grep({$n =~ _unit_glob($_);} @$pat)
$pat @$pat not grep({$n =~ _unit_glob($_);} @$pat)
Truth table50%2/4
A and B and not(C)
A= $patB= @$patC= not grep({$n =~ _unit_glob($_);} @$pat)
ABCresult
0XX0
10X0
1100
1111
8044 3 ▶ my $next = $svc->{active} ? _timer_next( $dev, $n, $svc ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$svc{'active'} ? : 3 0 3
8045 3 my $last = _parse_stamp( $svc->{last} );
8046 push @rows, [ $next // 9e12,
8047 defined $next ? Langertha::Holmgang::Sim::Linux::Calendar::format_local($next) : '-',
8048 defined $next ? Langertha::Holmgang::Sim::Linux::Calendar::left( $next - _sim_now() ) . ' left' : '-',
8049 defined $last ? $svc->{last} : '-',
8050 defined $last ? Langertha::Holmgang::Sim::Linux::Calendar::left( _sim_now() - $last ) . ' ago' : '-',
8051 3 ▶ $n, _timer_info( $dev, $n, $svc )->{activates} ];
Branch: 4 branches
BranchTrueFalseTotal
defined $next ? : 3 0 3
defined $next ? : 3 0 3
defined $last ? : 1 2 3
defined $last ? : 1 2 3
Condition50%1/2
$next // "9000000000000"
l!l
30
MC/DC0%0/1
$next // "9000000000000"
$next
Truth table50%1/2
A
A= $next
Aresult
11
00
8052 }
8053 2 ▶ @rows = sort { $a->[0] <=> $b->[0] || $a->[5] cmp $b->[5] } @rows;
Condition33%1/3
$$a[0] <=> $$b[0] || $$a[5] cmp $$b[5]
l!l&&r!l&&!r
100
MC/DC0%0/2
$$a[0] <=> $$b[0] || $$a[5] cmp $$b[5]
$$a[0] <=> $$b[0] $$a[5] cmp $$b[5]
Truth table33%1/3
A || B
A= $$a[0] <=> $$b[0]B= $$a[5] cmp $$b[5]
ABresult
1X1
011
000
8054 2 my @w = ( 0, 4, 4, 4, 6, 4, 9 );
8055 2 ▶ for my $r (@rows) { $w[$_] < length $r->[$_] and $w[$_] = length $r->[$_] for 1 .. 6 }
Branch: 1 branch
BranchTrueFalseTotal
$w[$_] < length $$r[$_] and $w[$_] = length $$r[$_] 11 7 18
8056 2 my $fmt = join( ' ', map {"%-$w[$_]s"} 1 .. 6 );
8057 2 my @l = ( sprintf( $fmt, qw( NEXT LEFT LAST PASSED UNIT ACTIVATES ) ) =~ s/\s+\z//r );
8058 2 push @l, sprintf( $fmt, @{$_}[ 1 .. 6 ] ) =~ s/\s+\z//r for @rows;
8059 2 push @l, '', scalar(@rows) . ' timers listed.';
8060 2 ▶ push @l, 'Pass --all to see loaded but inactive timers, too.' unless $all;
Branch: 1 branch
BranchTrueFalseTotal
unless $all 2 0 2
8061 2 return join "\n", @l;
8062 }
8063  
8064 # Zeitspanne wie systemd (format_timespan): 1800 -> "30min", 90 -> "1min 30s"
8065 6 ▶sub _timespan {
Subroutine _timespan: called CC=4 SCAR=13.9
8066 6 my ($s) = @_;
8067 6 ▶ return '0' unless $s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s 3 3 6
8068 3 my @p;
8069 3 for my $u ( [ 'w', 604800 ], [ 'd', 86400 ], [ 'h', 3600 ], [ 'min', 60 ], [ 's', 1 ] ) {
8070 15 ▶ next if $s < $u->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $s < $$u[1] 12 3 15
8071 3 my $n = int( $s / $u->[1] );
8072 3 $s -= $n * $u->[1];
8073 3 push @p, "$n$u->[0]";
8074 }
8075 3 return join ' ', @p;
8076 }
8077  
8078 # ExecStart=… -> Form von systemctl show
8079 9 ▶sub _exec_prop {
Subroutine _exec_prop: called CC=1 SCAR=0.0
8080 9 my ($cmd) = @_;
8081 9 $cmd =~ s/\A[-\@:+!]+//;
8082 9 my ($path) = split /\s+/, $cmd;
8083 9 return "{ path=$path ; argv[]=$cmd ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }";
8084 }
8085  
8086 # systemctl show UNIT… [-p A,B | --property=A,B]… [--value]
8087 35 ▶sub _systemctl_show {
Subroutine _systemctl_show: called CC=71 SCAR=45.3
8088 35 my ( $dev, $av ) = @_;
8089 35 require Langertha::Holmgang::Sim::Linux::Calendar;
8090 35 my ( @want, @units, $value );
8091 35 my @a = @$av;
8092 35 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 134 35 169
8093 134 my $x = shift @a;
8094 134 ▶ if ( $x eq '-p' || $x eq '--property' ) { push @want, split /,/, shift(@a) // '' }
Branch: 5 branches
BranchTrueFalseTotal
if ($x eq '-p' or $x eq '--property') { } 35 99 134
elsif ($x =~ /\A--property=(.*)\z/) { } 0 99 99
elsif ($x =~ /\A-p(.+)\z/) { } 0 99 99
elsif ($x eq '--value') { } 29 70 99
elsif ($x =~ /\A-/ or $x eq 'show') { } 35 35 70
Condition60%3/5
$x eq "-p" or $x eq "--property"
l!l&&r!l&&!r
35099
shift @a // ""
l!l
350
MC/DC50%1/2
$x eq "-p" or $x eq "--property"
$x eq "-p" $x eq "--property"
MC/DC0%0/1
shift @a // ""
shift @a
Truth table66%2/3
A or B
A= $x eq "-p"B= $x eq "--property"
ABresult
1X1
011
000
Truth table50%1/2
A
A= shift @a
Aresult
11
00
8095 0 elsif ( $x =~ /\A--property=(.*)\z/ ) { push @want, split /,/, $1 }
8096 0 elsif ( $x =~ /\A-p(.+)\z/ ) { push @want, split /,/, $1 }
8097 29 elsif ( $x eq '--value' ) { $value = 1 }
8098 ▶ elsif ( $x =~ /\A-/ || $x eq 'show' ) { }
Condition66%2/3
$x =~ /\A-/ or $x eq "show"
l!l&&r!l&&!r
03535
MC/DC50%1/2
$x =~ /\A-/ or $x eq "show"
$x =~ /\A-/ $x eq "show"
Truth table66%2/3
A or B
A= $x =~ /\A-/B= $x eq "show"
ABresult
1X1
011
000
8099 35 else { push @units, _unit($x) }
8100 }
8101 35 ▶ return ( 'Too few arguments.', 0 ) unless @units; # ohne Unit: Eigenschaften des Managers (nicht nachgebildet)
Branch: 1 branch
BranchTrueFalseTotal
unless @units 0 35 35
8102 35 my @blocks;
8103 35 for my $n (@units) {
8104 35 ▶ my $svc = ( $dev->{services} || {} )->{$n} // _load_unit( $dev, $n, 1 );
Condition80%4/5
($$dev{"services"} || {})->{$n} // _load_unit($dev, $n, 1)
l!l&&r!l&&!r
3221
$$dev{'services'} || {}
l!l
350
MC/DC0%0/2
($$dev{"services"} || {})->{$n} // _load_unit($dev, $n, 1)
$$dev{'services'} _load_unit($dev, $n, 1)
Truth table33%1/3
A // B
A= $$dev{'services'}B= _load_unit($dev, $n, 1)
ABresult
1X1
011
000
8105 35 my $u = _uname($n);
8106 35 my %p = ( Id => $u, Names => $u );
8107 35 ▶ if ( !$svc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $svc) { } 1 34 35
8108 1 %p = ( %p, LoadState => 'not-found', ActiveState => 'inactive', SubState => 'dead', UnitFileState => '', Description => $u );
8109 }
8110 else {
8111 34 ▶ my $t = _unit_loaded_text( $dev, $n, $svc ) // '';
Condition100%2/2
_unit_loaded_text($dev, $n, $svc) // ""
l!l
1222
MC/DC100%1/1
_unit_loaded_text($dev, $n, $svc) // ""
_unit_loaded_text($dev, $n, $svc)
Truth table100%2/2
A
A= _unit_loaded_text($dev, $n, $svc)
Aresult
11
00
8112 34 my $timer = $n =~ /\.timer\z/;
8113 34 ▶ my $i = $timer ? _timer_info( $dev, $n, $svc ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$timer ? : 3 31 34
8114 34 ▶ my $prop = sub { my ($k) = @_; my ($v) = $t =~ /^\s*\Q$k\E\s*=\s*(.*?)\s*$/m; $v };
Subroutine __ANON__: called CC=1 SCAR=0.0
8115 34 ▶ $p{Description} = $svc->{description} // $prop->('Description') // $u;
Condition83%5/6
($$svc{"description"} // &$prop("Description")) // $u
l!l&&r!l&&!r
2680
$$svc{"description"} // &$prop("Description")
l!l&&r!l&&!r
2248
MC/DC0%0/3
($$svc{"description"} // &$prop("Description")) // $u
$$svc{"description"} &$prop("Description") $u
Truth table75%3/4
A // B // C
A= $$svc{"description"}B= &$prop("Description")C= $u
ABCresult
1XX1
01X1
0011
0000
8116 34 ▶ $p{LoadState} = $svc->{masked} ? 'masked' : $timer && !@{ $i->{cal} } && !$i->{other} ? 'bad-setting' : 'loaded';
Branch: 2 branches
BranchTrueFalseTotal
$$svc{'masked'} ? : 0 34 34
$timer && !@{$$i{'cal'};} && !$$i{'other'} ? : 0 34 34
Condition50%3/6
$timer and not @{$$i{"cal"};} and not $$i{"other"}
!ll&&!rl&&r
3400
$timer and not @{$$i{"cal"};}
!ll&&!rl&&r
3130
MC/DC0%0/3
$timer and not @{$$i{"cal"};} and not $$i{"other"}
$timer not @{$$i{"cal"};} not $$i{"other"}
Truth table50%2/4
A and not(B) and not(C)
A= $timerB= not @{$$i{"cal"};}C= not $$i{"other"}
ABCresult
0XX0
10X0
1100
1111
8117 34 ▶ $p{ActiveState} = $svc->{active} ? 'active' : $svc->{failed} ? 'failed' : 'inactive';
Branch: 2 branches
BranchTrueFalseTotal
$$svc{'active'} ? : 31 3 34
$$svc{'failed'} ? : 0 3 3
8118 34 ▶ $p{SubState} = $svc->{active} ? ( $timer ? 'waiting' : 'running' ) : $svc->{failed} ? 'failed' : 'dead';
Branch: 3 branches
BranchTrueFalseTotal
$$svc{'active'} ? : 31 3 34
$timer ? : 3 28 31
$$svc{'failed'} ? : 0 3 3
8119 34 ▶ $p{UnitFileState} = $svc->{masked} ? 'masked' : _static( $dev, $n, $svc ) ? 'static' : ( $svc->{enabled} // 1 ) ? 'enabled' : 'disabled';
Branch: 3 branches
BranchTrueFalseTotal
$$svc{'masked'} ? : 0 34 34
_static($dev, $n, $svc) ? : 6 28 34
$$svc{'enabled'} // 1 ? : 28 0 28
Condition100%2/2
$$svc{"enabled"} // 1
l!l
226
MC/DC100%1/1
$$svc{"enabled"} // 1
$$svc{"enabled"}
Truth table100%2/2
A
A= $$svc{"enabled"}
Aresult
11
00
8120 34 $p{FragmentPath} = _unit_file( $n, $svc );
8121 34 ▶ if ($timer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timer) { } 3 31 34
8122 3 ▶ my $next = $svc->{active} ? _timer_next( $dev, $n, $svc ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$svc{'active'} ? : 3 0 3
8123 $p{TimersCalendar} = join "\n", map {
8124 3 my $ne = Langertha::Holmgang::Sim::Linux::Calendar::next_elapse( $_, _sim_now() );
8125 3 ▶ "{ OnCalendar=$_->{normalized} ; next_elapse=" . ( defined $ne ? Langertha::Holmgang::Sim::Linux::Calendar::format_local($ne) : 'n/a' ) . ' }'
Branch: 1 branch
BranchTrueFalseTotal
defined $ne ? : 3 0 3
8126 3 } @{ $i->{cal} };
8127 3 ▶ $p{NextElapseUSecRealtime} = defined $next ? Langertha::Holmgang::Sim::Linux::Calendar::format_local($next) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $next ? : 3 0 3
8128 3 ▶ $p{LastTriggerUSec} = defined _parse_stamp( $svc->{last} ) ? $svc->{last} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined _parse_stamp($$svc{'last'}) ? : 1 2 3
8129 3 ▶ $p{Persistent} = $i->{persistent} ? 'yes' : 'no';
Branch: 1 branch
BranchTrueFalseTotal
$$i{'persistent'} ? : 3 0 3
8130 3 ▶ $p{AccuracyUSec} = _timespan( _secs( $prop->('AccuracySec') // '1min' ) // 60 );
Condition75%3/4
_secs(&$prop("AccuracySec") // "1min") // 60
l!l
30
&$prop("AccuracySec") // "1min"
l!l
12
MC/DC0%0/1
_secs(&$prop("AccuracySec") // "1min") // 60
_secs(&$prop("AccuracySec") // "1min")
MC/DC100%1/1
&$prop("AccuracySec") // "1min"
&$prop("AccuracySec")
Truth table50%1/2
A
A= _secs(&$prop("AccuracySec") // "1min")
Aresult
11
00
Truth table100%2/2
A
A= &$prop("AccuracySec")
Aresult
11
00
8131 3 ▶ $p{RandomizedDelayUSec} = _timespan( _secs( $prop->('RandomizedDelaySec') // 0 ) // 0 );
Condition50%2/4
_secs(&$prop("RandomizedDelaySec") // 0) // 0
l!l
30
&$prop("RandomizedDelaySec") // 0
l!l
03
MC/DC0%0/1
_secs(&$prop("RandomizedDelaySec") // 0) // 0
_secs(&$prop("RandomizedDelaySec") // 0)
MC/DC0%0/1
&$prop("RandomizedDelaySec") // 0
&$prop("RandomizedDelaySec")
Truth table50%1/2
A
A= _secs(&$prop("RandomizedDelaySec") // 0)
Aresult
11
00
Truth table50%1/2
A
A= &$prop("RandomizedDelaySec")
Aresult
11
00
8132 3 $p{Unit} = $i->{activates};
8133 }
8134 else {
8135 # wirksame Werte der geladenen Fassung samt Drop-ins (letzte Zuweisung gilt)
8136 31 my $up = _unit_props($t);
8137 31 my %extra = %$up;
8138 31 delete @extra{qw( ExecStart ExecStartPre ExecStartPost ExecReload EnvironmentFile Environment )};
8139 31 %p = ( %extra, %p );
8140 31 ▶ $p{Type} = $up->{Type} // 'simple';
Condition100%2/2
$$up{"Type"} // "simple"
l!l
229
MC/DC100%1/1
$$up{"Type"} // "simple"
$$up{"Type"}
Truth table100%2/2
A
A= $$up{"Type"}
Aresult
11
00
8141 31 ▶ $p{Restart} = $up->{Restart} // 'no';
Condition100%2/2
$$up{"Restart"} // "no"
l!l
328
MC/DC100%1/1
$$up{"Restart"} // "no"
$$up{"Restart"}
Truth table100%2/2
A
A= $$up{"Restart"}
Aresult
11
00
8142 31 ▶ $p{User} = $up->{User} // $svc->{user} // '';
Condition100%5/5
($$up{"User"} // $$svc{"user"}) // ""
l!l
922
$$up{"User"} // $$svc{"user"}
l!l&&r!l&&!r
6322
MC/DC100%2/2
($$up{"User"} // $$svc{"user"}) // ""
$$up{"User"} $$svc{"user"}
Truth table100%3/3
A // B
A= $$up{"User"}B= $$svc{"user"}
ABresult
1X1
011
000
8143 31 ▶ $p{Group} = $up->{Group} // '';
Condition50%1/2
$$up{"Group"} // ""
l!l
031
MC/DC0%0/1
$$up{"Group"} // ""
$$up{"Group"}
Truth table50%1/2
A
A= $$up{"Group"}
Aresult
11
00
8144 31 ▶ $p{WorkingDirectory} = $up->{WorkingDirectory} // '';
Condition50%1/2
$$up{"WorkingDirectory"} // ""
l!l
031
MC/DC0%0/1
$$up{"WorkingDirectory"} // ""
$$up{"WorkingDirectory"}
Truth table50%1/2
A
A= $$up{"WorkingDirectory"}
Aresult
11
00
8145 31 ▶ $p{ExecStart} = join "\n", map { _exec_prop($_) } @{ $up->{ExecStart} || [] };
Condition100%2/2
$$up{'ExecStart'} || []
l!l
922
MC/DC100%1/1
$$up{'ExecStart'} || []
$$up{'ExecStart'}
Truth table100%2/2
A
A= $$up{'ExecStart'}
Aresult
11
00
8146 31 ▶ $p{Environment} = $up->{Environment} ? join( ' ', map {"$_=$up->{Environment}{$_}"} sort keys %{ $up->{Environment} } ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$$up{'Environment'} ? : 2 29 31
8147 0 ▶ $p{EnvironmentFiles} = join ' ', map { s/\A-//r . ( /\A-/ ? ' (ignore_errors=yes)' : ' (ignore_errors=no)' ) } @{ $up->{EnvironmentFile} || [] };
Branch: 1 branch
BranchTrueFalseTotal
/\A-/ ? : 0 0 0
Condition50%1/2
$$up{'EnvironmentFile'} || []
l!l
031
MC/DC0%0/1
$$up{'EnvironmentFile'} || []
$$up{'EnvironmentFile'}
Truth table50%1/2
A
A= $$up{'EnvironmentFile'}
Aresult
11
00
8148 31 ( $p{LimitNOFILE}, $p{LimitNOFILESoft} ) = ( '524288', '1024' );
8149 31 ▶ if ( defined( my $l = $up->{LimitNOFILE} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = $$up{"LimitNOFILE"})) 2 29 31
8150 2 ▶ ( $p{LimitNOFILESoft}, $p{LimitNOFILE} ) = $l =~ /\A(\d+):(\d+)\z/ ? ( $1, $2 ) : ( $l, $l );
Branch: 1 branch
BranchTrueFalseTotal
$l =~ /\A(\d+):(\d+)\z/ ? : 0 2 2
8151 }
8152 31 $p{MainPID} = _main_pid( $dev, $n );
8153 31 $p{ExecMainPID} = $p{MainPID};
8154 # Startzeit des laufenden Prozesses; NRestarts zaehlt wie systemd nur
8155 # automatische Neustarts (Restart= nach einem Signal, _signal)
8156 31 ▶ my $st = $svc->{active} ? _svc_since($svc) // _parse_stamp($BOOT_STAMP) : _svc_since($svc);
Branch: 1 branch
BranchTrueFalseTotal
$$svc{'active'} ? : 28 3 31
Condition66%2/3
_svc_since($svc) // _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
l!l&&r!l&&!r
14140
MC/DC0%0/2
_svc_since($svc) // _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
_svc_since($svc) _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
Truth table66%2/3
A // B
A= _svc_since($svc)B= _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
ABresult
1X1
011
000
8157 31 ▶ $p{ExecMainStartTimestamp} = $p{ActiveEnterTimestamp} = defined $st ? Langertha::Holmgang::Sim::Linux::Calendar::format_local($st) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $st ? : 29 2 31
8158 31 ▶ $p{NRestarts} = $svc->{_nrestarts} // 0;
Condition100%2/2
$$svc{"_nrestarts"} // 0
l!l
229
MC/DC100%1/1
$$svc{"_nrestarts"} // 0
$$svc{"_nrestarts"}
Truth table100%2/2
A
A= $$svc{"_nrestarts"}
Aresult
11
00
8159 31 ▶ $p{LoadState} = 'bad-setting' if !$svc->{masked} && _unit_bad( $n, $up );
Branch: 1 branch
BranchTrueFalseTotal
if not $$svc{"masked"} and _unit_bad($n, $up) 0 31 31
Condition33%1/3
not $$svc{"masked"} and _unit_bad($n, $up)
!ll&&!rl&&r
0310
MC/DC0%0/2
not $$svc{"masked"} and _unit_bad($n, $up)
not $$svc{"masked"} _unit_bad($n, $up)
Truth table33%1/3
not(A) and B
A= not $$svc{"masked"}B= _unit_bad($n, $up)
ABresult
0X0
100
111
8160 31 $p{DropInPaths} = join ' ', _dropins( $dev, $n );
8161 31 ▶ $p{NeedDaemonReload} = _unit_changed( $dev, $n, $svc ) ? 'yes' : 'no';
Branch: 1 branch
BranchTrueFalseTotal
_unit_changed($dev, $n, $svc) ? : 1 30 31
8162 31 ▶ $p{CanReload} = $n ne 'systemd-journald' && ( !exists $svc->{reload} || $svc->{reload} ) && $t =~ /^\s*ExecReload\s*=/m ? 'yes' : 'no';
Branch: 1 branch
BranchTrueFalseTotal
$n ne 'systemd-journald' && (!exists($$svc{'reload'}) || $$svc{'reload'}) && $t =~ /^\s*ExecReload\s*=/m ? : 4 27 31
Condition77%7/9
$n ne "systemd-journald" and !exists($$svc{"reload"}) || $$svc{"reload"} and $t =~ /^\s*ExecReload\s*=/m
!ll&&!rl&&r
1264
$n ne "systemd-journald" and !exists($$svc{"reload"}) || $$svc{"reload"}
!ll&&!rl&&r
1030
not exists $$svc{"reload"} or $$svc{"reload"}
l!l&&r!l&&!r
17130
MC/DC50%2/4
$n ne "systemd-journald" and !exists($$svc{"reload"}) || $$svc{"reload"} and $t =~ /^\s*ExecReload\s*=/m
$n ne "systemd-journald" not exists $$svc{"reload"} $$svc{"reload"} $t =~ /^\s*ExecReload\s*=/m
Truth table66%4/6
A and not(B) or C and D
A= $n ne "systemd-journald"B= not exists $$svc{"reload"}C= $$svc{"reload"}D= $t =~ /^\s*ExecReload\s*=/m
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
8163 }
8164 }
8165 # Reihenfolge wie systemctl show (systemd 257); unbekannte Eigenschaften gibt es nicht aus
8166 35 my @order = qw( Unit TimersCalendar NextElapseUSecRealtime LastTriggerUSec AccuracyUSec RandomizedDelayUSec Persistent
8167 Type Restart NRestarts MainPID ExecMainStartTimestamp ExecMainPID ExecStart Environment EnvironmentFiles WorkingDirectory
8168 LimitNOFILE LimitNOFILESoft Id Names Description LoadState ActiveState SubState ActiveEnterTimestamp FragmentPath DropInPaths UnitFileState NeedDaemonReload CanReload User Group );
8169 35 my %known = map { $_ => 1 } @order;
8170 35 push @order, sort grep { !$known{$_} } keys %p;
8171 35 my %w = map { $_ => 1 } @want;
8172 35 ▶ my @keys = grep { exists $p{$_} && ( !@want || $w{$_} ) } @order;
Condition100%6/6
exists $p{$_} && (!@want || $w{$_})
!ll&&!rl&&r
29780754
not @want or $w{$_}
l!l&&r!l&&!r
1539807
MC/DC100%3/3
exists $p{$_} && (!@want || $w{$_})
exists $p{$_} not @want $w{$_}
Truth table100%4/4
A && not(B) or C
A= exists $p{$_}B= not @wantC= $w{$_}
ABCresult
0XX0
1000
11X1
1011
8173 35 my @l;
8174 35 for my $k (@keys) {
8175 54 ▶ my @v = split /\n/, $p{$k} // '', -1;
Condition50%1/2
$p{$k} // ""
l!l
540
MC/DC0%0/1
$p{$k} // ""
$p{$k}
Truth table50%1/2
A
A= $p{$k}
Aresult
11
00
8176 54 ▶ @v = ('') unless @v;
Branch: 1 branch
BranchTrueFalseTotal
unless @v 1 53 54
8177 54 ▶ push @l, map { $value ? $_ : "$k=$_" } @v;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 30 24 54
8178 }
8179 35 push @blocks, join "\n", @l;
8180 }
8181 35 return ( join( "\n\n", @blocks ), 1 );
8182 }
8183  
8184 # --- Dienste ---------------------------------------------------------------------------
8185  
8186 255 ▶sub _unit { my ($n) = @_; $n =~ s/\.service\z//; return $n }
Subroutine _unit: called CC=1 SCAR=0.0
8187  
8188 99 ▶sub _restart_effect {
Subroutine _restart_effect: called CC=78 SCAR=58.8
8189 99 my ( $dev, $name, $verb ) = @_;
8190 99 my $svc = $dev->{services}{$name};
8191 99 ▶ if ( $name =~ /\Awg-quick\@(wg\d+)\z/ && $verb ne 'reload' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\Awg-quick\@(wg\d+)\z/ and $verb ne "reload") 4 95 99
Condition66%2/3
$name =~ /\Awg-quick\@(wg\d+)\z/ and $verb ne "reload"
!ll&&!rl&&r
9504
MC/DC50%1/2
$name =~ /\Awg-quick\@(wg\d+)\z/ and $verb ne "reload"
$name =~ /\Awg-quick\@(wg\d+)\z/ $verb ne "reload"
Truth table66%2/3
A and B
A= $name =~ /\Awg-quick\@(wg\d+)\z/B= $verb ne "reload"
ABresult
0X0
100
111
8192 # start/restart wie die Unit: wg-quick down (falls oben), dann wg-quick up
8193 4 my $n = $1;
8194 4 ▶ my $up = ( ( ( $dev->{interfaces} || {} )->{$n} || {} )->{state} // 'DOWN' ) ne 'DOWN';
Condition83%5/6
(($$dev{"interfaces"} || {})->{$n} || {})->{"state"} // "DOWN"
l!l
13
($$dev{'interfaces'} || {})->{$n} || {}
l!l
13
$$dev{'interfaces'} || {}
l!l
40
MC/DC0%0/1
(($$dev{"interfaces"} || {})->{$n} || {})->{"state"} // "DOWN"
$$dev{'interfaces'}
Truth table50%1/2
A
A= $$dev{'interfaces'}
Aresult
11
00
8195 4 ▶ if ( $verb eq 'start' && $up ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "start" and $up) 0 4 4
Condition66%2/3
$verb eq "start" and $up
!ll&&!rl&&r
130
MC/DC0%0/2
$verb eq "start" and $up
$verb eq "start" $up
Truth table66%2/3
A and B
A= $verb eq "start"B= $up
ABresult
0X0
100
111
8196 0 ▶ return if $svc && $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $svc and $$svc{"active"} 0 0 0
Condition0%0/3
$svc and $$svc{"active"}
!ll&&!rl&&r
000
MC/DC0%0/2
$svc and $$svc{"active"}
$svc $$svc{"active"}
Truth table0%0/3
A and B
A= $svcB= $$svc{"active"}
ABresult
0X0
100
111
8197 # von Hand hochgefahren: die Unit scheitert an der vorhandenen Schnittstelle
8198 0 ▶ $svc->{failed} = JSON::MaybeXS::true() if $svc;
Branch: 1 branch
BranchTrueFalseTotal
if $svc 0 0 0
8199 0 ▶ $svc->{journal} = [ @{ $svc->{journal} || [] }, "Oct 20 09:12:03 wg-quick[4711]: wg-quick: `$n' already exists" ] if $svc;
Branch: 1 branch
BranchTrueFalseTotal
if $svc 0 0 0
Condition0%0/2
$$svc{'journal'} || []
l!l
00
MC/DC0%0/1
$$svc{'journal'} || []
$$svc{'journal'}
Truth table0%0/2
A
A= $$svc{'journal'}
Aresult
11
00
8200 0 die "Job for $name.service failed because the control process exited with error code.\n"
8201 . "See \"systemctl status $name.service\" and \"journalctl -xeu $name.service\" for details.\n";
8202 }
8203 4 my $copy = Langertha::Holmgang::Sim::Linux::clone_state($dev);
8204 0 ▶ eval { _wg_down( $copy, $n ) if $up; 1 } or do { my $e = $@; die "Job for $name.service failed.\n$e" };
Branch: 2 branches
BranchTrueFalseTotal
eval { do { _wg_down($copy, $n) if $up; 1 } } or do { my $e = $@; die "Job for $name.service failed.\n$e" } 4 0 4
if $up 1 3 4
8205 4 my $down = Langertha::Holmgang::Sim::Linux::clone_state($copy);
8206 4 ▶ if ( !eval { _wg_up( $copy, $n ); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { _wg_up($copy, $n); 1 } }) 1 3 4
8207 1 my $e = $@;
8208 1 %$dev = %$down;
8209 1 ▶ my $s = $dev->{services}{$name} //= {};
Condition50%1/2
$$dev{"services"}{$name} //= {}
l!l
10
MC/DC0%0/1
$$dev{"services"}{$name} //= {}
$$dev{"services"}{$name}
Truth table50%1/2
A
A= $$dev{"services"}{$name}
Aresult
11
00
8210 1 ▶ $s->{active} = JSON::MaybeXS::false() if $s->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$s{"active"} 0 1 1
8211 1 $s->{failed} = JSON::MaybeXS::true();
8212 1 ▶ $s->{journal} = [ @{ $s->{journal} || [] }, map {"Oct 20 09:12:03 wg-quick[4711]: $_"} split /\n/, $e ];
Condition50%1/2
$$s{'journal'} || []
l!l
01
MC/DC0%0/1
$$s{'journal'} || []
$$s{'journal'}
Truth table50%1/2
A
A= $$s{'journal'}
Aresult
11
00
8213 1 die "Job for $name.service failed because the control process exited with error code.\n"
8214 . "See \"systemctl status $name.service\" and \"journalctl -xeu $name.service\" for details.\n";
8215 }
8216 3 my $s = $copy->{services}{$name};
8217 3 ▶ if ($s) { $s->{active} = JSON::MaybeXS::true(); $s->{failed} = JSON::MaybeXS::false() if $s->{failed} }
Branch: 2 branches
BranchTrueFalseTotal
if ($s) 3 0 3
if $$s{"failed"} 0 3 3
8218 3 %$dev = %$copy;
8219 3 return;
8220 }
8221 95 ▶ if ( $name =~ /\Awg-quick\@(wg\d+)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\Awg-quick\@(wg\d+)\z/) 0 95 95
8222 0 my $n = $1;
8223 0 my $t = _file_text( $dev, "/etc/wireguard/$n.conf" );
8224 0 ▶ if ( defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) 0 0 0
8225 0 ▶ my $old = $dev->{wg}{$n} || {};
Condition0%0/2
$$dev{'wg'}{$n} || {}
l!l
00
MC/DC0%0/1
$$dev{'wg'}{$n} || {}
$$dev{'wg'}{$n}
Truth table0%0/2
A
A= $$dev{'wg'}{$n}
Aresult
11
00
8226 0 my $new = _wg_parse( $t, $old );
8227 0 ▶ if ( $verb eq 'reload' ) { # wg syncconf <(wg-quick strip): nur Peers und Port
Branch: 2 branches
BranchTrueFalseTotal
if ($verb eq 'reload') { } 0 0 0
elsif (defined $$new{'mtu'} and $$dev{'interfaces'}{$n}) { } 0 0 0
8228 0 $new->{$_} = $old->{$_} for grep { exists $old->{$_} } qw( address mtu );
8229 0 ▶ delete $new->{mtu} unless exists $old->{mtu};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$old{"mtu"} 0 0 0
8230 0 ▶ delete $new->{address} unless exists $old->{address};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$old{"address"} 0 0 0
8231 }
8232 ▶ elsif ( defined $new->{mtu} && $dev->{interfaces}{$n} ) {
Condition0%0/3
defined $$new{"mtu"} and $$dev{"interfaces"}{$n}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $$new{"mtu"} and $$dev{"interfaces"}{$n}
defined $$new{"mtu"} $$dev{"interfaces"}{$n}
Truth table0%0/3
A and B
A= defined $$new{"mtu"}B= $$dev{"interfaces"}{$n}
ABresult
0X0
100
111
8233 0 $dev->{interfaces}{$n}{mtu} = $new->{mtu};
8234 }
8235 0 $dev->{wg}{$n} = $new;
8236 }
8237 }
8238 95 ▶ if ( $name eq 'nftables' && ref $dev->{files} eq 'HASH' && exists $dev->{files}{'/etc/nftables.conf'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "nftables" and ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/nftables.conf"}) 1 94 95
Condition66%4/6
$name eq "nftables" and ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/nftables.conf"}
!ll&&!rl&&r
9401
$name eq "nftables" and ref $$dev{"files"} eq "HASH"
!ll&&!rl&&r
9401
MC/DC33%1/3
$name eq "nftables" and ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/nftables.conf"}
$name eq "nftables" ref $$dev{"files"} eq "HASH" exists $$dev{"files"}{"/etc/nftables.conf"}
Truth table50%2/4
A and B and C
A= $name eq "nftables"B= ref $$dev{"files"} eq "HASH"C= exists $$dev{"files"}{"/etc/nftables.conf"}
ABCresult
0XX0
10X0
1100
1111
8239 1 my ( $o, $ok ) = _nft_load( $dev, _file_text( $dev, '/etc/nftables.conf' ), '/etc/nftables.conf' );
8240 1 ▶ die "Job for nftables.service failed because the control process exited with error code.\n$o\n" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 1 1
8241 }
8242 95 ▶ if ( ( $name eq 'ssh' || $name eq 'sshd' ) && _sshd_sim()->can('active')->($dev) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "ssh" || $name eq "sshd" and _sshd_sim()->can("active")->($dev)) 9 86 95
Condition66%4/6
$name eq "ssh" || $name eq "sshd" and _sshd_sim()->can("active")->($dev)
!ll&&!rl&&r
8609
$name eq "ssh" or $name eq "sshd"
l!l&&r!l&&!r
9086
MC/DC33%1/3
$name eq "ssh" || $name eq "sshd" and _sshd_sim()->can("active")->($dev)
$name eq "ssh" $name eq "sshd" _sshd_sim()->can("active")->($dev)
Truth table40%2/5
A or B and C
A= $name eq "ssh"B= $name eq "sshd"C= _sshd_sim()->can("active")->($dev)
ABCresult
00X0
1X00
0100
1X11
0111
8243 9 ▶ _sshd_sim()->can('load')->( $dev, $name, $verb, $CTX ? $CTX->{host} : undef );
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 9 0 9
8244 7 _ssh_access()->can('loaded')->($dev); # was sshd jetzt geladen hat (Match, AuthorizedKeysFile …)
8245 }
8246 93 ▶ if ( $name eq 'systemd-journald' && $verb ne 'reload' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "systemd-journald" and $verb ne "reload") 3 90 93
Condition66%2/3
$name eq "systemd-journald" and $verb ne "reload"
!ll&&!rl&&r
9003
MC/DC50%1/2
$name eq "systemd-journald" and $verb ne "reload"
$name eq "systemd-journald" $verb ne "reload"
Truth table66%2/3
A and B
A= $name eq "systemd-journald"B= $verb ne "reload"
ABresult
0X0
100
111
8247 3 ▶ my $t = $svc && defined $svc->{config} ? _file_text( $dev, $svc->{config} ) : _file_text( $dev, '/etc/systemd/journald.conf' );
Branch: 1 branch
BranchTrueFalseTotal
$svc && defined $$svc{'config'} ? : 3 0 3
Condition33%1/3
$svc and defined $$svc{"config"}
!ll&&!rl&&r
003
MC/DC0%0/2
$svc and defined $$svc{"config"}
$svc defined $$svc{"config"}
Truth table33%1/3
A and B
A= $svcB= defined $$svc{"config"}
ABresult
0X0
100
111
8248 0 ▶ if ( defined $t && $t =~ /^\s*SystemMaxUse\s*=\s*(\S+)/m ) { _journal_vacuum( $dev, size => _bytes($1) ) }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t and $t =~ /^\s*SystemMaxUse\s*=\s*(\S+)/m) 0 3 3
Condition33%1/3
defined $t and $t =~ /^\s*SystemMaxUse\s*=\s*(\S+)/m
!ll&&!rl&&r
030
MC/DC0%0/2
defined $t and $t =~ /^\s*SystemMaxUse\s*=\s*(\S+)/m
defined $t $t =~ /^\s*SystemMaxUse\s*=\s*(\S+)/m
Truth table33%1/3
A and B
A= defined $tB= $t =~ /^\s*SystemMaxUse\s*=\s*(\S+)/m
ABresult
0X0
100
111
8249 3 ▶ if ( defined $t && $t =~ /^\s*MaxRetentionSec\s*=\s*(\S+)/m && defined( my $age = _secs($1) ) ) { _journal_vacuum( $dev, age => $age ) }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t and $t =~ /^\s*MaxRetentionSec\s*=\s*(\S+)/m and defined(my $age = _secs($1))) 1 2 3
Condition66%4/6
defined $t and $t =~ /^\s*MaxRetentionSec\s*=\s*(\S+)/m and defined(my $age = _secs($1))
!ll&&!rl&&r
201
defined $t and $t =~ /^\s*MaxRetentionSec\s*=\s*(\S+)/m
!ll&&!rl&&r
021
MC/DC33%1/3
defined $t and $t =~ /^\s*MaxRetentionSec\s*=\s*(\S+)/m and defined(my $age = _secs($1))
defined $t $t =~ /^\s*MaxRetentionSec\s*=\s*(\S+)/m defined(my $age = _secs($1))
Truth table50%2/4
A and B and C
A= defined $tB= $t =~ /^\s*MaxRetentionSec\s*=\s*(\S+)/mC= defined(my $age = _secs($1))
ABCresult
0XX0
10X0
1100
1111
8250 # dauerhaft (Storage=persistent, oder auto mit /var/log/journal): legt das Verzeichnis
8251 # an und uebernimmt das Laufzeit-Journal aus /run/log/journal
8252 3 ▶ my ($st) = ( $t // '' ) =~ /^\s*Storage\s*=\s*(\S+)\s*$/m;
Condition50%1/2
$t // ""
l!l
30
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
Aresult
11
00
8253 3 ▶ _journal_flush($dev) if ( $st // 'auto' ) eq 'persistent' || ( $st // 'auto' ) eq 'auto' && _is_dir( $dev, '/var/log/journal' );
Branch: 1 branch
BranchTrueFalseTotal
if ($st // "auto") eq "persistent" or ($st // "auto") eq "auto" and _is_dir($dev, "/var/log/journal") 3 0 3
Condition20%2/10
($st // "auto") eq "persistent" or ($st // "auto") eq "auto" and _is_dir($dev, "/var/log/journal")
l!l&&r!l&&!r
300
$st // "auto"
l!l
30
($st // "auto") eq "auto" and _is_dir($dev, "/var/log/journal")
!ll&&!rl&&r
000
$st // "auto"
l!l
00
MC/DC0%0/3
($st // "auto") eq "persistent" or ($st // "auto") eq "auto" and _is_dir($dev, "/var/log/journal")
$st $st _is_dir($dev, "/var/log/journal")
Truth table25%1/4
A or B and C
A= $stB= $stC= _is_dir($dev, "/var/log/journal")
ABCresult
1XX1
0111
00X0
0100
8254 }
8255 93 ▶ if ( $dev->{bind} && $name eq ( $dev->{bind}{service} // 'named' ) && !( $verb eq 'start' && $svc->{active} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"bind"} and $name eq ($$dev{"bind"}{"service"} // "named") and not $verb eq "start" && $$svc{"active"}) 3 90 93
Condition54%6/11
$$dev{"bind"} and $name eq ($$dev{"bind"}{"service"} // "named") and not $verb eq "start" && $$svc{"active"}
!ll&&!rl&&r
9003
$$dev{"bind"} and $name eq ($$dev{"bind"}{"service"} // "named")
!ll&&!rl&&r
9003
$$dev{"bind"}{"service"} // "named"
l!l
03
$verb eq 'start' && $$svc{'active'}
!ll&&!rl&&r
300
MC/DC25%1/4
$$dev{"bind"} and $name eq ($$dev{"bind"}{"service"} // "named") and not $verb eq "start" && $$svc{"active"}
$$dev{"bind"} $name eq ($$dev{"bind"}{"service"} // "named") $verb eq 'start' $$svc{'active'}
MC/DC0%0/1
$$dev{"bind"}{"service"} // "named"
$$dev{"bind"}{"service"}
Truth table40%2/5
A and B and not(C && D)
A= $$dev{"bind"}B= $name eq ($$dev{"bind"}{"service"} // "named")C= $verb eq 'start'D= $$svc{'active'}
ABCDresult
0XXX0
10XX0
11110
110X1
11101
Truth table50%1/2
A
A= $$dev{"bind"}{"service"}
Aresult
11
00
8256 3 _part('Dns');
8257 3 ▶ Langertha::Holmgang::Sim::Linux::Dns::service_event( $dev, $verb, $CTX || { state => {} } );
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::CTX || {'state', {}}
l!l
30
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::CTX || {'state', {}}
$Langertha::Holmgang::Sim::Linux::CTX
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::CTX
Aresult
11
00
8258 }
8259 92 ▶ if ( $dev->{postfix} && $name eq 'postfix' && !( $verb eq 'start' && $svc->{active} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"postfix"} and $name eq "postfix" and not $verb eq "start" && $$svc{"active"}) 2 90 92
Condition55%5/9
$$dev{"postfix"} and $name eq "postfix" and not $verb eq "start" && $$svc{"active"}
!ll&&!rl&&r
9002
$$dev{"postfix"} and $name eq "postfix"
!ll&&!rl&&r
9002
$verb eq 'start' && $$svc{'active'}
!ll&&!rl&&r
200
MC/DC25%1/4
$$dev{"postfix"} and $name eq "postfix" and not $verb eq "start" && $$svc{"active"}
$$dev{"postfix"} $name eq "postfix" $verb eq 'start' $$svc{'active'}
Truth table40%2/5
A and B and not(C && D)
A= $$dev{"postfix"}B= $name eq "postfix"C= $verb eq 'start'D= $$svc{'active'}
ABCDresult
0XXX0
10XX0
11110
110X1
11101
8260 2 _part('Postfix');
8261 2 Langertha::Holmgang::Sim::Linux::Postfix::service_event( $dev, $verb );
8262 }
8263 # dnsmasq & Co.: reload (SIGHUP) liest nur Hosts-Dateien neu, nicht die
8264 # Konfiguration — die wirkt erst nach restart. Dienste mit reload_config
8265 # (gunicorn, prometheus, …) lesen sie auch beim reload.
8266 # Mehrere Dateien (config: [ … ]): running ist { pfad => text }; reload_config
8267 # true liest alle, eine Liste nur diese (z. B. prometheus.yml, nicht die
8268 # Startoptionen in /etc/default). Mit config_check prueft der Dienst vorher;
8269 # beim reload bleibt bei einem Fehler alles, wie es lief (Fehler im Journal).
8270 91 ▶ if ( ref $svc->{config} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$svc{"config"} eq "ARRAY") 14 77 91
8271 14 my $rc = $svc->{reload_config};
8272 14 ▶ return if $verb eq 'reload' && !$rc;
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "reload" and not $rc 0 14 14
Condition66%2/3
$verb eq "reload" and not $rc
!ll&&!rl&&r
1040
MC/DC0%0/2
$verb eq "reload" and not $rc
$verb eq "reload" not $rc
Truth table66%2/3
A and not(B)
A= $verb eq "reload"B= not $rc
ABresult
0X0
100
111
8273 14 ▶ my @paths = grep { my $p = $_; $verb ne 'reload' || ref $rc ne 'ARRAY' || grep { $_ eq $p } @$rc } @{ $svc->{config} };
Condition100%6/6
$verb ne 'reload' || ref $rc ne 'ARRAY' || grep({$_ eq $p;} @$rc)
l!l&&r!l&&!r
2422
$verb ne "reload" or ref $rc ne "ARRAY"
l!l&&r!l&&!r
2044
MC/DC100%3/3
$verb ne 'reload' || ref $rc ne 'ARRAY' || grep({$_ eq $p;} @$rc)
$verb ne "reload" ref $rc ne "ARRAY" grep({$_ eq $p;} @$rc)
Truth table100%4/4
A or B || C
A= $verb ne "reload"B= ref $rc ne "ARRAY"C= grep({$_ eq $p;} @$rc)
ABCresult
1XX1
01X1
0011
0000
8274 14 my ( $err, $extra ) = _config_check( $dev, $svc );
8275 14 ▶ if (@$err) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$err) 1 13 14
8276 1 _log( $dev, $name, $svc, @$err );
8277 1 return;
8278 }
8279 13 ▶ my %run = ref $svc->{running} eq 'HASH' ? %{ $svc->{running} } : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'running'} eq 'HASH' ? : 13 0 13
8280 0 ▶ for my $p (@paths) { my $t = _file_text( $dev, $p ); if ( defined $t ) { $run{$p} = $t } else { delete $run{$p} } }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) { } 24 0 24
8281 # Dateien, die die Hauptdatei nachlaedt (Regeldateien), kommen mit ihr neu
8282 13 ▶ if ( defined $svc->{config_main} ? grep { $_ eq $svc->{config_main} } @paths : 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $$svc{"config_main"} ? grep({$_ eq $$svc{"config_main"};} @paths) : 1) 13 0 13
defined $$svc{'config_main'} ? : 13 0 13
8283 13 my %cfg = map { $_ => 1 } @{ $svc->{config} };
8284 13 delete @run{ grep { !$cfg{$_} } keys %run };
8285 13 %run = ( %run, %$extra );
8286 }
8287 13 $svc->{running} = \%run;
8288 13 return;
8289 }
8290 77 ▶ if ( defined $svc->{config} && ( $verb ne 'reload' || $svc->{reload_config} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$svc{"config"} and $verb ne "reload" || $$svc{"reload_config"}) 13 64 77
Condition100%6/6
defined $$svc{"config"} and $verb ne "reload" || $$svc{"reload_config"}
!ll&&!rl&&r
61313
$verb ne "reload" or $$svc{"reload_config"}
l!l&&r!l&&!r
1033
MC/DC100%3/3
defined $$svc{"config"} and $verb ne "reload" || $$svc{"reload_config"}
defined $$svc{"config"} $verb ne "reload" $$svc{"reload_config"}
Truth table100%4/4
A and B or C
A= defined $$svc{"config"}B= $verb ne "reload"C= $$svc{"reload_config"}
ABCresult
0XX0
1000
11X1
1011
8291 13 my $t = _file_text( $dev, $svc->{config} );
8292 13 ▶ die "Job for $name.service failed because the control process exited with error code.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 13 13
8293 . "See \"systemctl status $name.service\" and \"journalctl -xeu $name.service\" for details.\n"
8294 unless defined $t;
8295 13 $svc->{running} = $t;
8296 }
8297 77 return;
8298 }
8299  
8300 # Muster einer Unit (Shell-Glob) als regulaerer Ausdruck; ohne Endung passt es
8301 # auch auf NAME.service (systemctl status 'billing*')
8302 1 ▶sub _unit_glob {
Subroutine _unit_glob: called CC=1 SCAR=0.0
8303 1 my ($g) = @_;
8304 1 ( my $r = quotemeta $g ) =~ s/\\\*/.*/g;
8305 1 $r =~ s/\\\?/./g;
8306 1 $r =~ s/\\\[/[/g;
8307 1 $r =~ s/\\\]/]/g;
8308 1 return qr/\A$r(?:\.service)?\z/;
8309 }
8310  
8311 # systemctl list-unit-files: UNIT FILE, STATE, VENDOR PRESET (systemd 252)
8312 0 ▶sub _list_unit_files {
Subroutine _list_unit_files: not called CC=8 SCAR=42.8
8313 0 my ( $dev, $names ) = @_;
8314 0 ▶ my $svcs = $dev->{services} || {};
Condition0%0/2
$$dev{'services'} || {}
l!l
00
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table0%0/2
A
A= $$dev{'services'}
Aresult
11
00
8315 my @r = map {
8316 0 my $v = $svcs->{$_};
8317 0 ▶ [ _uname($_), $v->{masked} ? 'masked' : _symlinked( $dev, $_, $v ) ? 'enabled' : _static( $dev, $_, $v ) ? 'static' : 'disabled' ] # wie is-enabled
Branch: 3 branches
BranchTrueFalseTotal
$$v{'masked'} ? : 0 0 0
_symlinked($dev, $_, $v) ? : 0 0 0
_static($dev, $_, $v) ? : 0 0 0
8318 } @$names;
8319 0 my ( $w1, $w2 ) = ( length 'UNIT FILE', length 'STATE' );
8320 0 ▶ for (@r) { $w1 = length $_->[0] if length $_->[0] > $w1; $w2 = length $_->[1] if length $_->[1] > $w2 }
Branch: 2 branches
BranchTrueFalseTotal
if length $$_[0] > $w1 0 0 0
if length $$_[1] > $w2 0 0 0
8321 return join "\n", sprintf( '%-*s %-*s %s', $w1, 'UNIT FILE', $w2, 'STATE', 'VENDOR PRESET' ),
8322 0 ( map { sprintf( '%-*s %-*s %s', $w1, $_->[0], $w2, $_->[1], 'enabled' ) } @r ), '', scalar(@r) . ' unit files listed.';
8323 }
8324  
8325 229 ▶sub _systemctl {
Subroutine _systemctl: called CC=164 SCAR=70.8
8326 229 my ( $dev, $av, $ctx ) = @_;
8327 { # systemctl [-p A] show …: erstes Wort ohne Option (Werte von -p uebersprungen)
8328 229 my @x = @$av;
8329 229 ▶ while (@x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@x) 229 0 229
8330 229 my $y = shift @x;
8331 0 ▶ if ( $y eq '-p' || $y eq '--property' ) { shift @x; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($y eq "-p" or $y eq "--property") 0 229 229
Condition33%1/3
$y eq "-p" or $y eq "--property"
l!l&&r!l&&!r
00229
MC/DC0%0/2
$y eq "-p" or $y eq "--property"
$y eq "-p" $y eq "--property"
Truth table33%1/3
A or B
A= $y eq "-p"B= $y eq "--property"
ABresult
1X1
011
000
8332 229 ▶ next if $y =~ /\A-/;
Branch: 1 branch
BranchTrueFalseTotal
if $y =~ /\A-/ 0 229 229
8333 229 ▶ return _systemctl_show( $dev, $av ) if $y eq 'show';
Branch: 1 branch
BranchTrueFalseTotal
if $y eq "show" 35 194 229
8334 194 last;
8335 }
8336 }
8337 194 my $now = grep { $_ eq '--now' } @$av;
8338 194 ▶ my $failed = grep { $_ eq '--failed' || $_ eq '--state=failed' } @$av;
Condition33%1/3
$_ eq '--failed' || $_ eq '--state=failed'
l!l&&r!l&&!r
00382
MC/DC0%0/2
$_ eq '--failed' || $_ eq '--state=failed'
$_ eq '--failed' $_ eq '--state=failed'
Truth table33%1/3
A || B
A= $_ eq '--failed'B= $_ eq '--state=failed'
ABresult
1X1
011
000
8339 # systemctl kill [-s SIG] dienst…: SIGHUP wirkt wie reload; TERM, KILL, INT treffen den
8340 # laufenden Dienst wie kill (Restart= der Unit gilt); nicht geladen, stehend, anderes: Luecke
8341 194 ▶ if ( ( $av->[0] // '' ) eq 'kill' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($$av[0] // "") eq "kill") 6 188 194
Condition50%1/2
$$av[0] // ""
l!l
1940
MC/DC0%0/1
$$av[0] // ""
$$av[0]
Truth table50%1/2
A
A= $$av[0]
Aresult
11
00
8342 6 my ( @rest, $sig ) = ();
8343 6 my @k = @{$av}[ 1 .. $#$av ];
8344 6 ▶ while (@k) {
Branch: 1 branch
BranchTrueFalseTotal
if (@k) 10 6 16
8345 10 my $x = shift @k;
8346 10 ▶ if ( $x eq '-s' || $x eq '--signal' ) { $sig = shift @k }
Branch: 4 branches
BranchTrueFalseTotal
if ($x eq '-s' or $x eq '--signal') { } 3 7 10
elsif ($x =~ /\A--signal=(.+)\z/) { } 1 6 7
elsif ($x =~ /\A--kill-whom=(?:all|main)\z/) { } 0 6 6
elsif (not $x =~ /\A-/) { } 6 0 6
Condition66%2/3
$x eq "-s" or $x eq "--signal"
l!l&&r!l&&!r
307
MC/DC50%1/2
$x eq "-s" or $x eq "--signal"
$x eq "-s" $x eq "--signal"
Truth table66%2/3
A or B
A= $x eq "-s"B= $x eq "--signal"
ABresult
1X1
011
000
8347 1 elsif ( $x =~ /\A--signal=(.+)\z/ ) { $sig = $1 }
8348 elsif ( $x =~ /\A--kill-whom=(?:all|main)\z/ ) { }
8349 6 elsif ( $x !~ /\A-/ ) { push @rest, $x }
8350 0 else { push @GAPS, join( ' ', 'systemctl', @$av ); return ( '', 0 ) }
8351 }
8352 6 ▶ my $s = _sig_of( $sig // 'TERM' );
Condition100%2/2
$sig // "TERM"
l!l
42
MC/DC100%1/1
$sig // "TERM"
$sig
Truth table100%2/2
A
A= $sig
Aresult
11
00
8353 6 ▶ return _systemctl( $dev, [ 'reload', @rest ], $ctx ) if $s eq 'HUP';
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "HUP" 1 5 6
8354 5 my @units = map { _unit($_) } @rest;
8355 5 ▶ if ( !@units || $s !~ /\A(?:TERM|KILL|INT)\z/ || grep { !( ( $dev->{services} || {} )->{$_} || {} )->{active} } @units ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @units && $s =~ /\A(?:TERM|KILL|INT)\z/ or grep {not +(($$dev{"services"} || {})->{$_} || {})->{"active"};} @units) 2 3 5
Condition70%7/10
not @units && $s =~ /\A(?:TERM|KILL|INT)\z/ or grep {not +(($$dev{"services"} || {})->{$_} || {})->{"active"};} @units
l!l&&r!l&&!r
113
@units && $s =~ /\A(?:TERM|KILL|INT)\z/
!ll&&!rl&&r
014
($$dev{'services'} || {})->{$_} || {}
l!l
40
$$dev{'services'} || {}
l!l
40
MC/DC66%2/3
not @units && $s =~ /\A(?:TERM|KILL|INT)\z/ or grep {not +(($$dev{"services"} || {})->{$_} || {})->{"active"};} @units
@units $s =~ /\A(?:TERM|KILL|INT)\z/ grep {not +(($$dev{"services"} || {})->{$_} || {})->{"active"};} @units
MC/DC0%0/1
($$dev{'services'} || {})->{$_} || {}
$$dev{'services'}
Truth table75%3/4
not(A && B) or C
A= @unitsB= $s =~ /\A(?:TERM|KILL|INT)\z/C= grep {not +(($$dev{"services"} || {})->{$_} || {})->{"active"};} @units
ABCresult
0XX1
10X1
1111
1100
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
8356 2 push @GAPS, join( ' ', 'systemctl', @$av );
8357 2 return ( '', 0 );
8358 }
8359 3 _signal( $dev, $_, $s ) for @units;
8360 3 return ( '', 1 );
8361 }
8362 188 ▶ my $all = grep { $_ eq '--all' || $_ eq '-a' } @$av;
Condition33%1/3
$_ eq '--all' || $_ eq '-a'
l!l&&r!l&&!r
00363
MC/DC0%0/2
$_ eq '--all' || $_ eq '-a'
$_ eq '--all' $_ eq '-a'
Truth table33%1/3
A || B
A= $_ eq '--all'B= $_ eq '-a'
ABresult
1X1
011
000
8363 188 ▶ my ($type) = map { /\A--type=(\w+)\z/ ? $1 : () } @$av;
Branch: 1 branch
BranchTrueFalseTotal
/\A--type=(\w+)\z/ ? : 0 363 363
8364 188 ▶ my @a = grep { !/\A--/ && !/\A-[qlfa]\z/ } @$av;
Condition66%2/3
/\A--/ || /\A-[qlfa]\z/
l!l&&r!l&&!r
20361
MC/DC50%1/2
/\A--/ || /\A-[qlfa]\z/
/\A--/ /\A-[qlfa]\z/
Truth table66%2/3
A || B
A= /\A--/B= /\A-[qlfa]\z/
ABresult
1X1
011
000
8365 188 ▶ my $verb = shift(@a) // 'list-units';
Condition50%1/2
shift @a // "list-units"
l!l
1880
MC/DC0%0/1
shift @a // "list-units"
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
8366 188 my @names = map { _unit($_) } @a;
8367 188 ▶ my $svcs = $dev->{services} //= {};
Condition100%2/2
$$dev{"services"} //= {}
l!l
1844
MC/DC100%1/1
$$dev{"services"} //= {}
$$dev{"services"}
Truth table100%2/2
A
A= $$dev{"services"}
Aresult
11
00
8368 # Debian: postgresql.service fasst die Cluster zusammen (ReloadPropagatedFrom=, PartOf=)
8369 188 ▶ if ( ref $dev->{postgres} eq 'HASH' && !$svcs->{postgresql} && $verb =~ /\A(?:reload|restart|start|stop|try-restart|reload-or-restart)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$dev{"postgres"} eq "HASH" and not $$svcs{"postgresql"} and $verb =~ /\A(?:reload|restart|start|stop|try-restart|reload-or-restart)\z/) 7 181 188
Condition66%4/6
ref $$dev{"postgres"} eq "HASH" and not $$svcs{"postgresql"} and $verb =~ /\A(?:reload|restart|start|stop|try-restart|reload-or-restart)\z/
!ll&&!rl&&r
18107
ref $$dev{"postgres"} eq "HASH" and not $$svcs{"postgresql"}
!ll&&!rl&&r
18107
MC/DC33%1/3
ref $$dev{"postgres"} eq "HASH" and not $$svcs{"postgresql"} and $verb =~ /\A(?:reload|restart|start|stop|try-restart|reload-or-restart)\z/
ref $$dev{"postgres"} eq "HASH" not $$svcs{"postgresql"} $verb =~ /\A(?:reload|restart|start|stop|try-restart|reload-or-restart)\z/
Truth table50%2/4
A and not(B) and C
A= ref $$dev{"postgres"} eq "HASH"B= not $$svcs{"postgresql"}C= $verb =~ /\A(?:reload|restart|start|stop|try-restart|reload-or-restart)\z/
ABCresult
0XX0
10X0
1100
1111
8370 7 ▶ @names = map { $_ eq 'postgresql' ? $dev->{postgres}{service} // 'postgresql@15-main' : $_ } @names;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'postgresql' ? : 2 5 7
Condition50%1/2
$$dev{"postgres"}{"service"} // "postgresql\@15-main"
l!l
20
MC/DC0%0/1
$$dev{"postgres"}{"service"} // "postgresql\@15-main"
$$dev{"postgres"}{"service"}
Truth table50%1/2
A
A= $$dev{"postgres"}{"service"}
Aresult
11
00
8371 }
8372 # systemctl status 'billing*': die passenden geladenen Units, ohne Treffer nichts
8373 188 ▶ if ( $verb eq 'status' && grep {/[*?[]/} @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "status" and grep {/[*?[]/;} @a) 0 188 188
Condition66%2/3
$verb eq "status" and grep {/[*?[]/;} @a
!ll&&!rl&&r
177110
MC/DC0%0/2
$verb eq "status" and grep {/[*?[]/;} @a
$verb eq "status" grep {/[*?[]/;} @a
Truth table66%2/3
A and B
A= $verb eq "status"B= grep {/[*?[]/;} @a
ABresult
0X0
100
111
8374 0 ▶ @names = map { my $p = $_; /[*?[]/ ? ( grep { _uname($_) =~ _unit_glob($p) } sort keys %$svcs ) : _unit($p) } @a;
Branch: 1 branch
BranchTrueFalseTotal
/[*?[]/ ? : 0 0 0
8375 0 ▶ return ( '', 1 ) unless @names;
Branch: 1 branch
BranchTrueFalseTotal
unless @names 0 0 0
8376 }
8377 188 ▶ return ( _list_timers( $dev, $all, \@a ), 1 ) if $verb eq 'list-timers';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "list-timers" 2 186 188
8378 186 ▶ if ( $verb eq 'list-units' || $verb eq 'list-unit-files' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "list-units" or $verb eq "list-unit-files") 0 186 186
Condition33%1/3
$verb eq "list-units" or $verb eq "list-unit-files"
l!l&&r!l&&!r
00186
MC/DC0%0/2
$verb eq "list-units" or $verb eq "list-unit-files"
$verb eq "list-units" $verb eq "list-unit-files"
Truth table33%1/3
A or B
A= $verb eq "list-units"B= $verb eq "list-unit-files"
ABresult
1X1
011
000
8379 0 ▶ my @n = sort grep { ( !$failed || $svcs->{$_}{failed} ) && ( !defined $type || _uname($_) =~ /\.\Q$type\E\z/ ) } keys %$svcs;
Condition0%0/9
(!$failed || $$svcs{$_}{'failed'}) && (!defined($type) || _uname($_) =~ /\.\Q$type\E\z/)
!ll&&!rl&&r
000
not $failed or $$svcs{$_}{"failed"}
l!l&&r!l&&!r
000
not defined $type or _uname($_) =~ /\.\Q$type\E\z/
l!l&&r!l&&!r
000
MC/DC0%0/4
(!$failed || $$svcs{$_}{'failed'}) && (!defined($type) || _uname($_) =~ /\.\Q$type\E\z/)
not $failed $$svcs{$_}{"failed"} not defined $type _uname($_) =~ /\.\Q$type\E\z/
Truth table0%0/7
not(A) or B && not(C) or D
A= not $failedB= $$svcs{$_}{"failed"}C= not defined $typeD= _uname($_) =~ /\.\Q$type\E\z/
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
8380 # Muster hinter dem Verb (billing*, *.timer) wie systemd: gegen den Namen der Unit
8381 0 ▶ @n = grep { my $u = _uname($_); grep { $u =~ _unit_glob($_) } @a } @n if @a;
Branch: 1 branch
BranchTrueFalseTotal
if @a 0 0 0
8382 0 ▶ return ( _list_unit_files( $dev, \@n ), 1 ) if $verb eq 'list-unit-files';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "list-unit-files" 0 0 0
8383 0 ▶ return ( ' UNIT LOAD ACTIVE SUB DESCRIPTION' . "\n0 loaded units listed.", 1 ) if !@n && $failed;
Branch: 1 branch
BranchTrueFalseTotal
if not @n and $failed 0 0 0
Condition0%0/3
not @n and $failed
!ll&&!rl&&r
000
MC/DC0%0/2
not @n and $failed
not @n $failed
Truth table0%0/3
not(A) and B
A= not @nB= $failed
ABresult
0X0
100
111
8384 return ( join( "\n", sprintf( ' %-30s %-6s %-8s %-8s %s', qw( UNIT LOAD ACTIVE SUB DESCRIPTION ) ),
8385 0 map { my $v = $svcs->{$_};
8386 sprintf( '%s %-30s loaded %-8s %-8s %s', $v->{failed} ? '●' : ' ', _uname($_),
8387 $v->{active} ? 'active' : $v->{failed} ? 'failed' : 'inactive',
8388 0 ▶ $v->{active} ? ( /\.timer\z/ ? 'waiting' : 'running' ) : $v->{failed} ? 'failed' : 'dead', $v->{description} // '' ) } @n ), 1 );
Branch: 6 branches
BranchTrueFalseTotal
$$v{'failed'} ? : 0 0 0
$$v{'active'} ? : 0 0 0
$$v{'failed'} ? : 0 0 0
$$v{'active'} ? : 0 0 0
/\.timer\z/ ? : 0 0 0
$$v{'failed'} ? : 0 0 0
Condition0%0/2
$$v{"description"} // ""
l!l
00
MC/DC0%0/1
$$v{"description"} // ""
$$v{"description"}
Truth table0%0/2
A
A= $$v{"description"}
Aresult
11
00
8389 }
8390 186 ▶ if ( $verb eq 'daemon-reload' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "daemon-reload") 15 171 186
8391 15 ▶ if ( $dev->{storage} ) { # systemd liest die fstab neu (Mount-Units)
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"storage"}) 1 14 15
8392 1 ▶ my $t = _file_text( $dev, '/etc/fstab' ) // '';
Condition50%1/2
_file_text($dev, "/etc/fstab") // ""
l!l
10
MC/DC0%0/1
_file_text($dev, "/etc/fstab") // ""
_file_text($dev, "/etc/fstab")
Truth table50%1/2
A
A= _file_text($dev, "/etc/fstab")
Aresult
11
00
8393 1 ▶ $dev->{storage}{fstab_loaded} = $t if $t ne ( $dev->{storage}{fstab_loaded} // '' );
Branch: 1 branch
BranchTrueFalseTotal
if $t ne ($$dev{"storage"}{"fstab_loaded"} // "") 1 0 1
Condition50%1/2
$$dev{"storage"}{"fstab_loaded"} // ""
l!l
10
MC/DC0%0/1
$$dev{"storage"}{"fstab_loaded"} // ""
$$dev{"storage"}{"fstab_loaded"}
Truth table50%1/2
A
A= $$dev{"storage"}{"fstab_loaded"}
Aresult
11
00
8394 }
8395 15 for my $n ( keys %$svcs ) {
8396 29 my $svc = $svcs->{$n};
8397 29 ▶ next unless exists $svc->{unit_loaded};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$svc{"unit_loaded"} 2 27 29
8398 27 my $t = _unit_text( $dev, $n, $svc );
8399 27 ▶ next unless defined $t && $t ne ( $svc->{unit_loaded} // '' );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t and $t ne ($$svc{"unit_loaded"} // "") 10 17 27
Condition80%4/5
defined $t and $t ne ($$svc{"unit_loaded"} // "")
!ll&&!rl&&r
3717
$$svc{"unit_loaded"} // ""
l!l
240
MC/DC100%2/2
defined $t and $t ne ($$svc{"unit_loaded"} // "")
defined $t $t ne ($$svc{"unit_loaded"} // "")
MC/DC0%0/1
$$svc{"unit_loaded"} // ""
$$svc{"unit_loaded"}
Truth table100%3/3
A and B
A= defined $tB= $t ne ($$svc{"unit_loaded"} // "")
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$svc{"unit_loaded"}
Aresult
11
00
8400 17 $svc->{unit_loaded} = $t;
8401 17 _timer_derive( $dev, $n, $svc );
8402 # Fehler der Unit meldet systemd beim Laden
8403 17 ▶ if ( my $bad = _unit_bad( $n, _unit_props($t) ) ) { _log( $dev, $n, $svc, "systemd[1]: $bad" ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $bad = _unit_bad($n, _unit_props($t))) 2 15 17
8404 }
8405 15 return ( '', 1 );
8406 }
8407 171 ▶ return ( "Too few arguments.", 0 ) unless @names;
Branch: 1 branch
BranchTrueFalseTotal
unless @names 0 171 171
8408 171 my @out;
8409 171 my $ok = 1;
8410 171 for my $n (@names) {
8411 172 my $svc = $svcs->{$n};
8412 172 ▶ if ( !$svc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($svc) 16 156 172
8413 0 ▶ my ($real) = grep { grep { $_ eq $n } @{ $svcs->{$_}{aliases} || [] } } sort keys %$svcs;
Condition50%1/2
$$svcs{$_}{'aliases'} || []
l!l
035
MC/DC0%0/1
$$svcs{$_}{'aliases'} || []
$$svcs{$_}{'aliases'}
Truth table50%1/2
A
A= $$svcs{$_}{'aliases'}
Aresult
11
00
8414 16 ▶ ( $n, $svc ) = ( $real, $svcs->{$real} ) if defined $real;
Branch: 1 branch
BranchTrueFalseTotal
if defined $real 0 16 16
8415 }
8416 172 ▶ $svc //= _load_unit( $dev, $n, $verb eq 'status' || $verb eq 'cat' || $verb =~ /\Ais-/ );
Condition77%7/9
$svc //= _load_unit($dev, $n, $verb eq "status" || $verb eq "cat" || $verb =~ /\Ais-/)
l!l&&r!l&&!r
156124
$verb eq 'status' || $verb eq 'cat' || $verb =~ /\Ais-/
l!l&&r!l&&!r
1150
$verb eq "status" or $verb eq "cat"
l!l&&r!l&&!r
1015
MC/DC100%2/2
$svc //= _load_unit($dev, $n, $verb eq "status" || $verb eq "cat" || $verb =~ /\Ais-/)
$svc _load_unit($dev, $n, $verb eq "status" || $verb eq "cat" || $verb =~ /\Ais-/)
MC/DC0%0/3
$verb eq 'status' || $verb eq 'cat' || $verb =~ /\Ais-/
$verb eq "status" $verb eq "cat" $verb =~ /\Ais-/
Truth table100%3/3
A //= B
A= $svcB= _load_unit($dev, $n, $verb eq "status" || $verb eq "cat" || $verb =~ /\Ais-/)
ABresult
1X1
011
000
Truth table50%2/4
A or B || C
A= $verb eq "status"B= $verb eq "cat"C= $verb =~ /\Ais-/
ABCresult
1XX1
01X1
0011
0000
8417 172 my $u = _uname($n);
8418 172 ▶ if ( !$svc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($svc) 4 168 172
8419 4 ▶ if ( $verb eq 'status' ) { push @out, "Unit $u could not be found."; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "status") 1 3 4
8420 3 ▶ if ( $verb =~ /\Ais-/ ) { push @out, $verb eq 'is-enabled' ? 'not-found' : 'inactive'; $ok = 0; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($verb =~ /\Ais-/) 1 2 3
$verb eq 'is-enabled' ? : 0 1 1
8421 2 push @out, "Failed to $verb $u: Unit $u not found.";
8422 2 $ok = 0;
8423 2 next;
8424 }
8425 168 ▶ if ( $verb eq 'status' ) {
Branch: 12 branches
BranchTrueFalseTotal
if ($verb eq 'status') { } 10 158 168
elsif ($verb eq 'is-active') { } 8 150 158
elsif ($verb eq 'is-failed') { } 0 150 150
elsif ($verb eq 'is-enabled') { } 5 145 150
elsif ($verb eq 'cat') { } 1 144 145
elsif ($verb =~ /\A(?:restart|reload|start|reload-or-restart|try-restart)\z/) { } 124 20 144
elsif ($verb eq 'stop') { } 14 6 20
elsif ($verb eq 'enable' or $verb eq 'disable') { } 6 0 6
elsif ($verb eq 'mask') { } 0 0 0
elsif ($verb eq 'unmask') { } 0 0 0
elsif ($verb eq 'reset-failed') { } 0 0 0
elsif ($verb eq 'edit') { } 0 0 0
8426 10 push @out, _systemctl_status( $dev, $n, $svc, $ctx->{host} );
8427 10 ▶ $ok = 0 unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 1 9 10
8428 }
8429 elsif ( $verb eq 'is-active' ) {
8430 8 ▶ push @out, $svc->{active} ? 'active' : $svc->{failed} ? 'failed' : 'inactive';
Branch: 2 branches
BranchTrueFalseTotal
$$svc{'active'} ? : 6 2 8
$$svc{'failed'} ? : 1 1 2
8431 8 ▶ $ok = 0 unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 2 6 8
8432 }
8433 0 ▶ elsif ( $verb eq 'is-failed' ) { push @out, $svc->{failed} ? 'failed' : $svc->{active} ? 'active' : 'inactive'; $ok = 0 unless $svc->{failed} }
Branch: 3 branches
BranchTrueFalseTotal
$$svc{'failed'} ? : 0 0 0
$$svc{'active'} ? : 0 0 0
unless $$svc{"failed"} 0 0 0
8434 elsif ( $verb eq 'is-enabled' ) {
8435 5 ▶ my $e = $svc->{masked} ? 'masked' : _symlinked( $dev, $n, $svc ) ? 'enabled' : _static( $dev, $n, $svc ) ? 'static' : 'disabled';
Branch: 3 branches
BranchTrueFalseTotal
$$svc{'masked'} ? : 0 5 5
_symlinked($dev, $n, $svc) ? : 1 4 5
_static($dev, $n, $svc) ? : 2 2 4
8436 5 push @out, $e;
8437 5 ▶ $ok = 0 unless $e eq 'enabled' || $e eq 'static';
Branch: 1 branch
BranchTrueFalseTotal
unless $e eq "enabled" or $e eq "static" 2 3 5
Condition100%3/3
$e eq "enabled" or $e eq "static"
l!l&&r!l&&!r
122
MC/DC100%2/2
$e eq "enabled" or $e eq "static"
$e eq "enabled" $e eq "static"
Truth table100%3/3
A or B
A= $e eq "enabled"B= $e eq "static"
ABresult
1X1
011
000
8438 }
8439 elsif ( $verb eq 'cat' ) {
8440 1 my $uf = _unit_file( $n, $svc );
8441 1 ▶ my $t = _file_text( $dev, $uf ) // $svc->{unit_loaded};
Condition33%1/3
_file_text($dev, $uf) // $$svc{"unit_loaded"}
l!l&&r!l&&!r
100
MC/DC0%0/2
_file_text($dev, $uf) // $$svc{"unit_loaded"}
_file_text($dev, $uf) $$svc{"unit_loaded"}
Truth table33%1/3
A // B
A= _file_text($dev, $uf)B= $$svc{"unit_loaded"}
ABresult
1X1
011
000
8442 1 ▶ $t = ( $t // '' ) . join '', map { "\n# $_\n" . ( _file_text( $dev, $_ ) // '' ) } _dropins( $dev, $n );
Condition50%2/4
$t // ""
l!l
10
_file_text($dev, $_) // ""
l!l
10
MC/DC0%0/1
$t // ""
$t
MC/DC0%0/1
_file_text($dev, $_) // ""
_file_text($dev, $_)
Truth table50%1/2
A
A= $t
Aresult
11
00
Truth table50%1/2
A
A= _file_text($dev, $_)
Aresult
11
00
8443 1 ▶ push @out, "# Warning: $u changed on disk, the version systemd has loaded is outdated.",
Branch: 1 branch
BranchTrueFalseTotal
if _unit_changed($dev, $n, $svc) 1 0 1
8444 "# This output shows the current version of the unit's original fragment and drop-in files.",
8445 "# If fragments or drop-ins were added or removed, they are not properly reflected in this output.",
8446 "# Run 'systemctl daemon-reload' to reload units." if _unit_changed( $dev, $n, $svc );
8447 1 ▶ push @out, "# $uf", ( $t // '' ) =~ s/\n\z//r;
Condition50%1/2
$t // ""
l!l
10
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
Aresult
11
00
8448 }
8449 elsif ( $verb =~ /\A(?:restart|reload|start|reload-or-restart|try-restart)\z/ ) {
8450 124 ▶ next if $verb eq 'try-restart' && !$svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "try-restart" and not $$svc{"active"} 0 124 124
Condition33%1/3
$verb eq "try-restart" and not $$svc{"active"}
!ll&&!rl&&r
12400
MC/DC0%0/2
$verb eq "try-restart" and not $$svc{"active"}
$verb eq "try-restart" not $$svc{"active"}
Truth table33%1/3
A and not(B)
A= $verb eq "try-restart"B= not $$svc{"active"}
ABresult
0X0
100
111
8451 # reload-or-restart: laeuft der Dienst und kann er neu laden, laedt er nur neu
8452 124 my $verb = $verb;
8453 124 ▶ if ( $verb eq 'reload-or-restart' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "reload-or-restart") 1 123 124
8454 1 ▶ my $t = $svc->{unit_loaded} // _unit_text( $dev, $n, $svc );
Condition33%1/3
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
l!l&&r!l&&!r
100
MC/DC0%0/2
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
$$svc{"unit_loaded"} _unit_text($dev, $n, $svc)
Truth table33%1/3
A // B
A= $$svc{"unit_loaded"}B= _unit_text($dev, $n, $svc)
ABresult
1X1
011
000
8455 1 ▶ $verb = 'reload' if $svc->{active} && defined $t && $t =~ /^\s*ExecReload\s*=/m;
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} and defined $t and $t =~ /^\s*ExecReload\s*=/m 1 0 1
Condition33%2/6
$$svc{"active"} and defined $t and $t =~ /^\s*ExecReload\s*=/m
!ll&&!rl&&r
001
$$svc{"active"} and defined $t
!ll&&!rl&&r
001
MC/DC0%0/3
$$svc{"active"} and defined $t and $t =~ /^\s*ExecReload\s*=/m
$$svc{"active"} defined $t $t =~ /^\s*ExecReload\s*=/m
Truth table25%1/4
A and B and C
A= $$svc{"active"}B= defined $tC= $t =~ /^\s*ExecReload\s*=/m
ABCresult
0XX0
10X0
1100
1111
8456 }
8457 0 ▶ if ( $svc->{masked} ) { push @out, "Failed to $verb $u: Unit $u is masked."; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($$svc{"masked"}) 0 124 124
8458 124 ▶ my $uft = $verb eq 'reload' ? $svc->{unit_loaded} // _unit_text( $dev, $n, $svc ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$verb eq 'reload' ? : 44 80 124
Condition100%3/3
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
l!l&&r!l&&!r
2834
MC/DC100%2/2
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
$$svc{"unit_loaded"} _unit_text($dev, $n, $svc)
Truth table100%3/3
A // B
A= $$svc{"unit_loaded"}B= _unit_text($dev, $n, $svc)
ABresult
1X1
011
000
8459 # Units ohne ExecReload (in der Unit, systemd-journald, oder reload: false im Zustand)
8460 124 ▶ if ( $verb eq 'reload' && ( !$svc->{active} || $n eq 'systemd-journald' || ( exists $svc->{reload} && !$svc->{reload} ) || $svc->{no_reload}
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "reload" and !$$svc{"active"} || $n eq "systemd-journald" || exists $$svc{"reload"} && !$$svc{"reload"} || $$svc{"no_reload"} || defined $uft && !($uft =~ /^\s*ExecReload\s*=/m)) 3 121 124
Condition90%19/21
$verb eq "reload" and !$$svc{"active"} || $n eq "systemd-journald" || exists $$svc{"reload"} && !$$svc{"reload"} || $$svc{"no_reload"} || defined $uft && !($uft =~ /^\s*ExecReload\s*=/m)
!ll&&!rl&&r
80413
not $$svc{"active"} or $n eq "systemd-journald" or exists $$svc{"reload"} and not $$svc{"reload"} or $$svc{"no_reload"} or defined $uft and not $uft =~ /^\s*ExecReload\s*=/m
l!l&&r!l&&!r
2141
not $$svc{"active"} or $n eq "systemd-journald" or exists $$svc{"reload"} and not $$svc{"reload"} or $$svc{"no_reload"}
l!l&&r!l&&!r
2042
not $$svc{"active"} or $n eq "systemd-journald" or exists $$svc{"reload"} and not $$svc{"reload"}
l!l&&r!l&&!r
1142
not $$svc{"active"} or $n eq "systemd-journald"
l!l&&r!l&&!r
0143
exists $$svc{"reload"} and not $$svc{"reload"}
!ll&&!rl&&r
4111
defined $uft and not $uft =~ /^\s*ExecReload\s*=/m
!ll&&!rl&&r
3291
MC/DC75%6/8
$verb eq "reload" and !$$svc{"active"} || $n eq "systemd-journald" || exists $$svc{"reload"} && !$$svc{"reload"} || $$svc{"no_reload"} || defined $uft && !($uft =~ /^\s*ExecReload\s*=/m)
$verb eq "reload" not $$svc{"active"} $n eq "systemd-journald" exists $$svc{"reload"} not $$svc{"reload"} $$svc{"no_reload"} defined $uft not $uft =~ /^\s*ExecReload\s*=/m
Truth table58%7/12
A and not(B) or C or D and not(E) or F or G and not(H)
A= $verb eq "reload"B= not $$svc{"active"}C= $n eq "systemd-journald"D= exists $$svc{"reload"}E= not $$svc{"reload"}F= $$svc{"no_reload"}G= defined $uftH= not $uft =~ /^\s*ExecReload\s*=/m
ABCDEFGHresult
0XXXXXXX0
1000X00X0
1000X0100
1001000X0
100100100
11XXXXXX1
101XXXXX1
10011XXX1
1000X1XX1
100101XX1
1000X0111
100100111
8461 || ( defined $uft && $uft !~ /^\s*ExecReload\s*=/m ) ) ) {
8462 3 push @out, "Failed to reload $u: Job type reload is not applicable for unit $u.";
8463 3 $ok = 0;
8464 3 next;
8465 }
8466 121 ▶ if ( $verb eq 'reload' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "reload") 41 80 121
8467 41 ▶ if ( defined( my $e = _svc_hook( $dev, $n, 'reload' ) ) ) { # laeuft mit der alten Konfiguration weiter
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $e = _svc_hook($dev, $n, "reload"))) 1 40 41
8468 1 $svc->{last_error} = $e;
8469 1 push @out, "Job for $n.service failed because the control process exited with error code.",
8470 "See \"systemctl status $n.service\" and \"journalctl -xeu $n.service\" for details.";
8471 1 $ok = 0;
8472 1 next;
8473 }
8474 40 _restart_effect( $dev, $n, 'reload' );
8475 38 _reopen_logs( $dev, $n );
8476 38 _pg_event( $dev, $n, 'reload' );
8477 _log( $dev, $n, $svc, "systemd[1]: Reloading $u" . _desc($svc) . '...',
8478 0 ▶ ( map { ( $svc->{exec} // $n ) . '[' . ( 50000 + ( $dev->{_tick} // 0 ) ) . ']: ' . _render( $_, $CTX ? $CTX->{state} : {} ) =~ s/\s+\z//r }
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 0 0 0
Condition0%0/5
$$svc{"exec"} // $n
l!l&&r!l&&!r
000
$$dev{"_tick"} // 0
l!l
00
MC/DC0%0/2
$$svc{"exec"} // $n
$$svc{"exec"} $n
MC/DC0%0/1
$$dev{"_tick"} // 0
$$dev{"_tick"}
Truth table0%0/3
A // B
A= $$svc{"exec"}B= $n
ABresult
1X1
011
000
Truth table0%0/2
A
A= $$dev{"_tick"}
Aresult
11
00
8479 38 ▶ @{ $svc->{reload_log} || [] } ),
Condition50%1/2
$$svc{'reload_log'} || []
l!l
038
MC/DC0%0/1
$$svc{'reload_log'} || []
$$svc{'reload_log'}
Truth table50%1/2
A
A= $$svc{'reload_log'}
Aresult
11
00
8480 "systemd[1]: Reloaded $u" . _desc($svc) . '.' );
8481 38 next;
8482 }
8483 80 my ( $o, $k ) = _systemd_start( $dev, $n, $svc, $verb );
8484 77 ▶ push @out, $o if length $o;
Branch: 1 branch
BranchTrueFalseTotal
if length $o 23 54 77
8485 77 ▶ $ok = 0 unless $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $k 22 55 77
8486 }
8487 elsif ( $verb eq 'stop' ) {
8488 14 ▶ if ( $svc->{active} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$svc{"active"}) 14 0 14
8489 14 ▶ $svc->{restarts} = ( $svc->{restarts} // 0 ) + 1;
Condition100%2/2
$$svc{"restarts"} // 0
l!l
77
MC/DC100%1/1
$$svc{"restarts"} // 0
$$svc{"restarts"}
Truth table100%2/2
A
A= $$svc{"restarts"}
Aresult
11
00
8490 14 $svc->{active} = JSON::MaybeXS::false();
8491 14 _pg_event( $dev, $n, 'stop' );
8492 14 _app_event( $dev, $n, 'stop' );
8493 14 _log( $dev, $n, $svc, "systemd[1]: Stopping $u" . _desc($svc) . '...', "systemd[1]: $u: Deactivated successfully.",
8494 "systemd[1]: Stopped $u" . _desc($svc) . '.' );
8495 }
8496 0 ▶ $dev->{deleted_open} = [ grep { ( $_->{by} // '' ) ne $n } @{ $dev->{deleted_open} } ] if $dev->{deleted_open};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"deleted_open"} 0 14 14
Condition0%0/2
$$_{"by"} // ""
l!l
00
MC/DC0%0/1
$$_{"by"} // ""
$$_{"by"}
Truth table0%0/2
A
A= $$_{"by"}
Aresult
11
00
8497 14 ▶ if ( $n =~ /\Awg-quick\@(wg\d+)\z/ && $dev->{interfaces}{$1} && ( $dev->{interfaces}{$1}{state} // '' ) ne 'DOWN' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /\Awg-quick\@(wg\d+)\z/ and $$dev{"interfaces"}{$1} and ($$dev{"interfaces"}{$1}{"state"} // "") ne "DOWN") 1 13 14
Condition62%5/8
$n =~ /\Awg-quick\@(wg\d+)\z/ and $$dev{"interfaces"}{$1} and ($$dev{"interfaces"}{$1}{"state"} // "") ne "DOWN"
!ll&&!rl&&r
1301
$n =~ /\Awg-quick\@(wg\d+)\z/ and $$dev{"interfaces"}{$1}
!ll&&!rl&&r
1301
$$dev{"interfaces"}{$1}{"state"} // ""
l!l
10
MC/DC33%1/3
$n =~ /\Awg-quick\@(wg\d+)\z/ and $$dev{"interfaces"}{$1} and ($$dev{"interfaces"}{$1}{"state"} // "") ne "DOWN"
$n =~ /\Awg-quick\@(wg\d+)\z/ $$dev{"interfaces"}{$1} $$dev{"interfaces"}{$1}{"state"}
Truth table50%2/4
A and B and C
A= $n =~ /\Awg-quick\@(wg\d+)\z/B= $$dev{"interfaces"}{$1}C= $$dev{"interfaces"}{$1}{"state"}
ABCresult
0XX0
10X0
1100
1111
8498 1 my $w = $1;
8499 1 my $copy = Langertha::Holmgang::Sim::Linux::clone_state($dev);
8500 1 ▶ if ( eval { _wg_down( $copy, $w ); 1 } ) { %$dev = %$copy }
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { _wg_down($copy, $w); 1 } }) { } 1 0 1
8501 0 else { $dev->{interfaces}{$w}{state} = 'DOWN' }
8502 1 $dev->{services}{$n}{active} = JSON::MaybeXS::false();
8503 }
8504 }
8505 ▶ elsif ( $verb eq 'enable' || $verb eq 'disable' ) {
Condition66%2/3
$verb eq "enable" or $verb eq "disable"
l!l&&r!l&&!r
330
MC/DC0%0/2
$verb eq "enable" or $verb eq "disable"
$verb eq "enable" $verb eq "disable"
Truth table66%2/3
A or B
A= $verb eq "enable"B= $verb eq "disable"
ABresult
1X1
011
000
8506 6 ▶ my $want = $verb eq 'enable' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$verb eq 'enable' ? : 3 3 6
8507 6 ▶ if ( $want && $svc->{masked} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want and $$svc{"masked"}) 0 6 6
Condition66%2/3
$want and $$svc{"masked"}
!ll&&!rl&&r
330
MC/DC0%0/2
$want and $$svc{"masked"}
$want $$svc{"masked"}
Truth table66%2/3
A and B
A= $wantB= $$svc{"masked"}
ABresult
0X0
100
111
8508 0 push @out, "Failed to enable unit: Unit file /etc/systemd/system/$u is masked.";
8509 0 $ok = 0;
8510 0 next;
8511 }
8512 6 ▶ if ( _static( $dev, $n, $svc ) && !( !$want && $svc->{enabled} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_static($dev, $n, $svc) and not !$want && $$svc{'enabled'}) { } 1 5 6
Condition83%5/6
_static($dev, $n, $svc) and not !$want && $$svc{"enabled"}
!ll&&!rl&&r
411
!$want && $$svc{'enabled'}
!ll&&!rl&&r
101
MC/DC66%2/3
_static($dev, $n, $svc) and not !$want && $$svc{"enabled"}
_static($dev, $n, $svc) !$want $$svc{'enabled'}
Truth table75%3/4
A and not(not(B) && C)
A= _static($dev, $n, $svc)B= !$wantC= $$svc{'enabled'}
ABCresult
0XX0
1110
10X1
1101
8513 1 push @out, 'The unit files have no installation config (WantedBy=, RequiredBy=, UpheldBy=,',
8514 'Also=, or Alias= settings in the [Install] section, and DefaultInstance= for',
8515 'template units). This means they are not meant to be enabled or disabled using systemctl.', ' ',
8516 'Possible reasons for having these kinds of units are:',
8517 "\x{2022} A unit may be statically enabled by being symlinked from another unit's",
8518 ' .wants/, .requires/, or .upholds/ directory.',
8519 "\x{2022} A unit's purpose may be to act as a helper for some other unit which has",
8520 ' a requirement dependency on it.',
8521 "\x{2022} A unit may be started when needed via activation (socket, path, timer,",
8522 ' D-Bus, udev, scripted systemctl call, ...).',
8523 "\x{2022} In case of template units, the unit is meant to be enabled with some",
8524 ' instance name specified.';
8525 }
8526 else {
8527 5 ▶ $svc->{enabled} = $want ? JSON::MaybeXS::true() : JSON::MaybeXS::false() if ( $svc->{enabled} // 1 ) xor $want;
Branch: 2 branches
BranchTrueFalseTotal
if $$svc{"enabled"} // 1 xor $want 5 0 5
$want ? : 2 3 5
Condition66%4/6
$$svc{"enabled"} // 1 xor $want
l&&rl&&!r!l&&r!l&&!r
0320
$$svc{"enabled"} // 1
l!l
32
MC/DC100%2/2
$$svc{"enabled"} // 1 xor $want
$$svc{"enabled"} $want
Truth table75%3/4
A xor B
A= $$svc{"enabled"}B= $want
ABresult
110
101
011
000
8528 5 ▶ my ($wb) = ( _unit_loaded_text( $dev, $n, $svc ) // '' ) =~ /^\s*WantedBy\s*=\s*(\S+)/m;
Condition50%1/2
_unit_loaded_text($dev, $n, $svc) // ""
l!l
50
MC/DC0%0/1
_unit_loaded_text($dev, $n, $svc) // ""
_unit_loaded_text($dev, $n, $svc)
Truth table50%1/2
A
A= _unit_loaded_text($dev, $n, $svc)
Aresult
11
00
8529 5 ▶ $wb //= $n =~ /\.timer\z/ ? 'timers.target' : 'multi-user.target';
Branch: 1 branch
BranchTrueFalseTotal
$n =~ /\.timer\z/ ? : 0 3 3
Condition100%2/2
$wb //= $n =~ /\.timer\z/ ? "timers.target" : "multi-user.target"
l!l
23
MC/DC100%1/1
$wb //= $n =~ /\.timer\z/ ? "timers.target" : "multi-user.target"
$wb
Truth table100%2/2
A
A= $wb
Aresult
11
00
8530 5 ▶ push @out, $want ? "Created symlink /etc/systemd/system/$wb.wants/$u \x{2192} " . _unit_file( $n, $svc ) . '.'
Branch: 1 branch
BranchTrueFalseTotal
$want ? : 2 3 5
8531 : "Removed \"/etc/systemd/system/$wb.wants/$u\".";
8532 }
8533 6 ▶ if ($now) {
Branch: 1 branch
BranchTrueFalseTotal
if ($now) 2 4 6
8534 2 ▶ if ($want) { my ( $o, $k ) = _systemd_start( $dev, $n, $svc, 'start' ); push @out, $o if length $o; $ok = 0 unless $k }
Branch: 4 branches
BranchTrueFalseTotal
if ($want) { } 2 0 2
elsif ($$svc{'active'}) { } 0 0 0
if length $o 0 2 2
unless $k 0 2 2
8535 0 ▶ elsif ( $svc->{active} ) { $svc->{restarts} = ( $svc->{restarts} // 0 ) + 1; $svc->{active} = JSON::MaybeXS::false(); _pg_event( $dev, $n, 'stop' ) }
Condition0%0/2
$$svc{"restarts"} // 0
l!l
00
MC/DC0%0/1
$$svc{"restarts"} // 0
$$svc{"restarts"}
Truth table0%0/2
A
A= $$svc{"restarts"}
Aresult
11
00
8536 }
8537 }
8538 0 ▶ elsif ( $verb eq 'mask' ) { $svc->{masked} = 1 unless $svc->{masked}; push @out, "Created symlink /etc/systemd/system/$u \x{2192} /dev/null." }
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"masked"} 0 0 0
8539 0 elsif ( $verb eq 'unmask' ) { delete $svc->{masked}; push @out, "Removed \"/etc/systemd/system/$u\"." }
8540 0 ▶ elsif ( $verb eq 'reset-failed' ) { $svc->{failed} = JSON::MaybeXS::false() if $svc->{failed} }
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"failed"} 0 0 0
8541 0 elsif ( $verb eq 'edit' ) { push @GAPS, "systemctl edit $n"; push @out, 'Error opening terminal: unknown.'; $ok = 0 }
8542 0 else { return ( "Unknown command verb $verb.", 0 ) }
8543 }
8544 166 return ( join( "\n", @out ), $ok );
8545 }
8546  
8547 # systemd-analyze calendar AUSDRUCK… | verify DATEI… | cat-config PFAD…; anderes ist eine Luecke
8548 9 ▶sub _systemd_analyze {
Subroutine _systemd_analyze: called CC=24 SCAR=33.9
8549 9 my ( $dev, $av ) = @_;
8550 9 my @a = grep { !/\A--(?:iterations|base-time)=/ } @$av;
8551 9 ▶ my $sub = shift(@a) // '';
Condition50%1/2
shift @a // ""
l!l
90
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
8552 9 require Langertha::Holmgang::Sim::Linux::Calendar;
8553 9 ▶ if ( $sub eq 'calendar' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "calendar") 4 5 9
8554 4 ▶ return ( 'Too few arguments.', 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 4 4
8555 4 my ( @out, $ok );
8556 4 $ok = 1;
8557 4 for my $e (@a) {
8558 4 my $c = Langertha::Holmgang::Sim::Linux::Calendar::parse($e);
8559 4 ▶ if ( !$c ) { push @out, "Failed to parse calendar specification '$e': Invalid argument"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($c) 1 3 4
8560 3 my $t = Langertha::Holmgang::Sim::Linux::Calendar::next_elapse( $c, _sim_now() );
8561 3 ▶ push @out, '' if @out;
Branch: 1 branch
BranchTrueFalseTotal
if @out 0 3 3
8562 3 push @out, " Original form: $e", "Normalized form: $c->{normalized}";
8563 3 ▶ if ( defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) { } 3 0 3
8564 3 push @out, ' Next elapse: ' . Langertha::Holmgang::Sim::Linux::Calendar::format_local($t);
8565 3 push @out, ' (in UTC): ' . Langertha::Holmgang::Sim::Linux::Calendar::format_local( $t, 1 );
8566 3 push @out, ' From now: ' . Langertha::Holmgang::Sim::Linux::Calendar::left( $t - _sim_now() ) . ' left';
8567 }
8568 0 else { push @out, ' Next elapse: never' }
8569 }
8570 4 return ( join( "\n", @out ), $ok );
8571 }
8572 5 ▶ if ( $sub eq 'verify' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "verify") 1 4 5
8573 1 my ( @out, $ok );
8574 1 $ok = 1;
8575 1 for my $p (@a) {
8576 1 my $t = _file_text( $dev, $p );
8577 0 ▶ if ( !defined $t ) { push @out, "Failed to prepare filename $p: No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 0 1 1
8578 1 ( my $n = $p ) =~ s{.*/}{};
8579 1 ▶ next unless $n =~ /\.timer\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $n =~ /\.timer\z/ 0 1 1
8580 1 my $i = _timer_info( $dev, $n, { unit => $p } );
8581 1 push @out, map {"$p:$_->[0]: Failed to parse calendar specification, ignoring: $_->[1]"} @{ $i->{bad} };
8582 1 ▶ if ( !@{ $i->{cal} } && !$i->{other} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$$i{"cal"};} or $$i{"other"}) 1 0 1
Condition33%1/3
@{$$i{"cal"};} or $$i{"other"}
l!l&&r!l&&!r
001
MC/DC0%0/2
@{$$i{"cal"};} or $$i{"other"}
@{$$i{"cal"};} $$i{"other"}
Truth table33%1/3
A or B
A= @{$$i{"cal"};}B= $$i{"other"}
ABresult
1X1
011
000
8583 1 push @out, "$n: Timer unit lacks value setting. Refusing.", "Unit $n has a bad unit file setting.";
8584 1 $ok = 0;
8585 }
8586 }
8587 1 return ( join( "\n", @out ), $ok );
8588 }
8589 4 ▶ if ( $sub eq 'cat-config' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "cat-config") 3 1 4
8590 3 my @p = grep { !/\A-/ } @a;
8591 3 ▶ return ( 'Too few arguments.', 0 ) unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 3 3
8592 3 my @out;
8593 3 for my $p (@p) {
8594 3 ( my $rel = $p ) =~ s{\A/(?:etc|run|usr/local/lib|usr/lib|lib)/}{};
8595 0 ▶ if ( $rel =~ m{\A/} ) { push @GAPS, join( ' ', 'systemd-analyze', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($rel =~ m[\A/]) 0 3 3
8596 3 my @roots = qw( /etc /run /usr/local/lib /usr/lib );
8597 3 my ($main) = grep { defined _file_text( $dev, $_ ) } map {"$_/$rel"} @roots;
8598 3 my %drop; # Dateiname -> Pfad, das erste Verzeichnis gewinnt
8599 3 for my $r ( reverse @roots ) {
8600 12 my $d = "$r/$rel.d/";
8601 12 ▶ $drop{ substr( $_, length $d ) } = $_ for grep { index( $_, $d ) == 0 && substr( $_, length $d ) =~ m{\A[^/]+\.conf\z} } keys %{ $dev->{files} || {} };
Condition60%3/5
index($_, $d) == 0 && substr($_, length $d) =~ m[\A[^/]+\.conf\z]
!ll&&!rl&&r
11109
$$dev{'files'} || {}
l!l
120
MC/DC50%1/2
index($_, $d) == 0 && substr($_, length $d) =~ m[\A[^/]+\.conf\z]
index($_, $d) == 0 substr($_, length $d) =~ m[\A[^/]+\.conf\z]
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table66%2/3
A && B
A= index($_, $d) == 0B= substr($_, length $d) =~ m[\A[^/]+\.conf\z]
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
8602 }
8603 3 ▶ my @f = ( ( $main // () ), map { $drop{$_} } sort keys %drop );
Condition33%1/3
$main // ()
l!l&&r!l&&!r
300
MC/DC0%0/2
$main // ()
$main ()
Truth table33%1/3
A // B
A= $mainB= ()
ABresult
1X1
011
000
8604 0 ▶ if ( !@f ) { push @GAPS, join( ' ', 'systemd-analyze', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (@f) 0 3 3
8605 3 push @out, map { "# $_\n" . ( _file_text( $dev, $_ ) =~ s/\n+\z//r ) } @f;
8606 }
8607 3 return ( join( "\n\n", @out ), 1 );
8608 }
8609 1 push @GAPS, join( ' ', 'systemd-analyze', @$av );
8610 1 return ( '', 0 );
8611 }
8612  
8613 # bash -c '…' / sh -c '…': die Zeile im Simulator ausfuehren
8614 0 ▶sub _shell_c {
Subroutine _shell_c: not called CC=6 SCAR=37.4
8615 0 my ( $dev, $av, $ctx ) = @_;
8616 0 my @a = @$av;
8617 0 ▶ shift @a while @a && $a[0] =~ /\A-[^c]/;
Branch: 1 branch
BranchTrueFalseTotal
@a and $a[0] =~ /\A-[^c]/ and do { shift @a } 0 0 0
Condition0%0/3
@a and $a[0] =~ /\A-[^c]/
!ll&&!rl&&r
000
MC/DC0%0/2
@a and $a[0] =~ /\A-[^c]/
@a $a[0] =~ /\A-[^c]/
Truth table0%0/3
A and B
A= @aB= $a[0] =~ /\A-[^c]/
ABresult
0X0
100
111
8618 0 ▶ return ( '', 1 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 0 0
8619 0 ▶ if ( $a[0] eq '-c' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a[0] eq "-c") 0 0 0
8620 0 ▶ my $line = $a[1] // return ( 'bash: -c: option requires an argument', 0 );
Condition0%0/2
$a[1] // (return "bash: -c: option requires an argument", 0)
l!l
00
MC/DC0%0/1
$a[1] // (return "bash: -c: option requires an argument", 0)
$a[1]
Truth table0%0/2
A
A= $a[1]
Aresult
11
00
8621 0 my ( $o, $k ) = __PACKAGE__->_run_inner( $dev, $line, $ctx );
8622 0 return ( $o, $k );
8623 }
8624 0 push @GAPS, join( ' ', 'bash', @a ); # Skript ausfuehren: nicht nachgebildet
8625 0 return ( '', 0 );
8626 }
8627  
8628 # timedatectl [status|show|set-timezone Z|list-timezones|timesync-status]
8629 4 ▶sub _timedatectl {
Subroutine _timedatectl: called CC=18 SCAR=30.7
8630 4 my ( $dev, $av ) = @_;
8631 4 require Langertha::Holmgang::Sim::Linux::Calendar;
8632 4 my $C = 'Langertha::Holmgang::Sim::Linux::Calendar';
8633 4 my @a = grep { !/\A--(?:no-pager|no-ask-password)\z/ } @$av;
8634 4 ▶ my $verb = shift(@a) // 'status';
Condition100%2/2
shift @a // "status"
l!l
22
MC/DC100%1/1
shift @a // "status"
shift @a
Truth table100%2/2
A
A= shift @a
Aresult
11
00
8635 4 ▶ my $tz = $dev->{timezone} // 'Europe/Berlin';
Condition50%1/2
$$dev{"timezone"} // "Europe/Berlin"
l!l
04
MC/DC0%0/1
$$dev{"timezone"} // "Europe/Berlin"
$$dev{"timezone"}
Truth table50%1/2
A
A= $$dev{"timezone"}
Aresult
11
00
8636 4 my $now = _sim_now();
8637 4 my $off = $C->can('offset')->( $now, $tz );
8638 4 ▶ if ( $verb eq 'status' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "status") 2 2 4
8639 2 my $loc = $C->can('format_local')->( $now, $tz );
8640 2 ( my $abbr = $loc ) =~ s/.* //;
8641 2 ▶ my $o = sprintf '%s%02d%02d', $off < 0 ? '-' : '+', abs($off) / 3600, ( abs($off) % 3600 ) / 60;
Branch: 1 branch
BranchTrueFalseTotal
$off < 0 ? : 0 2 2
8642 2 ( my $rtc = $C->can('format_local')->( $now, 1 ) ) =~ s/ UTC\z//;
8643 2 return ( join( "\n", " Local time: $loc", ' Universal time: ' . $C->can('format_local')->( $now, 1 ),
8644 " RTC time: $rtc", " Time zone: $tz ($abbr, $o)", 'System clock synchronized: yes',
8645 ' NTP service: active', ' RTC in local TZ: no' ), 1 );
8646 }
8647 2 ▶ if ( $verb eq 'show' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "show") 1 1 2
8648 1 my %p = ( Timezone => $tz, LocalRTC => 'no', CanNTP => 'yes', NTP => 'yes', NTPSynchronized => 'yes',
8649 TimeUSec => $C->can('format_local')->( $now, $tz ), RTCTimeUSec => $C->can('format_local')->( $now, $tz ) );
8650 1 ▶ my @want = map { /\A--property=(.*)\z/ ? split( /,/, $1 ) : () } @a;
Branch: 1 branch
BranchTrueFalseTotal
/\A--property=(.*)\z/ ? : 0 3 3
8651 1 ▶ for ( my $i = 0; $i < @a; $i++ ) { push @want, split /,/, $a[ $i + 1 ] // '' if $a[$i] eq '-p' }
Branch: 2 branches
BranchTrueFalseTotal
if ($i < @a) 3 1 4
if $a[$i] eq "-p" 1 2 3
Condition50%1/2
$a[$i + 1] // ""
l!l
10
MC/DC0%0/1
$a[$i + 1] // ""
$a[$i + 1]
Truth table50%1/2
A
A= $a[$i + 1]
Aresult
11
00
8652 1 my $value = grep { $_ eq '--value' } @a;
8653 1 ▶ my @k = grep { !@want || do { my $x = $_; grep { $_ eq $x } @want } } qw( Timezone LocalRTC CanNTP NTP NTPSynchronized TimeUSec RTCTimeUSec );
Condition66%2/3
!@want || do { my $x = $_; grep {$_ eq $x;} @want }
l!l&&r!l&&!r
016
MC/DC50%1/2
!@want || do { my $x = $_; grep {$_ eq $x;} @want }
!@want do { my $x = $_; grep {$_ eq $x;} @want }
Truth table66%2/3
not(A) || B
A= !@wantB= do { my $x = $_; grep {$_ eq $x;} @want }
ABresult
1X1
011
000
8654 1 ▶ return ( join( "\n", map { $value ? $p{$_} : "$_=$p{$_}" } @k ), 1 );
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 1 0 1
8655 }
8656 0 ▶ if ( $verb eq 'list-timezones' ) { return ( join( "\n", sort grep {m{/}} keys %Langertha::Holmgang::Sim::Linux::Calendar::ZONE ), 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "list-timezones") 0 1 1
8657 1 ▶ if ( $verb eq 'set-timezone' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "set-timezone") 1 0 1
8658 1 ▶ my $z = shift(@a) // return ( 'Too few arguments.', 0 );
Condition50%1/2
shift @a // (return "Too few arguments.", 0)
l!l
10
MC/DC0%0/1
shift @a // (return "Too few arguments.", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
8659 1 ▶ return ( "Failed to set time zone: Invalid or not installed time zone '$z'", 0 ) unless $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$z} && $z =~ m{/|\AUTC\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$z} and $z =~ m[/|\AUTC\z] 0 1 1
Condition33%1/3
$Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$z} and $z =~ m[/|\AUTC\z]
!ll&&!rl&&r
001
MC/DC0%0/2
$Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$z} and $z =~ m[/|\AUTC\z]
$Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$z} $z =~ m[/|\AUTC\z]
Truth table33%1/3
A and B
A= $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$z}B= $z =~ m[/|\AUTC\z]
ABresult
0X0
100
111
8660 1 ▶ $dev->{timezone} = $z unless $z eq $tz;
Branch: 1 branch
BranchTrueFalseTotal
unless $z eq $tz 1 0 1
8661 1 return ( '', 1 );
8662 }
8663 0 push @GAPS, join( ' ', 'timedatectl', @$av );
8664 0 return ( '', 0 );
8665 }
8666  
8667 # file PFAD…: Art einer Datei aus dem Zustand
8668 5 ▶sub _file_cmd {
Subroutine _file_cmd: called CC=20 SCAR=32.8
8669 5 my ( $dev, $av ) = @_;
8670 5 my @out;
8671 5 for my $p ( grep { !/\A-/ } @$av ) {
8672 7 my $e = _file_entry( $dev, $p );
8673 # ein Programm, das which an diesem Pfad findet (git, kubectl …): ausfuehrbare Datei
8674 7 ▶ if ( !$e && $p =~ m{\A/usr/(?:local/)?s?bin/([\w.+-]+)\z} && ( _which( 'which', $dev, [$1] ) )[0] eq $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $e and $p =~ m[\A/usr/(?:local/)?s?bin/([\w.+-]+)\z] and (_which("which", $dev, [$1]))[0] eq $p) 1 6 7
Condition83%5/6
not $e and $p =~ m[\A/usr/(?:local/)?s?bin/([\w.+-]+)\z] and (_which("which", $dev, [$1]))[0] eq $p
!ll&&!rl&&r
601
not $e and $p =~ m[\A/usr/(?:local/)?s?bin/([\w.+-]+)\z]
!ll&&!rl&&r
421
MC/DC66%2/3
not $e and $p =~ m[\A/usr/(?:local/)?s?bin/([\w.+-]+)\z] and (_which("which", $dev, [$1]))[0] eq $p
not $e $p =~ m[\A/usr/(?:local/)?s?bin/([\w.+-]+)\z] (_which("which", $dev, [$1]))[0] eq $p
Truth table75%3/4
not(A) and B and C
A= not $eB= $p =~ m[\A/usr/(?:local/)?s?bin/([\w.+-]+)\z]C= (_which("which", $dev, [$1]))[0] eq $p
ABCresult
0XX0
10X0
1100
1111
8675 1 push @out, "$p: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped";
8676 1 next;
8677 }
8678 6 ▶ if ( !$e ) { push @out, _is_dir( $dev, $p ) ? "$p: directory" : "$p: cannot open `$p' (No such file or directory)"; next }
Branch: 2 branches
BranchTrueFalseTotal
unless ($e) 2 4 6
_is_dir($dev, $p) ? : 1 1 2
8679 0 ▶ if ( defined $e->{link} ) { push @out, "$p: symbolic link to $e->{link}"; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$e{"link"}) 0 4 4
8680 4 ▶ my $t = $e->{content} // '';
Condition50%1/2
$$e{"content"} // ""
l!l
40
MC/DC0%0/1
$$e{"content"} // ""
$$e{"content"}
Truth table50%1/2
A
A= $$e{"content"}
Aresult
11
00
8681 my $kind = $p =~ /\.gz\z/ ? 'gzip compressed data, from Unix'
8682 : $p =~ /\.journal(?:~)?\z/ ? 'Journal file'
8683 : $t =~ /\A#!\s*\S*\b(?:ba|da)?sh\b/ ? 'POSIX shell script, ASCII text executable'
8684 : $t =~ /BEGIN OPENSSH PRIVATE KEY/ ? 'OpenSSH private key'
8685 4 ▶ : ( grep { !/\A\s*(?:#|\z)/ } split /\n/, $t ) == 1 && $t =~ /^(?:\S+\s+)?ssh-(ed25519|rsa)\s+AAAA/m ? 'OpenSSH ' . uc($1) . ' public key'
Branch: 9 branches
BranchTrueFalseTotal
$p =~ /\.gz\z/ ? : 0 4 4
$p =~ /\.journal(?:~)?\z/ ? : 0 4 4
$t =~ /\A#!\s*\S*\b(?:ba|da)?sh\b/ ? : 1 3 4
$t =~ /BEGIN OPENSSH PRIVATE KEY/ ? : 0 3 3
grep({not /\A\s*(?:#|\z)/;} split(/\n/, $t, 0)) == 1 && $t =~ /^(?:\S+\s+)?ssh-(ed25519|rsa)\s+AAAA/m ? : 1 2 3
length $t ? : 1 1 2
$t =~ /[^\x00-\x7f]/ ? : 0 1 1
_file_size($e) > 0 && _mode_of($e) & 73 ? : 1 0 1
_file_size($e) > 0 ? : 0 0 0
Condition50%3/6
grep({not /\A\s*(?:#|\z)/;} split(/\n/, $t, 0)) == 1 and $t =~ /^(?:\S+\s+)?ssh-(ed25519|rsa)\s+AAAA/m
!ll&&!rl&&r
201
_file_size($e) > 0 and _mode_of($e) & 73
!ll&&!rl&&r
001
MC/DC50%1/2
grep({not /\A\s*(?:#|\z)/;} split(/\n/, $t, 0)) == 1 and $t =~ /^(?:\S+\s+)?ssh-(ed25519|rsa)\s+AAAA/m
grep({not /\A\s*(?:#|\z)/;} split(/\n/, $t, 0)) == 1 $t =~ /^(?:\S+\s+)?ssh-(ed25519|rsa)\s+AAAA/m
MC/DC0%0/2
_file_size($e) > 0 and _mode_of($e) & 73
_file_size($e) > 0 _mode_of($e) & 73
Truth table66%2/3
A and B
A= grep({not /\A\s*(?:#|\z)/;} split(/\n/, $t, 0)) == 1B= $t =~ /^(?:\S+\s+)?ssh-(ed25519|rsa)\s+AAAA/m
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= _file_size($e) > 0B= _mode_of($e) & 73
ABresult
0X0
100
111
8686 : length $t ? ( $t =~ /[^\x00-\x7f]/ ? 'Unicode text, UTF-8 text' : 'ASCII text' )
8687 : _file_size($e) > 0 && ( _mode_of($e) & 0111 ) ? 'ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped'
8688 : _file_size($e) > 0 ? 'data' : 'empty';
8689 4 push @out, "$p: $kind";
8690 }
8691 5 return ( join( "\n", @out ), 1 );
8692 }
8693  
8694 # Pakete, deren Dateien der Simulator kennt (dpkg -L/-S/-l/-s); weitere ueber
8695 # packages: { name: [ pfade ] } im Zustand
8696 82 our %PACKAGES = (
8697 'openssh-server' => { version => '1:9.2p1-2+deb12u3', files => [], desc => 'secure shell (SSH) server, for secure access from remote machines' },
8698 'openssh-client' => { version => '1:9.2p1-2+deb12u3', files => [], desc => 'secure shell (SSH) client, for secure access to remote machines' },
8699 nftables => { version => '1.0.6-2+deb12u2', files => [], desc => 'Program to control packet filtering rules by Netfilter project' },
8700 logrotate => { version => '3.21.0-1', files => [ qw( /etc/cron.daily/logrotate /etc/logrotate.conf /etc/logrotate.d/btmp
8701 /etc/logrotate.d/wtmp /lib/systemd/system/logrotate.service /lib/systemd/system/logrotate.timer /usr/sbin/logrotate
8702 /usr/share/doc/logrotate/changelog.Debian.gz /usr/share/man/man5/logrotate.conf.5.gz /usr/share/man/man8/logrotate.8.gz
8703 /var/lib/logrotate ) ], desc => 'Log rotation utility' },
8704 cron => { version => '3.0pl1-162', files => [ qw( /etc/cron.d /etc/cron.d/.placeholder /etc/cron.daily /etc/crontab
8705 /etc/init.d/cron /lib/systemd/system/cron.service /usr/sbin/cron /usr/bin/crontab ) ], desc => 'process scheduling daemon' },
8706 );
8707  
8708 4 ▶sub _dpkg {
Subroutine _dpkg: called CC=17 SCAR=30.0
8709 4 my ( $dev, $av ) = @_;
8710 4 my @a = @$av;
8711 4 ▶ my $op = shift(@a) // '';
Condition50%1/2
shift @a // ""
l!l
40
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
8712 0 ▶ my %pk = ( %PACKAGES, map { ( $_ => { version => '1', files => $dev->{packages}{$_}, desc => '' } ) } keys %{ $dev->{packages} || {} } );
Condition50%1/2
$$dev{'packages'} || {}
l!l
04
MC/DC0%0/1
$$dev{'packages'} || {}
$$dev{'packages'}
Truth table50%1/2
A
A= $$dev{'packages'}
Aresult
11
00
8713 4 ▶ my $known = sub { my ($n) = @_; $pk{$n} };
Subroutine __ANON__: called CC=1 SCAR=0.0
8714 4 ▶ if ( $op eq '-L' || $op eq '--listfiles' || $op eq '-s' || $op eq '--status' || $op eq '-l' || $op eq '--list' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "-L" or $op eq "--listfiles" or $op eq "-s" or $op eq "--status" or $op eq "-l" or $op eq "--list") 3 1 4
Condition80%12/15
$op eq "-L" or $op eq "--listfiles" or $op eq "-s" or $op eq "--status" or $op eq "-l" or $op eq "--list"
l!l&&r!l&&!r
301
$op eq "-L" or $op eq "--listfiles" or $op eq "-s" or $op eq "--status" or $op eq "-l"
l!l&&r!l&&!r
211
$op eq "-L" or $op eq "--listfiles" or $op eq "-s" or $op eq "--status"
l!l&&r!l&&!r
202
$op eq "-L" or $op eq "--listfiles" or $op eq "-s"
l!l&&r!l&&!r
112
$op eq "-L" or $op eq "--listfiles"
l!l&&r!l&&!r
103
MC/DC50%3/6
$op eq "-L" or $op eq "--listfiles" or $op eq "-s" or $op eq "--status" or $op eq "-l" or $op eq "--list"
$op eq "-L" $op eq "--listfiles" $op eq "-s" $op eq "--status" $op eq "-l" $op eq "--list"
Truth table57%4/7
A or B or C or D or E or F
A= $op eq "-L"B= $op eq "--listfiles"C= $op eq "-s"D= $op eq "--status"E= $op eq "-l"F= $op eq "--list"
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
8715 3 my @out;
8716 3 my $ok = 1;
8717 3 for my $n (@a) {
8718 3 my $p = $known->($n);
8719 3 ▶ if ( !$p ) { push @GAPS, "dpkg $op $n"; return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($p) 1 2 3
8720 2 ▶ if ( $op =~ /\A-(?:L|-listfiles)\z/ ) { push @out, '/.', @{ $p->{files} } }
Branch: 2 branches
BranchTrueFalseTotal
if ($op =~ /\A-(?:L|-listfiles)\z/) { } 1 1 2
elsif ($op =~ /\A-(?:s|-status)\z/) { } 0 1 1
8721 0 elsif ( $op =~ /\A-(?:s|-status)\z/ ) { push @out, "Package: $n", 'Status: install ok installed', "Version: $p->{version}" }
8722 1 else { push @out, sprintf( 'ii %-14s %-15s amd64 %s', $n, $p->{version}, $p->{desc} ) }
8723 }
8724 2 return ( join( "\n", @out ), $ok );
8725 }
8726 1 ▶ if ( $op eq '-S' || $op eq '--search' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "-S" or $op eq "--search") 1 0 1
Condition33%1/3
$op eq "-S" or $op eq "--search"
l!l&&r!l&&!r
100
MC/DC0%0/2
$op eq "-S" or $op eq "--search"
$op eq "-S" $op eq "--search"
Truth table33%1/3
A or B
A= $op eq "-S"B= $op eq "--search"
ABresult
1X1
011
000
8727 1 my @out;
8728 1 for my $f (@a) {
8729 1 my ($n) = grep { my $x = $_; grep { $_ eq $f } @{ $pk{$x}{files} } } sort keys %pk;
8730 0 ▶ if ( !$n ) { push @GAPS, "dpkg -S $f"; return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($n) 0 1 1
8731 1 push @out, "$n: $f";
8732 }
8733 1 return ( join( "\n", @out ), 1 );
8734 }
8735 0 push @GAPS, join( ' ', 'dpkg', @$av );
8736 0 return ( '', 0 );
8737 }
8738  
8739 # PostgreSQL und seine Clients: Wirkung von Start, Neustart, reload, Stopp.
8740 107 ▶sub _pg_event {
Subroutine _pg_event: called CC=11 SCAR=24.9
8741 107 my ( $dev, $n, $verb ) = @_;
8742 107 ▶ my $svc = ( $dev->{services} || {} )->{$n} || {};
Condition50%2/4
($$dev{'services'} || {})->{$n} || {}
l!l
1070
$$dev{'services'} || {}
l!l
1070
MC/DC0%0/1
($$dev{'services'} || {})->{$n} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
8743 107 ▶ return unless $dev->{postgres} || $svc->{pg_connect};
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{"postgres"} or $$svc{"pg_connect"} 98 9 107
Condition100%3/3
$$dev{"postgres"} or $$svc{"pg_connect"}
l!l&&r!l&&!r
7298
MC/DC100%2/2
$$dev{"postgres"} or $$svc{"pg_connect"}
$$dev{"postgres"} $$svc{"pg_connect"}
Truth table100%3/3
A or B
A= $$dev{"postgres"}B= $$svc{"pg_connect"}
ABresult
1X1
011
000
8744 _pg()->can('service_event')->( $dev, $n, $verb eq 'start' || $verb eq 'restart' || $verb eq 'reload' || $verb eq 'stop' ? $verb : 'restart',
8745 9 ▶ $CTX ? $CTX->{state} : {}, $CTX ? $CTX->{host} : undef );
Branch: 3 branches
BranchTrueFalseTotal
$verb eq 'start' || $verb eq 'restart' || $verb eq 'reload' || $verb eq 'stop' ? : 9 0 9
$Langertha::Holmgang::Sim::Linux::CTX ? : 9 0 9
$Langertha::Holmgang::Sim::Linux::CTX ? : 9 0 9
Condition88%8/9
$verb eq "start" or $verb eq "restart" or $verb eq "reload" or $verb eq "stop"
l!l&&r!l&&!r
810
$verb eq "start" or $verb eq "restart" or $verb eq "reload"
l!l&&r!l&&!r
441
$verb eq "start" or $verb eq "restart"
l!l&&r!l&&!r
135
MC/DC0%0/4
$verb eq "start" or $verb eq "restart" or $verb eq "reload" or $verb eq "stop"
$verb eq "start" $verb eq "restart" $verb eq "reload" $verb eq "stop"
Truth table80%4/5
A or B or C or D
A= $verb eq "start"B= $verb eq "restart"C= $verb eq "reload"D= $verb eq "stop"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
8746 9 return;
8747 }
8748  
8749 1 ▶sub _service {
Subroutine _service: called CC=2 SCAR=7.0
8750 1 my ( $dev, $av, $ctx ) = @_;
8751 1 my ( $n, $verb ) = @$av;
8752 1 ▶ return ( 'Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]', 0 ) unless defined $verb;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $verb 0 1 1
8753 1 return _systemctl( $dev, [ $verb, $n ], $ctx );
8754 }
8755  
8756 1 ▶sub _reboot {
Subroutine _reboot: called CC=2 SCAR=7.1
8757 1 my ( $dev, $av, $ctx ) = @_;
8758 1 ▶ $dev->{reboots} = ( $dev->{reboots} // 0 ) + 1;
Condition50%1/2
$$dev{"reboots"} // 0
l!l
01
MC/DC0%0/1
$$dev{"reboots"} // 0
$$dev{"reboots"}
Truth table50%1/2
A
A= $$dev{"reboots"}
Aresult
11
00
8759 1 return ( "Connection to $ctx->{host} closed by remote host.", 0 );
8760 }
8761  
8762 # --- NetworkManager ----------------------------------------------------------------
8763  
8764 2 ▶sub _nmcli {
Subroutine _nmcli: called CC=45 SCAR=62.1
8765 2 my ( $dev, $av ) = @_;
8766 2 my @a;
8767 2 ▶ for ( my $i = 0; $i < @$av; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$av) 8 2 10
8768 8 my $x = $av->[$i];
8769 0 ▶ if ( $x =~ /\A-(?:f|g|-fields|-get-values)\z/ ) { $i++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /\A-(?:f|g|-fields|-get-values)\z/) 0 8 8
8770 8 ▶ next if $x =~ /\A-[tp]\z|\A--(?:terse|pretty)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /\A-[tp]\z|\A--(?:terse|pretty)\z/ 0 8 8
8771 8 push @a, $x;
8772 }
8773 2 ▶ my $nm = $dev->{nm} or return ( "Error: NetworkManager is not running.", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $nm = $$dev{"nm"} or return "Error: NetworkManager is not running.", 0 2 0 2
8774 2 ▶ my $cons = $nm->{connections} ||= {};
Condition50%1/2
$$nm{"connections"} ||= {}
l!l
20
MC/DC0%0/1
$$nm{"connections"} ||= {}
$$nm{"connections"}
Truth table50%1/2
A
A= $$nm{"connections"}
Aresult
11
00
8775 2 ▶ my $obj = shift(@a) // 'general';
Condition50%1/2
shift @a // "general"
l!l
20
MC/DC0%0/1
shift @a // "general"
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
8776 2 ▶ my $o = _abbrev( $obj, qw( connection device general networking radio ) )
Branch: 2 branches
BranchTrueFalseTotal
$obj eq 'c' || $obj eq 'con' ? : 0 0 0
$obj eq 'd' || $obj eq 'dev' ? : 0 0 0
Condition20%2/10
(_abbrev($obj, ("connection", "device", "general", "networking", "radio")) // ($obj eq "c" || $obj eq "con" ? "connection" : ($obj eq "d" || $obj eq "dev" ? "device" : undef))) // (return "Error: argument '${obj}' not understood. Try passing --help instead.", 0)
l!l
20
_abbrev($obj, ("connection", "device", "general", "networking", "radio")) // ($obj eq "c" || $obj eq "con" ? "connection" : ($obj eq "d" || $obj eq "dev" ? "device" : undef))
l!l
20
$obj eq "c" or $obj eq "con"
l!l&&r!l&&!r
000
$obj eq "d" or $obj eq "dev"
l!l&&r!l&&!r
000
MC/DC0%0/1
(_abbrev($obj, ("connection", "device", "general", "networking", "radio")) // ($obj eq "c" || $obj eq "con" ? "connection" : ($obj eq "d" || $obj eq "dev" ? "device" : undef))) // (return "Error: argument '${obj}' not understood. Try passing --help instead.", 0)
_abbrev($obj, ("connection", "device", "general", "networking", "radio"))
MC/DC0%0/2
$obj eq "d" or $obj eq "dev"
$obj eq "d" $obj eq "dev"
Truth table50%1/2
A
A= _abbrev($obj, ("connection", "device", "general", "networking", "radio"))
Aresult
11
00
Truth table0%0/3
A or B
A= $obj eq "d"B= $obj eq "dev"
ABresult
1X1
011
000
8777 // ( $obj eq 'c' || $obj eq 'con' ? 'connection' : $obj eq 'd' || $obj eq 'dev' ? 'device' : undef )
8778 // return ( "Error: argument '$obj' not understood. Try passing --help instead.", 0 );
8779 2 ▶ if ( $o eq 'connection' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "connection") 2 0 2
8780 2 ▶ my $verb = shift(@a) // 'show';
Condition50%1/2
shift @a // "show"
l!l
20
MC/DC0%0/1
shift @a // "show"
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
8781 2 ▶ $verb = _abbrev( $verb, qw( show modify up down reload ) ) // ( $verb eq 'mod' ? 'modify' : $verb );
Branch: 1 branch
BranchTrueFalseTotal
$verb eq 'mod' ? : 0 0 0
Condition33%1/3
_abbrev($verb, ("show", "modify", "up", "down", "reload")) // ($verb eq "mod" ? "modify" : $verb)
l!l&&r!l&&!r
200
MC/DC0%0/2
_abbrev($verb, ("show", "modify", "up", "down", "reload")) // ($verb eq "mod" ? "modify" : $verb)
_abbrev($verb, ("show", "modify", "up", "down", "reload")) ($verb eq "mod" ? "modify" : $verb)
Truth table33%1/3
A // B
A= _abbrev($verb, ("show", "modify", "up", "down", "reload"))B= ($verb eq "mod" ? "modify" : $verb)
ABresult
1X1
011
000
8782 2 ▶ if ( $verb eq 'show' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "show") 0 2 2
8783 0 my $n = shift @a;
8784 0 ▶ if ( !defined $n ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $n) 0 0 0
8785 return ( join( "\n", sprintf( '%-20s %-38s %-10s %s', qw( NAME UUID TYPE DEVICE ) ),
8786 0 map { sprintf( '%-20s %-38s %-10s %s', $_, $cons->{$_}{uuid} // '00000000-0000-0000-0000-000000000000',
8787 0 ▶ $cons->{$_}{type} // 'ethernet', $cons->{$_}{device} // '--' ) } sort keys %$cons ), 1 );
Condition0%0/6
$$cons{$_}{"uuid"} // "00000000-0000-0000-0000-000000000000"
l!l
00
$$cons{$_}{"type"} // "ethernet"
l!l
00
$$cons{$_}{"device"} // "--"
l!l
00
MC/DC0%0/1
$$cons{$_}{"uuid"} // "00000000-0000-0000-0000-000000000000"
$$cons{$_}{"uuid"}
MC/DC0%0/1
$$cons{$_}{"type"} // "ethernet"
$$cons{$_}{"type"}
MC/DC0%0/1
$$cons{$_}{"device"} // "--"
$$cons{$_}{"device"}
Truth table0%0/2
A
A= $$cons{$_}{"uuid"}
Aresult
11
00
Truth table0%0/2
A
A= $$cons{$_}{"type"}
Aresult
11
00
Truth table0%0/2
A
A= $$cons{$_}{"device"}
Aresult
11
00
8788 }
8789 0 ▶ my $c = $cons->{$n} or return ( "Error: $n - no such connection profile.", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $c = $$cons{$n} or return "Error: $n - no such connection profile.", 0 0 0 0
8790 0 ▶ my %p = ( 'connection.id' => $n, 'connection.interface-name' => $c->{device} // '--', %{ $c->{props} || {} } );
Condition0%0/4
$$c{"device"} // "--"
l!l
00
$$c{'props'} || {}
l!l
00
MC/DC0%0/1
$$c{"device"} // "--"
$$c{"device"}
MC/DC0%0/1
$$c{'props'} || {}
$$c{'props'}
Truth table0%0/2
A
A= $$c{"device"}
Aresult
11
00
Truth table0%0/2
A
A= $$c{'props'}
Aresult
11
00
8791 0 return ( join( "\n", map { sprintf( '%-40s%s', "$_:", $p{$_} ) } sort keys %p ), 1 );
8792 }
8793 2 ▶ if ( $verb eq 'modify' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "modify") 1 1 2
8794 1 ▶ my $n = shift @a // return ( 'Error: No connection specified.', 0 );
Condition50%1/2
shift @a // (return "Error: No connection specified.", 0)
l!l
10
MC/DC0%0/1
shift @a // (return "Error: No connection specified.", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
8795 1 ▶ my $c = $cons->{$n} or return ( "Error: unknown connection '$n'.", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $c = $$cons{$n} or return "Error: unknown connection '${n}'.", 0 1 0 1
8796 1 ▶ return ( "Error: '$n' - no properties to modify.", 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 1 1
8797 1 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 1 1 2
8798 1 my $k = shift @a;
8799 1 $k =~ s/\A\+|\A-//;
8800 1 ▶ my $v = shift @a // return ( "Error: value for '$k' is missing.", 0 );
Condition50%1/2
shift @a // (return "Error: value for '${k}' is missing.", 0)
l!l
10
MC/DC0%0/1
shift @a // (return "Error: value for '${k}' is missing.", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
8801 1 ▶ return ( "Error: invalid property '$k': '$k' not among [connection, ipv4, ipv6, …].", 0 )
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /\A(?:ipv4|ipv6|connection|802-3-ethernet|gsm)\.[\w-]+\z/ 0 1 1
8802 unless $k =~ /\A(?:ipv4|ipv6|connection|802-3-ethernet|gsm)\.[\w-]+\z/;
8803 1 $c->{props}{$k} = $v;
8804 }
8805 1 return ( '', 1 );
8806 }
8807 1 ▶ if ( $verb eq 'up' || $verb eq 'down' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "up" or $verb eq "down") 1 0 1
Condition33%1/3
$verb eq "up" or $verb eq "down"
l!l&&r!l&&!r
100
MC/DC0%0/2
$verb eq "up" or $verb eq "down"
$verb eq "up" $verb eq "down"
Truth table33%1/3
A or B
A= $verb eq "up"B= $verb eq "down"
ABresult
1X1
011
000
8808 1 ▶ my $n = shift @a // return ( 'Error: No connection specified.', 0 );
Condition50%1/2
shift @a // (return "Error: No connection specified.", 0)
l!l
10
MC/DC0%0/1
shift @a // (return "Error: No connection specified.", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
8809 1 ▶ my $c = $cons->{$n} or return ( "Error: unknown connection '$n'.", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $c = $$cons{$n} or return "Error: unknown connection '${n}'.", 0 1 0 1
8810 0 ▶ if ( $verb eq 'down' ) { $c->{active} = 0; return ( "Connection '$n' successfully deactivated.", 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "down") 0 1 1
8811 1 _nm_apply( $dev, $c );
8812 1 return ( "Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)", 1 );
8813 }
8814 0 return ( "Error: argument '$verb' not understood. Try passing --help instead.", 0 );
8815 }
8816 0 ▶ if ( $o eq 'device' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "device") 0 0 0
8817 0 ▶ my $verb = shift(@a) // 'status';
Condition0%0/2
shift @a // "status"
l!l
00
MC/DC0%0/1
shift @a // "status"
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
8818 0 ▶ if ( $verb eq 'reapply' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "reapply") 0 0 0
8819 0 ▶ my $d = shift @a // return ( 'Error: No interface specified.', 0 );
Condition0%0/2
shift @a // (return "Error: No interface specified.", 0)
l!l
00
MC/DC0%0/1
shift @a // (return "Error: No interface specified.", 0)
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
8820 0 ▶ my ($c) = grep { ( $_->{device} // '' ) eq $d } values %$cons;
Condition0%0/2
$$_{"device"} // ""
l!l
00
MC/DC0%0/1
$$_{"device"} // ""
$$_{"device"}
Truth table0%0/2
A
A= $$_{"device"}
Aresult
11
00
8821 0 ▶ return ( "Error: Device '$d' not found.", 0 ) unless $c;
Branch: 1 branch
BranchTrueFalseTotal
unless $c 0 0 0
8822 0 _nm_apply( $dev, $c );
8823 0 return ( "Connection successfully reapplied to device '$d'.", 1 );
8824 }
8825 return ( join( "\n", sprintf( '%-10s %-10s %-10s %s', qw( DEVICE TYPE STATE CONNECTION ) ),
8826 0 ▶ map { sprintf( '%-10s %-10s %-10s %s', $cons->{$_}{device} // '--', $cons->{$_}{type} // 'ethernet', 'connected', $_ ) }
Condition0%0/4
$$cons{$_}{"device"} // "--"
l!l
00
$$cons{$_}{"type"} // "ethernet"
l!l
00
MC/DC0%0/1
$$cons{$_}{"device"} // "--"
$$cons{$_}{"device"}
MC/DC0%0/1
$$cons{$_}{"type"} // "ethernet"
$$cons{$_}{"type"}
Truth table0%0/2
A
A= $$cons{$_}{"device"}
Aresult
11
00
Truth table0%0/2
A
A= $$cons{$_}{"type"}
Aresult
11
00
8827 sort keys %$cons ), 1 );
8828 }
8829 0 return ( "STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN\nconnected full missing enabled enabled enabled", 1 );
8830 }
8831  
8832 # Metrik einer Verbindung auf ihre (nicht-Kernel-)Routen anwenden.
8833 1 ▶sub _nm_apply {
Subroutine _nm_apply: called CC=12 SCAR=28.8
8834 1 my ( $dev, $c ) = @_;
8835 1 ▶ my $m = ( $c->{props} || {} )->{'ipv4.route-metric'};
Condition50%1/2
$$c{'props'} || {}
l!l
10
MC/DC0%0/1
$$c{'props'} || {}
$$c{'props'}
Truth table50%1/2
A
A= $$c{'props'}
Aresult
11
00
8836 1 ▶ $m = $c->{default_metric} if !defined $m || $m eq '-1';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $m or $m eq -1 0 1 1
Condition33%1/3
not defined $m or $m eq -1
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $m or $m eq -1
not defined $m $m eq -1
Truth table33%1/3
not(A) or B
A= not defined $mB= $m eq -1
ABresult
1X1
011
000
8837 1 ▶ return unless defined $m && defined $c->{device};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m and defined $$c{"device"} 0 1 1
Condition33%1/3
defined $m and defined $$c{"device"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $m and defined $$c{"device"}
defined $m defined $$c{"device"}
Truth table33%1/3
A and B
A= defined $mB= defined $$c{"device"}
ABresult
0X0
100
111
8838 1 ▶ for my $r ( @{ $dev->{routes} || [] } ) {
Condition50%1/2
$$dev{'routes'} || []
l!l
10
MC/DC0%0/1
$$dev{'routes'} || []
$$dev{'routes'}
Truth table50%1/2
A
A= $$dev{'routes'}
Aresult
11
00
8839 5 ▶ next unless ( $r->{dev} // '' ) eq $c->{device} && ( $r->{proto} // '' ) ne 'kernel';
Branch: 1 branch
BranchTrueFalseTotal
unless ($$r{"dev"} // "") eq $$c{"device"} and ($$r{"proto"} // "") ne "kernel" 4 1 5
Condition57%4/7
($$r{"dev"} // "") eq $$c{"device"} and ($$r{"proto"} // "") ne "kernel"
!ll&&!rl&&r
401
$$r{"dev"} // ""
l!l
50
$$r{"proto"} // ""
l!l
10
MC/DC0%0/2
($$r{"dev"} // "") eq $$c{"device"} and ($$r{"proto"} // "") ne "kernel"
$$r{"dev"} $$r{"proto"}
Truth table33%1/3
A and B
A= $$r{"dev"}B= $$r{"proto"}
ABresult
0X0
100
111
8840 1 $r->{metric} = 0 + $m;
8841 }
8842 1 return;
8843 }
8844  
8845 # --- ping (ohne Beobachtung des Falls) ---------------------------------------------
8846  
8847 4 ▶sub _ping {
Subroutine _ping: called CC=21 SCAR=34.4
8848 4 my ( $dev, $av ) = @_;
8849 4 my @a = @$av;
8850 4 my ( $count, $from, $to ) = (4);
8851 4 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 9 4 13
8852 9 my $x = shift @a;
8853 9 ▶ if ( $x eq '-c' ) { $count = shift @a }
Branch: 5 branches
BranchTrueFalseTotal
if ($x eq '-c') { } 3 6 9
elsif ($x =~ /\A-c(\d+)\z/) { } 1 5 6
elsif ($x eq '-I' or $x eq '-S') { } 0 5 5
elsif ($x =~ /\A-[WwisMt]\z/) { } 0 5 5
elsif ($x =~ /\A-/) { } 1 4 5
8854 1 elsif ( $x =~ /\A-c(\d+)\z/ ) { $count = $1 } # -c1 zusammengeschrieben
8855 0 ▶ elsif ( $x eq '-I' || $x eq '-S' ) { $from = shift @a }
Condition33%1/3
$x eq "-I" or $x eq "-S"
l!l&&r!l&&!r
005
MC/DC0%0/2
$x eq "-I" or $x eq "-S"
$x eq "-I" $x eq "-S"
Truth table33%1/3
A or B
A= $x eq "-I"B= $x eq "-S"
ABresult
1X1
011
000
8856 0 elsif ( $x =~ /\A-[WwisMt]\z/ ) { shift @a }
8857 elsif ( $x =~ /\A-/ ) { }
8858 4 else { $to = $x }
8859 }
8860 4 ▶ return ( "ping: usage error: Destination address required", 0 ) unless defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to 0 4 4
8861 4 my $name;
8862 4 ▶ if ( !defined _ip2n($to) ) { # Name: ueber /etc/hosts und die Nameserver aufloesen
Branch: 1 branch
BranchTrueFalseTotal
unless (defined _ip2n($to)) 2 2 4
8863 2 my ($ip) = _resolve( $dev, $to );
8864 2 ▶ return ( "ping: $to: Name or service not known", 0 ) unless defined $ip && defined _ip2n($ip);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip and defined _ip2n($ip) 1 1 2
Condition66%2/3
defined $ip and defined _ip2n($ip)
!ll&&!rl&&r
101
MC/DC50%1/2
defined $ip and defined _ip2n($ip)
defined $ip defined _ip2n($ip)
Truth table66%2/3
A and B
A= defined $ipB= defined _ip2n($ip)
ABresult
0X0
100
111
8865 1 ( $name, $to ) = ( $to, $ip );
8866 }
8867 3 ▶ $count = 4 unless defined $count && $count =~ /\A\d+\z/ && $count > 0 && $count < 20;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count and $count =~ /\A\d+\z/ and $count > 0 and $count < 20 0 3 3
Condition33%3/9
defined $count and $count =~ /\A\d+\z/ and $count > 0 and $count < 20
!ll&&!rl&&r
003
defined $count and $count =~ /\A\d+\z/ and $count > 0
!ll&&!rl&&r
003
defined $count and $count =~ /\A\d+\z/
!ll&&!rl&&r
003
MC/DC0%0/4
defined $count and $count =~ /\A\d+\z/ and $count > 0 and $count < 20
defined $count $count =~ /\A\d+\z/ $count > 0 $count < 20
Truth table20%1/5
A and B and C and D
A= defined $countB= $count =~ /\A\d+\z/C= $count > 0D= $count < 20
ABCDresult
0XXX0
10XX0
110X0
11100
11111
8868 3 ▶ my $src = defined $from && defined _ip2n($from) ? $from : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $from && defined _ip2n($from) ? : 0 3 3
Condition33%1/3
defined $from and defined _ip2n($from)
!ll&&!rl&&r
300
MC/DC0%0/2
defined $from and defined _ip2n($from)
defined $from defined _ip2n($from)
Truth table33%1/3
A and B
A= defined $fromB= defined _ip2n($from)
ABresult
0X0
100
111
8869 3 my ($r) = _lookup( $dev, $to, $src );
8870 3 ▶ return ( "ping: connect: Network is unreachable", 0 ) unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 3 3
8871 3 ▶ my @l = ( "PING " . ( $name // $to ) . " ($to) 56(84) bytes of data." );
Condition66%2/3
$name // $to
l!l&&r!l&&!r
120
MC/DC0%0/2
$name // $to
$name $to
Truth table66%2/3
A // B
A= $nameB= $to
ABresult
1X1
011
000
8872 3 push @l, "64 bytes from $to: icmp_seq=$_ ttl=64 time=0.4" . $_ . ' ms' for 1 .. $count;
8873 3 push @l, '', "--- $to ping statistics ---", "$count packets transmitted, $count received, 0% packet loss, time " . ( $count - 1 ) . '003ms';
8874 3 return ( join( "\n", @l ), 1 );
8875 }
8876  
8877 82 __PACKAGE__->meta->make_immutable;
8878  
8879 __END__
« blib/lib/Langertha/Holmgang/Shell/Filter.pm ↑ Summary blib/lib/Langertha/Holmgang/Structure.pm »