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

filter: Statementstmt 88.0% 7149 / 8124 Branchbran 69.9% 4240 / 6062 Conditioncond 57.5% 3418 / 5937 MC/DCmcdc 29.7% 915 / 3077 Subroutinesub 91.2% 481 / 527 Podpod 100% 11 / 11 totaltotal 68.3% 16214 / 23738 CC 5670 SCAR 50.6
CC
5670
Cov
74%
_systemctl
1192.3
_curl
863.2
_command
648.5
CRAP 156.8
« 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 88 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 88 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 88 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 88 ▶use Langertha::Holmgang::Shell ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 88 ▶use Langertha::Holmgang::Shell::Filter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 88 ▶use Langertha::Holmgang::Sim::Linux::Nft ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 88 ▶use Langertha::Holmgang::Sim::Linux::Calendar ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 88 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 88 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 88 ▶use Module::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 88 with 'Langertha::Holmgang::Role::Simulator';
17  
18 88 our $VERSION = '0.002';
19  
20  
21 # --- IPv4 ------------------------------------------------------------------------
22  
23 740 ▶sub _ip2n {
Subroutine _ip2n: called CC=4 SCAR=14.0
24 740 my ($ip) = @_;
25 740 ▶ 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/ 13 727 740
Condition66%2/3
defined $ip and $ip =~ /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/
!ll&&!rl&&r
013727
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 727 ▶ return undef if grep { $_ > 255 } $1, $2, $3, $4;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ > 255;} $1, $2, $3, $4 0 727 727
27 727 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 413 ▶sub _prefix {
Subroutine _prefix: called CC=8 SCAR=22.6
34 413 my ($p) = @_;
35 413 ▶ 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" 32 381 413
Condition66%2/3
$p eq "default" or $p eq "0.0.0.0/0"
l!l&&r!l&&!r
320381
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 381 ▶ 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 () 381 0 381
37 381 ▶ $len //= 32;
Condition50%1/2
$len //= 32
l!l
3810
MC/DC0%0/1
$len //= 32
$len
Truth table50%1/2
A
A= $len
Aresult
11
00
38 381 my $n = _ip2n($ip);
39 381 ▶ return () unless defined $n && $len <= 32;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n and $len <= 32 0 381 381
Condition33%1/3
defined $n and $len <= 32
!ll&&!rl&&r
00381
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 381 ▶ my $mask = $len ? ( 0xFFFFFFFF << ( 32 - $len ) ) & 0xFFFFFFFF : 0;
Branch: 1 branch
BranchTrueFalseTotal
$len ? : 381 0 381
41 381 return ( $n & $mask, $len, $n );
42 }
43  
44 260 ▶sub _in {
Subroutine _in: called CC=5 SCAR=16.3
45 260 my ( $ip, $pfx ) = @_;
46 260 ▶ my $n = _ip2n($ip) // return 0;
Condition50%1/2
_ip2n($ip) // (return 0)
l!l
2600
MC/DC0%0/1
_ip2n($ip) // (return 0)
_ip2n($ip)
Truth table50%1/2
A
A= _ip2n($ip)
Aresult
11
00
47 260 ▶ my ( $net, $len ) = _prefix($pfx) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
() = _prefix($pfx) or return 0 260 0 260
48 260 ▶ my $mask = $len ? ( 0xFFFFFFFF << ( 32 - $len ) ) & 0xFFFFFFFF : 0;
Branch: 1 branch
BranchTrueFalseTotal
$len ? : 244 16 260
49 260 ▶ return ( $n & $mask ) == $net ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($n & $mask) == $net ? : 231 29 260
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 88 our @GAPS;
63  
64 # Aufrufkontext (fuer Dienste, die andere Geraete beruehren) und Login-Benutzer von su
65 88 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 88 our ( $CWD_DIR, $SHENV );
70 88 our %EXT_NEED; # Befehl eines Zusatz-Simulators (Code-Referenz) => Pakete im Zustand, ohne die er fehlt (which)
71  
72 88 our $AS_USER;
73 88 our $IN_TIMEOUT; # unter timeout: eine haengende Verbindung endet still mit Status 124
74 88 our $START_RC; # $? zu Beginn einer Befehlszeile (Kette der Welt mit Beobachtungen)
75 88 our $ERRNULL; # innerhalb eines Glieds: { programm => 1 } mit 2>/dev/null (_errnull_progs)
76 88 our $SH; # Shell des laufenden Aufrufs: { vars, rc, args, arg0, ctl, errexit, defaults }
77 88 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 2458 ▶sub _web_world {
Subroutine _web_world: called CC=9 SCAR=22.4
82 2458 my ($ctx) = @_;
83 2458 ▶ my $s = $ctx && $ctx->{state};
Condition33%1/3
$ctx && $$ctx{'state'}
!ll&&!rl&&r
002458
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 2458 ▶ return 0 unless ref $s eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $s eq "HASH" 0 2458 2458
85 2458 ▶ 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 2279 179 2458
Condition86%13/15
ref $_ eq 'HASH' && ($$_{'nginx'} || $$_{'docker'} || $$_{'http'} || $$_{'probes'} || $$_{'pki'})
!ll&&!rl&&r
02855343
$$_{"nginx"} or $$_{"docker"} or $$_{"http"} or $$_{"probes"} or $$_{"pki"}
l!l&&r!l&&!r
34302855
$$_{"nginx"} or $$_{"docker"} or $$_{"http"} or $$_{"probes"}
l!l&&r!l&&!r
2431002855
$$_{"nginx"} or $$_{"docker"} or $$_{"http"}
l!l&&r!l&&!r
179642955
$$_{"nginx"} or $$_{"docker"}
l!l&&r!l&&!r
100793019
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 7148 ▶sub _web_cmd {
Subroutine _web_cmd: called CC=18 SCAR=29.0
93 7148 my ( $dev, $cmd ) = @_;
94 7148 ▶ return undef unless ref $dev eq 'HASH' && defined $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $dev eq "HASH" and defined $cmd 0 7148 7148
Condition33%1/3
ref $dev eq "HASH" and defined $cmd
!ll&&!rl&&r
007148
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 7148 ▶ 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
20406944
$$dev{"nginx"} or $$dev{"docker"} or $$dev{"http"} or $$dev{"probes"}
l!l&&r!l&&!r
173316944
$$dev{"nginx"} or $$dev{"docker"} or $$dev{"http"}
l!l&&r!l&&!r
17216975
$$dev{"nginx"} or $$dev{"docker"}
l!l&&r!l&&!r
531196976
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 7148 ▶ if ( $cmd eq 'curl' && $web ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "curl" and $web) 26 7122 7148
Condition100%3/3
$cmd eq "curl" and $web
!ll&&!rl&&r
71081426
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 7122 ▶ if ( $cmd eq 'docker' && $dev->{docker} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "docker" and $$dev{"docker"}) 57 7065 7122
Condition100%3/3
$cmd eq "docker" and $$dev{"docker"}
!ll&&!rl&&r
70541157
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 7065 ▶ if ( $cmd eq 'nginx' && $dev->{nginx} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "nginx" and $$dev{"nginx"}) 13 7052 7065
Condition100%3/3
$cmd eq "nginx" and $$dev{"nginx"}
!ll&&!rl&&r
70351713
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 7052 ▶ 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 7027 7052
Condition88%8/9
$cmd eq "openssl" || $cmd eq "update-ca-certificates" and $$dev{"pki"} || $$dev{"nginx"}
!ll&&!rl&&r
70141325
$cmd eq "openssl" or $cmd eq "update-ca-certificates"
l!l&&r!l&&!r
3447014
$$dev{"pki"} or $$dev{"nginx"}
l!l&&r!l&&!r
25013
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 7027 return undef;
113 }
114  
115 # Start, Neustart, reload eines Dienstes mit eigener Simulation (nginx):
116 # Fehlertext oder undef.
117 109 ▶sub _svc_hook {
Subroutine _svc_hook: called CC=3 SCAR=11.0
118 109 my ( $dev, $n, $verb ) = @_;
119 109 ▶ return undef unless $n eq 'nginx' && $dev->{nginx};
Branch: 1 branch
BranchTrueFalseTotal
unless $n eq "nginx" and $$dev{"nginx"} 97 12 109
Condition100%3/3
$n eq "nginx" and $$dev{"nginx"}
!ll&&!rl&&r
95212
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 2366 ▶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 88 our @MISSING;
146  
147 180 ▶sub device_type { 'linux' }
Subroutine device_type: called CC=1 SCAR=0.0
Pod documented
148  
149  
150 2299 ▶sub run_command {
Subroutine run_command: called CC=5 SCAR=16.1
Pod documented
151 2299 my ( $self, $dev, $line, $ctx ) = @_;
152 2299 local $EXIT;
153 2299 ▶ my @r = $self->_guarded( sub { $self->run( $dev, $line, $ctx ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
154 2299 ▶ 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) 13 2286 2299
if @r < 3 2 11 13
Condition100%6/6
not $r[1] and $Langertha::Holmgang::Sim::Linux::EXIT and $Langertha::Holmgang::Sim::Linux::EXIT != 1
!ll&&!rl&&r
184244413
not $r[1] and $Langertha::Holmgang::Sim::Linux::EXIT
!ll&&!rl&&r
18366457
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 2299 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 2462 ▶sub _guarded {
Subroutine _guarded: called CC=3 SCAR=11.0
181 2462 my ( $self, $code ) = @_;
182 2462 local @MISSING;
183 2462 my @r;
184 2462 my $ok = eval { @r = $code->(); 1 };
185 2462 ▶ if ( @MISSING ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@Langertha::Holmgang::Sim::Linux::MISSING) 2 2460 2462
186 2 my %seen;
187 2 return ( '', 0, join( '; ', map { $_.' is not installed' } grep { !$seen{$_}++ } @MISSING ) );
188 }
189 2460 ▶ die $@ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 2460 2460
190 2460 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 1687 ▶sub _need {
Subroutine _need: called CC=4 SCAR=13.9
196 1687 my ( $class ) = @_;
197 1687 my $file = Module::Runtime::module_notional_filename($class);
198 1687 ▶ return $class if $INC{$file};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{$file} 1658 29 1687
199 29 ▶ return $class if eval { Module::Runtime::require_module($class); 1 };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { &Module::Runtime::require_module($class); 1 } } 25 4 29
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 1665 ▶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 88 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 2303 ▶sub run {
Subroutine run: called CC=11 SCAR=24.0
Pod documented
229 2303 my ( $class, $dev, $line, $ctx ) = @_;
230 2303 ▶ _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 2130 2303
Condition100%3/3
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"}
!ll&&!rl&&r
922038173
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 2303 ▶ if ( my $cut = _locked_out( $dev, $ctx ) ) { return ( $cut, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $cut = _locked_out($dev, $ctx)) 2 2301 2303
232 2301 ▶ 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 2156 2301
if defined $no 4 141 145
233 2297 local @GAPS;
234 2297 local $CTX = $ctx;
235 2297 local $CWD_DIR;
236 2297 ▶ 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 2296 2297
Condition66%2/3
ref $dev eq "HASH" and $$dev{"timezone"}
!ll&&!rl&&r
022961
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 2297 ▶ local $START_RC = ref $dev eq 'HASH' ? delete $dev->{_rc} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $dev eq 'HASH' ? : 2297 0 2297
239 2297 my $web = _web_world($ctx);
240 2297 ▶ Langertha::Holmgang::Sim::Linux::Http::before( $ctx->{state} ) if $web;
Branch: 1 branch
BranchTrueFalseTotal
if $web 158 2139 2297
241 2297 my @r = $class->_run_inner( $dev, $line, $ctx );
242 2297 ▶ Langertha::Holmgang::Sim::Linux::Http::after( $ctx->{state} ) if $web;
Branch: 1 branch
BranchTrueFalseTotal
if $web 158 2139 2297
243 2297 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 2466 ▶sub _locked_out {
Subroutine _locked_out: called CC=12 SCAR=25.6
272 2466 my ( $dev, $ctx ) = @_;
273 2466 my $l = $dev->{nft_login};
274 2466 ▶ return undef unless ref $l eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $l eq "HASH" 2460 6 2466
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 2379 ▶sub _run_inner {
Subroutine _run_inner: called CC=20 SCAR=30.1
292 2379 my ( $class, $dev, $line, $ctx, $sh ) = @_;
293 2379 my $outer = scalar @GAPS;
294 2379 ▶ local $SH = $sh // _new_shell( defined $START_RC ? ( rc => $START_RC ) : () );
Branch: 1 branch
BranchTrueFalseTotal
defined $Langertha::Holmgang::Sim::Linux::START_RC ? : 10 2330 2340
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
3923400
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 2379 $START_RC = undef;
296 2379 my $owner = !$SH->{_started}; # die Shell beginnt hier (nicht source, nicht Kopie fuer $( ) bzw. ( ))
297 2379 $SH->{_started} = 1;
298 2379 $EXIT = 2;
299 2379 my @items = eval { Langertha::Holmgang::Shell::split_items($line) };
300 2379 ▶ if ( my $e = $@ ) { $e =~ s/\s+\z//; return ( $e, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 1 2378 2379
301 2378 my $nodes = Langertha::Holmgang::Shell::parse( \@items );
302 2378 ▶ return ( $nodes, 0 ) unless ref $nodes;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $nodes 1 2377 2378
303 2377 my ( $out, $ok ) = $class->_exec_nodes( $dev, $nodes, $ctx );
304 2377 ▶ 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 2368 2377
elsif (not $sh) { } 2337 31 2368
Condition100%2/2
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
l!l
92368
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 2377 ▶ 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 2372 2377
Condition100%5/5
$owner and defined(my $h = delete(($$Langertha::Holmgang::Sim::Linux::SH{"traps"} || {})->{"EXIT"}))
!ll&&!rl&&r
1323595
$$Langertha::Holmgang::Sim::Linux::SH{'traps'} || {}
l!l
72357
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 2377 ▶ $EXIT = $ok ? 0 : $SH->{rc} || 1;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 1892 485 2377
Condition50%1/2
$$Langertha::Holmgang::Sim::Linux::SH{"rc"} or 1
l!l
4850
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 2377 my @new = @GAPS[ $outer .. $#GAPS ];
321 2377 ▶ return ( join( "\n", @$out ), $ok ? 1 : 0, @new ? join( '; ', @new ) : undef );
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 1892 485 2377
@new ? : 76 2301 2377
322 }
323  
324 # Glieder ausfuehren (&&, ||, ;), mit $?, set -e, break/continue/exit
325 4478 ▶sub _exec_nodes {
Subroutine _exec_nodes: called CC=22 SCAR=31.2
326 4478 my ( $class, $dev, $nodes, $ctx ) = @_;
327 4478 my ( @out, $ok ) = ();
328 4478 $ok = 1;
329 4478 for my $i ( 0 .. $#$nodes ) {
330 4889 ▶ last if $SH->{ctl};
Branch: 1 branch
BranchTrueFalseTotal
if $$Langertha::Holmgang::Sim::Linux::SH{"ctl"} 9 4880 4889
331 4880 my $nd = $nodes->[$i];
332 4880 ▶ my $op = $nd->{op} // ';';
Condition50%1/2
$$nd{"op"} // ";"
l!l
48800
MC/DC0%0/1
$$nd{"op"} // ";"
$$nd{"op"}
Truth table50%1/2
A
A= $$nd{"op"}
Aresult
11
00
333 4880 ▶ next if $op eq '&&' && !$ok || $op eq '||' && $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "&&" and not $ok or $op eq "||" and $ok 20 4860 4880
Condition100%9/9
$op eq "&&" and not $ok or $op eq "||" and $ok
l!l&&r!l&&!r
1644860
$op eq "&&" and not $ok
!ll&&!rl&&r
466819616
$op eq "||" and $ok
!ll&&!rl&&r
485554
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 4860 delete $SH->{code};
335 4860 my ( $o, $k ) = $class->_exec_node( $dev, $nd, $ctx );
336 4860 ▶ push @out, $o if defined $o && length $o;
Branch: 1 branch
BranchTrueFalseTotal
if defined $o and length $o 1845 3015 4860
Condition66%2/3
defined $o and length $o
!ll&&!rl&&r
030151845
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 4860 ▶ $ok = $k ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 4337 523 4860
338 4860 ▶ $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" 4854 6 4860
$ok ? : 4337 517 4854
Condition100%4/4
$$Langertha::Holmgang::Sim::Linux::SH{"ctl"} // [""]
l!l
144846
$$Langertha::Holmgang::Sim::Linux::SH{"code"} // 1
l!l
47470
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 4860 ▶ 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 4857 4860
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
485703
not $ok and $$Langertha::Holmgang::Sim::Linux::SH{"errexit"} and not $$Langertha::Holmgang::Sim::Linux::SH{"in_cond"} and $op eq ";"
!ll&&!rl&&r
485703
not $ok and $$Langertha::Holmgang::Sim::Linux::SH{"errexit"} and not $$Langertha::Holmgang::Sim::Linux::SH{"in_cond"}
!ll&&!rl&&r
485703
not $ok and $$Langertha::Holmgang::Sim::Linux::SH{"errexit"}
!ll&&!rl&&r
43375203
($$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 4478 return ( \@out, $ok );
344 }
345  
346 # Befehlsersetzung $( ) in einer Kopie der Shell (Subshell)
347 4856 ▶sub _cmdsub {
Subroutine _cmdsub: called CC=1 SCAR=0.0
348 4856 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 4856 };
355 }
356  
357 4856 ▶sub _sh_expand {
Subroutine _sh_expand: called CC=6 SCAR=19.2
358 4856 my ( $class, $dev, $raw, $ctx ) = @_;
359 $SH->{defaults} = { HOME => '/root', USER => $AS_USER // 'root', LOGNAME => $AS_USER // 'root', SHELL => '/bin/bash',
360 4856 ▶ 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
04856
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
04856
$Langertha::Holmgang::Sim::Linux::CWD_DIR // "/root"
l!l
1654691
($$dev{"hostname"} // $$ctx{"host"}) // "localhost"
l!l
48560
$$dev{"hostname"} // $$ctx{"host"}
l!l&&r!l&&!r
253223240
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 4856 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 4853 ▶sub _words_of {
Subroutine _words_of: called CC=11 SCAR=24.0
368 4853 my ( $class, $dev, $raw, $ctx, $noglob ) = @_;
369 4853 my $x = $class->_sh_expand( $dev, $raw, $ctx );
370 4853 my @g;
371 4853 my @w = Langertha::Holmgang::Shell::shell_words( $x, \@g );
372 4853 ▶ return \@w if $noglob;
Branch: 1 branch
BranchTrueFalseTotal
if $noglob 16 4837 4853
373 4837 my @out;
374 4837 for my $i ( 0 .. $#w ) {
375 12987 my $w = $w[$i];
376 12987 ▶ 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*=/) 12945 42 12987
Condition77%7/9
ref $w or not $g[$i] or $w =~ /\A-/ or $w =~ /\A[A-Za-z_]\w*=/
l!l&&r!l&&!r
12945042
ref $w or not $g[$i] or $w =~ /\A-/
l!l&&r!l&&!r
12945042
ref $w or not $g[$i]
l!l&&r!l&&!r
3341261142
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 42 my $abs = _absp($w);
378 42 my @hit = _glob( $dev, $abs );
379 42 ▶ if ( @hit == 1 && $hit[0] eq $abs ) { push @out, $w; next }
Branch: 1 branch
BranchTrueFalseTotal
if (@hit == 1 and $hit[0] eq $abs) 33 9 42
Condition100%3/3
@hit == 1 and $hit[0] eq $abs
!ll&&!rl&&r
8133
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 4837 return \@out;
384 }
385  
386 4860 ▶sub _exec_node {
Subroutine _exec_node: called CC=18 SCAR=29.5
387 4860 my ( $class, $dev, $nd, $ctx ) = @_;
388 4860 my $t = $nd->{type};
389 4860 my @r = eval {
390 4860 ▶ return $class->_exec_cmd( $dev, $nd, $ctx ) if $t eq 'cmd';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "cmd" 4809 51 4860
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 4860 ▶ if ( my $e = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 2 4858 4860
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 4858 return @r;
422 }
423  
424 # Eingabe eines Glieds aus Heredoc bzw. Here-String
425 4723 ▶sub _doc_input {
Subroutine _doc_input: called CC=5 SCAR=16.1
426 4723 my ( $class, $dev, $nd, $ctx ) = @_;
427 4723 ▶ if ( defined $nd->{heredoc} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$nd{"heredoc"}) 6 4717 4723
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 4717 ▶ if ( defined $nd->{herestring} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$nd{"herestring"}) 1 4716 4717
434 1 my $w = $class->_words_of( $dev, $nd->{herestring}, $ctx );
435 1 return join( ' ', grep { !ref } @$w ) . "\n";
436 }
437 4716 return undef;
438 }
439  
440 4811 ▶sub _exec_cmd {
Subroutine _exec_cmd: called CC=94 SCAR=59.8
441 4811 my ( $class, $dev, $nd, $ctx ) = @_;
442 4811 my $raw = $nd->{raw};
443 # ! befehl: der Status umgekehrt
444 4811 ▶ if ( $raw =~ /\A!\s+(\S.*)\z/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /\A!\s+(\S.*)\z/s) 2 4809 4811
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 4809 ▶ 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 4803 4809
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 4803 my $w = $class->_words_of( $dev, $raw, $ctx );
457 4803 ▶ return ( '', 1 ) unless @$w;
Branch: 1 branch
BranchTrueFalseTotal
unless @$w 0 4803 4803
458 # nur Zuweisungen: Variablen der Shell
459 4803 ▶ 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 4756 4803
Condition100%3/3
ref $_ || !/\A[A-Za-z_]\w*\+?=/s
l!l&&r!l&&!r
32712422139
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 4756 my @a = @$w;
464 4756 my $cmd = $a[0];
465 4756 ▶ if ( !ref $cmd && $cmd eq 'exec' && @a > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $cmd and $cmd eq "exec" and @a > 1) 3 4753 4756
Condition83%5/6
not ref $cmd and $cmd eq "exec" and @a > 1
!ll&&!rl&&r
475303
not ref $cmd and $cmd eq "exec"
!ll&&!rl&&r
147523
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 4753 ▶ if ( !ref $cmd && !grep { ref $_ && $_->{op} =~ /\A(?:\||>|>>)\z/ } @a ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $cmd or grep {ref $_ and $$_{"op"} =~ /\A(?:\||>|>>)\z/;} @a) 4443 310 4753
Condition100%6/6
ref $cmd or grep {ref $_ and $$_{"op"} =~ /\A(?:\||>|>>)\z/;} @a
l!l&&r!l&&!r
13094443
ref $_ && $$_{'op'} =~ /\A(?:\||>|>>)\z/
!ll&&!rl&&r
125054320
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 4443 ▶ if ( $cmd =~ /\A(?:export|declare|typeset|local|readonly)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /\A(?:export|declare|typeset|local|readonly)\z/) 3 4440 4443
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 4440 4440
504 4440 ▶ if ( $cmd eq 'set' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "set") 4 4436 4440
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 4436 4436
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 4436 ▶ if ( $cmd eq 'umask' ) { return _umask( @a[ 1 .. $#a ] ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "umask") 7 4429 4436
521 4429 ▶ if ( $cmd eq 'exit' || $cmd eq 'return' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "exit" or $cmd eq "return") 7 4422 4429
Condition100%3/3
$cmd eq "exit" or $cmd eq "return"
l!l&&r!l&&!r
614422
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 4422 ▶ if ( $cmd eq 'read' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "read") 0 4422 4422
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 4422 ▶ if ( $cmd eq 'source' || $cmd eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "source" or $cmd eq ".") 0 4422 4422
Condition33%1/3
$cmd eq "source" or $cmd eq "."
l!l&&r!l&&!r
004422
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 4422 ▶ return _trap_cmd( @a[ 1 .. $#a ] ) if $cmd eq 'trap';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "trap" 9 4413 4422
540 4413 ▶ 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 4413 4413
541 }
542 # Shell-Funktion (name() { … }): ihr Rumpf mit den Argumenten, return endet sie
543 4723 ▶ 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 4717 4723
Condition100%5/5
not ref $cmd and my $fb = ($$Langertha::Holmgang::Sim::Linux::SH{"funcs"} || {})->{$cmd}
!ll&&!rl&&r
147166
$$Langertha::Holmgang::Sim::Linux::SH{'funcs'} || {}
l!l
154707
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 4717 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 4717 my %quiet = map { $_ => 1 } _errnull_progs($raw);
556 4717 ▶ local $ERRNULL = %quiet ? \%quiet : undef;
Branch: 1 branch
BranchTrueFalseTotal
%quiet ? : 13 4704 4717
557 4717 my ( $o, $k ) = $class->_pipeline( $dev, \@a, $ctx, $in );
558 4716 ▶ $o = _errnull_cut( $o, [ keys %quiet ] ) if %quiet;
Branch: 1 branch
BranchTrueFalseTotal
if %quiet 13 4703 4716
559 4716 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 4717 ▶sub _errnull_progs {
Subroutine _errnull_progs: called CC=18 SCAR=29.6
574 4717 my ($raw) = @_;
575 4717 ▶ return () unless $raw =~ m{2>>?\s*/dev/null};
Branch: 1 branch
BranchTrueFalseTotal
unless $raw =~ m[2>>?\s*/dev/null] 4704 13 4717
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 4721 ▶sub _pipeline {
Subroutine _pipeline: called CC=66 SCAR=51.4
807 4721 my ( $class, $dev, $words, $ctx, $stdin ) = @_;
808 4721 my @stages = ([]);
809 4721 my ( $redir, $file );
810 4721 my @w = @$words;
811 4721 my $infile;
812 4721 ▶ while (@w) {
Branch: 1 branch
BranchTrueFalseTotal
if (@w) 12558 4720 17278
813 12558 my $t = shift @w;
814 12558 ▶ if ( ref $t && $t->{op} eq '|' ) { push @stages, []; next }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t and $$t{"op"} eq "|") 124 12434 12558
Condition100%3/3
ref $t and $$t{"op"} eq "|"
!ll&&!rl&&r
12233201124
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 12434 ▶ if ( ref $t && $t->{op} eq '<' ) { # < datei: Eingabe des ersten Befehls
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t and $$t{"op"} eq "<") 5 12429 12434
Condition100%3/3
ref $t and $$t{"op"} eq "<"
!ll&&!rl&&r
122331965
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 12429 ▶ if ( ref $t && ( $t->{op} eq '>' || $t->{op} eq '>>' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t and $$t{"op"} eq ">" || $$t{"op"} eq ">>") 196 12233 12429
Condition66%4/6
ref $t and $$t{"op"} eq ">" || $$t{"op"} eq ">>"
!ll&&!rl&&r
122330196
$$t{"op"} eq ">" or $$t{"op"} eq ">>"
l!l&&r!l&&!r
168280
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 196 $redir = $t->{op};
823 196 $file = shift @w;
824 196 ▶ 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 196 196
Condition33%1/3
defined $file and not ref $file
!ll&&!rl&&r
00196
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 196 next;
826 }
827 12233 ▶ return ( 'bash: syntax error near unexpected token `' . $t->{op} . "'", 0 ) if ref $t;
Branch: 1 branch
BranchTrueFalseTotal
if ref $t 0 12233 12233
828 12233 push @{ $stages[-1] }, $t;
829 }
830 4720 ▶ if ( $redir && @stages == 1 && !@{ $stages[0] } ) { # > datei: leeren bzw. anlegen
Branch: 1 branch
BranchTrueFalseTotal
if ($redir and @stages == 1 and not @{$stages[0];}) 0 4720 4720
Condition83%5/6
$redir and @stages == 1 and not @{$stages[0];}
!ll&&!rl&&r
45251950
$redir and @stages == 1
!ll&&!rl&&r
45241195
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 4720 my $in = $stdin;
836 # /dev/tcp/HOST/PORT oeffnet die bash als Verbindung — ohne Netz nicht nachgebildet: Luecke
837 4720 ▶ 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 4719 4720
Condition100%3/3
defined $infile and $infile =~ m[\A/dev/(?:tcp|udp)/]
!ll&&!rl&&r
471631
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 4719 ▶ 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 4719 4719
Condition77%7/9
defined $infile and not $redir and @stages == 1 and not @{$stages[0];}
!ll&&!rl&&r
471720
defined $infile and not $redir and @stages == 1
!ll&&!rl&&r
471702
defined $infile and not $redir
!ll&&!rl&&r
471612
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 4719 ▶ if ( defined $infile ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $infile) 3 4716 4719
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 4719 ▶ return ( "bash: syntax error near unexpected token `|'", 0 ) if grep { !@$_ } @stages;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not @$_;} @stages 0 4719 4719
846 4719 ▶ delete $SH->{code} if $SH;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH 4719 0 4719
847 4719 my ( $out, $ok ) = $class->_command( $dev, $stages[0], $ctx, $in );
848 # ${PIPESTATUS[@]}: Status jeder Stufe
849 4719 ▶ my @ps = ( $ok ? 0 : ( $SH && $SH->{code} ) || 1 );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 4220 499 4719
Condition80%4/5
$Langertha::Holmgang::Sim::Linux::SH and $$Langertha::Holmgang::Sim::Linux::SH{"code"} or 1
l!l
43456
$Langertha::Holmgang::Sim::Linux::SH and $$Langertha::Holmgang::Sim::Linux::SH{"code"}
!ll&&!rl&&r
045643
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 4719 ▶ $SH->{pipestatus} = \@ps if $SH;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH 4719 0 4719
851 4719 my @err; # Meldungen der bash selbst (stderr) gehen nicht in die Pipe
852 4719 for my $i ( 1 .. $#stages ) {
853 124 local $AS_USER = $AS_USER;
854 124 ▶ 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 122 124
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 124 ▶ 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 124 124
Condition66%4/6
not $ok and defined $out and $out =~ /\Abash: [^\n]+: (?:command not found|No such file or directory)\z/
!ll&&!rl&&r
11680
not $ok and defined $out
!ll&&!rl&&r
11608
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 124 my $argv = [ _strip_sudo( @{ $stages[$i] } ) ];
863 124 ▶ if ( $argv->[0] eq 'tee' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$argv[0] eq "tee") 0 124 124
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 124 ▶ my ( $t, $k ) = Langertha::Holmgang::Shell::Filter::filter_output( $out // '', $argv );
Condition50%1/2
$out // ""
l!l
1240
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
874 124 ▶ if ( !defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 55 69 124
875 # hatte die vorige Stufe ein Zeilenende? (echo -n, printf ohne \n: nein) — fuer base64
876 55 my @prev = _strip_sudo( @{ $stages[ $i - 1 ] } );
877 55 ▶ 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
1450
($prev[0] // "") eq "echo" and grep {/\A-[a-zA-Z]*n/;} @prev[1 .. $#prev]
!ll&&!rl&&r
38161
$prev[0] // ""
l!l
550
($prev[0] // "") eq "printf" and not +($prev[1] // "") =~ /\\n\z/
!ll&&!rl&&r
4284
$prev[0] // ""
l!l
540
$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 55 ▶ delete $SH->{code} if $SH;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH 55 0 55
880 55 ( $t, $k ) = $class->_command( $dev, $argv, $ctx, $out );
881 }
882 124 ▶ push @ps, $k ? 0 : ( $SH && $SH->{code} ) || 1;
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 119 5 124
Condition40%2/5
$Langertha::Holmgang::Sim::Linux::SH and $$Langertha::Holmgang::Sim::Linux::SH{"code"} or 1
l!l
05
$Langertha::Holmgang::Sim::Linux::SH and $$Langertha::Holmgang::Sim::Linux::SH{"code"}
!ll&&!rl&&r
050
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 124 ( $out, $ok ) = ( $t, $k );
884 }
885 4719 ▶ if ($redir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($redir) 196 4523 4719
886 196 ▶ my ( $e, $wok ) = _write_path( $dev, $file, defined $out && length $out ? "$out\n" : '', $redir eq '>>', $ctx );
Branch: 1 branch
BranchTrueFalseTotal
defined $out && length $out ? : 180 16 196
Condition66%2/3
defined $out and length $out
!ll&&!rl&&r
016180
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 196 ▶ return ( $e, 0 ) unless $wok;
Branch: 1 branch
BranchTrueFalseTotal
unless $wok 16 180 196
888 180 return ( join( "\n", @err ), $ok );
889 }
890 4523 ▶ return ( join( "\n", @err, defined $out && length $out ? $out : () ), $ok ) if @err;
Branch: 2 branches
BranchTrueFalseTotal
if @err 0 4523 4523
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 4523 return ( $out, $ok );
892 }
893  
894 # Shell-Muster (*, ?) gegen die Pfade im Zustand; ohne Treffer bleibt das Wort
895 42 ▶sub _glob {
Subroutine _glob: called CC=10 SCAR=25.8
896 42 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 42 42
@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 42 ( my $re = quotemeta $w ) =~ s/\\\*/[^\/]*/g;
899 42 $re =~ s/\\\?/[^\/]/g;
900 # Zeichenklassen [0-9], [!a] bzw. [^a]
901 42 ▶ $re =~ s/\\\[((?:\\[!^])?)((?:(?!\\\]).)+)\\\]/'[' . ( length $1 ? '^' : '' ) . ( $2 =~ s{\\(.)}{$1}gr ) . ']'/ge;
Branch: 1 branch
BranchTrueFalseTotal
length $1 ? : 0 2 2
902 42 my %cand;
903 42 ▶ for my $p ( keys %{ $dev->{files} || {} } ) {
Condition50%1/2
$$dev{'files'} || {}
l!l
420
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
904 357 my @seg = split m{/}, $p;
905 357 $cand{ join '/', @seg[ 0 .. $_ ] } = 1 for 1 .. $#seg;
906 }
907 88 ▶ 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
420
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 42 my @hit = sort grep { $_ =~ $rx } keys %cand;
909 42 ▶ return @hit ? @hit : $w;
Branch: 1 branch
BranchTrueFalseTotal
@hit ? : 9 33 42
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 1063 ▶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
601003
$Langertha::Holmgang::Sim::Linux::AS_USER // $Langertha::Holmgang::Sim::Linux::LOGIN_USER
l!l&&r!l&&!r
5281003
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 386 ▶sub _may_create {
Subroutine _may_create: called CC=8 SCAR=20.9
979 386 my ( $dev, $path ) = @_;
980 386 my $user = _who();
981 386 ▶ return undef if $user eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $user eq "root" 374 12 386
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 109 ▶sub _read_ok {
Subroutine _read_ok: called CC=4 SCAR=14.0
1011 109 my ( $dev, $path ) = @_;
1012 109 my $user = _who();
1013 109 ▶ return 1 if $user eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $user eq "root" 106 3 109
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 1314 ▶sub _absp {
Subroutine _absp: called CC=5 SCAR=16.1
1053 1314 my ($p) = @_;
1054 1314 ▶ return _dotdot($p) if $p =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ m[\A/] 854 460 1314
1055 460 ▶ my $c = $CWD_DIR // '/root';
Condition100%2/2
$Langertha::Holmgang::Sim::Linux::CWD_DIR // "/root"
l!l
40852
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 460 $p =~ s{\A\./}{};
1057 460 ▶ return _dotdot( $p eq '.' ? $c : $c eq '/' ? "/$p" : "$c/$p" );
Branch: 2 branches
BranchTrueFalseTotal
$p eq '.' ? : 6 454 460
$c eq '/' ? : 2 452 454
1058 }
1059  
1060 # . und .. in einem absoluten Pfad aufloesen (/srv/a/../b -> /srv/b); ein / am Ende bleibt
1061 1316 ▶sub _dotdot {
Subroutine _dotdot: called CC=8 SCAR=20.8
1062 1316 my ($p) = @_;
1063 1316 ▶ return $p unless $p =~ m{(?:\A|/)\.\.?(?:/|\z)};
Branch: 1 branch
BranchTrueFalseTotal
unless $p =~ m[(?:\A|/)\.\.?(?:/|\z)] 1306 10 1316
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 88 our $STDIN_NL = 1;
1251  
1252 4986 ▶sub _strip_sudo {
Subroutine _strip_sudo: called CC=34 SCAR=41.4
1253 4986 my @a = @_;
1254 4986 ▶ while ( @a && $a[0] eq 'sudo' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] eq "sudo") 78 4981 5059
Condition66%2/3
@a and $a[0] eq "sudo"
!ll&&!rl&&r
0498178
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 78 shift @a;
1256 78 ▶ my $invoker = $AS_USER // 'root';
Condition100%2/2
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
672
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 78 my ( $list, $lu, $target, $nonint );
1258 78 ▶ while ( @a && $a[0] =~ /\A-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-/) 76 78 154
Condition100%3/3
@a and $a[0] =~ /\A-/
!ll&&!rl&&r
37576
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 76 my $o = shift @a;
1260 76 ▶ last if $o eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "--" 0 76 76
1261 76 ▶ if ( $o eq '-u' ) { $target = shift @a }
Branch: 7 branches
BranchTrueFalseTotal
if ($o eq '-u') { } 68 8 76
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 78 ▶ return ( 'sudo-list', $lu // $invoker ) if $list && !@a;
Branch: 1 branch
BranchTrueFalseTotal
if $list and not @a 3 75 78
Condition66%4/6
$list and not @a
!ll&&!rl&&r
7503
$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 75 ▶ 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 70 75
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
7005
$invoker ne "root" and @a and $Langertha::Holmgang::Sim::Linux::CTX and ref $$Langertha::Holmgang::Sim::Linux::CTX{"state"} eq "HASH"
!ll&&!rl&&r
7005
$invoker ne "root" and @a and $Langertha::Holmgang::Sim::Linux::CTX
!ll&&!rl&&r
7005
$invoker ne "root" and @a
!ll&&!rl&&r
7005
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 73 ▶ $AS_USER = $target // 'root';
Condition100%2/2
$target // "root"
l!l
685
MC/DC100%1/1
$target // "root"
$target
Truth table100%2/2
A
A= $target
Aresult
11
00
1281 }
1282 4981 return @a;
1283 }
1284  
1285 # Verzeichnisse, die "ls /" auf jedem Debian zeigt (dazu, was im Zustand liegt)
1286 88 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 88 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 88 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 88 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 88 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 88 our %FILTER = map { $_ => 1 } qw( head tail wc sort uniq cut awk tr fold );
1312  
1313 88 our $DATE_TZ; # TZ=… vor einem Befehl (wirkt auf date)
1314 88 our $BIN_MEMO; # innerhalb eines ls: { bin|sbin => [ namen ] } (_bin_names)
1315 88 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 88 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 88 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 16 ▶ 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 4 ▶ openssl => sub { return _openssl(@_) if $_[0]{kubernetes}; push @GAPS, join( ' ', 'openssl', @{ $_[1] } ); return ( '', 0 ) },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"kubernetes"} 3 1 4
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 88 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 3344 ▶ ( 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' ? : 88 3256 3344
$$_[0] eq 'lsblk' ? : 88 3168 3256
$$_[0] eq 'free' ? : 88 3080 3168
1548 [ lsblk => 'lsblk' ], [ blkid => 'blkid' ], [ findmnt => 'findmnt' ], [ mount => 'mount' ], [ umount => 'umount' ],
1549 968 ( map { [ $_ => 'lvm' ] } qw( pvs vgs lvs pvdisplay vgdisplay lvdisplay pvcreate vgextend lvcreate lvextend lvresize ) ),
1550 [ resize2fs => 'resize2fs' ], [ xfs_growfs => 'xfs_growfs' ],
1551 352 ( map { [ $_ => 'mkfs' ] } qw( mkfs mkfs.ext4 mkfs.ext3 mkfs.xfs ) ), [ tune2fs => 'tune2fs' ],
1552 264 ( map { [ $_ => 'fsck' ] } qw( e2fsck fsck fsck.ext4 ) ),
1553 528 ( map { [ $_ => 'swap' ] } qw( mkswap swapon swapoff fallocate dd free ) ),
1554 88 ( 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 5016 ▶sub _ext {
Subroutine _ext: called CC=2 SCAR=7.3
1691 5016 my ( $mod, $fn, $need, %o ) = @_;
1692 5016 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 5016 };
1703 5016 ▶ $EXT_NEED{$sub} = $o{gap} ? [] : $need;
Branch: 1 branch
BranchTrueFalseTotal
$o{'gap'} ? : 3344 1672 5016
1704 5016 return $sub;
1705 }
1706  
1707 82 ▶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 92 ▶sub prepare {
Subroutine prepare: called CC=18 SCAR=29.2
Pod documented
1713 92 my ( $class, $dev, $ctx ) = @_;
1714 92 local @MISSING; # a missing part dies here: the case does not load
1715 92 ▶ _redis()->can('_running')->($dev) if $dev->{redis};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"redis"} 2 90 92
1716 91 ▶ _maria()->can('_vars')->($dev) if $dev->{mariadb};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"mariadb"} 1 90 91
1717 91 for ( [ bind => 'Dns' ], [ postfix => 'Postfix' ], [ storage => 'Storage' ] ) {
1718 273 my ( $key, $mod ) = @$_;
1719 273 ▶ next unless $dev->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{$key} 256 17 273
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 91 ▶ for my $n ( sort keys %{ $dev->{services} || {} } ) {
Condition100%2/2
$$dev{'services'} || {}
l!l
3259
MC/DC100%1/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table100%2/2
A
A= $$dev{'services'}
Aresult
11
00
1725 45 my $svc = $dev->{services}{$n};
1726 45 ▶ $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 44 45
Condition100%2/2
$$svc{"unit_loaded"} // ""
l!l
243
MC/DC100%1/1
$$svc{"unit_loaded"} // ""
$$svc{"unit_loaded"}
Truth table100%2/2
A
A= $$svc{"unit_loaded"}
Aresult
11
00
1727 45 ▶ 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 29 45
Condition66%6/9
$$svc{"active"} and not $$svc{"_started"} and defined(my $t = $$svc{"unit_loaded"} // _unit_text($dev, $n, $svc))
!ll&&!rl&&r
02916
$$svc{"active"} and not $$svc{"_started"}
!ll&&!rl&&r
0045
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
l!l&&r!l&&!r
21429
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 45 ▶ 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"} 29 16 45
Condition66%4/6
ref $$svc{"config"} eq "ARRAY" and not defined $$svc{"running"} and $$svc{"active"}
!ll&&!rl&&r
29016
ref $$svc{"config"} eq "ARRAY" and not defined $$svc{"running"}
!ll&&!rl&&r
29016
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 16 my ( undef, $extra ) = _config_check( $dev, $svc );
1732 16 ▶ $svc->{running} = { ( map { my $t = _file_text( $dev, $_ ); defined $t ? ( $_ => $t ) : () } @{ $svc->{config} } ), %{ $extra || {} } };
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 27 0 27
Condition50%1/2
$extra || {}
l!l
160
MC/DC0%0/1
$extra || {}
$extra
Truth table50%1/2
A
A= $extra
Aresult
11
00
1733 }
1734 91 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 88 ▶ 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 21 ▶sub _mon {
Subroutine _mon: called CC=1 SCAR=0.0
1763 21 my ( $prog, $dev, $av, $ctx ) = @_;
1764 21 _part('Monitoring');
1765 21 my $m = 'Langertha::Holmgang::Sim::Linux::Monitoring';
1766 88 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1767 21 local @{"${m}::GAPS"};
1768 21 my ( $o, $ok ) = $m->can($prog)->( $dev, $av );
1769 21 push @GAPS, @{"${m}::GAPS"};
1770 21 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 88 ▶ 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 86 ▶sub _app_conf_error {
Subroutine _app_conf_error: called CC=13 SCAR=26.1
1789 86 my ( $dev, $n ) = @_;
1790 86 ▶ my $svc = ( $dev->{services} || {} )->{$n} || {};
Condition50%2/4
($$dev{'services'} || {})->{$n} || {}
l!l
860
$$dev{'services'} || {}
l!l
860
MC/DC0%0/1
($$dev{'services'} || {})->{$n} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
1791 86 ▶ if ( $svc->{config_check} ) { my ($e) = _config_check( $dev, $svc ); return $e if @$e }
Branch: 2 branches
BranchTrueFalseTotal
if ($$svc{"config_check"}) 19 67 86
if @$e 1 18 19
1792 85 my ( $lines, $exe );
1793 85 ▶ 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 82 85
elsif ($$dev{'mariadb'} and $n eq ($$dev{'mariadb'}{'service'} // 'mariadb')) { } 5 154 159
Condition60%3/5
$$dev{"redis"} and $n eq ($$dev{"redis"}{"service"} // "redis-server")
!ll&&!rl&&r
8203
$$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
7705
$$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 85 ▶ return undef unless $lines;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines 82 3 85
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 57 ▶sub _config_check {
Subroutine _config_check: called CC=5 SCAR=16.8
1802 57 my ( $dev, $svc ) = @_;
1803 57 ▶ my $kind = $svc->{config_check} or return ( [], {} );
Branch: 1 branch
BranchTrueFalseTotal
my $kind = $$svc{"config_check"} or return [], {} 57 0 57
1804 57 _part('Monitoring');
1805 57 my ( $err, $extra ) = Langertha::Holmgang::Sim::Linux::Monitoring::service_check( $dev, $svc, $kind );
1806 57 ▶ my $pid = 50000 + ( $dev->{_tick} // 0 );
Condition100%2/2
$$dev{"_tick"} // 0
l!l
1938
MC/DC100%1/1
$$dev{"_tick"} // 0
$$dev{"_tick"}
Truth table100%2/2
A
A= $$dev{"_tick"}
Aresult
11
00
1807 57 ▶ return ( [ map { ( $svc->{exec} // $kind ) . "[$pid]: $_" } @$err ], $extra || {} );
Condition40%2/5
$$svc{"exec"} // $kind
l!l&&r!l&&!r
200
$extra || {}
l!l
570
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 83 ▶sub _app_event {
Subroutine _app_event: called CC=8 SCAR=21.7
1812 83 my ( $dev, $n, $verb ) = @_;
1813 83 ▶ 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 80 83
Condition60%3/5
$$dev{"redis"} and $n eq ($$dev{"redis"}{"service"} // "redis-server")
!ll&&!rl&&r
8003
$$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 83 ▶ 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 78 83
Condition60%3/5
$$dev{"mariadb"} and $n eq ($$dev{"mariadb"}{"service"} // "mariadb")
!ll&&!rl&&r
7805
$$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 83 return;
1818 }
1819  
1820 23 ▶sub _acc { return _part('Accounts') }
Subroutine _acc: called CC=1 SCAR=0.0
1821 206 ▶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 73 ▶sub _psql {
Subroutine _psql: called CC=2 SCAR=6.9
1846 73 my ( $dev, $av, $ctx ) = @_;
1847 73 my $pg = _pg();
1848 88 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1849 73 local @{"${pg}::GAPS"};
1850 73 ▶ my ( $o, $ok ) = $pg->can('psql')->( $dev, $av, $ctx, $AS_USER // 'root' );
Condition100%2/2
$Langertha::Holmgang::Sim::Linux::AS_USER // "root"
l!l
649
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 73 push @GAPS, @{"${pg}::GAPS"};
1852 73 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 # --- Sandbox: ein echtes Programm statt einer Luecke (ADR 0011) -----------------------
1986  
1987  
1988 88 our %SANDBOX = map { $_ => 1 } qw( python3 python perl awk gawk mawk sed jq sha256sum sha1sum md5sum realpath basename
1989 dirname seq column od xxd hexdump head tail wc sort uniq cut tr fold nl tac rev paste comm join expr bc diff cmp );
1990  
1991 # was nur die Simulation weiss: andere Prozesse, Netz, Datenbanken, Konten, Platten, Kernel
1992 88 my $SANDBOX_REFUSE = qr{
1993 \bsubprocess\b | \bos\.(?:system|popen|exec\w*|spawn\w*|kill|getpid|getuid|geteuid|statvfs|uname|getloadavg)\b
1994 | \bPopen\b | \bpty\b | \bshutil\.(?:disk_usage|chown|which)\b | \bpsutil\b | \bplatform\.
1995 | \bsystem\s*\( | \bexec\s*\( | \bqx\b | ` | \|\s*getline | \bopen\s*\([^)]*[|]
1996 | \bsocket\b | \burllib\b | \brequests\b | \bhttp\.client\b | \bhttpx\b | \baiohttp\b | \bsmtplib\b | \bftplib\b | \bparamiko\b
1997 | \bIO::Socket\b | \bLWP\b | \bHTTP::Tiny\b | \bNet:: | \bDBI\b | \bpsycopg\w*\b | \bpymysql\b | \bMySQLdb\b | \bredis\b | \bsqlite3\b
1998 | \bpwd\b | \bgrp\b | \bgetpw\w+ | \bgetgr\w+ | \bgetlogin\b | \bsignal\b | \bdocker\b | \bkubernetes\b | \bdbus\b | \bsystemd\b
1999 | /proc(?:/|\b) | /sys(?:/|\b) | /run(?:/|\b) | /dev/(?!null\b|stdin\b|stdout\b|stderr\b)
2000 }x;
2001  
2002 # Darf diese Befehlszeile in die Sandbox? ( argv fuer die Sandbox ) oder die leere Liste
2003 18 ▶sub _sandbox_argv {
Subroutine _sandbox_argv: called CC=35 SCAR=38.3
2004 18 my ( $dev, $argv, $stdin ) = @_;
2005 18 ▶ return if defined $AS_USER && $AS_USER ne 'root';
Branch: 1 branch
BranchTrueFalseTotal
if defined $Langertha::Holmgang::Sim::Linux::AS_USER and $Langertha::Holmgang::Sim::Linux::AS_USER ne "root" 1 17 18
Condition66%2/3
defined $Langertha::Holmgang::Sim::Linux::AS_USER and $Langertha::Holmgang::Sim::Linux::AS_USER ne "root"
!ll&&!rl&&r
1701
MC/DC50%1/2
defined $Langertha::Holmgang::Sim::Linux::AS_USER and $Langertha::Holmgang::Sim::Linux::AS_USER ne "root"
defined $Langertha::Holmgang::Sim::Linux::AS_USER $Langertha::Holmgang::Sim::Linux::AS_USER ne "root"
Truth table66%2/3
A and B
A= defined $Langertha::Holmgang::Sim::Linux::AS_USERB= $Langertha::Holmgang::Sim::Linux::AS_USER ne "root"
ABresult
0X0
100
111
2006 17 ▶ return if $dev->{pod} || ref $dev->{files} ne 'HASH' && defined $dev->{files};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"pod"} or ref $$dev{"files"} ne "HASH" and defined $$dev{"files"} 0 17 17
Condition33%2/6
$$dev{"pod"} or ref $$dev{"files"} ne "HASH" and defined $$dev{"files"}
l!l&&r!l&&!r
0017
ref $$dev{"files"} ne "HASH" and defined $$dev{"files"}
!ll&&!rl&&r
1700
MC/DC0%0/3
$$dev{"pod"} or ref $$dev{"files"} ne "HASH" and defined $$dev{"files"}
$$dev{"pod"} ref $$dev{"files"} ne "HASH" defined $$dev{"files"}
Truth table25%1/4
A or B and C
A= $$dev{"pod"}B= ref $$dev{"files"} ne "HASH"C= defined $$dev{"files"}
ABCresult
1XX1
0111
00X0
0100
2007 17 my @a = @$argv;
2008 17 ( my $prog = $a[0] ) =~ s{\A.*/}{};
2009 17 ▶ my $text = join( "\n", @a, $stdin // '' );
Condition100%2/2
$stdin // ""
l!l
116
MC/DC100%1/1
$stdin // ""
$stdin
Truth table100%2/2
A
A= $stdin
Aresult
11
00
2010 17 ▶ if ( $a[0] =~ m{/} && !$SANDBOX{$prog} || !$SANDBOX{$prog} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a[0] =~ m[/] and not $Langertha::Holmgang::Sim::Linux::SANDBOX{$prog} or not $Langertha::Holmgang::Sim::Linux::SANDBOX{$prog}) 2 15 17
Condition66%4/6
$a[0] =~ m[/] and not $Langertha::Holmgang::Sim::Linux::SANDBOX{$prog} or not $Langertha::Holmgang::Sim::Linux::SANDBOX{$prog}
l!l&&r!l&&!r
2015
$a[0] =~ m[/] and not $Langertha::Holmgang::Sim::Linux::SANDBOX{$prog}
!ll&&!rl&&r
1502
MC/DC33%1/3
$a[0] =~ m[/] and not $Langertha::Holmgang::Sim::Linux::SANDBOX{$prog} or not $Langertha::Holmgang::Sim::Linux::SANDBOX{$prog}
$a[0] =~ m[/] not $Langertha::Holmgang::Sim::Linux::SANDBOX{$prog} not $Langertha::Holmgang::Sim::Linux::SANDBOX{$prog}
Truth table40%2/5
A and not(B) or not(C)
A= $a[0] =~ m[/]B= not $Langertha::Holmgang::Sim::Linux::SANDBOX{$prog}C= not $Langertha::Holmgang::Sim::Linux::SANDBOX{$prog}
ABCresult
11X1
0X11
1011
0X00
1000
2011 # ein Programm aus dem Zustand: nur mit einem Interpreter aus %SANDBOX in der ersten Zeile
2012 2 ▶ my $path = $a[0] =~ m{/} ? _absp( $a[0] ) : _prog_file( $dev, $a[0] ) // return;
Branch: 1 branch
BranchTrueFalseTotal
$a[0] =~ m[/] ? : 2 0 2
Condition0%0/2
_prog_file($dev, $a[0]) // (return)
l!l
00
MC/DC0%0/1
_prog_file($dev, $a[0]) // (return)
_prog_file($dev, $a[0])
Truth table0%0/2
A
A= _prog_file($dev, $a[0])
Aresult
11
00
2013 2 ▶ my $src = _file_text( $dev, $path ) // return;
Condition50%1/2
_file_text($dev, $path) // (return)
l!l
20
MC/DC0%0/1
_file_text($dev, $path) // (return)
_file_text($dev, $path)
Truth table50%1/2
A
A= _file_text($dev, $path)
Aresult
11
00
2014 2 ▶ my ($interp) = $src =~ m{\A\#!\s*(?:/usr/bin/env\s+|\S*/)([\w.+-]+)} or return;
Branch: 1 branch
BranchTrueFalseTotal
my($interp) = $src =~ m[\A\#!\s*(?:/usr/bin/env\s+|\S*/)([\w.+-]+)] or return 2 0 2
2015 2 ▶ return unless $SANDBOX{$interp};
Branch: 1 branch
BranchTrueFalseTotal
unless $Langertha::Holmgang::Sim::Linux::SANDBOX{$interp} 0 2 2
2016 2 $text .= "\n" . $src;
2017 2 $a[0] = $path;
2018 }
2019 # das Skript hinter dem Interpreter (python3 /opt/x.py) gehoert zum Text
2020 17 ▶ if ( $prog =~ /\A(?:python3?|perl|[gm]?awk|sed|jq)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog =~ /\A(?:python3?|perl|[gm]?awk|sed|jq)\z/) 15 2 17
2021 15 for my $x ( grep { !/\A-/ } @a[ 1 .. $#a ] ) {
2022 15 my $t = _file_text( $dev, _absp($x) );
2023 15 ▶ $text .= "\n" . $t if defined $t && length $t < 200_000;
Branch: 1 branch
BranchTrueFalseTotal
if defined $t and length $t < 200000 0 15 15
Condition33%1/3
defined $t and length $t < 200000
!ll&&!rl&&r
1500
MC/DC0%0/2
defined $t and length $t < 200000
defined $t length $t < 200000
Truth table33%1/3
A and B
A= defined $tB= length $t < 200000
ABresult
0X0
100
111
2024 }
2025 }
2026 17 ▶ return if $text =~ $SANDBOX_REFUSE;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /$SANDBOX_REFUSE/ 7 10 17
2027 # genannte Pfade: nichts, dessen Inhalt der Zustand nur beschreibt oder der Simulator ableitet
2028 10 my @named = map { s{[*?\[].*\z}{}sr =~ s{/+\z}{}r } $text =~ m{(/[\w.\@+*?\[\]-]+(?:/[\w.\@+*?\[\]-]+)*)}g;
2029 10 ▶ my $files = $dev->{files} || {};
Condition50%1/2
$$dev{'files'} || {}
l!l
100
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
2030 10 for my $p ( keys %$files ) {
2031 45 my $e = $files->{$p};
2032 45 ▶ next unless ref $e eq 'HASH' && !defined $e->{link} && ( defined $e->{size} || defined $e->{open_by} );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" and not defined $$e{"link"} and defined $$e{"size"} || defined $$e{"open_by"} 37 8 45
Condition88%8/9
ref $e eq "HASH" and not defined $$e{"link"} and defined $$e{"size"} || defined $$e{"open_by"}
!ll&&!rl&&r
16218
ref $e eq "HASH" and not defined $$e{"link"}
!ll&&!rl&&r
9729
defined $$e{"size"} or defined $$e{"open_by"}
l!l&&r!l&&!r
8021
MC/DC75%3/4
ref $e eq "HASH" and not defined $$e{"link"} and defined $$e{"size"} || defined $$e{"open_by"}
ref $e eq "HASH" not defined $$e{"link"} defined $$e{"size"} defined $$e{"open_by"}
Truth table80%4/5
A and not(B) and C or D
A= ref $e eq "HASH"B= not defined $$e{"link"}C= defined $$e{"size"}D= defined $$e{"open_by"}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2033 8 ▶ return if grep { length && ( $p eq $_ || index( $p, "$_/" ) == 0 ) } @named;
Branch: 1 branch
BranchTrueFalseTotal
if grep {length $_ and $p eq $_ || index($p, "$_/") == 0;} @named 2 6 8
Condition83%5/6
length $_ && ($p eq $_ || index($p, "$_/") == 0)
!ll&&!rl&&r
042
$p eq $_ or index($p, "$_/") == 0
l!l&&r!l&&!r
114
MC/DC66%2/3
length $_ && ($p eq $_ || index($p, "$_/") == 0)
length $_ $p eq $_ index($p, "$_/") == 0
Truth table75%3/4
A && B or C
A= length $_B= $p eq $_C= index($p, "$_/") == 0
ABCresult
0XX0
1000
11X1
1011
2034 6 ▶ return if grep { $_ eq '' } @named; # "/" selbst
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "";} @named 0 6 6
2035 }
2036 8 for my $m ( grep {length} @named ) {
2037 6 ▶ next if exists $files->{$m} || grep { index( $_, "$m/" ) == 0 } keys %$files;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$files{$m} or grep {index($_, "$m/") == 0;} keys %$files 4 2 6
Condition66%2/3
exists $$files{$m} or grep {index($_, "$m/") == 0;} keys %$files
l!l&&r!l&&!r
402
MC/DC50%1/2
exists $$files{$m} or grep {index($_, "$m/") == 0;} keys %$files
exists $$files{$m} grep {index($_, "$m/") == 0;} keys %$files
Truth table66%2/3
A or B
A= exists $$files{$m}B= grep {index($_, "$m/") == 0;} keys %$files
ABresult
1X1
011
000
2038 2 ▶ return if defined _file_text( $dev, $m ); # abgeleitet: nftables.conf, wg0.conf, .git, /proc/sys
Branch: 1 branch
BranchTrueFalseTotal
if defined _file_text($dev, $m) 0 2 2
2039 2 ▶ return if $m =~ m{\A/etc/(?:passwd|group|shadow|gshadow|hostname|hosts|resolv\.conf|fstab|mtab|os-release)\z};
Branch: 1 branch
BranchTrueFalseTotal
if $m =~ m[\A/etc/(?:passwd|group|shadow|gshadow|hostname|hosts|resolv\.conf|fstab|mtab|os-release)\z] 1 1 2
2040 }
2041 7 return @a;
2042 }
2043  
2044 # Die Dateien des Geraets fuer die Sandbox; undef, wenn es zu viel ist
2045 7 ▶sub _sandbox_files {
Subroutine _sandbox_files: called CC=14 SCAR=28.2
2046 7 my ($dev) = @_;
2047 7 my ( %f, %d );
2048 7 my $total = 0;
2049 7 ▶ my $uid = sub { my $u = ( $dev->{users} || {} )->{ $_[0] // 'root' }; ref $u eq 'HASH' ? $u->{uid} // 0 : 0 };
Subroutine __ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
ref $u eq 'HASH' ? : 5 17 22
Condition83%5/6
$$dev{'users'} || {}
l!l
202
$_[0] // "root"
l!l
517
$$u{"uid"} // 0
l!l
50
MC/DC100%1/1
$$dev{'users'} || {}
$$dev{'users'}
MC/DC100%1/1
$_[0] // "root"
$_[0]
MC/DC0%0/1
$$u{"uid"} // 0
$$u{"uid"}
Truth table100%2/2
A
A= $$dev{'users'}
Aresult
11
00
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
Truth table50%1/2
A
A= $$u{"uid"}
Aresult
11
00
2050 7 ▶ my $gid = sub { my $g = ( $dev->{groups} || {} )->{ $_[0] // 'root' }; ref $g eq 'HASH' ? $g->{gid} // 0 : 0 };
Subroutine __ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
ref $g eq 'HASH' ? : 5 17 22
Condition83%5/6
$$dev{'groups'} || {}
l!l
202
$_[0] // "root"
l!l
517
$$g{"gid"} // 0
l!l
50
MC/DC100%1/1
$$dev{'groups'} || {}
$$dev{'groups'}
MC/DC100%1/1
$_[0] // "root"
$_[0]
MC/DC0%0/1
$$g{"gid"} // 0
$$g{"gid"}
Truth table100%2/2
A
A= $$dev{'groups'}
Aresult
11
00
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
Truth table50%1/2
A
A= $$g{"gid"}
Aresult
11
00
2051 7 ▶ for my $p ( sort keys %{ $dev->{files} || {} } ) {
Condition50%1/2
$$dev{'files'} || {}
l!l
70
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
2052 32 ▶ next unless $p =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
unless $p =~ m[\A/] 0 32 32
2053 32 ▶ my $e = _file_entry( $dev, $p ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $e = _file_entry($dev, $p) or next 32 0 32
2054 32 ▶ if ( defined $e->{link} ) { $f{$p} = { link => $e->{link} }; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$e{"link"}) 5 27 32
2055 27 ▶ next if defined $e->{size} || defined $e->{open_by};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$e{"size"} or defined $$e{"open_by"} 5 22 27
Condition66%2/3
defined $$e{"size"} or defined $$e{"open_by"}
l!l&&r!l&&!r
5022
MC/DC50%1/2
defined $$e{"size"} or defined $$e{"open_by"}
defined $$e{"size"} defined $$e{"open_by"}
Truth table66%2/3
A or B
A= defined $$e{"size"}B= defined $$e{"open_by"}
ABresult
1X1
011
000
2056 22 ▶ my $t = _file_text( $dev, $p ) // next;
Condition50%1/2
_file_text($dev, $p) // (next)
l!l
220
MC/DC0%0/1
_file_text($dev, $p) // (next)
_file_text($dev, $p)
Truth table50%1/2
A
A= _file_text($dev, $p)
Aresult
11
00
2057 22 $total += length $t;
2058 22 ▶ return undef if $total > 8 * 1024 * 1024;
Branch: 1 branch
BranchTrueFalseTotal
if $total > 8388608 0 22 22
2059 22 $f{$p} = { content => $t, mode => _mode_of($e), uid => $uid->( $e->{owner} ), gid => $gid->( $e->{group} ), mtime => _mtime($e) };
2060 }
2061 7 ▶ for my $p ( sort keys %{ $dev->{dirs} || {} } ) {
Condition50%1/2
$$dev{'dirs'} || {}
l!l
07
MC/DC0%0/1
$$dev{'dirs'} || {}
$$dev{'dirs'}
Truth table50%1/2
A
A= $$dev{'dirs'}
Aresult
11
00
2062 0 my $e = $dev->{dirs}{$p};
2063 0 ▶ $e = {} unless ref $e eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" 0 0 0
2064 0 ▶ $d{$p} = { mode => oct( $e->{mode} // '0755' ), uid => $uid->( $e->{owner} ), gid => $gid->( $e->{group} ) };
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
2065 }
2066 7 return ( \%f, \%d );
2067 }
2068  
2069 # Ein echter Befehl ohne Nachbildung: in der Sandbox, sonst die Luecke (neutrale Antwort)
2070 26 ▶sub _real {
Subroutine _real: called CC=36 SCAR=43.1
2071 26 my ( $dev, $ctx, $argv, $stdin ) = @_;
2072 26 ▶ my $gap = sub { push @GAPS, join( ' ', @$argv ); return ( '', 0 ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
2073 26 ▶ my $sandbox = ( $ctx || {} )->{sandbox} // ( $CTX || {} )->{sandbox} or return $gap->();
Branch: 1 branch
BranchTrueFalseTotal
my $sandbox = ($ctx || {})->{"sandbox"} // ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"sandbox"} or return &$gap() 18 8 26
Condition57%4/7
($ctx || {})->{"sandbox"} // ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"sandbox"}
l!l&&r!l&&!r
1808
$ctx || {}
l!l
260
$Langertha::Holmgang::Sim::Linux::CTX || {}
l!l
80
MC/DC0%0/2
($ctx || {})->{"sandbox"} // ($Langertha::Holmgang::Sim::Linux::CTX || {})->{"sandbox"}
$ctx $Langertha::Holmgang::Sim::Linux::CTX
Truth table33%1/3
A // B
A= $ctxB= $Langertha::Holmgang::Sim::Linux::CTX
ABresult
1X1
011
000
2074 18 ▶ my @a = _sandbox_argv( $dev, $argv, $stdin ) or return $gap->();
Branch: 1 branch
BranchTrueFalseTotal
my(@a) = _sandbox_argv($dev, $argv, $stdin) or return &$gap() 7 11 18
2075 7 my ( $files, $dirs ) = _sandbox_files($dev);
2076 7 ▶ return $gap->() unless $files;
Branch: 1 branch
BranchTrueFalseTotal
unless $files 0 7 7
2077 7 ▶ my $host = ( $ctx || $CTX || {} )->{host};
Condition40%2/5
$ctx || $Langertha::Holmgang::Sim::Linux::CTX || {}
l!l
70
$ctx or $Langertha::Holmgang::Sim::Linux::CTX
l!l&&r!l&&!r
700
MC/DC0%0/2
$ctx || $Langertha::Holmgang::Sim::Linux::CTX || {}
$ctx $Langertha::Holmgang::Sim::Linux::CTX
Truth table33%1/3
A or B
A= $ctxB= $Langertha::Holmgang::Sim::Linux::CTX
ABresult
1X1
011
000
2078 my ( $r, $why ) = $sandbox->run(
2079 argv => \@a, files => $files, dirs => $dirs, stdin => $stdin, cwd => $CWD_DIR // '/root',
2080 7 ▶ env => { %{ $SHENV || {} } }, now => _pki_now($dev) // _sim_now(), tz => $DATE_TZ // $dev->{timezone} // 'Europe/Berlin',
Condition40%6/15
$Langertha::Holmgang::Sim::Linux::SHENV || {}
l!l
70
_pki_now($dev) // _sim_now()
l!l&&r!l&&!r
070
($Langertha::Holmgang::Sim::Linux::DATE_TZ // $$dev{"timezone"}) // "Europe/Berlin"
l!l
07
$Langertha::Holmgang::Sim::Linux::DATE_TZ // $$dev{"timezone"}
l!l&&r!l&&!r
007
($$dev{"hostname"} // $host) // "localhost"
l!l
70
$$dev{"hostname"} // $host
l!l&&r!l&&!r
070
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::SHENV || {}
$Langertha::Holmgang::Sim::Linux::SHENV
MC/DC0%0/2
_pki_now($dev) // _sim_now()
_pki_now($dev) _sim_now()
MC/DC0%0/2
($Langertha::Holmgang::Sim::Linux::DATE_TZ // $$dev{"timezone"}) // "Europe/Berlin"
$Langertha::Holmgang::Sim::Linux::DATE_TZ $$dev{"timezone"}
MC/DC0%0/2
($$dev{"hostname"} // $host) // "localhost"
$$dev{"hostname"} $host
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::SHENV
Aresult
11
00
Truth table33%1/3
A // B
A= _pki_now($dev)B= _sim_now()
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $Langertha::Holmgang::Sim::Linux::DATE_TZB= $$dev{"timezone"}
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $$dev{"hostname"}B= $host
ABresult
1X1
011
000
2081 7 ▶ host => $dev->{hostname} // $host // 'localhost',
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::CWD_DIR // "/root"
l!l
07
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
2082 );
2083 7 ▶ unless ($r) { # versucht und nicht brauchbar: die Luecke nennt den Grund
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 1 6 7
2084 1 ▶ push @GAPS, join( q{ }, @$argv ) . q{ (sandbox: } . ( $why // q{no result} ) . q{)};
Condition50%1/2
$why // "no result"
l!l
10
MC/DC0%0/1
$why // "no result"
$why
Truth table50%1/2
A
A= $why
Aresult
11
00
2085 1 return ( q{}, 0 );
2086 }
2087 6 ▶ for my $p ( sort keys %{ $r->{changed} || {} } ) {
Condition50%1/2
$$r{'changed'} || {}
l!l
60
MC/DC0%0/1
$$r{'changed'} || {}
$$r{'changed'}
Truth table50%1/2
A
A= $$r{'changed'}
Aresult
11
00
2088 6 ▶ next if $p =~ m{/__pycache__/|\.pyc\z};
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ m[/__pycache__/|\.pyc\z] 1 5 6
2089 5 my $c = $r->{changed}{$p};
2090 0 ▶ if ( defined $c->{link} ) { $dev->{files}{$p} = { link => $c->{link} }; next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$c{"link"}) 0 5 5
2091 5 my $old = $dev->{files}{$p};
2092 5 ▶ my $mode = sprintf '%04o', $c->{mode} // 0644;
Condition50%1/2
$$c{"mode"} // 420
l!l
50
MC/DC0%0/1
$$c{"mode"} // 420
$$c{"mode"}
Truth table50%1/2
A
A= $$c{"mode"}
Aresult
11
00
2093 5 ▶ if ( defined $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 3 2 5
2094 3 _file_set( $dev, $p, $c->{content} );
2095 3 ▶ if ( ref $old eq 'HASH' ? _mode_of($old) != oct $mode : $mode ne '0644' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $old eq "HASH" ? _mode_of($old) != oct $mode : $mode ne "0644") 0 3 3
ref $old eq 'HASH' ? : 1 2 3
2096 0 ▶ $dev->{files}{$p} = { content => $c->{content} } unless ref $dev->{files}{$p} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$dev{"files"}{$p} eq "HASH" 0 0 0
2097 0 $dev->{files}{$p}{mode} = $mode;
2098 }
2099 }
2100 2 ▶ else { $dev->{files}{$p} = $mode eq '0644' ? $c->{content} : { content => $c->{content}, mode => $mode } }
Branch: 1 branch
BranchTrueFalseTotal
$mode eq '0644' ? : 1 1 2
2101 }
2102 6 ▶ for my $p ( @{ $r->{deleted} || [] } ) {
Condition50%1/2
$$r{'deleted'} || []
l!l
60
MC/DC0%0/1
$$r{'deleted'} || []
$$r{'deleted'}
Truth table50%1/2
A
A= $$r{'deleted'}
Aresult
11
00
2103 1 ( my $dir = $p ) =~ s{/[^/]+\z}{};
2104 1 delete $dev->{files}{$p};
2105 1 ▶ $dev->{_dirs}{$dir} = 1 if length $dir && !_is_dir( $dev, $dir );
Branch: 1 branch
BranchTrueFalseTotal
if length $dir and not _is_dir($dev, $dir) 0 1 1
Condition33%1/3
length $dir and not _is_dir($dev, $dir)
!ll&&!rl&&r
010
MC/DC0%0/2
length $dir and not _is_dir($dev, $dir)
length $dir not _is_dir($dev, $dir)
Truth table33%1/3
A and not(B)
A= length $dirB= not _is_dir($dev, $dir)
ABresult
0X0
100
111
2106 }
2107 6 ▶ ( my $out = $r->{output} // '' ) =~ s/\n\z//;
Condition50%1/2
$$r{"output"} // ""
l!l
60
MC/DC0%0/1
$$r{"output"} // ""
$$r{"output"}
Truth table50%1/2
A
A= $$r{"output"}
Aresult
11
00
2108 6 ▶ $SH->{code} = $r->{exit} if $SH && $r->{exit} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH and $$r{"exit"} > 1 1 5 6
Condition66%2/3
$Langertha::Holmgang::Sim::Linux::SH and $$r{"exit"} > 1
!ll&&!rl&&r
051
MC/DC50%1/2
$Langertha::Holmgang::Sim::Linux::SH and $$r{"exit"} > 1
$Langertha::Holmgang::Sim::Linux::SH $$r{"exit"} > 1
Truth table66%2/3
A and B
A= $Langertha::Holmgang::Sim::Linux::SHB= $$r{"exit"} > 1
ABresult
0X0
100
111
2109 6 ▶ return ( $out, $r->{exit} ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$$r{'exit'} ? : 1 5 6
2110 }
2111  
2112 4805 ▶sub _command {
Subroutine _command: called CC=176 SCAR=64.7
2113 4805 my ( $class, $dev, $argv, $ctx, $stdin ) = @_;
2114 4805 local $AS_USER = $LOGIN_USER;
2115 4805 my @a = _strip_sudo(@$argv);
2116 4805 ▶ return ( '', 1 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 4805 4805
2117 4805 my $cmd = shift @a;
2118 # NAME=wert befehl …: Umgebung nur fuer diesen Befehl
2119 4805 ▶ local $SHENV = { %{ $SHENV || {} } };
Condition100%2/2
$Langertha::Holmgang::Sim::Linux::SHENV || {}
l!l
1234682
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
2120 4805 my %env;
2121 4805 ▶ 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 4805 4808
Condition66%2/3
$cmd =~ /\A([A-Za-z_]\w*)=(.*)\z/s and @a
!ll&&!rl&&r
480503
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
2122 # TZ=… wirkt auf date
2123 4805 ▶ local $DATE_TZ = exists $env{TZ} ? ( $env{TZ} =~ s/\A://r ) : $DATE_TZ;
Branch: 1 branch
BranchTrueFalseTotal
exists $env{'TZ'} ? : 1 4804 4805
2124 # nach cd: relative Pfade (die es gibt oder die ein Muster sind) gelten im aktuellen Verzeichnis
2125 4805 ▶ 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 4697 4805
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
466136108
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
2126 @a = map {
2127 108 my $x = $_;
2128 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
2129 && ( _file_entry( $dev, _absp($x) ) || _is_dir( $dev, _absp($x) ) ) ? _absp($x) : $x
2130 } @a;
2131 }
2132 4805 ▶ 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 4805 4805
2133 0 push @GAPS, join( ' ', $cmd, @a );
2134 0 return ( '', 0 );
2135 }
2136 # Skripte: bash|sh -c '…', bash|sh datei, ./datei bzw. /pfad/datei (ausfuehrbar)
2137 4805 ( my $sh = $cmd ) =~ s{\A/(?:usr/)?bin/}{};
2138 4805 ▶ 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 4802 4805
Condition66%6/9
defined $Langertha::Holmgang::Sim::Linux::AS_USER and $sh eq "bash" || $sh eq "sh" || $cmd =~ m[/]
!ll&&!rl&&r
4705973
$sh eq "bash" or $sh eq "sh" or $cmd =~ m[/]
l!l&&r!l&&!r
0397
$sh eq "bash" or $sh eq "sh"
l!l&&r!l&&!r
00100
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
2139 4805 ▶ if ( $sh eq 'bash' || $sh eq 'sh' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sh eq "bash" or $sh eq "sh") 21 4784 4805
Condition66%2/3
$sh eq "bash" or $sh eq "sh"
l!l&&r!l&&!r
2104784
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
2140 21 my $e;
2141 my $noexec;
2142 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
2143 21 ▶ if ($noexec) { # bash -n: nur lesen und zerlegen
Branch: 1 branch
BranchTrueFalseTotal
if ($noexec) 2 19 21
2144 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
2145 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
2146 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
2147 2 my $err = $@;
2148 2 ▶ my $nodes = $err ? undef : Langertha::Holmgang::Shell::parse( \@it );
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 0 2 2
2149 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
2150 2 $err =~ s/\s+\z//;
2151 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
2152 }
2153 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
2154 18 my ( undef, $text, $arg0, @args ) = @a;
2155 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
2156 }
2157 1 ▶ my $t = @a ? _file_text( $dev, _absp( $a[0] ) ) : $stdin;
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 1 0 1
2158 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
2159 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
2160 }
2161 # curl/wget gegen die HTTP-API eines Forgejo-Servers: auf dem Server selbst (localhost:3000 bzw. der
2162 # eigene Name), von anderen Geraeten ueber den oeffentlichen Namen (ROOT_URL, hinter dem Proxy)
2163 4784 ▶ 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'} ? : 86 4698 4784
Condition100%3/3
$cmd =~ /\A(?:curl|wget)\z/ and not $$dev{"pod"}
!ll&&!rl&&r
4697186
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
2164 4784 ▶ if ($fsrv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fsrv) 6 4778 4784
2165 6 my $self = $fsrv == $dev;
2166 6 _part('Git');
2167 6 my ($url) = grep {m{\Ahttps?://}} @a;
2168 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
2169 6 my ( $h, $port, $path ) = $url =~ m{\Ahttps?://([^/:]+)(?::(\d+))?(/[^\s]*)?\z};
2170 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
2171 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
2172 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
2173 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
2174 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
2175 unless $h =~ /\A[\d.]+\z|\Alocalhost\z/ || $hf =~ /^\s*[\d.:a-f]+\s+(?:\S+\s+)*\Q$h\E(?:\s|$)/m;
2176 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
2177 }
2178 4 $dev = $fsrv;
2179 4 my $method = 'GET';
2180 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
2181 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
2182 4 my $fail = grep { /\A-[a-zA-Z]*f[a-zA-Z]*\z|\A--fail\z/ } @a;
2183 4 ▶ if ( $cmd eq 'wget' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "wget") 1 3 4
2184 1 my $quiet = grep { /\A-[a-zA-Z]*q/ } @a;
2185 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
2186 0 my ($of) = map { $a[ $_ + 1 ] } grep { $a[$_] =~ /\A-[a-zA-Z]*O\z/ } 0 .. $#a;
2187 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
2188 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
2189 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
2190 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
2191 }
2192 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
2193 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
2194 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
2195 3 ▶ $out = '' if grep { $_ eq '-o' } @a;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "-o";} @a 0 3 3
2196 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
2197 3 return ( $out, 1 );
2198 }
2199 # im Pod (kubectl exec): Netzwerkzeuge ueber den Cluster, Umgebung des Containers
2200 4778 ▶ if ( my $pod = $dev->{pod} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pod = $$dev{"pod"}) 7 4771 4778
2201 7 _part('Kubernetes');
2202 7 my $K = 'Langertha::Holmgang::Sim::Linux::Kubernetes';
2203 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
2204 2 my ($src) = grep { $_->{name} eq $pod->{name} } $K->can('_pods')->( $dev->{kubernetes}, $pod->{ns} );
2205 2 ▶ return ( "bash: $cmd: command not found", 0 ) unless $src;
Branch: 1 branch
BranchTrueFalseTotal
unless $src 0 2 2
2206 2 local @Langertha::Holmgang::Sim::Linux::Kubernetes::GAPS;
2207 2 my @r = $K->can('pod_tool')->( $dev->{kubernetes}, $pod->{ns}, $src, [ $cmd, @a ] );
2208 2 push @GAPS, @Langertha::Holmgang::Sim::Linux::Kubernetes::GAPS;
2209 2 return @r;
2210 }
2211 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
2212 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
2213 KUBERNETES_SERVICE_HOST => '10.43.0.1', KUBERNETES_SERVICE_PORT => '443' );
2214 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
2215 }
2216 }
2217 # (nur Shell-Skripte mit Inhalt; ein anderes Programm bleibt eine Luecke), auch ueber PATH
2218 4776 my $web_cmd = _web_cmd( $dev, $cmd );
2219 4776 ▶ 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\.?/] ? : 15 4761 4776
!($web_cmd || $CMD{$cmd} || $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} || $Langertha::Holmgang::Sim::Linux::REAL{$cmd}) ? : 5 4756 4761
Condition100%9/9
$web_cmd || $CMD{$cmd} || $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} || $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
l!l&&r!l&&!r
4731255
$web_cmd or $CMD{$cmd} or $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}
l!l&&r!l&&!r
46983330
$web_cmd or $CMD{$cmd}
l!l&&r!l&&!r
120457863
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
2220 4776 ▶ if ( defined $prog_path && _shell_script( $dev, $prog_path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prog_path and _shell_script($dev, $prog_path)) 4 4772 4776
Condition100%3/3
defined $prog_path and _shell_script($dev, $prog_path)
!ll&&!rl&&r
4761114
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
2221 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
2222 4 return _script( $dev, _file_text( $dev, $prog_path ), $ctx, join( ' ', $cmd, @a ), $cmd, @a );
2223 }
2224 4772 ▶ if ( $cmd =~ m{/} && !$CMD{$cmd} ) { # anderes Programm mit Pfad (kein Shell-Skript)
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ m[/] and not $CMD{$cmd}) 11 4761 4772
Condition66%2/3
$cmd =~ m[/] and not $CMD{$cmd}
!ll&&!rl&&r
4761011
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
2225 11 ( my $abs = $cmd ) =~ s{\A/(s?bin)/}{/usr/$1/};
2226 11 my ( $n ) = $abs =~ m{\A/usr/s?bin/([^/]+)\z};
2227 11 ▶ my ( $p, $k ) = defined $n ? _which( 'which', $dev, [$n] ) : ( '', 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 6 5 11
2228 11 ▶ 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 6 11
Condition77%7/9
defined $n and $k and $p eq $abs and not _file_entry($dev, $cmd)
!ll&&!rl&&r
605
defined $n and $k and $p eq $abs
!ll&&!rl&&r
515
defined $n and $k
!ll&&!rl&&r
506
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
2229 else {
2230 6 ▶ 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 4 2 6
2231 4 ▶ return ( "bash: $cmd: Permission denied", 0 ) unless _mode_of($e) & 0111;
Branch: 1 branch
BranchTrueFalseTotal
unless _mode_of($e) & 73 0 4 4
2232 4 return _real( $dev, $ctx, [ $cmd, @a ], $stdin ); # Skript/Programm aus dem Zustand: nicht nachgebildet
2233 }
2234 }
2235 4766 ▶ my $f = $web_cmd // $CMD{$cmd};
Condition100%3/3
$web_cmd // $CMD{$cmd}
l!l&&r!l&&!r
120458363
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
2236 4766 ▶ 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 4766 4766
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
476150
$f || $Langertha::Holmgang::Sim::Linux::FILTER{$cmd} || $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
l!l&&r!l&&!r
4736255
$f or $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}
l!l&&r!l&&!r
47033330
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
2237 0 return _real( $dev, $ctx, [ $prog, @a ], $stdin ); # installiertes Programm ohne Nachbildung
2238 }
2239 4766 ▶ if ( !$f && $FILTER{$cmd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $f and $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}) 33 4733 4766
Condition100%3/3
not $f and $Langertha::Holmgang::Sim::Linux::FILTER{$cmd}
!ll&&!rl&&r
47033033
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
2240 # Filter mit Datei-Argument: head -n 5 /etc/x, awk '{print $1}' datei, …
2241 # relative Dateinamen (ohne cd: unter /root) wie absolute
2242 33 my %shown;
2243 33 ▶ @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 73 74
Condition100%6/6
not m[\A[-/]] and m[\A[\w.\@+][\w./\@+-]*\z] and defined _file_text($dev, _absp($_))
!ll&&!rl&&r
63101
not m[\A[-/]] and m[\A[\w.\@+][\w./\@+-]*\z]
!ll&&!rl&&r
60311
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
2244 33 ▶ my @files = grep { m{\A/} && defined _file_text( $dev, $_ ) } @a;
Condition100%3/3
m[\A/] && defined _file_text($dev, $_)
!ll&&!rl&&r
431021
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
2245 # Dateiargumente, die es nicht gibt: Meldung wie coreutils/mawk (Status 1), kein stdin
2246 33 ▶ 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
21010
$_ ne "-" and not defined _file_text($dev, _absp($_))
!ll&&!rl&&r
02110
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
2247 # als Benutzer ohne Leserecht (Weg oder Datei): Permission denied
2248 33 ▶ for my $f (@files) { $miss{$f} = 'Permission denied' unless _read_ok( $dev, $f ) }
Branch: 1 branch
BranchTrueFalseTotal
unless _read_ok($dev, $f) 1 20 21
2249 33 my @rest = grep { my $x = $_; !grep { $_ eq $x } @files } grep { !$miss{$_} } @a;
2250 33 @files = grep { !$miss{$_} } @files;
2251 11 ▶ my $miss_text = sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
2252 11 my ($p) = @_;
2253 11 my $why = $miss{$p};
2254 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
2255 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
2256 : $cmd eq 'sort' ? "sort: cannot read: $p: $why"
2257 : $cmd eq 'awk' ? "awk: cannot open $p ($why)"
2258 : "$cmd: $p: $why";
2259 33 };
2260 33 ▶ if ( %miss && !( $cmd eq 'wc' && @files ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%miss and not $cmd eq "wc" && @files) 10 23 33
Condition100%6/6
%miss and not $cmd eq "wc" && @files
!ll&&!rl&&r
22110
$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
2261 10 my @err = map { $miss_text->($_) } grep { $miss{$_} } @a;
2262 10 ▶ return ( join( "\n", @err ), 0 ) unless @files;
Branch: 1 branch
BranchTrueFalseTotal
unless @files 10 0 10
2263 0 my ($t) = Langertha::Holmgang::Shell::Filter::filter_output( join( '', map { _file_text( $dev, $_ ) } @files ), [ $cmd, @rest ] );
2264 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
2265 0 return ( join( "\n", grep {length} $t, @err ), 0 );
2266 }
2267 23 ▶ 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 14 23
Condition100%3/3
$cmd eq "wc" and @files
!ll&&!rl&&r
1319
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
2268 9 my ( @rows, @sum );
2269 9 my %is_file = map { $_ => 1 } @files;
2270 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
2271 12 ▶ if ( $miss{$p} ) { push @rows, \( $miss_text->($p) ); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($miss{$p}) 1 11 12
2272 11 my ($t) = Langertha::Holmgang::Shell::Filter::filter_output( _file_text( $dev, $p ), [ 'wc', @rest ] );
2273 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
2274 11 my @n = split ' ', $t;
2275 11 $sum[$_] += $n[$_] for 0 .. $#n;
2276 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
2277 }
2278 9 my @num = grep { ref eq 'ARRAY' } @rows;
2279 9 ▶ push @rows, [ @sum, 'total' ] if @files + keys(%miss) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @files + keys(%miss) > 1 3 6 9
2280 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
2281 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
2282 %miss ? 0 : 1 );
2283 }
2284 14 ▶ my $text = @files ? join( '', map { _file_text( $dev, $_ ) } @files ) : $stdin // '';
Branch: 1 branch
BranchTrueFalseTotal
@files ? : 9 5 14
Condition100%2/2
$stdin // ""
l!l
41
MC/DC100%1/1
$stdin // ""
$stdin
Truth table100%2/2
A
A= $stdin
Aresult
11
00
2285 14 my ( $t, $k ) = Langertha::Holmgang::Shell::Filter::filter_output( $text, [ $cmd, @rest ] );
2286 14 ▶ $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 14 14
Condition83%5/6
defined $t and $cmd eq "wc" and @files == 1
!ll&&!rl&&r
1310
defined $t and $cmd eq "wc"
!ll&&!rl&&r
2111
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
2287 14 ▶ return ( $t, $k ) if defined $t;
Branch: 1 branch
BranchTrueFalseTotal
if defined $t 12 2 14
2288 2 return _real( $dev, $ctx, [ $cmd, @a ], $stdin );
2289 }
2290 4733 ▶ if ( !$f ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($f) 30 4703 4733
2291 30 ▶ if ( $cmd =~ m{/} ) { # Programm mit Pfad: gibt es die Datei, laeuft es (Luecke), sonst wie bash
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ m[/]) 0 30 30
2292 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
2293 0 return _real( $dev, $ctx, [ $cmd, @a ], $stdin );
2294 }
2295 30 ▶ 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 25 30
Condition100%3/3
$Langertha::Holmgang::Sim::Linux::NOT_INSTALLED{$cmd} or not $Langertha::Holmgang::Sim::Linux::REAL{$cmd}
l!l&&r!l&&!r
3225
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
2296 # Echter Befehl ohne Simulation: neutrale Antwort, als Luecke vermerkt — oder echt in der Sandbox (_real)
2297 25 ▶ if ( $INTERACTIVE{$cmd} ) { push @GAPS, join( ' ', $cmd, @a ); return ( 'Error opening terminal: unknown.', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($Langertha::Holmgang::Sim::Linux::INTERACTIVE{$cmd}) 5 20 25
2298 20 return _real( $dev, $ctx, [ $cmd, @a ], $stdin );
2299 }
2300 4703 my ( $out, $ok ) = eval { $f->( $dev, \@a, $ctx, $stdin ) };
2301 4703 ▶ if ( my $e = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 9 4694 4703
2302 9 $e =~ s/\s+\z//;
2303 9 return ( $e, 0 );
2304 }
2305 4694 ▶ return ( $out // '', $ok );
Condition50%1/2
$out // ""
l!l
46940
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
2306 }
2307  
2308 # date: Uhr des Geraets (clock), sonst die Simulationszeit (_sim_now); -d ZEIT; Zone aus TZ=
2309 # (Vorgabe timezone des Geraets bzw. Europe/Berlin). -u zeigt UTC; -d liest auch dann Ortszeit.
2310 23 ▶sub _date {
Subroutine _date: called CC=29 SCAR=40.8
2311 23 my ( $dev, $av ) = @_;
2312 23 require POSIX;
2313 23 require Langertha::Holmgang::Sim::Linux::Calendar;
2314 23 my $C = 'Langertha::Holmgang::Sim::Linux::Calendar';
2315 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
2316 23 my ( $utc, $fmt, $when ) = ( 0, '%a %b %e %H:%M:%S %Z %Y' );
2317 23 my @a = @$av;
2318 23 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 34 23 57
2319 34 my $x = shift @a;
2320 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
2321 17 elsif ( $x =~ /\A\+(.*)\z/s ) { $fmt = $1 }
2322 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
2323 0 elsif ( $x =~ /\A(?:-d|--date=)(.+)\z/s ) { $when = $1 }
2324 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
2325 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
2326 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
2327 0 else { push @GAPS, join( ' ', 'date', @$av ); return ( '', 0 ) } # -s, -r …
2328 }
2329 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
2330 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
2331 23 my $t = $now;
2332 23 ▶ if ( defined $when ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $when) 13 10 23
2333 13 $t = _date_parse( $when, $tz, $C, $now );
2334 13 ▶ return ( "date: invalid date \x{2018}$when\x{2019}", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 1 12 13
2335 }
2336 22 my ( $off, $abbr ) = ( 0, 'UTC' );
2337 22 ▶ if ( !$utc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($utc) 18 4 22
2338 18 $off = $C->can('offset')->( $t, $tz );
2339 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
2340 }
2341 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
2342 0 $fmt =~ s/%:z/ substr( $hm, 0, 3 ) . ':' . substr( $hm, 3 ) /ge;
2343 22 $fmt =~ s/%Z/$abbr/g;
2344 22 $fmt =~ s/%z/$hm/g;
2345 22 $fmt =~ s/%s/$t/g;
2346 22 return ( POSIX::strftime( $fmt, gmtime( $t + $off ) ), 1 );
2347 }
2348  
2349 # --- Dateien -----------------------------------------------------------------------
2350  
2351 2726 ▶sub _file_text {
Subroutine _file_text: called CC=32 SCAR=37.1
2352 2726 my ( $dev, $path ) = @_;
2353 2726 ▶ return '' if $path eq '/dev/null';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/dev/null" 2 2724 2726
2354 2724 ▶ return _file_text( $dev, _dotdot($path) ) if $path =~ m{\A/.*/\.\.?(?:/|\z)};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[\A/.*/\.\.?(?:/|\z)] 1 2723 2724
2355 2723 ▶ 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 2720 2723
Condition100%6/6
not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and defined(my $r = _via_link($dev, $path))
!ll&&!rl&&r
17769443
ref $$dev{'files'} eq 'HASH' && exists $$dev{'files'}{$path}
!ll&&!rl&&r
189291776
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
2356 3 return _file_text( $dev, $r );
2357 }
2358 2720 ▶ 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}) 1776 944 2720
Condition100%3/3
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{$path}
!ll&&!rl&&r
189261776
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
2359 1776 my $e = $dev->{files}{$path};
2360 1776 ▶ return _with_append( $dev, $path, $e ) unless ref $e eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" 1605 171 1776
2361 171 ▶ if ( defined $e->{link} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$e{"link"}) 47 124 171
2362 47 my $t = $e->{link};
2363 47 ( my $dir = $path ) =~ s{/[^/]+\z}{};
2364 47 ▶ $t = "$dir/$t" unless $t =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ m[\A/] 5 42 47
2365 47 ▶ 1 while $t =~ s{/[^/]+/\.\./}{/};
Branch: 1 branch
BranchTrueFalseTotal
$t =~ s[/[^/]+/\.\./][/] and do { '???' } 5 47 52
2366 47 $t =~ s{/\./}{/}g;
2367 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
2368 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
2369 0 return undef;
2370 }
2371 124 ▶ return _with_append( $dev, $path, $e->{content} // '' );
Condition50%1/2
$$e{"content"} // ""
l!l
1240
MC/DC0%0/1
$$e{"content"} // ""
$$e{"content"}
Truth table50%1/2
A
A= $$e{"content"}
Aresult
11
00
2372 }
2373 944 ▶ if ( $path =~ m{\A/proc/sys/(.+)\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[\A/proc/sys/(.+)\z]) 6 938 944
2374 6 ( my $k = $1 ) =~ s{/}{.}g;
2375 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
2376 0 return undef;
2377 }
2378 938 ▶ 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 936 938
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
93602
$path =~ m[\A/etc/wireguard/(wg\d+)\.conf\z] and ref $$dev{"wg"} eq "HASH"
!ll&&!rl&&r
93512
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
2379 2 return _wg_conf( $dev->{wg}{$1} );
2380 }
2381 936 ▶ 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 932 936
Condition66%2/3
$path eq "/etc/nftables.conf" and ref $$dev{"nft"} eq "HASH"
!ll&&!rl&&r
93204
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
2382 932 ▶ 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 931 932
Condition66%2/3
$path eq "/proc/mdstat" and $$dev{"storage"}
!ll&&!rl&&r
93101
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
2383 931 ▶ if ( $path eq '/proc/partitions' && $dev->{storage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/proc/partitions" and $$dev{"storage"}) 0 931 931
Condition33%1/3
$path eq "/proc/partitions" and $$dev{"storage"}
!ll&&!rl&&r
93100
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
2384 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
2385 0 my $i = 0;
2386 return join( '', "major minor #blocks name\n\n",
2387 0 map { sprintf "%5d %7d %10d %s\n", 254, $i++, int( _bytes( $d->{$_}{size} ) / 1024 ), s{\A/dev/}{}r } sort keys %$d );
2388 }
2389 931 ▶ 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 928 931
if defined $$v{"text"} 3 0 3
2390 928 return undef;
2391 }
2392  
2393 # .git einer Arbeitskopie bzw. Bare-Repo des Servers (aus dem Git-Zustand abgeleitet)
2394 26733 ▶sub _git_virtual {
Subroutine _git_virtual: called CC=4 SCAR=13.9
2395 26733 my ( $dev, $path ) = @_;
2396 26733 ▶ 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)] 26720 13 26733
Condition100%6/6
$$dev{"git"} || $$dev{"forgejo"} and $path =~ m[\.git(?:/|\z)]
!ll&&!rl&&r
23744297613
$$dev{"git"} or $$dev{"forgejo"}
l!l&&r!l&&!r
2981823744
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
2397 13 _part('Git');
2398 13 return Langertha::Holmgang::Sim::Linux::Git::virtual( $dev, $path =~ s{/+\z}{}r );
2399 }
2400  
2401 # Stub-resolv.conf von systemd-resolved
2402 5 ▶sub _stub_resolv {
Subroutine _stub_resolv: called CC=4 SCAR=14.8
2403 5 my ($dev) = @_;
2404 5 my $r = $dev->{resolved};
2405 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
2406 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
2407 }
2408  
2409 368 ▶sub _write_path {
Subroutine _write_path: called CC=18 SCAR=32.0
2410 368 my ( $dev, $path, $text, $append, $ctx ) = @_;
2411 368 ▶ return ( '', 1 ) if $path eq '/dev/null';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/dev/null" 2 366 368
2412 # > /dev/tcp/HOST/PORT: Verbindung der bash, keine Datei — ohne Netz eine Luecke
2413 366 ▶ if ( $path =~ m{\A/dev/(?:tcp|udp)/} ) { return _dev_tcp( $dev, $path, '>' ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[\A/dev/(?:tcp|udp)/]) 15 351 366
2414 351 $path = _absp($path); # relativ (nach cd) und mit .. wie die Shell
2415 351 ▶ if ( $path =~ m{\A/proc/sys/(.+)\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[\A/proc/sys/(.+)\z]) 1 350 351
2416 1 ( my $k = $1 ) =~ s{/}{.}g;
2417 return ( "bash: $path: No such file or directory", 0 )
2418 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
2419 1 ( my $v = $text ) =~ s/\s+\z//;
2420 1 $dev->{sysctl}{$k} = $v;
2421 1 return ( '', 1 );
2422 }
2423 350 my ($dir) = $path =~ m{\A(.*)/[^/]+\z};
2424 350 ▶ 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 350 350
Condition33%1/3
$path =~ m[\A/] and defined $dir
!ll&&!rl&&r
00350
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
2425 350 ▶ 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 350 350
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
34640
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
2426 350 my $e = _file_entry( $dev, $path );
2427 350 ▶ if ( my $err = _may_create( $dev, $path ) ) { return ( "bash: $path: $err", 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = _may_create($dev, $path)) 3 347 350
2428 347 ▶ 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 347 347
Condition66%2/3
$e and defined $$e{"link"}
!ll&&!rl&&r
1651820
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
2429 0 $dev->{files}{$path} = $text;
2430 0 return ( '', 1 );
2431 }
2432 347 ▶ 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 347 347
Condition66%4/6
not $e || _is_dir($dev, $path) and my $meta = _new_meta($dev, $path, 0)
!ll&&!rl&&r
1821650
$e || _is_dir($dev, $path)
l!l&&r!l&&!r
1820165
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
2433 0 $dev->{files}{$path} = { content => $text, %$meta };
2434 0 return ( '', 1 );
2435 }
2436 347 my $old = _file_text( $dev, $path );
2437 347 ▶ _file_set( $dev, $path, $append ? ( $old // '' ) . $text : $text );
Branch: 1 branch
BranchTrueFalseTotal
$append ? : 26 321 347
Condition50%1/2
$old // ""
l!l
260
MC/DC0%0/1
$old // ""
$old
Truth table50%1/2
A
A= $old
Aresult
11
00
2438 347 return ( '', 1 );
2439 }
2440  
2441  
2442 163 ▶sub write {
Subroutine write: called CC=9 SCAR=22.0
Pod documented
2443 163 my ( $class, $dev, $path, $content, $ctx ) = @_;
2444 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
2445 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
2446 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
2447 161 my $web = _web_world($ctx);
2448 161 ▶ Langertha::Holmgang::Sim::Linux::Http::before( $ctx->{state} ) if $web;
Branch: 1 branch
BranchTrueFalseTotal
if $web 21 140 161
2449 161 my ( $e, $ok ) = _write_path( $dev, $path, $content, 0, $ctx );
2450 161 ▶ Langertha::Holmgang::Sim::Linux::Http::after( $ctx->{state} ) if $web;
Branch: 1 branch
BranchTrueFalseTotal
if $web 21 140 161
2451 161 ▶ return ( $ok ? "geschrieben: $path (" . length($content) . ' Zeichen)' : $e, $ok );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 161 0 161
2452 }
2453  
2454 111 ▶sub _cat {
Subroutine _cat: called CC=20 SCAR=30.1
2455 111 my ( $dev, $av, $ctx, $stdin ) = @_;
2456 111 my @out;
2457 111 my $ok = 1;
2458 # ohne Datei: die Eingabe (aus einer Pipe), -A/-E zeigen das Zeilenende als $
2459 111 ▶ if ( !grep { !/\A-/ } @$av ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {not /\A-/;} @$av) 5 106 111
2460 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
2461 0 ▶ $t =~ s/$/\$/mg if grep {/\A-\w*[AE]/} @$av;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/\A-\w*[AE]/;} @$av 0 5 5
2462 5 return ( $t, 1 );
2463 }
2464 106 for my $p ( grep { !/\A-/ } @$av ) {
2465 109 ▶ if ( $p =~ m{\A/proc/(\d+)/cmdline\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ m[\A/proc/(\d+)/cmdline\z]) 1 108 109
2466 1 my ($x) = grep { $_->{pid} == $1 } _procs($dev);
2467 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
2468 1 ▶ $ok = 0 unless $x;
Branch: 1 branch
BranchTrueFalseTotal
unless $x 0 1 1
2469 1 next;
2470 }
2471 108 ▶ if ( $p =~ m{\A/proc/(\d+)/limits\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ m[\A/proc/(\d+)/limits\z]) 1 107 108
2472 1 my $t = _proc_limits( $dev, $1 );
2473 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
2474 1 ▶ $ok = 0 unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 1 1
2475 1 next;
2476 }
2477 107 ▶ 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 106 107
Condition100%3/3
_file_entry($dev, $p) and not _read_ok($dev, $p)
!ll&&!rl&&r
20861
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
2478 1 push @out, "cat: $p: Permission denied";
2479 1 $ok = 0;
2480 1 next;
2481 }
2482 106 my $t = _file_text( $dev, $p );
2483 106 ▶ if ( !defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 11 95 106
2484 11 push @out, "cat: $p: No such file or directory";
2485 11 $ok = 0;
2486 11 next;
2487 }
2488 95 $t =~ s/\n\z//;
2489 95 push @out, $t;
2490 }
2491 # -A/-T zeigen Tabs als ^I, -A/-E Zeilenenden als $, -n nummeriert (ueber alle Dateien)
2492 106 ▶ my $f = join '', map { /\A-([AETvn]+)\z/ ? $1 : '' } @$av;
Branch: 1 branch
BranchTrueFalseTotal
/\A-([AETvn]+)\z/ ? : 2 109 111
2493 106 ▶ if ( $f =~ /[ATEn]/ && $ok ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /[ATEn]/ and $ok) 2 104 106
Condition66%2/3
$f =~ /[ATEn]/ and $ok
!ll&&!rl&&r
10402
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
2494 2 my @l = split /\n/, join( "\n", @out ), -1;
2495 2 ▶ @l = map { s/\t/^I/gr } @l if $f =~ /[AT]/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /[AT]/ 1 1 2
2496 2 ▶ @l = map {"$_\$"} @l if $f =~ /[AE]/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /[AE]/ 1 1 2
2497 2 my $i = 0;
2498 2 ▶ @l = map { sprintf '%6d %s', ++$i, $_ } @l if $f =~ /n/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /n/ 1 1 2
2499 2 return ( join( "\n", @l ), 1 );
2500 }
2501 104 return ( join( "\n", @out ), $ok );
2502 }
2503  
2504 37 ▶sub _grep_file {
Subroutine _grep_file: called CC=42 SCAR=39.3
2505 37 my ( $dev, $av, $ctx, $stdin ) = @_;
2506 37 my ( @opts, @plain, @pats );
2507 37 my @a = @$av;
2508 37 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 106 37 143
2509 106 my $x = shift @a;
2510 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
2511 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
2512 29 elsif ( $x =~ /\A-/ ) { push @opts, $x }
2513 76 else { push @plain, $x }
2514 }
2515 37 ▶ my @pat = @pats ? @pats : ( shift @plain );
Branch: 1 branch
BranchTrueFalseTotal
@pats ? : 0 37 37
2516 37 ▶ return ( 'Usage: grep [OPTION]... PATTERNS [FILE]...', 0 ) unless defined $pat[-1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pat[-1] 0 37 37
2517 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
2518 # Dateien (mit -r/-R auch Verzeichnisse); mehrere: Zeilen mit Dateinamen davor (wie GNU grep)
2519 34 ▶ my $flags = join '', map { /\A-([a-zA-Z]+)\z/ ? $1 : '' } @opts;
Branch: 1 branch
BranchTrueFalseTotal
/\A-([a-zA-Z]+)\z/ ? : 26 2 28
2520 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
2521 34 my ( @files, @err );
2522 34 for my $p (@plain) {
2523 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
2524 18 ▶ if ( _is_dir( $dev, $p ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_dir($dev, $p)) 16 2 18
2525 16 ▶ if ($rec) { # -r folgt Verweisen unterwegs nicht (nur -R), wie GNU grep
Branch: 1 branch
BranchTrueFalseTotal
if ($rec) { } 12 4 16
2526 12 ( my $d = $p ) =~ s{(?<=.)/+\z}{};
2527 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
2528 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
2529 }
2530 4 else { push @err, "grep: $p: Is a directory" }
2531 16 next;
2532 }
2533 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
2534 }
2535 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
2536 34 push @fo, map {"-$_"} grep { $flags =~ /$_/ } qw( n i v w x o E F P );
2537 34 @fo = do { my %s; grep { !$s{$_}++ } @fo };
2538 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
2539 34 my ( @out, $any );
2540 34 for my $f (@files) {
2541 60 my ( $t, $k ) = Langertha::Holmgang::Shell::Filter::filter_output( _file_text( $dev, $f ), [ 'grep', @fo, @pat ] );
2542 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
2543 60 ▶ my @l = length $t ? split /\n/, $t : ();
Branch: 1 branch
BranchTrueFalseTotal
length $t ? : 34 26 60
2544 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
2545 59 ▶ next unless @l;
Branch: 1 branch
BranchTrueFalseTotal
unless @l 26 33 59
2546 33 $any = 1;
2547 33 ▶ if ( $flags =~ /l/ ) { push @out, $f; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($flags =~ /l/) 11 22 33
2548 22 ▶ push @out, map { $_ eq '--' ? $_ : $names ? "$f:$_" : $_ } @l;
Branch: 2 branches
BranchTrueFalseTotal
$_ eq '--' ? : 0 24 24
$names ? : 14 10 24
2549 }
2550 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
2551 }
2552  
2553 78 ▶sub _sed {
Subroutine _sed: called CC=25 SCAR=34.0
2554 78 my ( $dev, $av, $ctx, $stdin ) = @_;
2555 78 my @a = @$av;
2556 78 my ( $inplace, $quiet, $ere ) = ( 0, 0, 0 );
2557 78 my @expr;
2558 my @files;
2559 78 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 215 78 293
2560 215 my $x = shift @a;
2561 215 ▶ if ( $x =~ /\A-i/ ) { $inplace = 1 }
Branch: 6 branches
BranchTrueFalseTotal
if ($x =~ /\A-i/) { } 60 155 215
elsif ($x eq '-e') { } 4 151 155
elsif ($x =~ /\A-([nErs]+)\z/) { } 9 142 151
elsif ($x eq '--regexp-extended') { } 0 142 142
elsif ($x eq '--quiet' or $x eq '--silent') { } 0 142 142
elsif (not @expr) { } 76 66 142
2562 4 elsif ( $x eq '-e' ) { push @expr, shift @a }
2563 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
2564 0 elsif ( $x eq '--regexp-extended' ) { $ere = 1 }
2565 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
00142
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
2566 76 elsif ( !@expr ) { push @expr, $x }
2567 66 else { push @files, $x }
2568 }
2569 78 ▶ 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 78 78
Condition44%4/9
@expr and @files || !$inplace && defined $stdin
!ll&&!rl&&r
0078
@files or not $inplace and defined $stdin
l!l&&r!l&&!r
66120
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
2570 unless @expr && ( @files || !$inplace && defined $stdin );
2571 78 ▶ return ( 'sed: no input files', 0 ) if $inplace && !@files;
Branch: 1 branch
BranchTrueFalseTotal
if $inplace and not @files 0 78 78
Condition66%2/3
$inplace and not @files
!ll&&!rl&&r
18600
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
2572 78 my @cmds;
2573 78 for my $e (@expr) {
2574 80 for my $part ( _sed_split($e) ) {
2575 87 my $c = _sed_cmd( $part, $ere );
2576 87 ▶ return ( $c, 0 ) unless ref $c;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c 0 87 87
2577 87 push @cmds, $c;
2578 }
2579 }
2580 78 my @out;
2581 78 ▶ for my $f ( @files ? @files : (undef) ) {
Branch: 1 branch
BranchTrueFalseTotal
@files ? : 66 12 78
2582 78 ▶ my $t = defined $f ? _file_text( $dev, $f ) : $stdin;
Branch: 1 branch
BranchTrueFalseTotal
defined $f ? : 66 12 78
2583 78 ▶ return ( "sed: can't read $f: No such file or directory", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 78 78
2584 78 my $r = _sed_apply( \@cmds, $t, $quiet );
2585 78 ▶ if ($inplace) { _file_set( $dev, $f, $r ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($inplace) { } 60 18 78
2586 18 else { push @out, $r }
2587 }
2588 78 return ( join( '', @out ) =~ s/\n\z//r, 1 );
2589 }
2590  
2591 # sed-Skript an ; und Zeilenende in Befehle zerlegen; Inhalt von /re/ und s/…/…/ bleibt ganz
2592 80 ▶sub _sed_split {
Subroutine _sed_split: called CC=21 SCAR=30.7
2593 80 my ($e) = @_;
2594 80 my ( @cmd, $delim, $left ) = ();
2595 80 my $cur = '';
2596 80 my @c = split //, $e;
2597 80 ▶ for ( my $i = 0; $i < @c; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @c) 1957 80 2037
2598 1957 my $x = $c[$i];
2599 1957 ▶ if ( defined $delim ) { # in /re/ bzw. s/…/…/: bis zum letzten Trennzeichen
Branch: 1 branch
BranchTrueFalseTotal
if (defined $delim) 1809 148 1957
2600 1809 $cur .= $x;
2601 1809 ▶ if ( $x eq '\\' && $i + 1 < @c ) { $cur .= $c[ ++$i ]; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "\\" and $i + 1 < @c) 38 1771 1809
Condition66%2/3
$x eq "\\" and $i + 1 < @c
!ll&&!rl&&r
1771038
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
2602 1771 ▶ undef $delim if $x eq $delim && !--$left;
Branch: 1 branch
BranchTrueFalseTotal
if $x eq $delim and not --$left 79 1692 1771
Condition100%3/3
$x eq $delim and not --$left
!ll&&!rl&&r
16276579
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
2603 1771 next;
2604 }
2605 148 ▶ 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 141 148
if $cur =~ /\S/ 7 0 7
Condition66%2/3
$x eq ";" or $x eq "\n"
l!l&&r!l&&!r
70141
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
2606 141 ▶ if ( $x eq '/' ) { ( $delim, $left ) = ( '/', 1 ); $cur .= $x; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "/") 14 127 141
2607 127 my $at_cmd = $cur =~ m{\A\s*(?:(?:\d+|\$|/.*/)(?:,(?:\d+|\$|/.*/))?)?\s*!?\s*\z};
2608 # i/a/c an Befehlsstelle: der Text reicht bis zum Zeilenende (a\ + Zeilenumbruch: naechste Zeile)
2609 127 ▶ 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 120 127
Condition55%5/9
$x =~ /\A[iac]\z/ and $at_cmd and $i + 1 >= @c || $c[$i + 1] =~ /[\s\\]/
!ll&&!rl&&r
12007
$x =~ /\A[iac]\z/ and $at_cmd
!ll&&!rl&&r
12007
$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
2610 7 my $all = join '', @c[ $i + 1 .. $#c ];
2611 7 my $rest = $all;
2612 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
2613 7 my ($text) = $rest =~ /\A([^\n]*)/;
2614 7 push @cmd, "$cur$x\x00$text";
2615 7 $cur = '';
2616 7 $i += length($all) - length($rest) + length($text);
2617 7 next;
2618 }
2619 # s an Befehlsstelle (nach hoechstens einer Adresse und !)
2620 120 ▶ if ( $x eq 's' && $i + 1 < @c && $at_cmd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "s" and $i + 1 < @c and $at_cmd) 65 55 120
Condition66%4/6
$x eq "s" and $i + 1 < @c and $at_cmd
!ll&&!rl&&r
55065
$x eq "s" and $i + 1 < @c
!ll&&!rl&&r
55065
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
2621 65 ( $delim, $left ) = ( $c[ $i + 1 ], 2 );
2622 65 $cur .= $x . $c[ ++$i ];
2623 65 next;
2624 }
2625 55 $cur .= $x;
2626 }
2627 80 ▶ push @cmd, $cur if $cur =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $cur =~ /\S/ 73 7 80
2628 80 ▶ return map { /\x00/ ? s/\A\s+//r : s/\A\s+|\s+\z//gr } @cmd;
Branch: 1 branch
BranchTrueFalseTotal
/\x00/ ? : 7 80 87
2629 }
2630  
2631 # Ein sed-Befehl: [adresse[,adresse]][!] d | p | s/…/…/[gI]; Adresse N, $ oder /re/.
2632 87 ▶sub _sed_cmd {
Subroutine _sed_cmd: called CC=17 SCAR=28.7
2633 87 my ( $e, $ere ) = @_;
2634 87 my $bad = "sed: -e expression #1, char " . length($e) . ": unknown command: `" . substr( $e, 0, 1 ) . "'";
2635 87 my $addr = qr{\d+|\$|/(?:[^/\\]|\\.)*/};
2636 87 ▶ 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 87 0 87
2637 87 my %c = ( neg => $neg );
2638 87 for ( [ a1 => $a1 ], [ a2 => $a2 ] ) {
2639 174 my ( $k, $v ) = @$_;
2640 174 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 136 38 174
2641 38 ▶ if ( $v =~ m{\A/(.*)/\z}s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ m[\A/(.*)/\z]s) { } 14 24 38
2642 14 ▶ my $re = $ere ? $1 : _bre($1);
Branch: 1 branch
BranchTrueFalseTotal
$ere ? : 0 14 14
2643 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
2644 }
2645 24 else { $c{$k} = $v }
2646 }
2647 87 ▶ if ( $rest =~ /\A([dp])\s*\z/ ) { $c{op} = $1; return \%c }
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\A([dp])\s*\z/) 15 72 87
2648 72 ▶ 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 65 72
2649 65 ▶ 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 65 0 65
2650 65 ▶ $from = $ere ? $from =~ s/\\(\Q$d\E)/\Q$1\E/gr : _bre( $from, $d ); # \<trenner>: der Trenner selbst
Branch: 1 branch
BranchTrueFalseTotal
$ere ? : 3 62 65
2651 65 $to =~ s/\\\Q$d\E/$d/g; # s/a\/b/c\/d/: Trenner im Ersatz entwertet
2652 65 ▶ if ( $from eq '' ) { # s//…/: das zuletzt benutzte Muster (hier: der Adresse)
Branch: 1 branch
BranchTrueFalseTotal
if ($from eq "") 1 64 65
2653 1 my ($last) = grep { ref } @c{qw( a2 a1 )};
2654 1 ▶ return "sed: -e expression #1, char 0: no previous regular expression" unless $last;
Branch: 1 branch
BranchTrueFalseTotal
unless $last 0 1 1
2655 1 ▶ @c{qw( op to global re )} = ( 's', $to, $fl =~ /g/ ? 1 : 0, $last );
Branch: 1 branch
BranchTrueFalseTotal
$fl =~ /g/ ? : 0 1 1
2656 1 return \%c;
2657 }
2658 64 ▶ $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" 64 0 64
$fl =~ /I/ ? : 0 64 64
2659 64 ▶ @c{qw( op to global )} = ( 's', $to, $fl =~ /g/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$fl =~ /g/ ? : 1 63 64
2660 64 return \%c;
2661 }
2662  
2663 # GNU-BRE -> Perl: blanke ( ) { } | + ? sind Zeichen, mit Backslash Operatoren;
2664 # mit $delim (s|…|…|) ist \<trenner> der Trenner als Zeichen
2665 76 ▶sub _bre {
Subroutine _bre: called CC=11 SCAR=24.3
2666 76 my ( $re, $delim ) = @_;
2667 76 my $out = '';
2668 76 my @t = $re =~ /(\\.|.)/gs;
2669 76 for my $i ( 0 .. $#t ) {
2670 745 my $t = $t[$i];
2671 745 ▶ if ( defined $delim && $t eq "\\$delim" ) { $out .= quotemeta $delim }
Branch: 5 branches
BranchTrueFalseTotal
if (defined $delim and $t eq "\\$delim") { } 4 741 745
elsif ($t =~ /\A\\([(){}|+?])\z/) { } 7 734 741
elsif ($t =~ /\A[(){}|+?]\z/) { } 9 725 734
elsif ($t eq '$' and $i < $#t) { } 2 723 725
elsif ($t eq '^' and $i > 0 and $t[$i - 1] ne '[') { } 0 723 723
Condition100%3/3
defined $delim and $t eq "\\$delim"
!ll&&!rl&&r
916504
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
2672 7 elsif ( $t =~ /\A\\([(){}|+?])\z/ ) { $out .= $1 }
2673 9 elsif ( $t =~ /\A[(){}|+?]\z/ ) { $out .= "\\$t" }
2674 2 ▶ elsif ( $t eq '$' && $i < $#t ) { $out .= '\$' } # $ nur am Ende ein Anker
Condition100%3/3
$t eq "\$" and $i < $#t
!ll&&!rl&&r
705182
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
2675 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
72300
$t eq "^" and $i > 0
!ll&&!rl&&r
701220
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
2676 723 else { $out .= $t }
2677 }
2678 76 return $out;
2679 }
2680  
2681 78 ▶sub _sed_apply {
Subroutine _sed_apply: called CC=31 SCAR=34.4
2682 78 my ( $cmds, $t, $quiet ) = @_;
2683 78 my $nl = $t =~ /\n\z/;
2684 78 my @lines = split /\n/, $t, -1;
2685 78 ▶ pop @lines if $nl;
Branch: 1 branch
BranchTrueFalseTotal
if $nl 66 12 78
2686 78 my @out;
2687 my %in; # offene Bereiche je Befehl
2688 # GNU: 0,/re/ — der Bereich ist von Anfang an offen und endet beim ersten Treffer
2689 78 ▶ $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
8502
defined $$c{"a1"} and not ref $$c{"a1"} and $$c{"a1"} eq 0
!ll&&!rl&&r
70152
defined $$c{"a1"} and not ref $$c{"a1"}
!ll&&!rl&&r
591117
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
2690 157 ▶ my $hit = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
2691 157 my ( $a, $i, $line ) = @_;
2692 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
2693 78 };
2694 78 for my $i ( 1 .. @lines ) {
2695 429 my $ps = $lines[ $i - 1 ];
2696 429 my ( $deleted, @after );
2697 429 for my $n ( 0 .. $#$cmds ) {
2698 478 my $c = $cmds->[$n];
2699 478 my $m;
2700 478 ▶ if ( !defined $c->{a1} ) { $m = 1 }
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $$c{'a1'}) { } 321 157 478
elsif (not defined $$c{'a2'}) { } 119 38 157
elsif ($in{$n}) { } 9 29 38
elsif (&$hit($$c{'a1'}, $i, $ps)) { } 8 21 29
2701 119 elsif ( !defined $c->{a2} ) { $m = $hit->( $c->{a1}, $i, $ps ) }
2702 elsif ( $in{$n} ) {
2703 9 $m = 1;
2704 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
2705 }
2706 elsif ( $hit->( $c->{a1}, $i, $ps ) ) {
2707 8 $m = 1;
2708 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
2709 }
2710 478 ▶ $m = !$m if $c->{neg};
Branch: 1 branch
BranchTrueFalseTotal
if $$c{"neg"} 3 475 478
2711 478 ▶ next unless $m;
Branch: 1 branch
BranchTrueFalseTotal
unless $m 122 356 478
2712 356 ▶ if ( $c->{op} eq 'd' ) { $deleted = 1; last }
Branch: 5 branches
BranchTrueFalseTotal
if ($$c{'op'} eq 'd') { } 12 344 356
elsif ($$c{'op'} eq 'p') { } 8 336 344
elsif ($$c{'op'} eq 'i') { } 2 334 336
elsif ($$c{'op'} eq 'a') { } 4 330 334
elsif ($$c{'op'} eq 'c') { } 1 329 330
2713 8 elsif ( $c->{op} eq 'p' ) { push @out, $ps }
2714 2 elsif ( $c->{op} eq 'i' ) { push @out, $c->{text} }
2715 4 elsif ( $c->{op} eq 'a' ) { push @after, $c->{text} }
2716 1 elsif ( $c->{op} eq 'c' ) { push @out, $c->{text}; $deleted = 1; last }
2717 else {
2718 329 my $re = $c->{re};
2719 329 ▶ if ( $c->{global} ) { $ps =~ s/$re/_expand($c->{to})/ge }
Branch: 1 branch
BranchTrueFalseTotal
if ($$c{'global'}) { } 1 328 329
2720 328 else { $ps =~ s/$re/_expand($c->{to})/e }
2721 }
2722 }
2723 429 ▶ push @out, $ps unless $deleted || $quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $deleted or $quiet 402 27 429
Condition100%3/3
$deleted or $quiet
l!l&&r!l&&!r
1314402
MC/DC100%2/2
$deleted or $quiet
$deleted $quiet
Truth table100%3/3
A or B
A= $deletedB= $quiet
ABresult
1X1
011
000
2724 429 push @out, @after;
2725 }
2726 78 ▶ return join( "\n", @out ) . ( @out && $nl ? "\n" : '' );
Branch: 1 branch
BranchTrueFalseTotal
@out && $nl ? : 66 12 78
Condition66%2/3
@out and $nl
!ll&&!rl&&r
01266
MC/DC50%1/2
@out and $nl
@out $nl
Truth table66%2/3
A and B
A= @outB= $nl
ABresult
0X0
100
111
2727 }
2728  
2729 # Ersatztext einer sed-Ersetzung: \1 .. \9 und & aus dem letzten Treffer.
2730 67 ▶sub _expand {
Subroutine _expand: called CC=7 SCAR=19.6
2731 67 my ($to) = @_;
2732 67 my $all = $&;
2733 67 my @c;
2734 {
2735 88 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2736 67 @c = map { ${$_} } 1 .. 9;
2737 }
2738 67 my $r = $to;
2739 67 ▶ $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
2740 67 return $r;
2741 }
2742  
2743 325 ▶sub _echo {
Subroutine _echo: called CC=4 SCAR=13.9
2744 325 my ( $dev, $av ) = @_;
2745 325 my @a = @$av;
2746 325 my $n = 0;
2747 325 ▶ 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/) 2 325 327
if $a[0] =~ /n/ 2 0 2
Condition100%3/3
@a and $a[0] =~ /\A-[neE]+\z/
!ll&&!rl&&r
173082
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
2748 325 return ( join( ' ', @a ), 1 );
2749 }
2750  
2751 # Bytes, ueber die eine Pruefsumme rechnet: der Inhalt. Hat der Zustand keinen (Archiv
2752 # mit tar-Mitgliedern, nur eine Groesse), stehen die Daten des Eintrags ohne Eigentuemer,
2753 # Rechte und Zeiten dafuer -- fest, gleich fuer eine Kopie, verschieden fuer anderen Inhalt.
2754 # Nur eine leere Datei hat den Hash der leeren Eingabe.
2755 88 my %ENTRY_META = map { $_ => 1 } qw( owner group mode mtime atime ctime open_by uid gid );
2756 88 my $DIGEST_JSON = JSON::MaybeXS->new( canonical => 1, utf8 => 1 );
2757  
2758 12 ▶sub _digest_bytes {
Subroutine _digest_bytes: called CC=7 SCAR=21.8
2759 12 my ( $e, $text ) = @_;
2760 12 require Encode;
2761 12 ▶ return Encode::encode( 'UTF-8', $text ) if defined $text;
Branch: 1 branch
BranchTrueFalseTotal
if defined $text 7 5 12
2762 5 ▶ return '' unless ref $e eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" 0 5 5
2763 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
2764 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
2765 5 return "holmgang-sim-entry\0" . $DIGEST_JSON->encode( \%d );
2766 }
2767  
2768 # md5sum datei … bzw. aus der Eingabe; ohne Inhalt im Zustand siehe _digest_bytes
2769 9 ▶sub _md5sum {
Subroutine _md5sum: called CC=10 SCAR=24.5
2770 9 my ( $dev, $av, $ctx, $stdin ) = @_;
2771 9 require Digest::MD5;
2772 9 require Encode;
2773 0 ▶ my $md5 = sub { Digest::MD5::md5_hex( Encode::encode( 'UTF-8', $_[0] ) ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
2774 9 my @f = grep { !/\A-/ } @$av;
2775 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
2776 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
2777 9 my ( @l, $ok ) = ();
2778 9 $ok = 1;
2779 9 for my $p (@f) {
2780 10 my $e = _file_entry( $dev, _absp($p) );
2781 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
2782 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
2783 9 push @l, Digest::MD5::md5_hex( _digest_bytes( $e, $t ) ) . " $p";
2784 }
2785 9 return ( join( "\n", @l ), $ok );
2786 }
2787  
2788 # printf wie bash: Escapes, %s %b %c %d %i %o %u %x %X %e %f %g (Breite, Genauigkeit, *),
2789 # 'A als Zeichencode; mehr Argumente als Umwandlungen: das Format wiederholt sich.
2790 45 ▶sub _printf {
Subroutine _printf: called CC=29 SCAR=40.5
2791 45 my ( $dev, $av ) = @_;
2792 45 my @a = @$av;
2793 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
2794 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
2795 45 my $fmt = shift @a;
2796 45 ▶ return ( 'printf: usage: printf [-v var] format [arguments]', 0 ) unless defined $fmt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fmt 0 45 45
2797 45 my %e = ( n => "\n", t => "\t", r => "\r", '\\' => '\\', a => "\a", b => "\b", f => "\f", v => "\x0b", '"' => '"', "'" => "'", e => "\e" );
2798 47 ▶ my $esc = sub {
Subroutine __ANON__: called CC=4 SCAR=14.9
2799 47 my ($s) = @_;
2800 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
2801 47 return $s;
2802 45 };
2803 45 my ( @err, $ok ) = ();
2804 45 $ok = 1;
2805 4 ▶ my $num = sub {
Subroutine __ANON__: called CC=9 SCAR=23.6
2806 4 my ( $x, $float ) = @_;
2807 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
2808 4 ▶ return ord substr( $x, 1 ) if $x =~ /\A['"]./s;
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /\A['"]./s 1 3 4
2809 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
2810 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
2811 1 push @err, "bash: printf: $x: invalid number";
2812 1 $ok = 0;
2813 1 ▶ return $x =~ /\A\s*([-+]?\d+(?:\.\d+)?)/ ? 0 + $1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$x =~ /\A\s*([-+]?\d+(?:\.\d+)?)/ ? : 0 1 1
2814 45 };
2815 45 my $out = '';
2816 45 my $conv = qr/%(%|([-+ #0]*)(\*|\d+)?(?:\.(\*|\d+))?([diouxXeEfFgGcsbq]))/;
2817 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
2818 45 while (1) {
2819 47 my $used = 0;
2820 47 my $piece = $esc->($fmt);
2821 47 $piece =~ s{$conv}{
2822 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
2823 0 ▶ if ( $all eq '%' ) { '%' }
Branch: 1 branch
BranchTrueFalseTotal
if ($all eq '%') { } 0 10 10
2824 else {
2825 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
2826 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
2827 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
2828 10 my $arg = shift @a;
2829 10 $used++;
2830 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
2831 : $c eq 's' ? sprintf( "${spec}s", $arg // '' )
2832 : $c eq 'b' ? sprintf( "${spec}s", $esc->( $arg // '' ) )
2833 : $c eq 'c' ? sprintf( "${spec}s", substr( $arg // '', 0, 1 ) )
2834 : $c =~ /[eEfFgG]/ ? sprintf( "$spec$c", $num->( $arg, 1 ) )
2835 : sprintf( $spec . ( $c eq 'i' ? 'd' : $c ), int $num->($arg) );
2836 }
2837 }ge;
2838 47 $out .= $piece;
2839 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
2840 }
2841 45 $out =~ s/\n\z//;
2842 45 return ( join( "\n", grep { length } $out, @err ), $ok );
2843 }
2844  
2845 # --- ip --------------------------------------------------------------------------------
2846  
2847 82 ▶sub _abbrev {
Subroutine _abbrev: called CC=4 SCAR=14.3
2848 82 my ( $w, @full ) = @_;
2849 82 ▶ return undef unless defined $w;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $w 0 82 82
2850 82 ▶ for my $f (@full) { return $f if index( $f, $w ) == 0 }
Branch: 1 branch
BranchTrueFalseTotal
if index($f, $w) == 0 82 71 153
2851 0 return undef;
2852 }
2853  
2854 40 ▶sub _ip {
Subroutine _ip: called CC=28 SCAR=39.4
2855 40 my ( $dev, $av ) = @_;
2856 40 my @a = @$av;
2857 40 my %o;
2858 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
2859 4 my $x = shift @a;
2860 4 ▶ $o{4} = 1 if $x eq '-4';
Branch: 1 branch
BranchTrueFalseTotal
if $x eq -4 0 4 4
2861 4 ▶ $o{6} = 1 if $x eq '-6';
Branch: 1 branch
BranchTrueFalseTotal
if $x eq -6 1 3 4
2862 4 ▶ $o{br} = 1 if $x =~ /\A-br/;
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /\A-br/ 1 3 4
2863 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
2864 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
2865 }
2866 40 my $obj = shift @a;
2867 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
2868 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
2869 // ( $obj eq 'r' ? 'route' : $obj eq 'a' ? 'address' : $obj eq 'l' ? 'link' : $obj eq 'n' ? 'neigh' : undef );
2870 40 ▶ $o = 'address' if $obj eq 'addr';
Branch: 1 branch
BranchTrueFalseTotal
if $obj eq "addr" 2 38 40
2871 40 ▶ return ( qq{Object "$obj" is unknown, try "ip help".}, 0 ) unless $o;
Branch: 1 branch
BranchTrueFalseTotal
unless $o 0 40 40
2872 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
2873 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
2874 2 return ( $j, 1 );
2875 }
2876 38 ▶ return _ip_route( $dev, \@a, \%o ) if $o eq 'route';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "route" 30 8 38
2877 8 ▶ return _ip_rule( $dev, \@a ) if $o eq 'rule';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "rule" 2 6 8
2878 6 ▶ return _ip_addr( $dev, \@a, \%o ) if $o eq 'address';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "address" 2 4 6
2879 4 ▶ return _ip_link( $dev, \@a, \%o ) if $o eq 'link';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "link" 4 0 4
2880 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
2881 }
2882  
2883 # ip -j: Routen, Adressen, Schnittstellen als JSON wie iproute2
2884 2 ▶sub _ip_json {
Subroutine _ip_json: called CC=22 SCAR=34.4
2885 2 my ( $dev, $o, @a ) = @_;
2886 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
2887 2 require JSON::MaybeXS;
2888 2 my $J = JSON::MaybeXS->new( canonical => 1, utf8 => 0 );
2889 2 ▶ if ( $o eq 'route' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "route") 1 1 2
2890 1 my $table = 'main';
2891 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
2892 my @r = map {
2893 4 my $r = $_;
2894 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
2895 qw( via dev proto scope src metric ) ), flags => [] };
2896 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
2897 1 return $J->encode( \@r );
2898 }
2899 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
2900 1 my $idx = 0;
2901 1 my @l;
2902 1 for my $n ( _ifaces($dev) ) {
2903 4 $idx++;
2904 4 my $i = _iface( $dev, $n );
2905 my %e = ( ifindex => $idx, ifname => $n, mtu => 0 + ( $i->{mtu} // 1500 ), operstate => $i->{state} // 'UP',
2906 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
2907 4 ▶ if ( $o eq 'address' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "address") 4 0 4
2908 $e{addr_info} = [ map {
2909 4 my ( $ip, $len ) = split m{/};
2910 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
2911 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
2912 }
2913 4 push @l, \%e;
2914 }
2915 1 return $J->encode( \@l );
2916 }
2917 0 return undef;
2918 }
2919  
2920 # ss: Sockets aus dem Zustand (sockets: [ Zeilen ]) unter dem Kopf von ss
2921 188 ▶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
1490
$$dev{'interfaces'} || {}
l!l
14939
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
2922  
2923 35 ▶sub _ss {
Subroutine _ss: called CC=41 SCAR=42.0
2924 35 my ( $dev, $av ) = @_;
2925 35 my $head = sprintf( '%-6s %-7s %-6s %-6s %-25s %-25s %s', qw( Netid State Recv-Q Send-Q ), 'Local Address:Port', 'Peer Address:Port', 'Process' );
2926 35 ▶ my @l = @{ $dev->{sockets} || [] };
Condition50%1/2
$$dev{'sockets'} || []
l!l
035
MC/DC0%0/1
$$dev{'sockets'} || []
$$dev{'sockets'}
Truth table50%1/2
A
A= $$dev{'sockets'}
Aresult
11
00
2927 # Lauscher der Datenbankdienste aus ihren laufenden Werten
2928 35 ▶ my $svc = $dev->{services} || {};
Condition50%1/2
$$dev{'services'} || {}
l!l
350
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
2929 35 ▶ 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 34 35
Condition57%4/7
$$dev{"redis"} and ($$svc{$$dev{"redis"}{"service"} // "redis-server"} || {})->{"active"}
!ll&&!rl&&r
3401
$$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
2930 1 my $run = _redis()->can('_running')->($dev);
2931 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
2932 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
2933 'users:(("redis-server",pid=811,fd=6))' );
2934 }
2935 }
2936 35 ▶ if ( $dev->{mariadb} && ( $svc->{ $dev->{mariadb}{service} // 'mariadb' } || {} )->{active} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"mariadb"} and ($$svc{$$dev{"mariadb"}{"service"} // "mariadb"} || {})->{"active"}) 0 35 35
Condition14%1/7
$$dev{"mariadb"} and ($$svc{$$dev{"mariadb"}{"service"} // "mariadb"} || {})->{"active"}
!ll&&!rl&&r
3500
$$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
2937 0 my $v = _maria()->can('_vars')->($dev);
2938 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
2939 0 split /\s*,\s*/, $v->{bind_address} // '127.0.0.1';
2940 }
2941 # laufende Dienste mit listen bzw. nginx: dort, wo ihre Konfiguration es sagt
2942 35 for my $n ( sort keys %$svc ) {
2943 60 my $s = $svc->{$n};
2944 60 ▶ 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" 50 10 60
Condition83%10/12
ref $s eq "HASH" and $$s{"active"} and $$s{"listen"} || ($$s{"exec"} // $n) eq "nginx"
!ll&&!rl&&r
34710
ref $s eq "HASH" and $$s{"active"}
!ll&&!rl&&r
0357
$$s{"listen"} or ($$s{"exec"} // $n) eq "nginx"
l!l&&r!l&&!r
6447
$$s{"exec"} // $n
l!l&&r!l&&!r
40110
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
2945 10 ▶ my @a = $s->{_listen} ? @{ $s->{_listen} } : _svc_listen( $dev, $n, $s );
Branch: 1 branch
BranchTrueFalseTotal
$$s{'_listen'} ? : 2 8 10
2946 10 my $pid = _main_pid( $dev, $n );
2947 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
2948 10 my $fd = 5;
2949 10 for my $a (@a) {
2950 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
2951 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
2952 $a =~ /\A\[/ ? '[::]:*' : '0.0.0.0:*', qq{users:(("$comm",pid=$pid,fd=} . $fd++ . '))' );
2953 }
2954 }
2955 35 ▶ my $ssh = ( $dev->{services} || {} )->{ssh};
Condition50%1/2
$$dev{'services'} || {}
l!l
350
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
2956 # sshd: Ports aus seiner Konfiguration (Sshd), ohne sshd_config im Zustand 22
2957 35 ▶ if ( $ssh && $ssh->{active} && !grep {/:22\s/} @l ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ssh and $$ssh{"active"} and not grep({/:22\s/;} @l)) 22 13 35
Condition66%4/6
$ssh and $$ssh{"active"} and not grep({/:22\s/;} @l)
!ll&&!rl&&r
13022
$ssh and $$ssh{"active"}
!ll&&!rl&&r
13022
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
2958 22 ▶ my $eff = %{ $ssh->{effective} || {} } ? $ssh->{effective}
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'} eq 'HASH' && exists $$dev{'files'}{'/etc/ssh/sshd_config'} ? : 1 20 21
Condition100%5/5
$$ssh{'effective'} || {}
l!l
220
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/ssh/sshd_config"}
!ll&&!rl&&r
1461
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
2959 22 ▶ : ( ref $dev->{files} eq 'HASH' && exists $dev->{files}{'/etc/ssh/sshd_config'}
Branch: 1 branch
BranchTrueFalseTotal
%{$$ssh{'effective'} or {};} ? : 1 21 22
2960 ? _ssh_access()->can('config_for')->( $dev, { user => "\0", from => "\0", groups => [], port => 0 } ) : {} );
2961 22 ▶ 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 20 22
Condition80%4/5
_sshd_sim()->can("active")->($dev) or $$eff{"port"}
l!l&&r!l&&!r
2020
$$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
2962 22 my ($pr) = grep { $_->{unit} eq 'ssh' } _procs($dev);
2963 22 ▶ my $pid = $pr ? $pr->{pid} : 701;
Branch: 1 branch
BranchTrueFalseTotal
$pr ? : 22 0 22
2964 22 for my $p (@ports) {
2965 22 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))} ),
2966 sprintf( '%-6s %-7s %-6s %-6s %-25s %-25s %s', 'tcp', 'LISTEN', 0, 128, "[::]:$p", '[::]:*', qq{users:(("sshd",pid=$pid,fd=4))} );
2967 }
2968 }
2969 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 35 35
2970 35 return ( join( "\n", $head, @l ), 1 );
2971 }
2972  
2973 9 ▶sub _ifaces {
Subroutine _ifaces: called CC=2 SCAR=7.0
2974 9 my ($dev) = @_;
2975 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
2976 9 return ( 'lo', grep { $_ ne 'lo' } sort keys %$i );
2977 }
2978  
2979 30 ▶sub _iface {
Subroutine _iface: called CC=3 SCAR=11.0
2980 30 my ( $dev, $n ) = @_;
2981 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
2982 23 return $dev->{interfaces}{$n};
2983 }
2984  
2985 64 ▶sub _route_text {
Subroutine _route_text: called CC=13 SCAR=27.8
2986 64 my ( $r, $with_table ) = @_;
2987 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
2988 64 ▶ $s .= " via $r->{via}" if defined $r->{via};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"via"} 18 46 64
2989 64 ▶ $s .= " dev $r->{dev}" if defined $r->{dev};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"dev"} 64 0 64
2990 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
2991 64 ▶ $s .= " proto $r->{proto}" if defined $r->{proto};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"proto"} 46 18 64
2992 64 ▶ $s .= " scope $r->{scope}" if defined $r->{scope};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"scope"} 45 19 64
2993 64 ▶ $s .= " src $r->{src}" if defined $r->{src};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"src"} 45 19 64
2994 64 ▶ $s .= " metric $r->{metric}" if defined $r->{metric};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"metric"} 2 62 64
2995 64 ▶ $s .= " onlink" if $r->{onlink};
Branch: 1 branch
BranchTrueFalseTotal
if $$r{"onlink"} 0 64 64
2996 64 return $s;
2997 }
2998  
2999 154 ▶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 149 154
3000  
3001 30 ▶sub _ip_route {
Subroutine _ip_route: called CC=98 SCAR=61.8
3002 30 my ( $dev, $av, $o ) = @_;
3003 30 my @a = @$av;
3004 30 ▶ my $sub = @a ? shift @a : 'show';
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 14 16 30
3005 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
3006 // ( $sub eq 'del' ? 'delete' : undef );
3007 30 ▶ if ( !$cmd ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmd) 0 30 30
3008 # ip route 10.0.0.0/8 ... = show mit Filter
3009 0 unshift @a, $sub;
3010 0 $cmd = 'show';
3011 }
3012 30 ▶ $cmd = 'show' if $cmd eq 'list';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "list" 0 30 30
3013 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
3014 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
3015 18 my %f = ( table => 'main' );
3016 18 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 2 18 20
3017 2 my $k = shift @a;
3018 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
3019 0 elsif ( $k eq 'dev' ) { $f{dev} = shift @a }
3020 0 elsif ( $k eq 'proto' ) { $f{proto} = shift @a }
3021 0 elsif ( $k eq 'via' ) { $f{via} = shift @a }
3022 1 elsif ( $k =~ /\A(?:default|[\d.]+(?:\/\d+)?)\z/ ) { $f{dst} = _canon_dst($k) }
3023 ▶ 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
3024 0 else { return ( qq{Error: either "to" is duplicate, or "$k" is a garbage.}, 0 ) }
3025 }
3026 18 my $all = $f{table} eq 'all';
3027 return ( 'Error: ipv4: FIB table does not exist.', 0 )
3028 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
3029 my @hit = grep {
3030 77 my $r = $_;
3031 ( $all || _table_of($r) eq $f{table} )
3032 && ( !defined $f{dev} || ( $r->{dev} // '' ) eq $f{dev} )
3033 && ( !defined $f{proto} || ( $r->{proto} // 'boot' ) eq $f{proto} )
3034 && ( !defined $f{via} || ( $r->{via} // '' ) eq $f{via} )
3035 && ( !defined $f{dst} || $r->{dst} eq $f{dst} )
3036 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
3037 18 ▶ if ( $cmd eq 'flush' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "flush") 0 18 18
3038 0 my %drop = map { $_ => 1 } @hit;
3039 0 @{ $dev->{routes} } = grep { !$drop{$_} } @{ $dev->{routes} };
3040 0 return ( '', 1 );
3041 }
3042 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
3043 18 ▶ @hit = $o->{6} ? grep { $v6->($_) } @hit : grep { !$v6->($_) } @hit;
Branch: 1 branch
BranchTrueFalseTotal
$$o{'6'} ? : 1 17 18
3044 18 return ( join( "\n", map { _route_text( $_, $all ) } @hit ), 1 );
3045 }
3046 12 ▶ if ( $cmd eq 'get' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "get") 3 9 12
3047 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
3048 3 my %g;
3049 3 ▶ while (@a) { my $k = shift @a; $g{$k} = shift @a }
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 2 3 5
3050 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
3051 3 my ( $r, $table ) = _lookup( $dev, $to, $g{from}, $g{iif} );
3052 3 ▶ return ( 'RTNETLINK answers: Network is unreachable', 0 ) unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 3 3
3053 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
3054 3 my $s = $to;
3055 3 ▶ $s .= " from $g{from}" if defined $g{from};
Branch: 1 branch
BranchTrueFalseTotal
if defined $g{"from"} 2 1 3
3056 3 ▶ $s .= " via $r->{via}" if defined $r->{via};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"via"} 3 0 3
3057 3 ▶ $s .= " dev $r->{dev}" if defined $r->{dev};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"dev"} 3 0 3
3058 3 ▶ $s .= " table $table" if $table ne 'main';
Branch: 1 branch
BranchTrueFalseTotal
if $table ne "main" 1 2 3
3059 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
3060 3 $s .= " uid 0";
3061 3 return ( "$s \n cache ", 1 );
3062 }
3063 # add/delete/replace/change/append
3064 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
3065 9 ▶ $dst = shift @a if $dst eq 'to';
Branch: 1 branch
BranchTrueFalseTotal
if $dst eq "to" 0 9 9
3066 9 my %r;
3067 my $type;
3068 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
3069 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
3070 9 $r{dst} = $c;
3071 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
3072 9 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 11 8 19
3073 11 my $k = shift @a;
3074 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
3075 10 my $v = shift @a;
3076 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
3077 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
3078 10 $r{$k} = $v;
3079 }
3080 0 elsif ( $k eq 'onlink' ) { $r{onlink} = 1 }
3081 1 else { return ( qq{Error: either "to" is duplicate, or "$k" is a garbage.}, 0 ) }
3082 }
3083 return ( qq{Error: argument "$r{metric}" is wrong: "metric" value is invalid}, 0 )
3084 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
3085 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
3086 1 return ( qq{Cannot find device "$r{dev}"}, 0 );
3087 }
3088 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
3089 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
3090 5 my $gwdev = _connected_dev( $dev, $r{via} );
3091 5 ▶ if ( !$r{onlink} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r{"onlink"}) 5 0 5
3092 5 ▶ return ( 'Error: Nexthop has invalid gateway.', 0 ) unless $gwdev;
Branch: 1 branch
BranchTrueFalseTotal
unless $gwdev 1 4 5
3093 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
3094 }
3095 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
3096 }
3097 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
3098 0 return ( 'Error: Device for nexthop is not up.', 0 );
3099 }
3100 6 ▶ $r{metric} = 0 + $r{metric} if defined $r{metric};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r{"metric"} 3 3 6
3101 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
3102 18 ▶ my $same = sub {
Subroutine __ANON__: called CC=5 SCAR=16.8
3103 18 my ($x) = @_;
3104 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
3105 6 };
3106 6 my @routes = @{ $dev->{routes} };
3107 6 ▶ if ( $cmd eq 'delete' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "delete") 2 4 6
3108 my ($i) = grep {
3109 2 my $x = $routes[$_];
3110 $x->{dst} eq $r{dst} && _table_of($x) eq _table_of( \%r )
3111 && ( !defined $r{via} || ( $x->{via} // '' ) eq $r{via} )
3112 && ( !defined $r{dev} || ( $x->{dev} // '' ) eq $r{dev} )
3113 && ( !defined $r{metric} || ( $x->{metric} // 0 ) == $r{metric} )
3114 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
3115 2 ▶ return ( 'RTNETLINK answers: No such process', 0 ) unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 1 1 2
3116 1 splice @{ $dev->{routes} }, $i, 1;
3117 1 return ( '', 1 );
3118 }
3119 4 my ($i) = grep { $same->( $routes[$_] ) } 0 .. $#routes;
3120 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
3121 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
3122 2 push @{ $dev->{routes} }, \%r;
3123 2 return ( '', 1 );
3124 }
3125 1 ▶ if ( $cmd eq 'change' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "change") 0 1 1
3126 0 ▶ return ( 'RTNETLINK answers: No such file or directory', 0 ) unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 0 0
3127 0 $dev->{routes}[$i] = \%r;
3128 0 return ( '', 1 );
3129 }
3130 # replace
3131 1 ▶ if ( defined $i ) { $dev->{routes}[$i] = \%r }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) { } 1 0 1
3132 0 else { push @{ $dev->{routes} }, \%r }
3133 1 return ( '', 1 );
3134 }
3135  
3136 5 ▶sub _connected_dev {
Subroutine _connected_dev: called CC=17 SCAR=31.7
3137 5 my ( $dev, $ip ) = @_;
3138 5 for my $n ( _ifaces($dev) ) {
3139 15 ▶ my $i = _iface( $dev, $n ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $i = _iface($dev, $n) or next 15 0 15
3140 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
3141 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
3142 15 ▶ return $n if _in( $ip, $a );
Branch: 1 branch
BranchTrueFalseTotal
if _in($ip, $a) 4 11 15
3143 }
3144 }
3145 # Kernel-Routen auf Schnittstellen (z. B. wg0 ohne Adresse im selben Netz)
3146 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
3147 return $r->{dev} if !defined $r->{via} && defined $r->{dev} && $r->{dst} ne 'default'
3148 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
3149 }
3150 1 return undef;
3151 }
3152  
3153 1 ▶sub _src_for {
Subroutine _src_for: called CC=6 SCAR=19.6
3154 1 my ( $dev, $r ) = @_;
3155 1 ▶ return $r->{src} if defined $r->{src};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"src"} 0 1 1
3156 1 ▶ my $i = defined $r->{dev} ? _iface( $dev, $r->{dev} ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $$r{'dev'} ? : 1 0 1
3157 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
3158 1 ▶ return defined $first ? ( split m{/}, $first )[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $first ? : 1 0 1
3159 }
3160  
3161 38 ▶sub _best {
Subroutine _best: called CC=11 SCAR=26.2
3162 38 my ( $routes, $ip, $table ) = @_;
3163 38 my ( $best, $blen, $bm );
3164 38 for my $r (@$routes) {
3165 57 ▶ next unless _table_of($r) eq $table && $r->{dst} !~ /:/;
Branch: 1 branch
BranchTrueFalseTotal
unless _table_of($r) eq $table and not $$r{"dst"} =~ /:/ 5 52 57
Condition66%2/3
_table_of($r) eq $table and not $$r{"dst"} =~ /:/
!ll&&!rl&&r
5052
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
3166 52 ▶ my ( $net, $len ) = _prefix( $r->{dst} ) or next;
Branch: 1 branch
BranchTrueFalseTotal
() = _prefix($$r{"dst"}) or next 52 0 52
3167 52 ▶ next unless _in( $ip, $r->{dst} );
Branch: 1 branch
BranchTrueFalseTotal
unless _in($ip, $$r{"dst"}) 9 43 52
3168 43 ▶ my $m = $r->{metric} // 0;
Condition100%2/2
$$r{"metric"} // 0
l!l
142
MC/DC100%1/1
$$r{"metric"} // 0
$$r{"metric"}
Truth table100%2/2
A
A= $$r{"metric"}
Aresult
11
00
3169 43 ▶ 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) 43 0 43
Condition33%3/9
not defined $best or $len > $blen or $len == $blen and $m < $bm
l!l&&r!l&&!r
4300
not defined $best or $len > $blen
l!l&&r!l&&!r
32110
$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
3170 }
3171 38 return $best;
3172 }
3173  
3174 38 ▶sub _lookup {
Subroutine _lookup: called CC=17 SCAR=31.5
3175 38 my ( $dev, $ip, $from, $iif ) = @_;
3176 38 my @rules = sort { $a->{priority} <=> $b->{priority} } _all_rules($dev);
3177 38 for my $ru (@rules) {
3178 83 ▶ 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 82 83
Condition77%7/9
defined $$ru{"from"} and $$ru{"from"} ne "all" and not defined $from && _in($from, $$ru{"from"})
!ll&&!rl&&r
8111
defined $$ru{"from"} and $$ru{"from"} ne "all"
!ll&&!rl&&r
8102
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
3179 82 ▶ 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 82 82
Condition33%2/6
defined $$ru{"to"} and $$ru{"to"} ne "all" and not _in($ip, $$ru{"to"})
!ll&&!rl&&r
8200
defined $$ru{"to"} and $$ru{"to"} ne "all"
!ll&&!rl&&r
8200
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
3180 82 ▶ 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 82 82
Condition16%1/6
defined $$ru{"iif"} and not defined $iif && $iif eq $$ru{"iif"}
!ll&&!rl&&r
8200
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
3181 82 ▶ my $t = $ru->{table} // 'main';
Condition50%1/2
$$ru{"table"} // "main"
l!l
820
MC/DC0%0/1
$$ru{"table"} // "main"
$$ru{"table"}
Truth table50%1/2
A
A= $$ru{"table"}
Aresult
11
00
3182 82 ▶ next if $t eq 'local' || $t eq 'default';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "local" or $t eq "default" 44 38 82
Condition100%3/3
$t eq "local" or $t eq "default"
l!l&&r!l&&!r
38638
MC/DC100%2/2
$t eq "local" or $t eq "default"
$t eq "local" $t eq "default"
Truth table100%3/3
A or B
A= $t eq "local"B= $t eq "default"
ABresult
1X1
011
000
3183 38 ▶ my $r = _best( $dev->{routes} || [], $ip, $t );
Condition100%2/2
$$dev{'routes'} || []
l!l
326
MC/DC100%1/1
$$dev{'routes'} || []
$$dev{'routes'}
Truth table100%2/2
A
A= $$dev{'routes'}
Aresult
11
00
3184 38 ▶ return ( $r, $t ) if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 32 6 38
3185 }
3186 6 return ();
3187 }
3188  
3189 # --- ip rule -------------------------------------------------------------------------
3190  
3191 39 ▶sub _all_rules {
Subroutine _all_rules: called CC=2 SCAR=6.9
3192 39 my ($dev) = @_;
3193 39 ▶ return ( { priority => 0, table => 'local' }, @{ $dev->{rules} || [] },
Condition100%2/2
$$dev{'rules'} || []
l!l
336
MC/DC100%1/1
$$dev{'rules'} || []
$$dev{'rules'}
Truth table100%2/2
A
A= $$dev{'rules'}
Aresult
11
00
3194 { priority => 32766, table => 'main' }, { priority => 32767, table => 'default' } );
3195 }
3196  
3197 4 ▶sub _rule_text {
Subroutine _rule_text: called CC=7 SCAR=20.5
3198 4 my ($r) = @_;
3199 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
3200 4 ▶ $s .= " to $r->{to}" if defined $r->{to};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"to"} 0 4 4
3201 4 ▶ $s .= " fwmark $r->{fwmark}" if defined $r->{fwmark};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"fwmark"} 0 4 4
3202 4 ▶ $s .= " iif $r->{iif}" if defined $r->{iif};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"iif"} 0 4 4
3203 4 ▶ $s .= " oif $r->{oif}" if defined $r->{oif};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{"oif"} 0 4 4
3204 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
3205 4 return $s;
3206 }
3207  
3208 2 ▶sub _ip_rule {
Subroutine _ip_rule: called CC=29 SCAR=45.2
3209 2 my ( $dev, $av ) = @_;
3210 2 my @a = @$av;
3211 2 ▶ my $sub = @a ? shift @a : 'show';
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 1 1 2
3212 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
3213 // return ( qq{Command "$sub" is unknown, try "ip rule help".}, 0 );
3214 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
3215 1 return ( join( "\n", map { _rule_text($_) } sort { $a->{priority} <=> $b->{priority} } _all_rules($dev) ), 1 );
3216 }
3217 0 ▶ if ( $cmd eq 'flush' ) { $dev->{rules} = []; return ( '', 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "flush") 0 1 1
3218 1 my %r;
3219 1 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 3 1 4
3220 3 my $k = shift @a;
3221 3 my $v = shift @a;
3222 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
3223 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
3224 1 elsif ( $k =~ /\A(?:lookup|table)\z/ ) { $r{table} = $v }
3225 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
3226 0 else { return ( qq{Error: argument "$k" is wrong: Failed to parse rule type}, 0 ) }
3227 }
3228 1 delete $r{$_} for grep { !defined $r{$_} } keys %r;
3229 1 for my $k (qw( from to )) {
3230 2 ▶ next unless defined $r{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r{$k} 1 1 2
3231 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
3232 1 $r{$k} = $c;
3233 }
3234 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
3235 1 ▶ if ( $cmd eq 'delete' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "delete") 0 1 1
3236 my ($i) = grep {
3237 0 my $x = $dev->{rules}[$_];
3238 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
3239 0 } 0 .. $#{ $dev->{rules} };
3240 0 ▶ return ( 'RTNETLINK answers: No such file or directory', 0 ) unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 0 0
3241 0 splice @{ $dev->{rules} }, $i, 1;
3242 0 return ( '', 1 );
3243 }
3244 return ( 'Error: argument "' . $r{priority} . '" is wrong: preference value is invalid', 0 )
3245 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
3246 1 ▶ if ( !defined $r{priority} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $r{"priority"}) 0 1 1
3247 0 my ($low) = sort { $a <=> $b } map { $_->{priority} } @{ $dev->{rules} };
3248 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
3249 }
3250 1 $r{priority} = 0 + $r{priority};
3251 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
3252 1 push @{ $dev->{rules} }, \%r;
3253 0 @{ $dev->{rules} } = sort { $a->{priority} <=> $b->{priority} } @{ $dev->{rules} };
3254 1 return ( '', 1 );
3255 }
3256  
3257 # --- ip addr / link --------------------------------------------------------------------
3258  
3259 2 ▶sub _ip_addr {
Subroutine _ip_addr: called CC=43 SCAR=53.0
3260 2 my ( $dev, $av, $o ) = @_;
3261 2 my @a = @$av;
3262 2 ▶ my $sub = @a ? shift @a : 'show';
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 2 0 2
3263 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
3264 0 ▶ if ( !$cmd ) { unshift @a, $sub; $cmd = 'show' }
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmd) 0 2 2
3265 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
3266 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
3267 1 my $only = shift @a;
3268 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
3269 1 my @out;
3270 1 my $idx = 0;
3271 1 for my $n ( _ifaces($dev) ) {
3272 4 $idx++;
3273 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
3274 1 my $i = _iface( $dev, $n );
3275 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
3276 1 ▶ if ( $o->{br} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$o{"br"}) 0 1 1
3277 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
3278 0 next;
3279 }
3280 push @out, "$idx: $n: <" . ( $n eq 'lo' ? 'LOOPBACK,UP,LOWER_UP' : $st eq 'DOWN' ? 'BROADCAST,MULTICAST' : 'BROADCAST,MULTICAST,UP,LOWER_UP' )
3281 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
3282 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
3283 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
3284 }
3285 1 return ( join( "\n", @out ), 1 );
3286 }
3287 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
3288 1 my %k;
3289 1 ▶ while (@a) { my $x = shift @a; $k{$x} = shift @a }
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 1 1 2
3290 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
3291 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
3292 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
3293 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
3294 1 ▶ if ( $cmd eq 'add' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "add") 1 0 1
3295 1 ▶ return ( 'RTNETLINK answers: File exists', 0 ) if grep { $_ eq $addr } @$list;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $addr;} @$list 0 1 1
3296 1 push @$list, $addr;
3297 1 ▶ if ( my ( $net, $len ) = _prefix($addr) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = _prefix($addr)) 1 0 1
3298 1 ▶ push @{ $dev->{routes} }, { dst => _n2ip($net) . "/$len", dev => $ifn, proto => 'kernel', scope => 'link',
Branch: 1 branch
BranchTrueFalseTotal
if $len < 32 1 0 1
3299 src => ( split m{/}, $addr )[0] } if $len < 32;
3300 }
3301 1 return ( '', 1 );
3302 }
3303 0 my $n = @$list;
3304 0 @$list = grep { $_ ne $addr } @$list;
3305 0 ▶ return ( 'RTNETLINK answers: Cannot assign requested address', 0 ) if @$list == $n;
Branch: 1 branch
BranchTrueFalseTotal
if @$list == $n 0 0 0
3306 0 my $src = ( split m{/}, $addr )[0];
3307 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
3308 0 return ( '', 1 );
3309 }
3310  
3311 4 ▶sub _ip_link {
Subroutine _ip_link: called CC=38 SCAR=43.6
3312 4 my ( $dev, $av, $o ) = @_;
3313 4 my @a = @$av;
3314 4 ▶ my $sub = @a ? shift @a : 'show';
Branch: 1 branch
BranchTrueFalseTotal
@a ? : 3 1 4
3315 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
3316 0 ▶ if ( !$cmd ) { unshift @a, $sub; $cmd = 'show' }
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmd) 0 4 4
3317 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
3318 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
3319 2 my $only = shift @a;
3320 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
3321 2 my @out;
3322 2 my $idx = 0;
3323 2 for my $n ( _ifaces($dev) ) {
3324 8 $idx++;
3325 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
3326 5 my $i = _iface( $dev, $n );
3327 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
3328 5 ▶ if ( $o->{br} ) { push @out, sprintf( '%-16s %-14s', $n, $st ); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($$o{"br"}) 4 1 5
3329 push @out, "$idx: $n: <" . ( $n eq 'lo' ? 'LOOPBACK,UP,LOWER_UP' : $st eq 'DOWN' ? 'BROADCAST,MULTICAST' : 'BROADCAST,MULTICAST,UP,LOWER_UP' )
3330 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
3331 push @out, $n eq 'lo' ? ' link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00'
3332 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
3333 }
3334 2 return ( join( "\n", @out ), 1 );
3335 }
3336 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
3337 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
3338 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
3339 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
3340 2 ▶ return ( 'Command line is not complete. Try option "help"', 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 2 2
3341 2 my %set;
3342 2 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 2 1 3
3343 2 my $k = shift @a;
3344 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
3345 2 my $v = shift @a;
3346 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
3347 1 ▶ return ( 'Error: mtu less than device minimum.', 0 ) if $v < 68;
Branch: 1 branch
BranchTrueFalseTotal
if $v < 68 0 1 1
3348 1 ▶ return ( 'Error: mtu greater than device maximum.', 0 ) if $v > 65535;
Branch: 1 branch
BranchTrueFalseTotal
if $v > 65535 0 1 1
3349 1 $set{mtu} = 0 + $v;
3350 }
3351 0 elsif ( $k eq 'up' ) { $set{state} = 'UP' }
3352 0 elsif ( $k eq 'down' ) { $set{state} = 'DOWN' }
3353 0 else { return ( qq{Error: either "dev" is duplicate, or "$k" is a garbage.}, 0 ) }
3354 }
3355 1 $i->{$_} = $set{$_} for keys %set;
3356 1 return ( '', 1 );
3357 }
3358  
3359 # --- WireGuard ---------------------------------------------------------------------
3360  
3361 4 ▶sub _wg_conf {
Subroutine _wg_conf: called CC=11 SCAR=25.2
3362 4 my ($w) = @_;
3363 4 my @l = ( '[Interface]' );
3364 4 ▶ push @l, "Address = $w->{address}" if defined $w->{address};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$w{"address"} 4 0 4
3365 4 ▶ push @l, "ListenPort = $w->{listen_port}" if defined $w->{listen_port};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$w{"listen_port"} 4 0 4
3366 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
3367 4 ▶ push @l, "MTU = $w->{mtu}" if defined $w->{mtu};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$w{"mtu"} 0 4 4
3368 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
3369 5 my $p = $w->{peers}{$k};
3370 5 push @l, '', '[Peer]';
3371 5 ▶ push @l, "# $p->{name}" if defined $p->{name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"name"} 0 5 5
3372 5 push @l, "PublicKey = $k";
3373 5 ▶ push @l, "Endpoint = $p->{endpoint}" if defined $p->{endpoint};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"endpoint"} 3 2 5
3374 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
3375 5 ▶ push @l, "PersistentKeepalive = $p->{keepalive}" if defined $p->{keepalive};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"keepalive"} 0 5 5
3376 }
3377 4 return join( "\n", @l ) . "\n";
3378 }
3379  
3380 # wgN.conf lesen -> Zustand (ohne Address/MTU: die setzt wg-quick)
3381 9 ▶sub _wg_parse {
Subroutine _wg_parse: called CC=20 SCAR=30.8
3382 9 my ( $text, $old ) = @_;
3383 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
3384 9 my ( $sec, $peer, %pp );
3385 33 ▶ my $flush = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
3386 33 ▶ return unless $peer;
Branch: 1 branch
BranchTrueFalseTotal
unless $peer 18 15 33
3387 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
3388 15 $w{peers}{$peer} = { %$prev, allowed_ips => [], %pp };
3389 15 _wg_claim( \%w, $peer );
3390 15 ( $peer, %pp ) = ();
3391 9 };
3392 9 my $n = 0;
3393 9 for my $line ( split /\n/, $text ) {
3394 102 $n++;
3395 102 ( my $l = $line ) =~ s/#.*//;
3396 102 $l =~ s/\A\s+|\s+\z//g;
3397 102 ▶ next unless length $l;
Branch: 1 branch
BranchTrueFalseTotal
unless length $l 27 75 102
3398 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
3399 # wie wg: aller Leerraum faellt weg ("Allowed IPs = a, b" ist AllowedIPs=a,b)
3400 50 ( my $flat = $l ) =~ s/\s+//g;
3401 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
3402 50 $k = lc $k;
3403 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
3404 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
3405 17 ▶ $w{address} = $v if $k eq 'address';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "address" 0 17 17
3406 17 ▶ $w{mtu} = 0 + $v if $k eq 'mtu';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "mtu" 0 17 17
3407 }
3408 ▶ 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
3409 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
3410 15 elsif ( $k eq 'allowedips' ) { $pp{allowed_ips} = [ grep {length} split /\s*,\s*/, $v ] }
3411 1 elsif ( $k eq 'endpoint' ) { $pp{endpoint} = $v }
3412 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
3413 1 elsif ( $k ne 'presharedkey' ) { die "Line unrecognized: `$flat'\nConfiguration parsing error\n" }
3414 }
3415 0 else { die "Line unrecognized: `$flat'\nConfiguration parsing error\n" }
3416 }
3417 8 $flush->();
3418 8 return \%w;
3419 }
3420  
3421 # Eine AllowedIP gehoert in wg genau einem Peer: wer sie bekommt, nimmt sie den anderen.
3422 18 ▶sub _wg_claim {
Subroutine _wg_claim: called CC=6 SCAR=18.1
3423 18 my ( $w, $peer ) = @_;
3424 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
3425 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
3426 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
3427 11 my @keep = grep { !$mine{$_} } @$l;
3428 11 ▶ $w->{peers}{$k}{allowed_ips} = \@keep if @keep != @$l;
Branch: 1 branch
BranchTrueFalseTotal
if @keep != @$l 2 9 11
3429 }
3430 18 return;
3431 }
3432  
3433 # [Interface] einer wgN.conf: was wg-quick daraus macht (Address, MTU, Table, Hooks, SaveConfig)
3434 10 ▶sub _wg_quick_conf {
Subroutine _wg_quick_conf: called CC=9 SCAR=22.0
3435 10 my ($text) = @_;
3436 10 my ( %c, $sec );
3437 10 for my $line ( split /\n/, $text ) {
3438 180 ( my $l = $line ) =~ s/#.*//;
3439 180 $l =~ s/\A\s+|\s+\z//g;
3440 180 ▶ next unless length $l;
Branch: 1 branch
BranchTrueFalseTotal
unless length $l 41 139 180
3441 139 ▶ if ( $l =~ /\A\[(\w+)\]\z/ ) { $sec = lc $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A\[(\w+)\]\z/) 32 107 139
3442 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
3443 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
3444 63 $k = lc $k;
3445 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
3446 10 elsif ( $k eq 'address' ) { push @{ $c{address} }, grep {length} split /\s*,\s*/, $v }
3447 33 else { $c{$k} = $v }
3448 }
3449 10 return \%c;
3450 }
3451  
3452 # PreUp/PostUp: scheitert ein Befehl, bricht wg-quick up ab. PreDown/PostDown
3453 # ($soft): die Schnittstelle geht trotzdem herunter (wie der Stop der Unit).
3454 18 ▶sub _wg_hooks {
Subroutine _wg_hooks: called CC=5 SCAR=16.6
3455 18 my ( $dev, $n, $cmds, $soft ) = @_;
3456 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
3457 9 ( my $x = $c ) =~ s/%i/$n/g;
3458 9 my ( $o, $ok ) = __PACKAGE__->_run_inner( $dev, $x, $CTX );
3459 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
3460 }
3461 18 return;
3462 }
3463  
3464 # wg-quick up (von Hand: die Unit wg-quick@ behaelt ihren Stand): Schnittstelle mit Address/MTU, Peers aus der Datei, Routen zu den
3465 # AllowedIPs (ohne Table = off), PreUp/PostUp.
3466 8 ▶sub _wg_up {
Subroutine _wg_up: called CC=39 SCAR=49.2
3467 8 my ( $dev, $n ) = @_;
3468 8 my $file = "/etc/wireguard/$n.conf";
3469 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
3470 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
3471 7 my $q = _wg_quick_conf($t);
3472 7 ( my $strip = $t ) =~ s/^\s*(Address|DNS|MTU|Table|PreUp|PostUp|PreDown|PostDown|SaveConfig)\s*=.*\n?//mgi;
3473 7 my $w = _wg_parse( $strip, $dev->{wg}{$n} );
3474 # ein UDP-Port gehoert genau einer laufenden WireGuard-Schnittstelle
3475 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
3476 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
3477 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
3478 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";
3479 }
3480 6 _wg_hooks( $dev, $n, $q->{preup} );
3481 6 $dev->{wg}{$n} = $w;
3482 6 ▶ $w->{address} = join( ', ', @{ $q->{address} } ) if $q->{address};
Branch: 1 branch
BranchTrueFalseTotal
if $$q{"address"} 6 0 6
3483 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
3484 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
3485 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
3486 6 $if->{state} = 'UP';
3487 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
3488 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
3489 6 my ( $ip, $len ) = split m{/}, $a;
3490 6 ▶ my $net = _n2ip( _ip2n($ip) & ( $len ? ( 0xffffffff << ( 32 - $len ) ) & 0xffffffff : 0 ) ) . "/$len";
Branch: 1 branch
BranchTrueFalseTotal
$len ? : 6 0 6
3491 push @$routes, { dst => $net, dev => $n, proto => 'kernel', scope => 'link', src => $ip }
3492 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
3493 }
3494 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
3495 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
3496 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
3497 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
3498 18 ▶ my $dst = $ip =~ m{/32\z} ? $ip : $ip;
Branch: 1 branch
BranchTrueFalseTotal
$ip =~ m[/32\z] ? : 12 6 18
3499 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
3500 18 push @$routes, { dst => $dst, dev => $n, scope => 'link' };
3501 }
3502 }
3503 }
3504 6 _wg_hooks( $dev, $n, $q->{postup} );
3505 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";
3506 }
3507  
3508 # wg-quick down (zaehlt interfaces.wgN.downs): SaveConfig = true schreibt erst die laufende Konfiguration in die
3509 # Datei (Interface-Abschnitt bleibt, Peers aus dem laufenden Zustand); Routen weg,
3510 # PreDown/PostDown.
3511 3 ▶sub _wg_down {
Subroutine _wg_down: called CC=16 SCAR=30.8
3512 3 my ( $dev, $n ) = @_;
3513 3 my $file = "/etc/wireguard/$n.conf";
3514 die "wg-quick: `$n' is not a WireGuard interface\n"
3515 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
3516 3 my $t = _file_text( $dev, $file );
3517 3 ▶ my $q = defined $t ? _wg_quick_conf($t) : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 3 0 3
3518 3 _wg_hooks( $dev, $n, $q->{predown}, 1 );
3519 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
3520 1 my ($head) = $t =~ /\A(.*?)(?=^\s*\[Peer\])/ms;
3521 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
3522 1 $head =~ s/\n*\z/\n/;
3523 1 my ($peers) = _wg_conf( $dev->{wg}{$n} ) =~ /(^\[Peer\].*)\z/ms;
3524 1 ▶ _file_set( $dev, $file, $head . ( defined $peers ? "\n$peers" : '' ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $peers ? : 1 0 1
3525 }
3526 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
3527 3 ▶ if ( my $if = $dev->{interfaces}{$n} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $if = $$dev{"interfaces"}{$n}) 3 0 3
3528 3 $if->{state} = 'DOWN';
3529 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
3530 }
3531 3 _wg_hooks( $dev, $n, $q->{postdown}, 1 );
3532 3 return "[#] ip link delete dev $n";
3533 }
3534  
3535 # Zeitpunkt des Simulators (wie date): Tue Oct 21 12:00:00 CEST 2026
3536 88 our $NOW = 1792576800;
3537  
3538 # "2 days, 3 hours ago" -> Sekunden seit 1970 (wie wg show latest-handshakes; nie = 0)
3539 6 ▶sub _wg_epoch {
Subroutine _wg_epoch: called CC=4 SCAR=13.9
3540 6 my ($h) = @_;
3541 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
3542 3 my %u = ( year => 365 * 86400, day => 86400, hour => 3600, minute => 60, second => 1 );
3543 3 my $s = 0;
3544 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
3545 3 return $NOW - $s;
3546 }
3547  
3548 5 ▶sub _wg_show_if {
Subroutine _wg_show_if: called CC=31 SCAR=41.8
3549 5 my ( $n, $w, $what ) = @_;
3550 5 my @l;
3551 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
3552 5 ▶ if ( defined $what ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $what) 4 1 5
3553 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
3554 4 ▶ return join "\n", @peers if $what eq 'peers';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "peers" 0 4 4
3555 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
3556 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
3557 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
3558 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
3559 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
3560 1 ▶ if ( $what eq 'dump' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "dump") 1 0 1
3561 return join "\n", join( "\t", '(hidden)', $w->{public_key} // '(none)', $w->{listen_port} // 0, 'off' ), map {
3562 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
3563 join "\t", $_, '(none)', $p->{endpoint} // '(none)',
3564 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
3565 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
3566 } @peers;
3567 }
3568 0 die "Invalid parameter: `$what'\n";
3569 }
3570 push @l, "interface: $n", " public key: " . ( $w->{public_key} // '' ), ' private key: (hidden)',
3571 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
3572 1 for my $k (@peers) {
3573 1 my $p = $w->{peers}{$k};
3574 1 push @l, '', "peer: $k";
3575 1 ▶ push @l, " endpoint: $p->{endpoint}" if defined $p->{endpoint};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"endpoint"} 1 0 1
3576 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
3577 1 ▶ push @l, " latest handshake: $p->{handshake}" if defined $p->{handshake};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"handshake"} 0 1 1
3578 1 ▶ push @l, " transfer: $p->{transfer}" if defined $p->{transfer};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"transfer"} 0 1 1
3579 1 ▶ push @l, " persistent keepalive: every $p->{keepalive} seconds" if defined $p->{keepalive};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"keepalive"} 0 1 1
3580 }
3581 1 return join "\n", @l;
3582 }
3583  
3584 12 ▶sub _wg {
Subroutine _wg: called CC=56 SCAR=53.5
3585 12 my ( $dev, $av ) = @_;
3586 12 my @a = @$av;
3587 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
3588 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
3589 12 ▶ if ( $sub eq 'show' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "show") 5 7 12
3590 5 my $n = shift @a;
3591 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
3592 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
3593 1 return ( join( "\n\n", map { _wg_show_if( $_, $wg->{$_} ) } sort keys %$wg ), 1 );
3594 }
3595 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
3596 1 my $what = shift @a;
3597 1 return ( join( "\n", map { my $i = $_; map {"$i\t$_"} split /\n/, _wg_show_if( $i, $wg->{$i}, $what ) } sort keys %$wg ), 1 );
3598 }
3599 3 ▶ return ( "Unable to access interface: No such device", 0 ) unless $wg->{$n};
Branch: 1 branch
BranchTrueFalseTotal
unless $$wg{$n} 0 3 3
3600 3 return ( _wg_show_if( $n, $wg->{$n}, shift @a ), 1 );
3601 }
3602 7 ▶ if ( $sub eq 'showconf' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "showconf") 1 6 7
3603 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
3604 1 ▶ return ( "Unable to access interface: No such device", 0 ) unless $wg->{$n};
Branch: 1 branch
BranchTrueFalseTotal
unless $$wg{$n} 0 1 1
3605 1 return ( _wg_conf( $wg->{$n} ) =~ s/\n\z//r, 1 );
3606 }
3607 6 ▶ if ( $sub eq 'set' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "set") 4 2 6
3608 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
3609 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
3610 4 my $peer;
3611 4 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 7 3 10
3612 7 my $k = shift @a;
3613 0 ▶ if ( $k eq 'listen-port' ) { $w->{listen_port} = shift @a; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "listen-port") 0 7 7
3614 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
3615 7 ▶ if ( $k eq 'peer' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "peer") 4 3 7
3616 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
3617 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
3618 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
3619 3 $peer = $key;
3620 3 next;
3621 }
3622 3 ▶ return ( "Invalid argument: $k", 0 ) unless defined $peer;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $peer 0 3 3
3623 0 ▶ if ( $k eq 'remove' ) { delete $w->{peers}{$peer}; undef $peer; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "remove") 0 3 3
3624 3 my $v = shift @a;
3625 3 ▶ return ( "Invalid argument: $k", 0 ) unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 3 3
3626 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
3627 3 my @ips = grep {length} split /\s*,\s*/, $v;
3628 3 for (@ips) {
3629 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
3630 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
3631 }
3632 3 $w->{peers}{$peer}{allowed_ips} = \@ips;
3633 3 _wg_claim( $w, $peer );
3634 }
3635 0 elsif ( $k eq 'endpoint' ) { $w->{peers}{$peer}{endpoint} = $v }
3636 0 elsif ( $k eq 'persistent-keepalive' ) { $w->{peers}{$peer}{keepalive} = $v }
3637 elsif ( $k eq 'preshared-key' ) { }
3638 0 else { return ( "Invalid argument: $k", 0 ) }
3639 }
3640 3 return ( '', 1 );
3641 }
3642 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
3643 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
3644 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
3645 2 ▶ return ( "Unable to modify interface: No such device", 0 ) unless $wg->{$n};
Branch: 1 branch
BranchTrueFalseTotal
unless $$wg{$n} 0 2 2
3646 2 my $text;
3647 2 my ($in) = $src =~ /\A<\(\s*wg-quick\s+strip\s+(\S+?)\)?\z/;
3648 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
3649 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
3650 2 $f =~ s/\)\z//;
3651 2 ▶ $f = $1 if $f =~ m{(wg\d+)};
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /(wg\d+)/ 2 0 2
3652 2 $text = _file_text( $dev, "/etc/wireguard/$f.conf" );
3653 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
3654 }
3655 0 else { $text = _file_text( $dev, $src ) }
3656 2 ▶ return ( "fopen: No such file or directory", 0 ) unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 2 2
3657 2 $wg->{$n} = _wg_parse( $text, $wg->{$n} );
3658 2 return ( '', 1 );
3659 }
3660 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
3661 0 return ( 'aGVsbG8tdGhpcy1pcy1hLXNpbXVsYXRlZC1rZXktMDA=', 1 );
3662 }
3663 0 return ( "Invalid subcommand: `$sub'\nUsage: wg <cmd> [<args>]", 0 );
3664 }
3665  
3666 5 ▶sub _wgquick {
Subroutine _wgquick: called CC=12 SCAR=31.0
3667 5 my ( $dev, $av ) = @_;
3668 5 my ( $sub, $n ) = @$av;
3669 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
3670 5 ▶ $n = $1 if $n =~ m{(wg\d+)};
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ /(wg\d+)/ 5 0 5
3671 5 my $file = "/etc/wireguard/$n.conf";
3672 5 ▶ if ( $sub eq 'strip' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "strip") 0 5 5
3673 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
3674 0 $t =~ s/^\s*(Address|DNS|MTU|Table|PreUp|PostUp|PreDown|PostDown|SaveConfig)\s*=.*\n?//mgi;
3675 0 return ( $t =~ s/\n\z//r, 1 );
3676 }
3677 5 ▶ if ( $sub eq 'save' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "save") 0 5 5
3678 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
3679 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
3680 0 return ( '', 1 );
3681 }
3682 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
3683 5 my $copy = Langertha::Holmgang::Sim::Linux::clone_state($dev);
3684 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
3685 5 ▶ if ( my $e = $@ ) { $e =~ s/\s+\z//; return ( $e, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 1 4 5
3686 4 %$dev = %$copy;
3687 4 return ( $out, 1 );
3688 }
3689 0 return ( 'Usage: wg-quick [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]', 0 );
3690 }
3691  
3692 # --- nftables ------------------------------------------------------------------------
3693  
3694 36 ▶sub _norm_rule {
Subroutine _norm_rule: called CC=1 SCAR=0.0
3695 36 my ($r) = @_;
3696 36 $r =~ s/\s+/ /g;
3697 36 $r =~ s/\A\s+|\s+\z//g;
3698 36 $r =~ s/\b(iifname|oifname)\s+(?!["{@]|!=|(?:v?map)\b)([^\s{}",]+)/$1 "$2"/g;
3699 36 $r =~ s/\b(iifname|oifname)\s+"([^"]+)"/$1 "$2"/g;
3700 36 return $r;
3701 }
3702  
3703 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
3704  
3705 # Handles der Regeln einer Tabelle. Beim ersten Blick aus der Reihenfolge
3706 # gezaehlt, danach fest wie in nft: eine neue Regel bekommt die naechste
3707 # Nummer, die anderen behalten ihre. Gefuehrt in _handles/_next_handle
3708 # (Buchfuehrung des Simulators; der Diff des Endzustands sieht sie nicht).
3709 112 ▶sub _handles {
Subroutine _handles: called CC=10 SCAR=23.3
3710 112 my ($t) = @_;
3711 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
3712 112 ▶ if ( !defined $t->{_next_handle} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$t{"_next_handle"}) 21 91 112
3713 21 my $n = 1 + scalar keys %$chains;
3714 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
3715 21 $t->{_next_handle} = $n + 1;
3716 }
3717 112 my %h;
3718 112 for my $c ( sort keys %$chains ) {
3719 124 my $ch = $chains->{$c};
3720 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
3721 124 ▶ my $own = ref $ch->{_handles} eq 'ARRAY' ? $ch->{_handles} : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $$ch{'_handles'} eq 'ARRAY' ? : 123 1 124
3722 124 ▶ splice @$own, $n if @$own > $n;
Branch: 1 branch
BranchTrueFalseTotal
if @$own > $n 0 124 124
3723 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
3724 124 $ch->{_handles} = $own;
3725 124 $h{$c} = [@$own];
3726 }
3727 112 return \%h;
3728 }
3729  
3730 21 ▶sub _nft_chain_text {
Subroutine _nft_chain_text: called CC=8 SCAR=20.9
3731 21 my ( $tname, $t, $c, $with_h, $handles ) = @_;
3732 21 my $ch = $t->{chains}{$c};
3733 21 ▶ my @l = ("\tchain $c {" . ( $with_h ? ' # handle ' . ( 1 + ( grep { $_ lt $c } keys %{ $t->{chains} } ) ) : '' ));
Branch: 1 branch
BranchTrueFalseTotal
$with_h ? : 7 14 21
3734 21 ▶ if ( $ch->{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$ch{"type"}) 20 1 21
3735 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
3736 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
3737 }
3738 21 my $i = 0;
3739 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
3740 42 ▶ push @l, "\t\t$r" . ( $with_h ? " # handle $handles->{$c}[$i]" : '' );
Branch: 1 branch
BranchTrueFalseTotal
$with_h ? : 18 24 42
3741 42 $i++;
3742 }
3743 21 push @l, "\t}";
3744 21 return @l;
3745 }
3746  
3747 4 ▶sub _nft_set_text {
Subroutine _nft_set_text: called CC=6 SCAR=19.7
3748 4 my ( $name, $s ) = @_;
3749 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
3750 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
3751 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
3752 4 push @l, "\t}";
3753 4 return @l;
3754 }
3755  
3756 13 ▶sub _nft_table_text {
Subroutine _nft_table_text: called CC=7 SCAR=19.5
3757 13 my ( $tname, $t, $with_h ) = @_;
3758 13 my $h = _handles($t);
3759 13 ▶ my @l = ( "table $tname {" . ( $with_h ? ' # handle 1' : '' ) );
Branch: 1 branch
BranchTrueFalseTotal
$with_h ? : 1 12 13
3760 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
3761 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
3762 13 for my $i ( 0 .. $#c ) {
3763 14 push @l, _nft_chain_text( $tname, $t, $c[$i], $with_h, $h );
3764 14 ▶ push @l, '' if $i < $#c;
Branch: 1 branch
BranchTrueFalseTotal
if $i < $#c 1 13 14
3765 }
3766 13 push @l, '}';
3767 13 return @l;
3768 }
3769  
3770 # Regelsatz im Dateiformat von nft (wie /etc/nftables.conf): flush ruleset,
3771 # table F T { chain C { type …; policy …; regel … } }, add/insert/delete-Zeilen.
3772 # Alles oder nichts, wie nft -f.
3773 9 ▶sub _nft_load {
Subroutine _nft_load: called CC=45 SCAR=43.1
3774 9 my ( $dev, $text, $file, $check_only ) = @_;
3775 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
3776 9 my ( $table, $chain, $set, %def );
3777 9 my $n = 0;
3778 9 ▶ my $err = sub { ( "$file:$n:1-1: Error: syntax error, unexpected $_[0]\n$_[1]", 0 ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
3779 9 for my $raw ( split /\n/, $text ) {
3780 116 $n++;
3781 116 ( my $l = $raw ) =~ s/#.*//;
3782 116 $l =~ s/\A\s+|\s+\z//g;
3783 116 ▶ next unless length $l;
Branch: 1 branch
BranchTrueFalseTotal
unless length $l 18 98 116
3784 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
3785 94 ▶ if ( $l =~ /\Ainclude\b/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\Ainclude\b/) 0 94 94
3786 0 push @GAPS, "nft -f $file ($l)";
3787 0 return ( '', 0 );
3788 }
3789 94 ▶ $l =~ s/\$(\w+)/exists $def{$1} ? $def{$1} : "\$$1"/ge;
Branch: 1 branch
BranchTrueFalseTotal
exists $def{$1} ? : 4 0 4
3790 94 ▶ return ( "$file:$n: Error: unknown identifier '$1'\n$raw", 0 ) if $l =~ /\$(\w+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\$(\w+)/ 0 94 94
3791 94 ▶ if ( defined $set ) { # Set-Block: bis die Klammern aufgehen
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set) 16 78 94
3792 16 $set->{text} .= " $l";
3793 16 my $open = () = $set->{text} =~ /\{/g;
3794 16 my $close = () = $set->{text} =~ /\}/g;
3795 16 ▶ next if $open > $close;
Branch: 1 branch
BranchTrueFalseTotal
if $open > $close 12 4 16
3796 4 ( my $spec = $set->{text} ) =~ s/\A\s*\{|\}\s*\z//g;
3797 4 my $e = _nft_set_spec( $copy->{nft}{$table}, $set->{name}, $spec );
3798 4 ▶ return ( "$file:$n: $e", 0 ) if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 4 4
3799 4 undef $set;
3800 4 next;
3801 }
3802 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
3803 4 $set = { name => $1, text => $2 };
3804 4 $l = $2;
3805 4 my $open = () = $l =~ /\{/g;
3806 4 my $close = () = $l =~ /\}/g;
3807 4 ▶ next if $open > $close;
Branch: 1 branch
BranchTrueFalseTotal
if $open > $close 4 0 4
3808 0 ( my $spec = $l ) =~ s/\A\s*\{|\}\s*\z//g;
3809 0 my $e = _nft_set_spec( $copy->{nft}{$table}, $set->{name}, $spec );
3810 0 ▶ return ( "$file:$n: $e", 0 ) if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 0 0
3811 0 undef $set;
3812 0 next;
3813 }
3814 74 ▶ if ( !defined $table ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $table) 19 55 74
3815 19 ▶ if ( $l eq 'flush ruleset' ) { $copy->{nft} = {}; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l eq "flush ruleset") 8 11 19
3816 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
3817 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
3818 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
3819 11 next;
3820 }
3821 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
3822 0 my ( $o, $k ) = _nft( $copy, [ split /\s+/, $l ] );
3823 0 ▶ return ( "$file:$n: $o", 0 ) unless $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $k 0 0 0
3824 0 next;
3825 }
3826 0 return $err->( 'string', $raw );
3827 }
3828 55 ▶ if ( !defined $chain ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chain) 21 34 55
3829 21 ▶ if ( $l eq '}' ) { undef $table; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l eq "}") 10 11 21
3830 11 ▶ if ( $l =~ /\Achain\s+(\S+)\s*\{\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\Achain\s+(\S+)\s*\{\z/) 11 0 11
3831 11 $chain = $1;
3832 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
3833 11 next;
3834 }
3835 0 return $err->( 'string', $raw );
3836 }
3837 34 ▶ if ( $l eq '}' ) { undef $chain; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l eq "}") 10 24 34
3838 24 my $c = $copy->{nft}{$table}{chains}{$chain};
3839 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
3840 10 @{$c}{qw( type hook priority )} = ( $1, $2, $3 );
3841 10 ▶ $c->{policy} = $4 if defined $4;
Branch: 1 branch
BranchTrueFalseTotal
if defined $4 10 0 10
3842 10 next;
3843 }
3844 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
3845 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
3846 14 push @{ $c->{rules} }, _norm_rule($l);
3847 }
3848 9 ▶ return $err->( 'end of file', '' ) if defined $table;
Branch: 1 branch
BranchTrueFalseTotal
if defined $table 1 8 9
3849 8 for my $t ( values %{ $copy->{nft} } ) {
3850 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
3851 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
3852 14 my $e = _nft_rule_refs( $t, $r );
3853 14 ▶ return ( "$file: $e\n$r", 0 ) if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 14 14
3854 }
3855 }
3856 # Regeln, die der Auswerter nicht versteht: Luecke (das Urteil daran waere geraten)
3857 8 for my $t ( values %{ $copy->{nft} } ) {
3858 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
3859 }
3860 8 ▶ $dev->{nft} = $copy->{nft} unless $check_only;
Branch: 1 branch
BranchTrueFalseTotal
unless $check_only 7 1 8
3861 8 return ( '', 1 );
3862 }
3863  
3864 # Typnamen fuer "icmp type" / "icmpv6 type" wie nft sie kennt; ein unbekannter Name ist
3865 # ein Fehler (nft lehnt die Regel ab), nicht still angenommen.
3866 88 our %ICMP_TYPES = map { $_ => 1 } qw( echo-reply destination-unreachable source-quench redirect echo-request
3867 router-advertisement router-solicitation time-exceeded parameter-problem timestamp-request timestamp-reply
3868 info-request info-reply address-mask-request address-mask-reply );
3869 88 our %ICMPV6_TYPES = map { $_ => 1 } qw( destination-unreachable packet-too-big time-exceeded parameter-problem
3870 echo-request echo-reply mld-listener-query mld-listener-report mld-listener-done mld-listener-reduction
3871 nd-router-solicit nd-router-advert nd-neighbor-solicit nd-neighbor-advert nd-redirect router-renumbering
3872 ind-neighbor-solicit ind-neighbor-advert mld2-listener-report );
3873  
3874 36 ▶sub _nft_bad_type {
Subroutine _nft_bad_type: called CC=7 SCAR=19.5
3875 36 my ($rule) = @_;
3876 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
3877 4 my ( $fam, $list ) = ( $1, $2 );
3878 4 ▶ my $known = $fam eq 'icmpv6' ? \%ICMPV6_TYPES : \%ICMP_TYPES;
Branch: 1 branch
BranchTrueFalseTotal
$fam eq 'icmpv6' ? : 3 1 4
3879 4 for my $t ( grep {length} split /[\s,{}]+/, $list ) {
3880 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
3881 2 ▶ return 'Error: Could not parse ' . ( $fam eq 'icmpv6' ? 'ICMPv6' : 'ICMP' ) . " type\n$t";
Branch: 1 branch
BranchTrueFalseTotal
$fam eq 'icmpv6' ? : 2 0 2
3882 }
3883 }
3884 34 return undef;
3885 }
3886  
3887 # Regel einer Filter- oder Sprungkette, die der Auswerter (Sim::Nft) nicht
3888 # versteht: Luecke der Simulation — ein Urteil daran waere geraten. NAT-Ketten
3889 # urteilen nicht und bleiben aussen vor.
3890 30 ▶sub _nft_gap {
Subroutine _nft_gap: called CC=4 SCAR=13.9
3891 30 my ( $ch, $text ) = @_;
3892 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
3893 29 my $why = Langertha::Holmgang::Sim::Linux::Nft::parse_error($text);
3894 29 ▶ push @GAPS, "nft: $why" if $why;
Branch: 1 branch
BranchTrueFalseTotal
if $why 1 28 29
3895 29 return;
3896 }
3897  
3898 # Set-Angabe "type ipv4_addr; flags interval; elements = { … }" in die Tabelle;
3899 # liefert einen Fehlertext oder undef.
3900 6 ▶sub _nft_set_spec {
Subroutine _nft_set_spec: called CC=10 SCAR=24.5
3901 6 my ( $t, $name, $spec ) = @_;
3902 6 my %s = ( elements => [] );
3903 6 ▶ my $type = $spec =~ /\btype\s+(\w+)/ ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$spec =~ /\btype\s+(\w+)/ ? : 6 0 6
3904 6 ▶ return "Error: set definition does not specify key\nset $name" unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 6 6
3905 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
3906 6 $s{type} = $type;
3907 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
3908 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
3909 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
3910 6 ▶ if ( $spec =~ /\belements\s*=\s*\{([^}]*)\}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec =~ /\belements\s*=\s*\{([^}]*)\}/) 4 2 6
3911 4 my $e = _nft_add_elements( $t->{sets}{$name}, $1 );
3912 4 ▶ return $e if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 4 4
3913 }
3914 6 return undef;
3915 }
3916  
3917 6 ▶sub _nft_add_elements {
Subroutine _nft_add_elements: called CC=11 SCAR=25.4
3918 6 my ( $s, $list ) = @_;
3919 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
3920 6 for my $e ( grep {length} map { s/\A\s+|\s+\z//gr } split /,/, $list ) {
3921 7 $e =~ s/\A"|"\z//g;
3922 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
3923 7 my $want6 = $s->{type} eq 'ipv6_addr';
3924 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
3925 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
3926 }
3927 elsif ( $s->{type} eq 'inet_service' ) {
3928 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
3929 }
3930 6 ▶ push @{ $s->{elements} }, $e unless grep { $_ eq $e } @{ $s->{elements} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $e;} @{$$s{"elements"};} 6 0 6
3931 }
3932 5 return undef;
3933 }
3934  
3935 # Verweise einer Regel: benannte Sets und Ketten muessen in der Tabelle stehen
3936 32 ▶sub _nft_rule_refs {
Subroutine _nft_rule_refs: called CC=7 SCAR=19.7
3937 32 my ( $t, $r ) = @_;
3938 32 for my $s ( $r =~ /@([\w-]+)/g ) {
3939 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
3940 }
3941 31 for my $c ( $r =~ /\b(?:jump|goto)\s+([^\s,}]+)/g ) {
3942 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
3943 }
3944 31 return undef;
3945 }
3946  
3947 # nft add|create|delete|flush set …, nft add|delete element … { … }
3948 6 ▶sub _nft_set_cmd {
Subroutine _nft_set_cmd: called CC=23 SCAR=35.4
3949 6 my ( $t, $tn, $verb, $obj, $cn, $rest, $syntax ) = @_;
3950 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
3951 6 ▶ if ( $obj eq 'set' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj eq "set") 3 3 6
3952 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
3953 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
3954 2 ( my $spec = $rest ) =~ s/\A\s*\{|\}\s*\z//g;
3955 2 my $copy = Langertha::Holmgang::Sim::Linux::clone_state($t);
3956 2 my $e = _nft_set_spec( $copy, $cn, $spec );
3957 2 ▶ return ( $e, 0 ) if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 2 2
3958 2 %$t = %$copy;
3959 2 return ( '', 1 );
3960 }
3961 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
3962 1 ▶ if ( $verb eq 'delete' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($verb eq 'delete') { } 1 0 1
elsif ($verb eq 'flush') { } 0 0 0
3963 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
3964 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
3965 0 delete $t->{sets}{$cn};
3966 0 ▶ delete $t->{sets} unless %{ $t->{sets} };
Branch: 1 branch
BranchTrueFalseTotal
unless %{$$t{"sets"};} 0 0 0
3967 }
3968 0 elsif ( $verb eq 'flush' ) { $s->{elements} = [] }
3969 0 else { return $syntax->(qq{string "$verb"}) }
3970 0 return ( '', 1 );
3971 }
3972 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
3973 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
3974 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
3975 2 my $copy = Langertha::Holmgang::Sim::Linux::clone_state($s);
3976 2 my $e = _nft_add_elements( $copy, $list );
3977 2 ▶ return ( $e, 0 ) if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 1 1 2
3978 1 %$s = %$copy;
3979 1 return ( '', 1 );
3980 }
3981 1 ▶ if ( $verb eq 'delete' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "delete") 1 0 1
3982 1 my @del = grep {length} map { s/\A\s+|\s+\z//gr } split /,/, $list;
3983 1 for my $d (@del) {
3984 return ( "Error: Could not process rule: No such file or directory\ndelete element $tn $cn { $d }", 0 )
3985 1 ▶ unless grep { $_ eq $d } @{ $s->{elements} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $d;} @{$$s{"elements"};} 0 1 1
3986 }
3987 1 my %d = map { $_ => 1 } @del;
3988 1 $s->{elements} = [ grep { !$d{$_} } @{ $s->{elements} } ];
3989 1 return ( '', 1 );
3990 }
3991 0 return $syntax->(qq{string "$verb"});
3992 }
3993  
3994 # /etc/nftables.conf, wenn die Datei nicht eigens im Zustand steht: der laufende
3995 # Regelsatz im Dateiformat (so wie ihn `nft list ruleset > …` schriebe).
3996 4 ▶sub _nft_conf {
Subroutine _nft_conf: called CC=3 SCAR=11.1
3997 4 my ($dev) = @_;
3998 4 my @l = ( '#!/usr/sbin/nft -f', '', 'flush ruleset', '' );
3999 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
4000 4 return join( "\n", @l );
4001 }
4002  
4003 # Lesen legt keinen leeren Regelsatz an (sonst sieht "sonst nichts geaendert" eine Aenderung)
4004 67 ▶sub _nft {
Subroutine _nft: called CC=4 SCAR=14.0
4005 67 my ( $dev, $av ) = @_;
4006 67 my $had = exists $dev->{nft};
4007 67 my @r = _nft_cmd( $dev, $av );
4008 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
4009 67 return @r;
4010 }
4011  
4012 67 ▶sub _nft_cmd {
Subroutine _nft_cmd: called CC=113 SCAR=59.6
4013 67 my ( $dev, $av ) = @_;
4014 67 my @a = @$av;
4015 67 my ( $with_h, $check ) = ( 0, 0 );
4016 # Optionen duerfen wie bei getopt auch hinter dem Befehl stehen (nft list ruleset -a);
4017 # "priority -10" ist keine Option
4018 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
4019 67 my @opt;
4020 67 ▶ for ( my $i = 0; $i < @a; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @a) 412 67 479
4021 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
4022 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
4023 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
4024 14 push @opt, @take;
4025 14 $i--;
4026 }
4027 67 unshift @a, @opt;
4028 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
4029 15 my $o = shift @a;
4030 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
4031 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
4032 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
4033 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
4034 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
4035 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
4036 4 return _nft_load( $dev, $t, $f, $check );
4037 }
4038 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
4039 1 push @GAPS, join( ' ', 'nft', @$av );
4040 1 return ( '', 0 );
4041 }
4042 }
4043 0 ▶ @a = map { split /\s+/ } @a if @a == 1; # nft 'add rule …'
Branch: 1 branch
BranchTrueFalseTotal
if @a == 1 0 61 61
4044 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
4045 # Lesen legt keinen nft-Zustand an (sonst saehe "sonst nichts geaendert" eine Aenderung; wie bei allen Lesebefehlen)
4046 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
4047 61 _handles($_) for values %$T; # Handles stehen fest, bevor sich etwas aendert (wie im Kernel von Anfang an)
4048 61 ▶ my $syntax = sub { ( "Error: syntax error, unexpected $_[0]\n" . join( ' ', @$av ), 0 ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
4049 61 ▶ if ( $verb eq 'list' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "list") 19 42 61
4050 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
4051 19 ▶ if ( $what eq 'ruleset' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "ruleset") 9 10 19
4052 9 my @l;
4053 9 push @l, _nft_table_text( $_, $T->{$_}, $with_h ) for sort keys %$T;
4054 9 return ( join( "\n", @l ), 1 );
4055 }
4056 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
4057 9 ▶ if ( $what eq 'sets' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "sets") 0 9 9
4058 0 my @l;
4059 0 for my $tn ( sort keys %$T ) {
4060 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
4061 0 push @l, "table $tn {", ( map { _nft_set_text( $_, $T->{$tn}{sets}{$_} ) } sort keys %{ $T->{$tn}{sets} } ), '}';
4062 }
4063 0 return ( join( "\n", @l ), 1 );
4064 }
4065 9 my ( $fam, $tab, $chain ) = @a;
4066 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
4067 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
4068 8 my $tn = "$fam $tab";
4069 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
4070 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
4071 8 ▶ if ( $what eq 'set' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "set") 1 7 8
4072 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
4073 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
4074 1 return ( join( "\n", "table $tn {", _nft_set_text( $sn, $T->{$tn}{sets}{$sn} ), '}' ), 1 );
4075 }
4076 7 ▶ if ( $what eq 'chain' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "chain") 7 0 7
4077 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
4078 7 return ( join( "\n", "table $tn {", _nft_chain_text( $tn, $T->{$tn}, $chain, $with_h, _handles( $T->{$tn} ) ), '}' ), 1 );
4079 }
4080 0 return $syntax->("string \"$what\"");
4081 }
4082 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
4083 2 %$T = ();
4084 2 return ( '', 1 );
4085 }
4086 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
4087 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
4088 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
4089 40 my $tab;
4090 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
4091 0 else { ( $fam, $tab ) = ( 'ip', $fam ) }
4092 40 ▶ return $syntax->('end of file') unless defined $tab;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tab 0 40 40
4093 40 my $tn = "$fam $tab";
4094 40 ▶ if ( $obj eq 'table' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj eq "table") 1 39 40
4095 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
4096 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
4097 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
4098 1 return ( '', 1 );
4099 }
4100 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
4101 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
4102 0 elsif ( $verb eq 'flush' ) { $_->{rules} = [] for values %{ $T->{$tn}{chains} } }
4103 0 return ( '', 1 );
4104 }
4105 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
4106 39 my $t = $T->{$tn};
4107 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
4108 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
4109 33 ▶ if ( $obj eq 'chain' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj eq "chain") 7 26 33
4110 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
4111 3 my $spec = join ' ', @a;
4112 3 $spec =~ s/\A\{|\}\z//g;
4113 3 my %c = ( rules => [] );
4114 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
4115 1 @c{qw( type hook priority )} = ( $1, $2, $3 );
4116 1 ▶ $c{policy} = $1 if $spec =~ /policy\s+(accept|drop)/;
Branch: 1 branch
BranchTrueFalseTotal
if $spec =~ /policy\s+(accept|drop)/ 1 0 1
4117 }
4118 1 elsif ( $spec =~ /\A\s*policy\s+(accept|drop)\s*;?\s*\z/ ) { $c{policy} = $1 }
4119 0 elsif ( $spec =~ /\S/ ) { return $syntax->(qq{string "$spec"}) }
4120 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
4121 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
4122 3 ▶ $t->{chains}{$cn}{policy} = $c{policy} if $c{policy};
Branch: 1 branch
BranchTrueFalseTotal
if $c{"policy"} 2 1 3
4123 3 return ( '', 1 );
4124 }
4125 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
4126 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
4127 4 elsif ( $verb eq 'flush' ) { $t->{chains}{$cn}{rules} = []; $t->{chains}{$cn}{_handles} = [] }
4128 4 return ( '', 1 );
4129 }
4130 26 ▶ return $syntax->(qq{string "$obj"}) unless $obj eq 'rule';
Branch: 1 branch
BranchTrueFalseTotal
unless $obj eq "rule" 0 26 26
4131 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
4132 25 my $handles = _handles($t)->{$cn};
4133 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
4134 25 my $pos;
4135 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
4136 3 my ( $k, $v ) = splice @a, 0, 2;
4137 3 ▶ return $syntax->(qq{string "$v"}) unless $v =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ /\A\d+\z/ 0 3 3
4138 3 ▶ if ( $k eq 'index' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq 'index') { } 0 3 3
4139 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
4140 0 $pos = $v;
4141 }
4142 else {
4143 3 my ($i) = grep { $handles->[$_] == $v } 0 .. $#$handles;
4144 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
4145 3 $pos = $i;
4146 }
4147 3 ▶ if ( $verb eq 'delete' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "delete") 2 1 3
4148 2 splice @$rules, $pos, 1;
4149 2 splice @{ $ch->{_handles} }, $pos, 1;
4150 2 return ( '', 1 );
4151 }
4152 }
4153 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
4154 . ", expecting handle\n" . join( ' ', 'delete rule', $tn, $cn, @a ), 0 ) if $verb eq 'delete';
4155 22 my $text = _norm_rule( join ' ', @a );
4156 22 ▶ return $syntax->('end of file') unless length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless length $text 0 22 22
4157 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
4158 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
4159 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
4160 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/;
4161 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
4162 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
4163 16 _nft_gap( $ch, $text );
4164 16 ▶ if ( $verb eq 'replace' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "replace") 0 16 16
4165 0 ▶ return ( "Error: syntax error, unexpected string, expecting handle", 0 ) unless defined $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
4166 0 $rules->[$pos] = $text;
4167 0 return ( '', 1 );
4168 }
4169 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
4170 16 splice @$rules, $at, 0, $text;
4171 16 splice @{ $ch->{_handles} }, $at, 0, $t->{_next_handle}++;
4172 16 return ( '', 1 );
4173 }
4174  
4175 # --- sysctl ------------------------------------------------------------------------
4176  
4177 5 ▶sub _sysctl {
Subroutine _sysctl: called CC=35 SCAR=42.9
4178 5 my ( $dev, $av ) = @_;
4179 5 my @a = @$av;
4180 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
4181 5 my ( $w, $all, $load, $quiet ) = ( 0, 0, undef, 0 );
4182 5 my @keys;
4183 5 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 7 5 12
4184 7 my $x = shift @a;
4185 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
4186 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
4187 0 elsif ( $x eq '-q' ) { $quiet = 1 }
4188 ▶ 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
4189 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
4190 1 elsif ( $x eq '--system' ) { $load = '--system' }
4191 4 else { push @keys, $x }
4192 }
4193 3 ▶ my $set = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
4194 3 my ( $k, $v ) = @_;
4195 3 ( my $p = $k ) =~ s{\.}{/}g;
4196 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
4197 2 $s->{$k} = $v;
4198 2 return "$k = $v";
4199 5 };
4200 5 ▶ if ( defined $load ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $load) 1 4 5
4201 my @files = $load eq '--system'
4202 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
4203 : ($load);
4204 1 my @out;
4205 1 my $ok = 1;
4206 1 for my $f (@files) {
4207 2 my $t = _file_text( $dev, $f );
4208 2 ▶ if ( !defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 1 1 2
4209 1 ▶ next if $load eq '--system';
Branch: 1 branch
BranchTrueFalseTotal
if $load eq "--system" 1 0 1
4210 0 return ( "sysctl: cannot open \"$f\": No such file or directory", 0 );
4211 }
4212 1 ▶ push @out, "* Applying $f ..." if $load eq '--system';
Branch: 1 branch
BranchTrueFalseTotal
if $load eq "--system" 1 0 1
4213 1 for my $l ( split /\n/, $t ) {
4214 1 $l =~ s/[#;].*//;
4215 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
4216 1 ( my $k = $1 ) =~ s{/}{.}g;
4217 1 my $r = $set->( $k, $2 );
4218 1 ▶ $ok = 0 if $r =~ /\Asysctl:/;
Branch: 1 branch
BranchTrueFalseTotal
if $r =~ /\Asysctl:/ 0 1 1
4219 1 push @out, $r;
4220 }
4221 }
4222 1 return ( join( "\n", @out ), $ok );
4223 }
4224 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
4225 0 ▶ return ( join( "\n", map {"$_ = $s->{$_}"} sort keys %$s ), 1 ) if $all;
Branch: 1 branch
BranchTrueFalseTotal
if $all 0 0 0
4226 0 return ( "Usage:\n sysctl [options] [variable[=value] ...]", 0 );
4227 }
4228 4 my @out;
4229 4 my $ok = 1;
4230 4 for my $k (@keys) {
4231 4 ▶ if ( $k =~ /\A([^=]+)=(.*)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /\A([^=]+)=(.*)\z/) 2 2 4
4232 2 my $r = $set->( $1, $2 );
4233 2 ▶ $ok = 0 if $r =~ /\Asysctl:/;
Branch: 1 branch
BranchTrueFalseTotal
if $r =~ /\Asysctl:/ 1 1 2
4234 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
4235 2 next;
4236 }
4237 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
4238 2 ( my $p = $k ) =~ s{\.}{/}g;
4239 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
4240 1 push @out, "$k = $s->{$k}";
4241 }
4242 4 return ( join( "\n", @out ), $ok );
4243 }
4244  
4245 0 ▶sub _conntrack {
Subroutine _conntrack: not called CC=9 SCAR=45.0
4246 0 my ( $dev, $av ) = @_;
4247 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
4248 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
4249 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
4250 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
4251 return ( "cpu=0 \tfound=0 invalid=0 insert=0 insert_failed=0 drop="
4252 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
4253 }
4254 0 return ( "conntrack v1.4.7 (conntrack-tools): 0 flow entries have been shown.", 1 );
4255 }
4256  
4257 # --- Dateien mit Rechten und Groesse, Dateisysteme ----------------------------------
4258  
4259 88 my %UNIT = ( '' => 1, B => 1, K => 1024, M => 1024**2, G => 1024**3, T => 1024**4 );
4260  
4261 # Zeit der Simulation: Dienstag, 20.10.2026 12:00 (fest, deterministisch).
4262 88 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 );
4263 223 ▶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
4264  
4265 # Zeit der Umgebung aus pki.now (dieses Geraet, sonst eines im Zustand): Sekunden oder undef
4266 27 ▶sub _pki_now {
Subroutine _pki_now: called CC=7 SCAR=20.2
4267 27 my ($dev) = @_;
4268 27 ▶ 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
0027
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
4269 53 ▶ 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"} 50 3 53
Condition66%4/6
ref $d eq "HASH" and ref $$d{"pki"} eq "HASH" and $$d{"pki"}{"now"}
!ll&&!rl&&r
5003
ref $d eq "HASH" and ref $$d{"pki"} eq "HASH"
!ll&&!rl&&r
0503
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
4270 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
4271 3 require Time::Local;
4272 3 return Time::Local::timegm( $sec, $m, $h, $D, $M - 1, $Y );
4273 }
4274 24 return undef;
4275 }
4276  
4277 # free [-m|-h]: Speicher aus memory des Geraets (MB), sonst eine kleine VM
4278 2 ▶sub _free_mem {
Subroutine _free_mem: called CC=2 SCAR=7.1
4279 2 my ( $dev, $av ) = @_;
4280 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
4281 2 my $h = grep { $_ eq '-h' } @$av;
4282 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
4283 return ( join( "\n", ' total used free shared buff/cache available',
4284 sprintf( 'Mem: %12s%12s%12s%12s%12s%12s', $f->( $m->{total} ), $f->( $m->{used} ), $f->( $m->{free} ), $f->(12), $f->( $m->{cache} ),
4285 2 $f->( $m->{total} - $m->{used} ) ), sprintf( 'Swap: %12s%12s%12s', $f->(0), $f->(0), $f->(0) ) ), 1 );
4286 }
4287  
4288 # "Aug 2 03:10" (Jahr 2026) -> Sekunden; ohne Angabe: jetzt
4289 96 ▶sub _mtime {
Subroutine _mtime: called CC=7 SCAR=20.1
4290 96 my ($e) = @_;
4291 96 ▶ my $m = ( ref $e eq 'HASH' ? $e->{mtime} : undef ) // return _sim_now();
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' ? : 96 0 96
Condition100%2/2
(ref $e eq "HASH" ? $$e{"mtime"} : undef) // (return _sim_now())
l!l
5244
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
4292 52 require Time::Local;
4293 # aeltere Dateien wie ls sie zeigt: "Mar 12 2025" (Mitternacht)
4294 52 ▶ 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 51 52
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
4295 51 ▶ 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() 51 0 51
4296 51 ▶ return Time::Local::timegm( 0, $mi, $h, $d, $MON{$mon} // 9, 2026 );
Condition50%1/2
$MON{$mon} // 9
l!l
510
MC/DC0%0/1
$MON{$mon} // 9
$MON{$mon}
Truth table50%1/2
A
A= $MON{$mon}
Aresult
11
00
4297 }
4298  
4299 # Alte Journal-Archive loeschen, bis hoechstens $limit Bytes belegt sind bzw.
4300 # keines aelter als $age Sekunden ist (system.journal bleibt).
4301 2 ▶sub _journal_vacuum {
Subroutine _journal_vacuum: called CC=11 SCAR=26.3
4302 2 my ( $dev, %o ) = @_;
4303 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
4304 2 grep { $_ !~ m{/system\.journal\z|/user-\d+\.journal\z} } _under( $dev, '/var/log/journal' );
4305 2 my $t = 0;
4306 2 $t += _file_size( _file_entry( $dev, $_ ) ) for _under( $dev, '/var/log/journal' );
4307 2 my $freed = 0;
4308 2 for my $p (@j) {
4309 2 my $e = _file_entry( $dev, $p );
4310 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
4311 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
4312 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
4313 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
4314 1 $freed += _file_size($e);
4315 1 delete $dev->{files}{$p};
4316 }
4317 2 return $freed;
4318 }
4319  
4320 9 ▶sub _secs {
Subroutine _secs: called CC=5 SCAR=16.8
4321 9 my ($v) = @_;
4322 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
4323 9 my %f = ( s => 1, min => 60, m => 60, h => 3600, d => 86400, day => 86400, days => 86400, w => 604800, week => 604800,
4324 weeks => 604800, month => 2592000, months => 2592000, y => 31536000, second => 1, seconds => 1, sec => 1, secs => 1,
4325 minute => 60, minutes => 60, mins => 60, hour => 3600, hours => 3600, hr => 3600 );
4326 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
4327 }
4328  
4329 # "14G", "1.5M", 12345 -> Bytes
4330 304 ▶sub _bytes {
Subroutine _bytes: called CC=4 SCAR=14.1
4331 304 my ($v) = @_;
4332 304 ▶ return 0 unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 304 304
4333 304 ▶ return 0 + $v if $v =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /\A\d+\z/ 19 285 304
4334 285 ▶ 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 285 0 285
4335 285 return int( $n * $UNIT{ uc $u } );
4336 }
4337  
4338 # Bytes -> wie df -h / ls -lh (1 Nachkommastelle unter 10)
4339 76 ▶sub _human {
Subroutine _human: called CC=4 SCAR=13.9
4340 76 my ($b) = @_;
4341 76 for my $u (qw( T G M K )) {
4342 165 my $f = $UNIT{$u};
4343 165 ▶ next if $b < $f;
Branch: 1 branch
BranchTrueFalseTotal
if $b < $f 90 75 165
4344 75 my $x = $b / $f;
4345 75 ▶ 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 49 75
4346 }
4347 1 return "$b";
4348 }
4349  
4350 # Ziel eines Symlinks als absoluter, bereinigter Pfad
4351 17 ▶sub _link_target {
Subroutine _link_target: called CC=3 SCAR=11.0
4352 17 my ( $from, $t ) = @_;
4353 17 ( my $dir = $from ) =~ s{/[^/]+\z}{};
4354 17 ▶ $t = "$dir/$t" unless $t =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ m[\A/] 7 10 17
4355 17 ▶ 1 while $t =~ s{/[^/]+/\.\./}{/};
Branch: 1 branch
BranchTrueFalseTotal
$t =~ s[/[^/]+/\.\./][/] and do { '???' } 2 17 19
4356 17 $t =~ s{/\./}{/}g;
4357 17 $t =~ s{(?<=.)/+\z}{};
4358 17 return $t;
4359 }
4360  
4361 # Pfad durch einen Symlink davor (/srv/app/current/x -> /srv/app/releases/1/x); undef ohne
4362 26684 ▶sub _via_link {
Subroutine _via_link: called CC=9 SCAR=22.5
4363 26684 my ( $dev, $path, $depth ) = @_;
4364 26684 ▶ 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 26618 26684
Condition80%4/5
($depth // 0) > 5 or ref $$dev{"files"} ne "HASH"
l!l&&r!l&&!r
06626618
$depth // 0
l!l
626678
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
4365 26618 my @seg = split m{/}, $path;
4366 26618 for my $i ( 1 .. $#seg - 1 ) {
4367 52834 my $pre = join '/', @seg[ 0 .. $i ];
4368 52834 my $e = $dev->{files}{$pre};
4369 52834 ▶ next unless ref $e eq 'HASH' && defined $e->{link};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" and defined $$e{"link"} 52828 6 52834
Condition66%2/3
ref $e eq "HASH" and defined $$e{"link"}
!ll&&!rl&&r
5282806
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
4370 6 my $new = join '/', _link_target( $pre, $e->{link} ), @seg[ $i + 1 .. $#seg ];
4371 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
4372 }
4373 26612 return undef;
4374 }
4375  
4376 # Eintrag einer Datei als Hash { content, size, mode, owner, group, open_by, link } (Kopie fuer Text)
4377 25894 ▶sub _file_entry {
Subroutine _file_entry: called CC=14 SCAR=26.4
4378 25894 my ( $dev, $path ) = @_;
4379 25894 ▶ return _file_entry( $dev, _dotdot($path) ) if $path =~ m{\A/.*/\.\.?(?:/|\z)};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[\A/.*/\.\.?(?:/|\z)] 1 25893 25894
4380 25893 ▶ 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 25890 25893
Condition100%6/6
not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and defined(my $r = _via_link($dev, $path))
!ll&&!rl&&r
1014248763
ref $$dev{'files'} eq 'HASH' && exists $$dev{'files'}{$path}
!ll&&!rl&&r
36248431014
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
4381 3 return _file_entry( $dev, $r );
4382 }
4383 25890 ▶ 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 25885 25890
Condition100%6/6
not ref $$dev{"files"} eq "HASH" && exists $$dev{"files"}{$path} and my $v = _git_virtual($dev, $path)
!ll&&!rl&&r
1014248715
ref $$dev{'files'} eq 'HASH' && exists $$dev{'files'}{$path}
!ll&&!rl&&r
36248401014
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
4384 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
4385 }
4386 25885 ▶ 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} 24871 1014 25885
Condition100%3/3
ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{$path}
!ll&&!rl&&r
36248351014
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
4387 1014 my $e = $dev->{files}{$path};
4388 1014 ▶ return ref $e eq 'HASH' ? $e : { content => $e };
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' ? : 522 492 1014
4389 }
4390  
4391 214 ▶sub _file_size {
Subroutine _file_size: called CC=3 SCAR=11.0
4392 214 my ($e) = @_;
4393 214 ▶ return _bytes( $e->{size} ) if defined $e->{size};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$e{"size"} 52 162 214
4394 162 ▶ return length( $e->{content} // '' );
Condition100%2/2
$$e{"content"} // ""
l!l
1611
MC/DC100%1/1
$$e{"content"} // ""
$$e{"content"}
Truth table100%2/2
A
A= $$e{"content"}
Aresult
11
00
4395 }
4396  
4397 # Inhalt setzen; Metadaten (Rechte, Eigentuemer) bleiben, eine feste Groesse faellt weg.
4398 414 ▶sub _file_set {
Subroutine _file_set: called CC=2 SCAR=6.9
4399 414 my ( $dev, $path, $text ) = @_;
4400 414 my $old = $dev->{files}{$path};
4401 414 ▶ if ( ref $old eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $old eq 'HASH') { } 6 408 414
4402 6 my %e = %$old;
4403 6 delete @e{qw( size link )};
4404 6 $e{content} = $text;
4405 6 $dev->{files}{$path} = \%e;
4406 }
4407 408 else { $dev->{files}{$path} = $text }
4408 414 return;
4409 }
4410  
4411 # Verzeichnisse ergeben sich aus den Dateipfaden (und den Einhaengepunkten).
4412 # Verzeichnisse, die jedes Debian 12 (mit cron, OpenSSH, sudo) hat — leer, wenn der Zustand nichts darin nennt
4413 88 our %STD_DIRS = map { $_ => 1 } qw( /bin /boot /dev /etc /home /lib /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp
4414 /usr /usr/bin /usr/sbin /usr/lib /usr/local /usr/local/bin /usr/local/sbin /usr/local/etc /usr/local/lib /usr/share
4415 /var /var/backups /var/cache /var/lib /var/log /var/mail /var/spool /var/tmp /var/spool/cron /var/spool/cron/crontabs
4416 /etc/cron.d /etc/cron.daily /etc/cron.hourly /etc/cron.weekly /etc/cron.monthly /etc/default /etc/ssh /etc/ssh/sshd_config.d
4417 /etc/sudoers.d /etc/sysctl.d /etc/systemd /etc/systemd/system /etc/security /etc/ssl /etc/ssl/certs /etc/ssl/private
4418 /etc/logrotate.d /etc/apt /etc/network /lib/systemd /lib/systemd/system );
4419  
4420 1454 ▶sub _is_dir {
Subroutine _is_dir: called CC=21 SCAR=30.9
4421 1454 my ( $dev, $path ) = @_;
4422 1454 ▶ $path = _dotdot($path) if $path =~ m{\A/.*/\.\.?(?:/|\z)};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[\A/.*/\.\.?(?:/|\z)] 0 1454 1454
4423 1454 $path =~ s{/+\z}{};
4424 1454 ▶ return 1 if $STD_DIRS{$path};
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::STD_DIRS{$path} 474 980 1454
4425 980 ▶ return 1 if $path eq '' || exists( ( $dev->{mounts} || {} )->{$path} );
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "" or exists(($$dev{"mounts"} || {})->{$path}) 17 963 980
Condition100%5/5
$path eq "" or exists(($$dev{"mounts"} || {})->{$path})
l!l&&r!l&&!r
125963
$$dev{'mounts'} || {}
l!l
95873
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
4426 963 ▶ return 1 if exists( ( $dev->{dirs} || {} )->{$path} );
Branch: 1 branch
BranchTrueFalseTotal
if exists(($$dev{"dirs"} || {})->{$path}) 140 823 963
Condition100%2/2
$$dev{'dirs'} || {}
l!l
311652
MC/DC100%1/1
$$dev{'dirs'} || {}
$$dev{'dirs'}
Truth table100%2/2
A
A= $$dev{'dirs'}
Aresult
11
00
4427 823 ▶ return 1 if exists( ( $dev->{_dirs} || {} )->{$path} ); # leer geraeumt (rm, mv): bleibt
Branch: 1 branch
BranchTrueFalseTotal
if exists(($$dev{"_dirs"} || {})->{$path}) 7 816 823
Condition100%2/2
$$dev{'_dirs'} || {}
l!l
21802
MC/DC100%1/1
$$dev{'_dirs'} || {}
$$dev{'_dirs'}
Truth table100%2/2
A
A= $$dev{'_dirs'}
Aresult
11
00
4428 816 ▶ my $e = ref $dev->{files} eq 'HASH' ? $dev->{files}{$path} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'} eq 'HASH' ? : 804 12 816
4429 816 ▶ 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 810 816
Condition70%7/10
ref $e eq "HASH" and defined $$e{"link"} and ($_[2] // 0) < 5
!ll&&!rl&&r
81006
ref $e eq "HASH" and defined $$e{"link"}
!ll&&!rl&&r
80466
$_[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
4430 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 810 810
Condition66%2/3
not defined $e and defined(my $r = _via_link($dev, $path))
!ll&&!rl&&r
397710
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
4431 810 ▶ if ( my $v = _git_virtual( $dev, $path ) ) { return 1 if $v->{dir} }
Branch: 2 branches
BranchTrueFalseTotal
if (my $v = _git_virtual($dev, $path)) 1 809 810
if $$v{"dir"} 1 0 1
4432 809 ▶ return scalar grep { index( $_, "$path/" ) == 0 } keys %{ $dev->{files} || {} };
Condition100%2/2
$$dev{'files'} || {}
l!l
79712
MC/DC100%1/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table100%2/2
A
A= $$dev{'files'}
Aresult
11
00
4433 }
4434  
4435 1692 ▶sub _under {
Subroutine _under: called CC=3 SCAR=11.0
4436 1692 my ( $dev, $path ) = @_;
4437 1692 $path =~ s{/+\z}{};
4438 1692 ▶ return sort grep { $path eq '' ? 1 : index( $_, "$path/" ) == 0 } keys %{ $dev->{files} || {} };
Branch: 1 branch
BranchTrueFalseTotal
$path eq '' ? : 0 8652 8652
Condition100%2/2
$$dev{'files'} || {}
l!l
164844
MC/DC100%1/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table100%2/2
A
A= $$dev{'files'}
Aresult
11
00
4439 }
4440  
4441 # Einhaengepunkte; ohne Angabe im Fall ein Wurzeldateisystem mit reichlich Platz
4442 176 ▶sub _mounts {
Subroutine _mounts: called CC=3 SCAR=11.0
4443 176 my ($dev) = @_;
4444 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
4445 37 return { '/' => { dev => '/dev/vda1', size => '40G', used => '9G' } };
4446 }
4447  
4448 # mount: die Einhaengepunkte mit Typ und Optionen
4449 3 ▶sub _mount_cmd {
Subroutine _mount_cmd: called CC=7 SCAR=20.2
4450 3 my ( $dev, $av ) = @_;
4451 3 ▶ if ( grep { !/\A-/ } @$av ) { push @GAPS, join( ' ', 'mount', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not /\A-/;} @$av) 1 2 3
4452 2 my $m = _mounts($dev);
4453 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' ),
4454 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
4455 2 unshift @l, 'proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)', 'sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)';
4456 2 return ( join( "\n", @l ), 1 );
4457 }
4458  
4459 142 ▶sub _mount_of {
Subroutine _mount_of: called CC=3 SCAR=11.0
4460 142 my ( $dev, $path ) = @_;
4461 38 my ($best) = sort { length $b <=> length $a }
4462 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
4463 142 return $best;
4464 }
4465  
4466 # Belegung je Einhaengepunkt: Grundlast + Dateien + geloeschte, noch offene Dateien
4467 29 ▶sub _df_rows {
Subroutine _df_rows: called CC=13 SCAR=25.9
4468 29 my ($dev) = @_;
4469 29 my $m = _mounts($dev);
4470 29 my %used = map { $_ => _bytes( $m->{$_}{used} ) } keys %$m;
4471 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
4472 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
4473 122 $used{$mp} += _file_size( _file_entry( $dev, $p ) );
4474 }
4475 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
4476 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
4477 1 $used{$mp} += _bytes( $d->{size} );
4478 }
4479 return map {
4480 29 my $size = _bytes( $m->{$_}{size} );
4481 67 ▶ my $u = $used{$_} > $size ? $size : $used{$_};
Branch: 1 branch
BranchTrueFalseTotal
$used{$_} > $size ? : 0 67 67
4482 # fuer root reservierte Bloecke (ext*, reserved_pct) stehen anderen nicht zur Verfuegung
4483 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
4484 67 ▶ my $av = $size - $u - $res > 0 ? $size - $u - $res : 0;
Branch: 1 branch
BranchTrueFalseTotal
$size - $u - $res > 0 ? : 67 0 67
4485 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
4486 pct => $u + $av ? int( 100 * $u / ( $u + $av ) + 0.999 ) : 0 };
4487 } sort keys %$m;
4488 }
4489  
4490 9 ▶sub _free {
Subroutine _free: called CC=2 SCAR=7.0
4491 9 my ( $dev, $mount ) = @_;
4492 9 my ($r) = grep { $_->{mount} eq $mount } _df_rows($dev);
4493 9 ▶ return $r ? $r->{avail} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 9 0 9
4494 }
4495  
4496 14 ▶sub _df {
Subroutine _df: called CC=15 SCAR=31.1
4497 14 my ( $dev, $av ) = @_;
4498 14 my $h = grep {/\A-\w*h/} @$av;
4499 14 my @paths = grep { !/\A-/ } @$av;
4500 14 my @rows = _df_rows($dev);
4501 14 ▶ return ( 'df: no file systems processed', 0 ) unless @rows;
Branch: 1 branch
BranchTrueFalseTotal
unless @rows 0 14 14
4502 14 ▶ if (@paths) {
Branch: 1 branch
BranchTrueFalseTotal
if (@paths) 14 0 14
4503 14 my %want;
4504 14 for my $p (@paths) {
4505 14 my $mp = _mount_of( $dev, $p );
4506 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
4507 14 $want{$mp} = 1;
4508 }
4509 14 @rows = grep { $want{ $_->{mount} } } @rows;
4510 }
4511 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
4512 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
4513 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
4514 push @l, sprintf( '%-15s ' . ( $ty ? '%-5s ' : '%s' ) . '%6s %6s %6s %4s %s', $_->{dev}, $ty ? $_->{type} : '', $f->( $_->{size} ), $f->( $_->{used} ), $f->( $_->{avail} ), "$_->{pct}%", $_->{mount} )
4515 14 ▶ for @rows;
Branch: 2 branches
BranchTrueFalseTotal
$ty ? : 0 14 14
$ty ? : 0 14 14
4516 14 return ( join( "\n", @l ), 1 );
4517 }
4518  
4519 1 ▶sub _du {
Subroutine _du: called CC=12 SCAR=29.8
4520 1 my ( $dev, $av ) = @_;
4521 1 my $h = grep {/\A-\w*h/} @$av;
4522 1 my $sum = grep {/\A-\w*s/} @$av;
4523 1 my @paths = grep { !/\A-/ } @$av;
4524 1 ▶ @paths = ('.') unless @paths;
Branch: 1 branch
BranchTrueFalseTotal
unless @paths 0 1 1
4525 1 my @l;
4526 1 for my $p (@paths) {
4527 1 my $total;
4528 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
4529 elsif ( _is_dir( $dev, $p ) ) {
4530 1 $total = 0;
4531 1 my %sub;
4532 1 for my $f ( _under( $dev, $p ) ) {
4533 1 my $sz = _file_size( _file_entry( $dev, $f ) );
4534 1 $total += $sz;
4535 1 ( my $d = $f ) =~ s{/[^/]+\z}{};
4536 0 ▶ while ( length $d > length $p ) { $sub{$d} += $sz; $d =~ s{/[^/]+\z}{} }
Branch: 1 branch
BranchTrueFalseTotal
if (length $d > length $p) 0 1 1
4537 }
4538 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
4539 }
4540 0 else { return ( "du: cannot access '$p': No such file or directory", 0 ) }
4541 1 ▶ push @l, ( $h ? _human($total) : int( $total / 1024 ) ) . "\t$p";
Branch: 1 branch
BranchTrueFalseTotal
$h ? : 1 0 1
4542 }
4543 1 return ( join( "\n", @l ), 1 );
4544 }
4545  
4546 274 ▶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
21460
MC/DC100%1/1
$$e{"mode"} // "0644"
$$e{"mode"}
Truth table100%2/2
A
A= $$e{"mode"}
Aresult
11
00
4547  
4548 112 ▶sub _mode_text {
Subroutine _mode_text: called CC=11 SCAR=24.0
4549 112 my ( $m, $dir, $link ) = @_;
4550 112 ▶ my $s = $link ? 'l' : $dir ? 'd' : '-';
Branch: 2 branches
BranchTrueFalseTotal
$link ? : 1 111 112
$dir ? : 68 43 111
4551 112 for my $sh ( 6, 3, 0 ) {
4552 336 my $b = ( $m >> $sh ) & 7;
4553 336 my $sp = $m & { 6 => 04000, 3 => 02000, 0 => 01000 }->{$sh};
4554 336 ▶ my $x = $sp ? ( $sh ? ( $b & 1 ? 's' : 'S' ) : ( $b & 1 ? 't' : 'T' ) ) : ( $b & 1 ? 'x' : '-' );
Branch: 5 branches
BranchTrueFalseTotal
$sp ? : 8 328 336
$sh ? : 7 1 8
$b & 1 ? : 7 0 7
$b & 1 ? : 1 0 1
$b & 1 ? : 210 118 328
4555 336 ▶ $s .= ( $b & 4 ? 'r' : '-' ) . ( $b & 2 ? 'w' : '-' ) . $x;
Branch: 2 branches
BranchTrueFalseTotal
$b & 4 ? : 313 23 336
$b & 2 ? : 119 217 336
4556 }
4557 112 return $s;
4558 }
4559  
4560 88 ▶sub _ls_line {
Subroutine _ls_line: called CC=16 SCAR=27.9
4561 88 my ( $dev, $path, $name, $h ) = @_;
4562 88 my $e = _file_entry( $dev, $path );
4563 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 88 88
Condition66%2/3
not $e and defined(my $b = _virtual_bin($dev, $path))
!ll&&!rl&&r
29590
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
4564 88 ▶ if ( !$e ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($e) 59 29 88
4565 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
4566 return sprintf( '%s 2 %-8s %-8s %8s %s %s', _mode_text( oct( $d->{mode} // '0755' ), 1 ), $d->{owner} // 'root',
4567 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
4568 }
4569 29 my $size = _file_size($e);
4570 28 ▶ 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 27 28
$h ? : 0 29 29
$$e{'link'} ? : 1 28 29
Condition100%6/6
$$e{"type"} // ""
l!l
127
$$e{"owner"} // "root"
l!l
1118
$$e{"group"} // "root"
l!l
1019
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
4571 $e->{owner} // 'root', $e->{group} // 'root', $h ? _human($size) : $size, _ls_time($e), $name,
4572 29 ▶ $e->{link} ? " -> $e->{link}" : '' );
Branch: 1 branch
BranchTrueFalseTotal
$$e{'link'} ? : 1 28 29
4573 }
4574  
4575 83 ▶sub _ls {
Subroutine _ls: called CC=78 SCAR=47.9
4576 83 my ( $dev, $av ) = @_;
4577 83 local $BIN_MEMO = {};
4578 83 local $LS_TIME;
4579 83 for (@$av) {
4580 130 ▶ if ( $_ eq '--full-time' ) { $LS_TIME = 'full-iso' }
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq '--full-time') { } 1 129 130
elsif (/\A--time-style=(?:posix-)?(full-iso|long-iso|iso)\z/) { } 2 127 129
4581 2 elsif (/\A--time-style=(?:posix-)?(full-iso|long-iso|iso)\z/) { $LS_TIME = $1 }
4582 }
4583 83 ▶ my $opt = join '', map { /\A-(\w+)\z/ ? $1 : '' } @$av;
Branch: 1 branch
BranchTrueFalseTotal
/\A-(\w+)\z/ ? : 39 91 130
4584 83 ▶ $opt .= 'l' if grep { $_ eq '--full-time' } @$av;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "--full-time";} @$av 1 82 83
4585 83 my @paths = grep { !/\A-/ } @$av;
4586 83 ▶ @paths = ('.') unless @paths; # ohne Pfad: das aktuelle Verzeichnis
Branch: 1 branch
BranchTrueFalseTotal
unless @paths 3 80 83
4587 83 ▶ @paths = sort @paths unless $opt =~ /[fU]/; # Operanden sortiert wie GNU ls
Branch: 1 branch
BranchTrueFalseTotal
unless $opt =~ /[fU]/ 83 0 83
4588 83 ▶ my ( $long, $h, $rec ) = ( $opt =~ /[ln]/ ? 1 : 0, $opt =~ /h/ ? 1 : 0, $opt =~ /R/ ? 1 : 0 );
Branch: 3 branches
BranchTrueFalseTotal
$opt =~ /[ln]/ ? : 33 50 83
$opt =~ /h/ ? : 0 83 83
$opt =~ /R/ ? : 1 82 83
4589 83 my $all = $opt =~ /a/;
4590 83 ▶ my $hidden_ok = $all || $opt =~ /A/;
Condition100%3/3
$all || $opt =~ /A/
l!l&&r!l&&!r
7175
MC/DC100%2/2
$all || $opt =~ /A/
$all $opt =~ /A/
Truth table100%3/3
A || B
A= $allB= $opt =~ /A/
ABresult
1X1
011
000
4591 83 ▶ my $multi = @paths > 1 || $rec;
Condition100%3/3
@paths > 1 || $rec
l!l&&r!l&&!r
6176
MC/DC100%2/2
@paths > 1 || $rec
@paths > 1 $rec
Truth table100%3/3
A || B
A= @paths > 1B= $rec
ABresult
1X1
011
000
4592 83 my ( @out, @files_out );
4593 83 my $ok = 1;
4594 # erst Dateien, dann Verzeichnisse (wie GNU ls)
4595 83 my @dirs;
4596 83 for my $p (@paths) {
4597 91 ( my $dir = _absp($p) ) =~ s{(?<=.)/+\z}{}; # relativ zum aktuellen Verzeichnis, angezeigt wie angegeben
4598 91 ▶ my $le = ref $dev->{files} eq 'HASH' ? $dev->{files}{$dir} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'} eq 'HASH' ? : 91 0 91
4599 91 my $followed;
4600 91 ▶ 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 90 91
elsif (not $le and defined(my $r = _via_link($dev, $dir))) { } 0 110 110
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
9001
ref $le eq "HASH" and defined $$le{"link"} and !($opt =~ /[ld]/) || $p =~ m[/\z]
!ll&&!rl&&r
9001
ref $le eq "HASH" and defined $$le{"link"}
!ll&&!rl&&r
71191
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
4601 1 $dir = _link_target( $dir, $le->{link} ); # ls link/ bzw. ohne -l: Inhalt des Ziels
4602 1 $followed = 1;
4603 }
4604 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
20700
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
4605 # als Benutzer: x auf dem Weg, r am Verzeichnis
4606 91 ▶ 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 88 91
Condition50%3/6
_who() ne "root" and _file_entry($dev, $dir) || _is_dir($dev, $dir)
!ll&&!rl&&r
8803
_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
4607 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
4608 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
4609 1 push @out, "ls: cannot open directory '$p': Permission denied";
4610 1 $ok = 0;
4611 1 next;
4612 }
4613 }
4614 # usrmerge: /bin und /sbin sind Verweise nach usr/ (ls -l zeigt den Verweis)
4615 89 ▶ 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 88 89
Condition77%7/9
$dir =~ m[\A/s?bin\z] and $opt =~ /[ld]/ and not $p =~ m[/\z] and not $le
!ll&&!rl&&r
8801
$dir =~ m[\A/s?bin\z] and $opt =~ /[ld]/ and not $p =~ m[/\z]
!ll&&!rl&&r
8801
$dir =~ m[\A/s?bin\z] and $opt =~ /[ld]/
!ll&&!rl&&r
8621
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
4616 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
4617 1 next;
4618 }
4619 88 ▶ 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 86 88
$long ? : 2 0 2
4620 86 ▶ 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 81 86
Condition83%5/6
$opt =~ /d/ and _is_dir($dev, $dir) and not _file_entry($dev, $dir)
!ll&&!rl&&r
8105
$opt =~ /d/ and _is_dir($dev, $dir)
!ll&&!rl&&r
8015
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
4621 5 ▶ push @files_out, $long ? _ls_line( $dev, $dir, $p, $h ) : $p;
Branch: 1 branch
BranchTrueFalseTotal
$long ? : 5 0 5
4622 5 next;
4623 }
4624 81 ▶ 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)) 20 61 81
Condition100%3/3
not $followed and _file_entry($dev, $dir)
!ll&&!rl&&r
16020
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
4625 20 ▶ push @files_out, $long ? _ls_line( $dev, $dir, $p, $h ) : $p;
Branch: 1 branch
BranchTrueFalseTotal
$long ? : 17 3 20
4626 20 next;
4627 }
4628 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
4629 0 _part('Storage');
4630 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
4631 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
4632 0 next;
4633 }
4634 }
4635 61 my $names = _ls_names( $dev, $dir );
4636 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
4637 9 push @out, "ls: cannot access '$p': No such file or directory";
4638 9 $ok = 0;
4639 9 next;
4640 }
4641 52 push @dirs, [ $p, $dir ]; # wie angegeben, aufgeloest (Symlink)
4642 }
4643 83 push @out, @files_out;
4644 83 my @queue = @dirs;
4645 83 ▶ while ( defined( my $q = shift @queue ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $q = shift @queue)) 54 83 137
4646 54 my ( $p, $dir ) = @$q;
4647 54 my $names = _ls_names( $dev, $dir );
4648 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
4649 54 ▶ if ( $opt =~ /t/ ) { # -t: neueste zuerst (gleich alt: nach Namen)
Branch: 1 branch
BranchTrueFalseTotal
if ($opt =~ /t/) 3 51 54
4650 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
4651 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
4652 }
4653 54 ▶ @n = reverse @n if $opt =~ /r/;
Branch: 1 branch
BranchTrueFalseTotal
if $opt =~ /r/ 1 53 54
4654 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
4655 54 ▶ push @out, "$p:" if $multi;
Branch: 1 branch
BranchTrueFalseTotal
if $multi 8 46 54
4656 54 ▶ if ($long) {
Branch: 1 branch
BranchTrueFalseTotal
if ($long) { } 11 43 54
4657 11 ▶ push @out, 'total ' . 4 * ( @n + ( $all ? 2 : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
$all ? : 6 5 11
4658 11 ▶ if ($all) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all) 6 5 11
4659 6 ( my $up = $dir ) =~ s{/[^/]+\z}{};
4660 6 ▶ push @out, _ls_line( $dev, $dir, '.', $h ), _ls_line( $dev, length $up ? $up : '/', '..', $h );
Branch: 1 branch
BranchTrueFalseTotal
length $up ? : 6 0 6
4661 }
4662 11 for (@n) {
4663 push @out, ref $names->{$_}
4664 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
4665 54 ▶ : $dir eq '/dev' && $dev->{storage} && !_file_entry( $dev, "/dev/$_" ) && !_is_dir( $dev, "/dev/$_" )
Branch: 1 branch
BranchTrueFalseTotal
ref $$names{$_} ? : 3 51 54
4666 ? "brw-rw---- 1 root disk 254, 0 Oct 20 09:00 $_"
4667 : _ls_line( $dev, ( $dir eq "/" ? "" : $dir ) . "/$_", $_, $h );
4668 }
4669 }
4670 else {
4671 43 ▶ my @x = ( $all ? ( '.', '..' ) : (), @n );
Branch: 1 branch
BranchTrueFalseTotal
$all ? : 1 42 43
4672 43 push @out, @x; # ohne Terminal (Werkzeug-Aufruf): ein Name je Zeile
4673 }
4674 54 ▶ if ($rec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rec) 3 51 54
4675 3 ▶ my $base = $p =~ m{/\z} ? $p : "$p/";
Branch: 1 branch
BranchTrueFalseTotal
$p =~ m[/\z] ? : 0 3 3
4676 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
4677 }
4678 }
4679 83 return ( join( "\n", @out ), $ok );
4680 }
4681  
4682 # Namen in einem Verzeichnis: Dateien, Unterverzeichnisse, virtuelle Eintraege
4683 # (wg, /proc/sys, *.wants von systemd als Verweise: Wert ist dann \"ziel")
4684 116 ▶sub _ls_names {
Subroutine _ls_names: called CC=45 SCAR=44.8
4685 116 my ( $dev, $dir ) = @_;
4686 116 my %names;
4687 116 ▶ my $pre = $dir eq '/' ? '/' : "$dir/";
Branch: 1 branch
BranchTrueFalseTotal
$dir eq '/' ? : 8 108 116
4688 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
4689 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
4690 }
4691 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
4692 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
4693 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
4694 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
4695 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
4696 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
4697 116 ▶ if ( $dir =~ m{\A/proc/sys(?:/(.+))?\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ m[\A/proc/sys(?:/(.+))?\z]) 4 112 116
4698 4 ▶ my $p = defined $1 ? ( $1 =~ tr{/}{.}r ) . '.' : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 4 0 4
4699 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
4700 }
4701 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
4702 2 my $w = _wants($dev);
4703 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
4704 }
4705 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
4706 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
4707 116 return \%names;
4708 }
4709  
4710 # Programme in /usr/bin bzw. /usr/sbin (usrmerge: /bin und /sbin verweisen dorthin): genau
4711 # die, die which auf diesem Geraet findet — was ls zeigt, passt zu which, type und
4712 # "command not found"
4713 15 ▶sub _bin_names {
Subroutine _bin_names: called CC=3 SCAR=11.4
4714 15 my ( $dev, $kind ) = @_;
4715 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
4716 0 return _bin_names_all( $dev, $kind );
4717 }
4718  
4719 9 ▶sub _bin_names_all {
Subroutine _bin_names_all: called CC=6 SCAR=17.9
4720 9 my ( $dev, $kind ) = @_;
4721 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
4722 9 my @cand = grep { /\A(?:\[|[A-Za-z0-9_][\w.+@-]*)\z/ } keys %CMD, keys %REAL, keys %FILTER, keys %INTERACTIVE, keys %exec,
4723 qw( ls bash sh cat cp mv rm mkdir tail head grep sed awk find echo printf true false test [ );
4724 9 my %seen;
4725 my @n;
4726 9 for my $n ( sort grep { !$seen{$_}++ } @cand ) {
4727 2329 my ( $p, $ok ) = _which( 'which', $dev, [$n] );
4728 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
4729 }
4730 9 return @n;
4731 }
4732  
4733 # Programm aus _bin_names unter /usr/bin, /bin, /usr/sbin, /sbin? Liefert den Namen oder undef
4734 147 ▶sub _virtual_bin {
Subroutine _virtual_bin: called CC=4 SCAR=13.9
4735 147 my ( $dev, $path ) = @_;
4736 147 ▶ 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 143 147
4737 4 ▶ return undef if _file_entry( $dev, $path );
Branch: 1 branch
BranchTrueFalseTotal
if _file_entry($dev, $path) 1 3 4
4738 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
4739 }
4740  
4741 2 ▶sub _bin_ls_line {
Subroutine _bin_ls_line: called CC=1 SCAR=0.0
4742 2 my ( $n, $shown ) = @_;
4743 2 return sprintf( '-rwxr-xr-x 1 root root %8d Oct 20 09:00 %s', 30000 + 113 * unpack( '%32C*', $n ), $shown );
4744 }
4745  
4746 # Welche Units in welchem *.wants haengen (enabled): { ziel => [ [ unit, unit-datei ] ] }
4747 2 ▶sub _wants {
Subroutine _wants: called CC=9 SCAR=23.6
4748 2 my ($dev) = @_;
4749 2 my %w;
4750 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
4751 6 my $svc = $dev->{services}{$n};
4752 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
4753 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
4754 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
4755 6 push @{ $w{$wb} }, [ _uname($n), _unit_file( $n, $svc ) ];
4756 }
4757 2 return \%w;
4758 }
4759  
4760 # Hat die Unit einen Verweis in einem *.wants? (enabled; static nur, wenn ausdruecklich enabled)
4761 11 ▶sub _symlinked {
Subroutine _symlinked: called CC=4 SCAR=13.9
4762 11 my ( $dev, $n, $svc ) = @_;
4763 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
4764 4 ▶ return _static( $dev, $n, $svc ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
_static($dev, $n, $svc) ? : 0 4 4
4765 }
4766  
4767 21 ▶sub _stat {
Subroutine _stat: called CC=35 SCAR=40.6
4768 21 my ( $dev, $av ) = @_;
4769 21 my @a = @$av;
4770 21 my $fmt;
4771 21 ▶ for ( my $i = 0; $i < @a; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @a) 21 1 22
4772 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
4773 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
4774 }
4775 21 ▶ if ( defined $fmt ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fmt) 20 1 21
4776 20 my @out;
4777 20 for my $p ( grep { !/\A-/ } @a ) {
4778 20 my $e = _file_entry( $dev, $p );
4779 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
4780 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
4781 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
4782 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
4783 my %v = ( a => sprintf( '%o', $m ), A => _mode_text( $m, !$e ), U => $x->{owner} // 'root', G => $x->{group} // 'root',
4784 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
4785 F => $e ? 'regular file' : 'directory', '%' => '%' );
4786 20 my ( $iso, $ep ) = _mtime_iso( $x );
4787 20 $v{$_} = $iso for qw( y x z );
4788 20 $v{$_} = $ep for qw( Y X Z );
4789 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
4790 20 $line =~ s/\\n/\n/g;
4791 20 push @out, $line;
4792 }
4793 20 return ( join( "\n", @out ), 1 );
4794 }
4795 1 my @out;
4796 1 for my $p ( grep { !/\A-/ } @a ) {
4797 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
4798 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
4799 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
4800 push @out, " File: $p", " Size: 4096\tBlocks: 8\tIO Block: 4096 directory",
4801 sprintf( 'Access: (%04o/%s) Uid: (%5d/%8s) Gid: (%5d/%8s)', $m, _mode_text( $m, 1 ), _uid( $dev, $d->{owner} ), $d->{owner} // 'root',
4802 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
4803 1 next;
4804 }
4805 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
4806 0 my $m = _mode_of($e);
4807 push @out, " File: $p", " Size: " . _file_size($e) . "\tBlocks: 8\tIO Block: 4096 regular file",
4808 sprintf( 'Access: (%04o/%s) Uid: (%5d/%8s) Gid: (%5d/%8s)', $m, _mode_text($m), _uid( $dev, $e->{owner} ), $e->{owner} // 'root',
4809 _gid( $dev, $e->{group} ), $e->{group} // 'root' ),
4810 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
4811 }
4812 1 return ( join( "\n", @out ), 1 );
4813 }
4814  
4815 # Prozesse: je laufender Dienst einer (exec), PID fest nach Namen sortiert
4816 # Prozesse der laufenden Dienste: Befehlszeile aus der Fassung, mit der sie laufen (_started,
4817 # ExecStart), sonst exec; gunicorn mit seinen Workern (--workers/-w, sonst workers = in der
4818 # --config-Datei, sonst 1) als Kinder des Masters
4819 98 ▶sub _procs {
Subroutine _procs: called CC=16 SCAR=28.1
4820 98 my ($dev) = @_;
4821 98 ▶ my $s = $dev->{services} || {};
Condition50%1/2
$$dev{'services'} || {}
l!l
980
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
4822 98 my $pid = 400;
4823 98 my @p;
4824 98 for my $n ( grep { $s->{$_}{active} } sort keys %$s ) {
4825 236 $pid += 37;
4826 236 my $svc = $s->{$n};
4827 236 ▶ my $pid = $svc->{_pid} // $pid; # im Simulator (neu) gestartet: eigene PID
Condition66%2/3
$$svc{"_pid"} // $pid
l!l&&r!l&&!r
302060
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
4828 236 ▶ my $line = ( ( $svc->{_started} || {} )->{ExecStart} || [] )->[0];
Condition100%4/4
($$svc{'_started'} || {})->{'ExecStart'} || []
l!l
34202
$$svc{'_started'} || {}
l!l
37199
MC/DC100%1/1
($$svc{'_started'} || {})->{'ExecStart'} || []
$$svc{'_started'}
Truth table100%2/2
A
A= $$svc{'_started'}
Aresult
11
00
4829 236 ▶ my $cmd = defined $line ? ( $line =~ s/\A[-@+!:]+//r ) : $svc->{exec} // $n;
Branch: 1 branch
BranchTrueFalseTotal
defined $line ? : 34 202 236
Condition66%2/3
$$svc{"exec"} // $n
l!l&&r!l&&!r
157450
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
4830 236 $cmd =~ s/\$\{?MAINPID\}?/$pid/g;
4831 236 ▶ my $user = $svc->{user} // ( $svc->{_started} || {} )->{User} // 'root';
Condition85%6/7
($$svc{"user"} // ($$svc{"_started"} || {})->{"User"}) // "root"
l!l
48188
$$svc{"user"} // ($$svc{"_started"} || {})->{"User"}
l!l&&r!l&&!r
480188
$$svc{'_started'} || {}
l!l
5183
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
4832 236 push @p, { pid => $pid, ppid => 1, user => $user, cmd => $cmd, unit => $n };
4833 236 ▶ if ( $cmd =~ /\bgunicorn\b/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /\bgunicorn\b/) 16 220 236
4834 16 my ($w) = $cmd =~ /(?:--workers[ =]|-w\s*)(\d+)/;
4835 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
4836 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
4837 }
4838 }
4839 98 return @p;
4840 }
4841  
4842 51 ▶sub _main_pid {
Subroutine _main_pid: called CC=2 SCAR=6.9
4843 51 my ( $dev, $n ) = @_;
4844 51 my ($p) = grep { $_->{unit} eq $n } _procs($dev);
4845 51 ▶ return $p ? $p->{pid} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 47 4 51
4846 }
4847  
4848 # Startzeit eines Dienstes (Epoche): der letzte Start im Simulator (_since, Zeit der
4849 # Journalzeile "Started"), sonst since im Zustand ("Thu 2026-10-29 06:10:12 CET"), sonst undef
4850 88 our $BOOT_STAMP = 'Tue 2026-10-20 09:00:00 CEST'; # Vorgabe fuer laufende Dienste ohne Angabe
4851 73 ▶sub _svc_since {
Subroutine _svc_since: called CC=2 SCAR=6.9
4852 73 my ($svc) = @_;
4853 73 ▶ return $svc->{_since} if defined $svc->{_since};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$svc{"_since"} 20 53 73
4854 53 return _parse_stamp( $svc->{since} );
4855 }
4856  
4857 # Jetzt auf dem Geraet (Epoche): seine Uhr (clock), sonst die der Simulation
4858 121 ▶sub _dev_now {
Subroutine _dev_now: called CC=2 SCAR=6.9
4859 121 my ($dev) = @_;
4860 121 ▶ return _sim_now() unless defined $dev->{clock};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$dev{"clock"} 107 14 121
4861 14 _part('Monitoring');
4862 14 return Langertha::Holmgang::Sim::Linux::Monitoring::now_epoch($dev);
4863 }
4864  
4865 # "5h ago" wie systemd; ein Start in derselben Minute wie die Uhr ist "1s ago"
4866 9 ▶sub _ago {
Subroutine _ago: called CC=2 SCAR=6.9
4867 9 my ( $dev, $t ) = @_;
4868 9 my $s = _dev_now($dev) - $t;
4869 9 ▶ return Langertha::Holmgang::Sim::Linux::Calendar::left( $s > 0 ? $s : 1 ) . ' ago';
Branch: 1 branch
BranchTrueFalseTotal
$s > 0 ? : 8 1 9
4870 }
4871  
4872 # Startzeit eines Prozesses fuer ps: die seines Dienstes oder undef (Vorgabe von ps)
4873 36 ▶sub _proc_since {
Subroutine _proc_since: called CC=4 SCAR=13.9
4874 36 my ( $dev, $p ) = @_;
4875 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
4876 36 ▶ return $svc ? _svc_since($svc) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$svc ? : 32 4 36
4877 }
4878  
4879 # Zeilen, die ein laufender Dienst in seine Logdatei geschrieben hat (app_log), als
4880 # Laufzeitspur _append: { pfad => { base => inhalt beim Schreiben, lines => [ … ] } } —
4881 # sie gelten nur, solange die Datei den Inhalt von damals hat (sonst neu geschrieben)
4882 1729 ▶sub _with_append {
Subroutine _with_append: called CC=7 SCAR=20.0
4883 1729 my ( $dev, $path, $t ) = @_;
4884 1729 ▶ return $t unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 1729 1729
4885 1729 ▶ my $a = ( $dev->{_append} || {} )->{$path} or return $t;
Branch: 1 branch
BranchTrueFalseTotal
my $a = ($$dev{"_append"} || {})->{$path} or return $t 13 1716 1729
Condition100%2/2
$$dev{'_append'} || {}
l!l
191710
MC/DC100%1/1
$$dev{'_append'} || {}
$$dev{'_append'}
Truth table100%2/2
A
A= $$dev{'_append'}
Aresult
11
00
4886 13 ▶ return $t unless $a->{base} eq $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $$a{"base"} eq $t 1 12 13
4887 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
4888 }
4889  
4890 # app_log eines Dienstes: { file, start: [ zeilen ], fail: [ zeilen ] } — bei Start bzw.
4891 # Fehlstart angehaengt; {ts} (JJJJ-MM-TT HH:MM:SS, Uhr des Geraets), {listen}, {pid}
4892 75 ▶sub _app_log {
Subroutine _app_log: called CC=18 SCAR=30.5
4893 75 my ( $dev, $n, $svc, $kind, $t ) = @_;
4894 75 my $al = $svc->{app_log};
4895 75 ▶ return unless ref $al eq 'HASH' && defined $al->{file};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $al eq "HASH" and defined $$al{"file"} 73 2 75
Condition66%2/3
ref $al eq "HASH" and defined $$al{"file"}
!ll&&!rl&&r
7302
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
4896 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
4897 2 require POSIX;
4898 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
4899 my %v = ( ts => POSIX::strftime( '%Y-%m-%d %H:%M:%S', _local_tm($t) ), pid => _main_pid( $dev, $n ) || 3120,
4900 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
4901 2 my $p = $al->{file};
4902 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
4903 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
4904 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
4905 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
4906 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
4907 2 $dev->{_append}{$p} = { base => $raw, lines => [ @keep, map { s/\{(ts|listen|pid)\}/$v{$1}/gr } @lines ] };
4908 2 return;
4909 }
4910  
4911 # Lauscher eines Dienstes ( "adresse:port", … ): listen am Dienst (Liste, oder { file, regex }
4912 # — die Fangruppen aus der Datei, wie der Dienst sie gelesen hat), sonst fuer nginx die
4913 # listen-Zeilen seiner Konfiguration (nginx.conf, conf.d/*.conf, sites-enabled/*)
4914 18 ▶sub _svc_listen {
Subroutine _svc_listen: called CC=15 SCAR=28.6
4915 18 my ( $dev, $n, $svc ) = @_;
4916 18 my $l = $svc->{listen};
4917 18 ▶ my $run = ref $svc->{running} eq 'HASH' ? $svc->{running} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'running'} eq 'HASH' ? : 0 18 18
4918 22 ▶ my $norm = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
4919 22 my ($a) = @_;
4920 22 $a =~ s/\Alocalhost:/127.0.0.1:/;
4921 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
4922 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
4923 18 };
4924 18 ▶ return map { $norm->($_) } @$l if ref $l eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $l eq "ARRAY" 4 14 18
4925 14 ▶ if ( ref $l eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $l eq "HASH") 2 12 14
4926 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
4927 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
4928 2 my @a;
4929 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
4930 2 return map { $norm->($_) } @a;
4931 }
4932 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
4933 12 my %seen;
4934 my @a;
4935 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
4936 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
4937 12 $t =~ s/#[^\n]*//g;
4938 12 push @a, grep { !$seen{$_}++ } map { $norm->($_) } $t =~ /^\s*listen\s+([^;\s]+)[^;]*;/mg;
4939 }
4940 12 return @a;
4941 }
4942  
4943 # Jetzt als Ortszeit-Sekunden (wie _mtime sie liefert: timegm der Ortszeit)
4944 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
4945  
4946 # mtime eines Eintrags wie stat %y ("2026-09-30 01:30:00.000000000 +0200") und als Epoche (%Y)
4947 23 ▶sub _mtime_iso {
Subroutine _mtime_iso: called CC=1 SCAR=0.0
4948 23 my ($e) = @_;
4949 23 require POSIX;
4950 23 my $lt = _mtime($e);
4951 23 my $off = Langertha::Holmgang::Sim::Linux::Calendar::offset( $lt - 3600 );
4952 23 return ( POSIX::strftime( '%Y-%m-%d %H:%M:%S', gmtime $lt ) . sprintf( '.000000000 %+03d%02d', $off / 3600, abs( $off % 3600 ) / 60 ), $lt - $off );
4953 }
4954  
4955 # Epoche -> mtime im Zustand ("Sep 30 01:30", in einem anderen Jahr "Sep 30 2025")
4956 16 ▶sub _mtime_str {
Subroutine _mtime_str: called CC=2 SCAR=7.0
4957 16 my ($t) = @_;
4958 16 my @g = _local_tm($t);
4959 16 my $mon = (qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ))[ $g[4] ];
4960 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
4961 }
4962  
4963 # Zeitspalte von ls -l nach --time-style (full-iso, long-iso, iso; sonst wie im Zustand)
4964 88 ▶sub _ls_time {
Subroutine _ls_time: called CC=8 SCAR=22.3
4965 88 my ($e) = @_;
4966 88 ▶ my $m = ref $e eq 'HASH' ? $e->{mtime} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' ? : 88 0 88
4967 88 ▶ return $m // 'Oct 20 09:00' unless $LS_TIME;
Branch: 1 branch
BranchTrueFalseTotal
unless $Langertha::Holmgang::Sim::Linux::LS_TIME 85 3 88
Condition100%2/2
$m // "Oct 20 09:00"
l!l
1471
MC/DC100%1/1
$m // "Oct 20 09:00"
$m
Truth table100%2/2
A
A= $m
Aresult
11
00
4968 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
4969 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
4970 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
4971 0 return substr( $iso, 5, 11 ); # iso
4972 }
4973  
4974 # Epoche -> Ortszeit als gmtime-Liste (wie localtime in Europe/Berlin)
4975 90 ▶sub _local_tm { my ($t) = @_; return gmtime( $t + Langertha::Holmgang::Sim::Linux::Calendar::offset($t) ) }
Subroutine _local_tm: called CC=1 SCAR=0.0
4976  
4977 # /proc/<pid>/limits eines Dienstes: offene Dateien aus der Fassung, mit der er laeuft
4978 1 ▶sub _proc_limits {
Subroutine _proc_limits: called CC=8 SCAR=22.3
4979 1 my ( $dev, $pid ) = @_;
4980 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
4981 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
4982 1 my ( $soft, $hard ) = ( 1024, 524288 );
4983 1 ▶ if ( defined( my $l = $st->{LimitNOFILE} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = $$st{"LimitNOFILE"})) 1 0 1
4984 1 ▶ ( $soft, $hard ) = $l =~ /\A(\w+):(\w+)\z/ ? ( $1, $2 ) : ( $l, $l );
Branch: 1 branch
BranchTrueFalseTotal
$l =~ /\A(\w+):(\w+)\z/ ? : 0 1 1
4985 1 ▶ $_ = $_ eq 'infinity' ? 'unlimited' : $_ for $soft, $hard;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'infinity' ? : 0 2 2
4986 }
4987 1 my $f = '%-26s%-21s%-21s%-10s';
4988 1 return join "\n", sprintf( $f, 'Limit', 'Soft Limit', 'Hard Limit', 'Units' ),
4989 sprintf( $f, 'Max cpu time', 'unlimited', 'unlimited', 'seconds' ),
4990 sprintf( $f, 'Max file size', 'unlimited', 'unlimited', 'bytes' ),
4991 sprintf( $f, 'Max core file size', 0, 'unlimited', 'bytes' ),
4992 sprintf( $f, 'Max processes', 63238, 63238, 'processes' ),
4993 sprintf( $f, 'Max open files', $soft, $hard, 'files' ),
4994 sprintf( $f, 'Max locked memory', 8388608, 8388608, 'bytes' );
4995 }
4996  
4997 12 ▶sub _base64 {
Subroutine _base64: called CC=10 SCAR=24.2
4998 12 my ( $dev, $av, $ctx, $stdin ) = @_;
4999 12 require MIME::Base64;
5000 12 my ($decode) = grep { /\A(?:-d|--decode)\z/ } @$av;
5001 12 my @files = grep { !/\A-/ } @$av;
5002 12 my $in;
5003 12 ▶ if (@files) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) { } 0 12 12
5004 0 $in = _file_text( $dev, $files[0] );
5005 0 ▶ return ( "base64: $files[0]: No such file or directory", 0 ) unless defined $in;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in 0 0 0
5006 }
5007 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
5008 12 ▶ if ($decode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decode) 9 3 12
5009 9 ( my $b = $in ) =~ s/\s+//g;
5010 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
5011 9 my $d = MIME::Base64::decode_base64($b);
5012 9 utf8::decode($d); # Text der Simulation sind Zeichen; gueltiges UTF-8 als Zeichen zurueck
5013 9 return ( $d =~ s/\n\z//r, 1 );
5014 }
5015 3 my $wrap = !grep { /\A(?:-w0|--wrap=0)\z/ } @$av;
5016 3 utf8::encode( my $bytes = $in ); # kodiert werden die Bytes (UTF-8), wie GNU base64
5017 3 my $e = MIME::Base64::encode_base64( $bytes, '' );
5018 3 ▶ $e =~ s/(.{76})(?=.)/$1\n/g if $wrap;
Branch: 1 branch
BranchTrueFalseTotal
if $wrap 2 1 3
5019 3 return ( $e, 1 );
5020 }
5021  
5022 # ps [aux] | -ef | -eo spalten | --ppid N | -p N | -C name
5023 17 ▶sub _ps {
Subroutine _ps: called CC=48 SCAR=46.9
5024 17 my ( $dev, $av ) = @_;
5025 17 require POSIX;
5026 17 my @all = ( { pid => 1, ppid => 0, user => 'root', cmd => '/sbin/init' }, _procs($dev) );
5027 @all = map { # nginx: Master und Worker wie echt
5028 17 ( split ' ', $_->{cmd} )[0] =~ m{(?:\A|/)nginx\z}
5029 ? ( { %$_, cmd => 'nginx: master process /usr/sbin/nginx -g daemon on; master_process on;' },
5030 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
5031 : $_
5032 } @all;
5033 17 my ( $fmt, @filt ) = ('aux');
5034 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
5035 17 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 26 17 43
5036 26 my $x = shift @a;
5037 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
5038 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
5039 0 elsif ( $x =~ /\A-e?o(\S+)\z/ ) { $fmt = "o:$1" }
5040 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
5041 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
5042 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
5043 elsif ( $x =~ /\A-([fFeAl]+)([pCuU])\z/ ) { # -fp PID, -fu benutzer, …
5044 1 my ( $fl, $o ) = ( $1, $2 );
5045 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
5046 1 unshift @a, "-$o";
5047 }
5048 ▶ 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
5049 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
5050 1 my %u = map { $_ => 1 } split /,/, $v;
5051 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
5052 }
5053 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
5054 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
5055 }
5056 17 my @p = grep { my $p = $_; !grep { !$_->($p) } @filt } @all;
5057 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
5058 17 my @l;
5059 17 ▶ if ( $fmt eq 'ef' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fmt eq 'ef') { } 3 14 17
elsif ($fmt =~ /\Ao:(.*)\z/) { } 10 4 14
5060 3 ▶ push @l, 'UID PID PPID C STIME TTY TIME CMD' unless $noh;
Branch: 1 branch
BranchTrueFalseTotal
unless $noh 3 0 3
5061 3 push @l, map { sprintf( '%-8s %7d %7d 0 %-5s ? 00:00:12 %s', $_->{user}, $_->{pid}, $_->{ppid}, _ps_start( $dev, $_ ), $_->{cmd} ) } @p;
5062 }
5063 elsif ( $fmt =~ /\Ao:(.*)\z/ ) {
5064 10 my @spec = split /[,\s]+/, $1;
5065 10 my @c = map { lc s/=.*//r } @spec;
5066 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
5067 10 my %head = ( etimes => 'ELAPSED', comm => 'COMMAND', ucomm => 'COMMAND', args => 'COMMAND', command => 'COMMAND', cmd => 'CMD', '%cpu' => '%CPU', '%mem' => '%MEM' );
5068 10 my %w = ( pid => 7, ppid => 7, etime => 11, etimes => 7, user => 8, uid => 5, comm => 15 );
5069 my %val = (
5070 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
5071 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
5072 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
5073 3 ▶ etime => sub {
Subroutine __ANON__: called CC=5 SCAR=28.4
5074 3 my $t = _proc_since( $dev, $_[0] );
5075 3 ▶ return '4-00:12:00' unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 3 0 3
5076 0 my $s = _dev_now($dev) - $t;
5077 0 ▶ $s = 1 if $s < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $s < 1 0 0 0
5078 0 my ( $d, $h, $m ) = ( int( $s / 86400 ), int( $s % 86400 / 3600 ), int( $s % 3600 / 60 ) );
5079 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
5080 },
5081 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
5082 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
5083 2 ▶ lstart => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
5084 2 my $t = _proc_since( $dev, $_[0] );
5085 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
5086 },
5087 0 ▶ nlwp => sub { 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5088 10 );
5089 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
5090 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
5091 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
5092 10 for my $p (@p) { push @l, sprintf( $f, map { $val{$_}->($p) } @c ) =~ s/\s+\z//r }
5093 }
5094 else {
5095 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
5096 push @l, $_->{pid} == 1 ? 'root 1 0.0 0.1 168000 12000 ? Ss Oct20 0:04 /sbin/init'
5097 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
5098 }
5099 17 ▶ return ( join( "\n", @l ), @p ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
@p ? : 17 0 17
5100 }
5101  
5102 # Spalte START/STIME von ps: heute gestartet "09:12", sonst "Oct20"
5103 28 ▶sub _ps_start {
Subroutine _ps_start: called CC=4 SCAR=22.9
5104 28 my ( $dev, $p ) = @_;
5105 28 my $t = _proc_since( $dev, $p );
5106 28 ▶ return 'Oct20' unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 28 0 28
5107 0 require POSIX;
5108 0 my @s = _local_tm($t);
5109 0 my @n = _local_tm( _dev_now($dev) );
5110 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
5111 }
5112  
5113 # Signal an einen Dienst: HUP liest neu ein (wie reload), sonst endet er (KILL: failed)
5114 6 ▶sub _signal {
Subroutine _signal: called CC=17 SCAR=29.6
5115 6 my ( $dev, $unit, $sig ) = @_;
5116 6 ▶ my $svc = $dev->{services}{$unit} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $svc = $$dev{"services"}{$unit} or return 6 0 6
5117 6 ▶ if ( $sig eq 'HUP' ) { _restart_effect( $dev, $unit, 'reload' ); return }
Branch: 1 branch
BranchTrueFalseTotal
if ($sig eq "HUP") 1 5 6
5118 5 ▶ return unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 0 5 5
5119 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
5120 5 $svc->{active} = JSON::MaybeXS::false();
5121 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
5122 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
5123 # Restart= der geladenen Unit: systemd startet den Dienst neu — always immer, on-failure,
5124 # on-abnormal und on-abort nach einem unsauberen Signal (nicht TERM, INT, HUP, PIPE),
5125 # on-success nach einem sauberen
5126 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
5127 5 my $clean = $sig =~ /\A(?:TERM|INT|HUP|PIPE)\z/;
5128 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
5129 2 ▶ $svc->{failed} = JSON::MaybeXS::false() if $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"failed"} 1 1 2
5130 2 _systemd_start( $dev, $unit, $svc, 'start' );
5131 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
5132 0 else { $svc->{failed} = JSON::MaybeXS::true() } # Neustart gescheitert: die Unit steht auf failed
5133 }
5134 5 return;
5135 }
5136  
5137 8 ▶sub _sig_of {
Subroutine _sig_of: called CC=2 SCAR=7.0
5138 8 my ($x) = @_;
5139 8 my $s = uc( $x =~ s/\A-(?:s\s*)?//r );
5140 8 $s =~ s/\ASIG//;
5141 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
5142 }
5143  
5144 1 ▶sub _pkill {
Subroutine _pkill: called CC=16 SCAR=34.3
5145 1 my ( $dev, $av ) = @_;
5146 1 my ( $sig, $exact, @pat ) = ( 'TERM', 0 );
5147 1 my @a = @$av;
5148 1 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 2 1 3
5149 2 my $x = shift @a;
5150 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
5151 ▶ 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
5152 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
5153 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
5154 1 elsif ( $x =~ /\A-(?:[A-Z]+|\d+)\z/ ) { $sig = _sig_of($x) }
5155 1 else { push @pat, $x }
5156 }
5157 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
5158 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
5159 1 my @hit = grep { ( $_->{cmd} =~ s{.*/}{}r ) =~ $re } _procs($dev);
5160 1 _signal( $dev, $_->{unit}, $sig ) for @hit;
5161 1 ▶ return ( '', @hit ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
@hit ? : 1 0 1
5162 }
5163  
5164 3 ▶sub _kill {
Subroutine _kill: called CC=9 SCAR=22.6
5165 3 my ( $dev, $av ) = @_;
5166 3 my ( $sig, @pids ) = ('TERM');
5167 3 my @a = @$av;
5168 3 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 4 3 7
5169 4 my $x = shift @a;
5170 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
5171 0 elsif ( $x eq '-l' ) { return ( ' 1) SIGHUP 2) SIGINT 3) SIGQUIT 9) SIGKILL 15) SIGTERM', 1 ) }
5172 1 elsif ( $x =~ /\A-/ ) { $sig = _sig_of($x) }
5173 3 else { push @pids, $x }
5174 }
5175 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
5176 3 my %by = map { $_->{pid} => $_ } _procs($dev);
5177 3 my ( @out, $ok ) = ();
5178 3 $ok = 1;
5179 3 for my $p (@pids) {
5180 3 ▶ if ( my $pr = $by{$p} ) { _signal( $dev, $pr->{unit}, $sig ); next }
Branch: 1 branch
BranchTrueFalseTotal
if (my $pr = $by{$p}) 2 1 3
5181 1 push @out, "bash: kill: ($p) - No such process";
5182 1 $ok = 0;
5183 }
5184 3 return ( join( "\n", @out ), $ok );
5185 }
5186  
5187 # getfacl: die Rechte als ACL (der Zustand kennt keine erweiterten ACLs)
5188 1 ▶sub _getfacl {
Subroutine _getfacl: called CC=23 SCAR=40.2
5189 1 my ( $dev, $av ) = @_;
5190 1 my @p = grep { !/\A-/ } @$av;
5191 1 ▶ return ( "Usage: getfacl [-aceEsRLPtpndvh] file ...\nTry `getfacl --help' for more information.", 0 ) unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 1 1
5192 1 my ( @out, $ok, $strip );
5193 1 $ok = 1;
5194 1 for my $p (@p) {
5195 1 my $e = _file_entry( $dev, $p );
5196 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
5197 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
5198 1 ▶ my $m = $e ? _mode_of($e) : oct( $d->{mode} );
Branch: 1 branch
BranchTrueFalseTotal
$e ? : 1 0 1
5199 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
5200 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
5201 1 ( my $shown = $p ) =~ s{\A/+}{};
5202 1 ▶ $strip = 1 if $p =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ m[\A/] 1 0 1
5203 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
5204 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
5205 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
5206 1 push @out, 'user::' . $rwx->( $m >> 6 ), 'group::' . $rwx->( $m >> 3 ), 'other::' . $rwx->($m), '';
5207 }
5208 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
5209 1 ▶ unshift @out, "getfacl: Removing leading '/' from absolute path names" if $strip;
Branch: 1 branch
BranchTrueFalseTotal
if $strip 1 0 1
5210 1 return ( join( "\n", @out ), $ok );
5211 }
5212  
5213 # crontab -l [-u benutzer] liest /var/spool/cron/crontabs/<benutzer>
5214 17 ▶sub _crontab {
Subroutine _crontab: called CC=27 SCAR=37.3
5215 17 my ( $dev, $av, $ctx, $stdin ) = @_;
5216 17 my @a = @$av;
5217 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
5218 17 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 31 17 48
5219 31 my $x = shift @a;
5220 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
5221 11 elsif ( $x =~ /\A-([lre])\z/ ) { $verb = $1 }
5222 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
5223 }
5224 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
5225 16 my $f = "/var/spool/cron/crontabs/$user";
5226 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
5227 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
5228 9 $t =~ s/\A# DO NOT EDIT THIS FILE[^\n]*\n(?:#[^\n]*\n){0,2}//; # Kopf, den crontab beim Installieren schreibt
5229 9 return ( $t =~ s/\n\z//r, 1 );
5230 }
5231 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
5232 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
5233 0 delete $dev->{files}{$f};
5234 0 return ( '', 1 );
5235 }
5236 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
5237 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
5238 6 ▶ return ( "$file: No such file or directory", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 6 6
5239 6 my $n = 0;
5240 6 for my $l ( split /\n/, $t ) {
5241 12 my $bad = _cron_line_error($l);
5242 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
5243 10 $n++;
5244 }
5245 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
5246 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"
5247 . "# (Cron version -- \$Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp \$)\n";
5248 4 $dev->{files}{$f} = { content => $head . $t, owner => $user, group => 'crontab', mode => '0600' };
5249 4 return ( '', 1 );
5250 }
5251 0 push @GAPS, join( ' ', 'crontab', @$av );
5252 0 return ( '', 0 );
5253 }
5254  
5255 # Zeile eines crontab wie Debian-cron sie prueft: undef oder der Fehler ("bad minute" …)
5256 88 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 )] );
5257 12 ▶sub _cron_line_error {
Subroutine _cron_line_error: called CC=21 SCAR=34.1
5258 12 my ($l) = @_;
5259 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
5260 9 ▶ if ( $l =~ /\A\s*@(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A\s*@(\S+)/) 1 8 9
5261 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
5262 1 ▶ return $l =~ /\A\s*@\S+\s+\S/ ? undef : 'bad command';
Branch: 1 branch
BranchTrueFalseTotal
$l =~ /\A\s*\@\S+\s+\S/ ? : 1 0 1
5263 }
5264 8 my @f = split ' ', $l, 6;
5265 8 my @spec = ( [ minute => 0, 59 ], [ hour => 0, 23 ], [ 'day-of-month' => 1, 31 ], [ month => 1, 12 ], [ 'day-of-week' => 0, 7 ] );
5266 8 for my $i ( 0 .. 4 ) {
5267 36 my ( $name, $lo, $hi ) = @{ $spec[$i] };
5268 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
5269 36 my $names = $CRON_NAMES{$name};
5270 36 for my $part ( split /,/, $v, -1 ) {
5271 36 my ( $range, $step ) = split m{/}, $part, 2;
5272 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
5273 35 ▶ next if $range eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $range eq "*" 24 11 35
5274 11 my @ends = split /-/, $range, 2;
5275 11 for (@ends) {
5276 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
5277 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
5278 }
5279 }
5280 }
5281 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
5282 }
5283  
5284 2 ▶sub _pgrep {
Subroutine _pgrep: called CC=8 SCAR=21.1
5285 2 my ( $dev, $av ) = @_;
5286 2 my ( $long, @pat ) = ( 0 );
5287 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
5288 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
5289 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
5290 2 my @hit = grep { $_->{cmd} =~ $re } _procs($dev);
5291 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
5292 }
5293  
5294 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
5295 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
5296  
5297 # Darf $user die Datei lesen/schreiben/ausfuehren? (r|w|x)
5298 32 ▶sub _can {
Subroutine _can: called CC=18 SCAR=30.6
5299 32 my ( $dev, $user, $path, $what ) = @_;
5300 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
5301 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
5302 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
5303 30 my $m = _mode_of($e);
5304 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
5305 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
5306 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
5307 19 ▶ return ( $m & $bit ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$m & $bit ? : 14 5 19
5308 }
5309  
5310 # Datei-Eintrag als Hash im Zustand (fuer Rechte/Eigentuemer)
5311 20 ▶sub _entry_rw {
Subroutine _entry_rw: called CC=2 SCAR=6.9
5312 20 my ( $dev, $path ) = @_;
5313 20 my $e = $dev->{files}{$path};
5314 20 ▶ $dev->{files}{$path} = $e = { content => $e } unless ref $e eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $e eq "HASH" 2 18 20
5315 20 return $e;
5316 }
5317  
5318 # Ziele von chmod/chown: Dateien und (mit -R bzw. ausdruecklich) Verzeichnisse
5319 # als 'dir:<pfad>'.
5320 23 ▶sub _targets {
Subroutine _targets: called CC=10 SCAR=23.2
5321 23 my ( $dev, $rec, @paths ) = @_;
5322 23 my @t;
5323 23 for my $p (@paths) {
5324 23 ( my $q = $p ) =~ s{(?<=.)/+\z}{};
5325 23 ▶ if ( _file_entry( $dev, $q ) ) { push @t, $q; next }
Branch: 1 branch
BranchTrueFalseTotal
if (_file_entry($dev, $q)) 15 8 23
5326 8 ▶ if ( _is_dir( $dev, $q ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_dir($dev, $q)) 8 0 8
5327 8 push @t, "dir:$q";
5328 8 ▶ if ($rec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rec) 1 7 8
5329 1 my %d;
5330 1 for my $f ( _under( $dev, $q ) ) {
5331 2 push @t, $f;
5332 2 ( my $x = $f ) =~ s{/[^/]+\z}{};
5333 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
5334 }
5335 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
5336 1 push @t, map {"dir:$_"} sort keys %d;
5337 }
5338 8 next;
5339 }
5340 0 return ( undef, $p );
5341 }
5342 23 return \@t;
5343 }
5344  
5345 26 ▶sub _target_entry {
Subroutine _target_entry: called CC=3 SCAR=11.1
5346 26 my ( $dev, $t ) = @_;
5347 26 ▶ return _entry_rw( $dev, $t ) unless $t =~ /\Adir:(.*)\z/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ /\Adir:(.*)\z/s 17 9 26
5348 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
5349 }
5350  
5351 16 ▶sub _chmod {
Subroutine _chmod: called CC=32 SCAR=40.0
5352 16 my ( $dev, $av ) = @_;
5353 16 my @a = @$av;
5354 16 my $rec = 0;
5355 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
5356 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
5357 16 ▶ return ( "chmod: missing operand after '$spec'", 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 16 16
5358 16 my ( $t, $bad ) = _targets( $dev, $rec, @a );
5359 16 ▶ return ( "chmod: cannot access '$bad': No such file or directory", 0 ) unless $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 16 16
5360 16 for my $p (@$t) {
5361 16 my $isdir = $p =~ /\Adir:/;
5362 16 my $e = _target_entry( $dev, $p );
5363 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
5364 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
5365 else {
5366 3 for my $part ( split /,/, $spec ) {
5367 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
5368 4 ▶ $who = 'a' if $who eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $who eq "" 0 4 4
5369 4 my $bits = 0;
5370 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
5371 4 for ( split //, $perm ) {
5372 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
5373 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
5374 1 $bits |= { r => 4, w => 2, x => 1 }->{$_};
5375 }
5376 4 ▶ for my $w ( $who =~ /a/ ? qw( u g o ) : split //, $who ) {
Branch: 1 branch
BranchTrueFalseTotal
$who =~ /a/ ? : 0 4 4
5377 4 my $sh = { u => 6, g => 3, o => 0 }->{$w};
5378 4 my $sp = { u => 04000, g => 02000, o => 01000 }->{$w};
5379 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
5380 4 ▶ if ( $op eq '+' ) { $m |= ( $bits << $sh ) | $spb }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '+') { } 3 1 4
elsif ($op eq '-') { } 1 0 1
5381 1 elsif ( $op eq '-' ) { $m &= ~( ( $bits << $sh ) | $spb ) }
5382 0 else { $m = ( $m & ~( ( 7 << $sh ) | $sp ) ) | ( $bits << $sh ) | $spb }
5383 }
5384 }
5385 }
5386 16 my $new = sprintf '%04o', $m & 07777;
5387 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
5388 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
5389 }
5390 16 return ( '', 1 );
5391 }
5392  
5393 8 ▶sub _chown {
Subroutine _chown: called CC=39 SCAR=41.2
5394 8 my ( $dev, $av, $ctx, $stdin, $only_group ) = @_;
5395 8 my @a = @$av;
5396 8 my $rec = 0;
5397 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
5398 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
5399 8 ▶ my ( $u, $g ) = $only_group ? ( undef, $spec ) : split /[:.]/, $spec, 2;
Branch: 1 branch
BranchTrueFalseTotal
$only_group ? : 0 8 8
5400 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
5401 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
5402 # numerische IDs: auf den Namen abbilden, sonst die Zahl selbst (wie ls -l ohne Eintrag)
5403 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
5404 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
5405 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
5406 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
5407 }
5408 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
5409 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
5410 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
5411 1 $groups{$g} = 1;
5412 }
5413 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
5414 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
5415 7 my ( $t, $bad ) = _targets( $dev, $rec, @a );
5416 7 ▶ return ( "chown: cannot access '$bad': No such file or directory", 0 ) unless $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 7 7
5417 7 for my $p (@$t) {
5418 10 my $e = _target_entry( $dev, $p );
5419 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
5420 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
5421 }
5422 7 return ( '', 1 );
5423 }
5424  
5425 25 ▶sub _rm {
Subroutine _rm: called CC=40 SCAR=39.2
5426 25 my ( $dev, $av ) = @_;
5427 25 my @a = @$av;
5428 25 my ( $f, $r, $v ) = ( 0, 0, 0 );
5429 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
5430 8 my $o = shift @a;
5431 8 ▶ $f = 1 if $o =~ /f/;
Branch: 1 branch
BranchTrueFalseTotal
if $o =~ /f/ 6 2 8
5432 8 ▶ $r = 1 if $o =~ /r/i;
Branch: 1 branch
BranchTrueFalseTotal
if $o =~ /r/i 3 5 8
5433 8 ▶ $v = 1 if $o =~ /v/;
Branch: 1 branch
BranchTrueFalseTotal
if $o =~ /v/ 1 7 8
5434 }
5435 25 ▶ return ( 'rm: missing operand', 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 25 25
5436 25 my ( @out, $ok ) = ();
5437 25 $ok = 1;
5438 25 for my $raw (@a) { # wie GNU rm: Fehler je Operand, die uebrigen laufen weiter
5439 26 my $p = _absp($raw) =~ s{(?<=.)/+\z}{}r;
5440 26 my @gone;
5441 # als Benutzer: w und x am Elternordner (sticky: nur der Eigentuemer), x auf dem Weg
5442 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
5443 4 ( my $par = $p ) =~ s{/[^/]+\z}{};
5444 4 ▶ $par = '/' unless length $par;
Branch: 1 branch
BranchTrueFalseTotal
unless length $par 0 4 4
5445 4 my $pm = _dir_meta( $dev, $par );
5446 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
5447 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
5448 || ( oct( $pm->{mode} // '0755' ) & 01000 ) && $owner ne _who() && ( $pm->{owner} // 'root' ) ne _who() ) {
5449 3 push @out, "rm: cannot remove '$raw': Permission denied";
5450 3 $ok = 0;
5451 3 next;
5452 }
5453 }
5454 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
5455 elsif ( _is_dir( $dev, $p ) ) {
5456 0 ▶ if ( !$r ) { push @out, "rm: cannot remove '$raw': Is a directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 1 1
5457 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
5458 1 @gone = _under( $dev, $p );
5459 }
5460 else {
5461 1 ▶ next if $f;
Branch: 1 branch
BranchTrueFalseTotal
if $f 0 1 1
5462 1 push @out, "rm: cannot remove '$raw': No such file or directory";
5463 1 $ok = 0;
5464 1 next;
5465 }
5466 22 my @keep = _parents_of( $dev, $p );
5467 22 for my $g (@gone) {
5468 21 my $e = _file_entry( $dev, $g );
5469 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
5470 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
5471 21 delete $dev->{files}{$g};
5472 21 ▶ _maria()->can('file_removed')->( $dev, $g ) if $dev->{mariadb};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"mariadb"} 1 20 21
5473 21 ▶ push @out, "removed '$g'" if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 1 20 21
5474 }
5475 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
5476 1 ( my $q = $p ) =~ s{(?<=.)/+\z}{};
5477 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
5478 }
5479 22 _keep_dirs( $dev, @keep );
5480 }
5481 25 return ( join( "\n", @out ), $ok );
5482 }
5483  
5484 2 ▶sub _truncate {
Subroutine _truncate: called CC=8 SCAR=21.2
5485 2 my ( $dev, $av ) = @_;
5486 2 my @a = @$av;
5487 2 my $size;
5488 my @files;
5489 2 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 4 2 6
5490 4 my $x = shift @a;
5491 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
5492 0 elsif ( $x =~ /\A--size=(.+)\z/ ) { $size = $1 }
5493 2 else { push @files, $x }
5494 }
5495 2 ▶ return ( "truncate: you must specify either '--size' or '--reference'", 0 ) unless defined $size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 0 2 2
5496 2 for my $p (@files) {
5497 2 my $e = _entry_rw( $dev, $p );
5498 2 my $b = _bytes($size);
5499 2 delete $e->{size};
5500 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
5501 2 ▶ $e->{size} = $b if $b > length $e->{content};
Branch: 1 branch
BranchTrueFalseTotal
if $b > length $$e{"content"} 0 2 2
5502 }
5503 2 return ( '', 1 );
5504 }
5505  
5506 # touch [-a|-m|-c] [-d DATUM|--date=DATUM|-t [[CC]JJ]MMTThhmm[.ss]|-r DATEI] DATEI…:
5507 # setzt die Zeit (mtime) wie GNU — ohne Angabe jetzt (Uhr des Geraets), -d wie date -d
5508 # ("20 days ago", "2026-09-30 01:30", yesterday); -c legt nichts an
5509 19 ▶sub _touch {
Subroutine _touch: called CC=57 SCAR=52.5
5510 19 my ( $dev, $av ) = @_;
5511 19 my ( $when, $ref, $nocreate, @files );
5512 19 my @a = @$av;
5513 19 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 26 19 45
5514 26 my $x = shift @a;
5515 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
5516 0 elsif ( $x =~ /\A--date=(.*)\z/s ) { $when = [ d => $1 ] }
5517 0 elsif ( $x =~ /\A-[acmhf]*d(.+)\z/s ) { $when = [ d => $1 ] }
5518 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
5519 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
5520 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
5521 0 elsif ( $x =~ /\A--reference=(.*)\z/ ) { $ref = $1 }
5522 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
5523 0 elsif ( $x eq '--' ) { push @files, @a; last }
5524 0 elsif ( $x =~ /\A--/ ) { return ( "touch: unrecognized option '$x'\nTry 'touch --help' for more information.", 0 ) }
5525 0 elsif ( $x =~ /\A-(.)/ ) { return ( "touch: invalid option -- '$1'\nTry 'touch --help' for more information.", 0 ) }
5526 19 else { push @files, $x }
5527 }
5528 19 ▶ return ( "touch: missing file operand\nTry 'touch --help' for more information.", 0 ) unless @files;
Branch: 1 branch
BranchTrueFalseTotal
unless @files 0 19 19
5529 19 my $mtime;
5530 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
5531 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
5532 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
5533 }
5534 ▶ 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
5535 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
5536 4 ▶ return ( "touch: invalid date format '$when->[1]'", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 1 3 4
5537 3 $mtime = _mtime_str($t);
5538 }
5539 elsif ($when) {
5540 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
5541 or return ( "touch: invalid date format '$when->[1]'", 0 );
5542 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
5543 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
5544 1 my $mon = (qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ))[ $mo - 1 ];
5545 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
5546 }
5547 13 else { $mtime = _mtime_str( _dev_now($dev) ) }
5548 18 for my $raw (@files) {
5549 18 my $p = _absp($raw);
5550 18 ▶ if ( _file_entry( $dev, $p ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_file_entry($dev, $p)) 1 17 18
5551 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
5552 1 my $e = _entry_rw( $dev, $p );
5553 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
5554 1 next;
5555 }
5556 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
5557 16 my ($dir) = $p =~ m{\A(.*)/[^/]+\z};
5558 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
5559 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
5560 12 my $meta = _new_meta( $dev, $p, 0 );
5561 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
5562 }
5563 14 return ( '', 1 );
5564 }
5565  
5566 # Forgejo-Server, den curl/wget mit dieser URL erreicht (das Geraet selbst oder ueber den Namen)
5567 86 ▶sub _forgejo_for {
Subroutine _forgejo_for: called CC=13 SCAR=27.6
5568 86 my ( $dev, $a ) = @_;
5569 86 my ($url) = grep {m{\Ahttps?://}} @$a;
5570 86 ▶ return $dev->{forgejo} ? $dev : undef unless defined $url;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $url 0 86 86
$$dev{'forgejo'} ? : 0 0 0
5571 86 my ($h) = $url =~ m{\Ahttps?://([^/:]+)};
5572 86 ▶ return $dev if $dev->{forgejo};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"forgejo"} 2 84 86
5573 84 ▶ my $st = ( $CTX || {} )->{state} || {};
Condition50%2/4
($Langertha::Holmgang::Sim::Linux::CTX || {})->{'state'} || {}
l!l
840
$Langertha::Holmgang::Sim::Linux::CTX || {}
l!l
840
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
5574 84 my $any;
5575 84 for my $k ( sort keys %$st ) {
5576 155 ▶ 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 151 155
Condition66%2/3
ref $$st{$k} eq 'HASH' && $$st{$k}{'forgejo'}
!ll&&!rl&&r
01514
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
5577 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
5578 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
5579 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
5580 }
5581 82 return $any; # in einer Welt mit Forgejo gibt es curl/wget; andere Ziele sind nicht erreichbar
5582 }
5583  
5584 0 ▶sub _dirname {
Subroutine _dirname: not called CC=5 SCAR=34.0
5585 0 my ( $dev, $av ) = @_;
5586 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
5587 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
5588 }
5589  
5590 0 ▶sub _basename {
Subroutine _basename: not called CC=4 SCAR=30.0
5591 0 my ( $dev, $av ) = @_;
5592 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
5593 0 my ( $p, $suf ) = @p;
5594 0 ( my $b = $p ) =~ s{/+\z}{};
5595 0 $b =~ s{.*/}{};
5596 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
5597 0 return ( $b, 1 );
5598 }
5599  
5600 0 ▶sub _hashsum {
Subroutine _hashsum: not called CC=5 SCAR=34.0
5601 0 my ( $alg, $dev, $av ) = @_;
5602 0 require Digest::MD5;
5603 0 require Digest::SHA;
5604 0 my ( @out, $ok );
5605 0 $ok = 1;
5606 0 for my $p ( grep { !/\A-/ } @$av ) {
5607 0 ▶ my $t = _file_entry( $dev, $p ) ? _file_text( $dev, $p ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
_file_entry($dev, $p) ? : 0 0 0
5608 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
5609 0 my $bytes = Encode::encode( 'UTF-8', $t );
5610 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
5611 }
5612 0 return ( join( "\n", @out ), $ok );
5613 }
5614  
5615 # gzip -d/-dc/-t, gunzip, zcat: echte gzip-Daten (z. B. aus einem Helm-Release-Secret)
5616 2 ▶sub _gzip {
Subroutine _gzip: called CC=23 SCAR=42.9
5617 2 my ( $mode, $dev, $av, $ctx, $stdin ) = @_;
5618 2 require IO::Uncompress::Gunzip;
5619 2 ▶ my $opt = join '', map { /\A-([a-z]+)\z/ ? $1 : '' } @$av;
Branch: 1 branch
BranchTrueFalseTotal
/\A-([a-z]+)\z/ ? : 1 0 1
5620 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
5621 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
5622 2 my $test = $opt =~ /t/;
5623 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
5624 2 my @f = grep { !/\A-/ } @$av;
5625 2 ▶ my @src = @f ? @f : (undef);
Branch: 1 branch
BranchTrueFalseTotal
@f ? : 0 2 2
5626 2 my ( @out, $ok );
5627 2 $ok = 1;
5628 2 for my $p (@src) {
5629 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
5630 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
5631 2 ▶ my $bytes = utf8::is_utf8($raw) ? Encode::encode( 'UTF-8', $raw ) : $raw;
Branch: 1 branch
BranchTrueFalseTotal
utf8::is_utf8($raw) ? : 0 2 2
5632 2 my $plain;
5633 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
5634 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
5635 0 $ok = 0;
5636 0 next;
5637 }
5638 2 ▶ next if $test;
Branch: 1 branch
BranchTrueFalseTotal
if $test 0 2 2
5639 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
5640 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
5641 0 ( my $to = $p ) =~ s/\.(?:gz|z|tgz)\z//i;
5642 0 ▶ $to = "$p.out" if $to eq $p;
Branch: 1 branch
BranchTrueFalseTotal
if $to eq $p 0 0 0
5643 0 $dev->{files}{$to} = $text;
5644 0 delete $dev->{files}{$p};
5645 }
5646 2 return ( join( '', @out ) =~ s/\n\z//r, $ok );
5647 }
5648  
5649 58 ▶sub _find {
Subroutine _find: called CC=116 SCAR=55.1
5650 58 my ( $dev, $av, $ctx ) = @_;
5651 58 my @a = @$av;
5652 58 my @roots;
5653 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
5654 58 ▶ @roots = ('.') unless @roots;
Branch: 1 branch
BranchTrueFalseTotal
unless @roots 0 58 58
5655 58 my ( $maxd, $mind, @exec, $has_action );
5656 # Ausdruck wie find: Tests und Aktionen als Code, Operatoren ! -a -o ( ) als Text
5657 58 my @tok;
5658 58 our ( @FIND_ACT, $FIND_PRUNE );
5659 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
5660 58 ▶ my $add = sub { push @tok, $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
5661 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
5662 58 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 152 57 209
5663 152 my $x = shift @a;
5664 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
5665 152 my $v;
5666 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
5667 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
5668 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
5669 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
5670 ▶ 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
5671 29 my $re = $glob->( $need->(), $x eq '-iname' );
5672 29 ▶ $add->( sub { ( my $b = $_[0] ) =~ s{.*/}{}; $b =~ $re } );
Subroutine __ANON__: called CC=1 SCAR=0.0
5673 }
5674 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
5675 elsif ( $x eq '-perm' ) {
5676 18 $v = $need->();
5677 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
5678 165 ▶ $add->( sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
5679 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
5680 165 my ( $k, $want ) = @$perm;
5681 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
5682 18 } );
5683 }
5684 elsif ( $x eq '-size' ) {
5685 1 $v = $need->();
5686 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
5687 1 my $lim = $n * { '' => 512, c => 1, k => 1024, M => 1024**2, G => 1024**3 }->{$u};
5688 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
5689 }
5690 elsif ( $x eq '-type' ) {
5691 26 $v = $need->();
5692 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
5693 26 my %t = map { $_ => 1 } split /,/, $v;
5694 26 ▶ $add->( sub { $t{ $_[2] } } );
Subroutine __ANON__: called CC=1 SCAR=0.0
5695 }
5696 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
5697 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
5698 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
5699 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
5700 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
5701 0 ▶ elsif ( $x eq '-true' ) { $add->( sub {1} ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
5702 0 ▶ elsif ( $x eq '-false' ) { $add->( sub {0} ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
5703 ▶ 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
5704 9 $v = $need->();
5705 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
5706 9 ▶ my $unit = $x eq '-mtime' ? 86400 : 60;
Branch: 1 branch
BranchTrueFalseTotal
$x eq '-mtime' ? : 9 0 9
5707 9 my $lim = $n * $unit;
5708 22 ▶ $add->( sub {
Subroutine __ANON__: called CC=8 SCAR=23.7
5709 # ohne mtime im Zustand (Verzeichnisse, Vorgabe): gerade eben
5710 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
5711 22 my $d = int( ( _local_now($dev) - $mt ) / $unit ) * $unit;
5712 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
5713 9 } );
5714 }
5715 elsif ( $x eq '-newer' ) {
5716 1 $v = $need->();
5717 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
5718 1 my $t = _mtime($r);
5719 1 ▶ $add->( sub { _mtime( $_[1] ) > $t } );
Subroutine __ANON__: called CC=1 SCAR=0.0
5720 }
5721 elsif ( $x eq '-newermt' ) {
5722 1 $v = $need->();
5723 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
5724 1 $t += Langertha::Holmgang::Sim::Linux::Calendar::offset($t); # mtime im Zustand ist Ortszeit
5725 1 ▶ $add->( sub { _mtime( $_[1] ) > $t } );
Subroutine __ANON__: called CC=1 SCAR=0.0
5726 }
5727 ▶ 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
5728 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
5729 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
5730 8 ▶ ( $x eq '-maxdepth' ? $maxd : $mind ) = $v;
Branch: 1 branch
BranchTrueFalseTotal
$x eq '-maxdepth' ? : 7 1 8
5731 }
5732 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
5733 ▶ 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
5734 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
5735 2 elsif ( $x eq '-ls' ) { $act->('ls') }
5736 1 elsif ( $x eq '-printf' ) { $act->( 'printf', $need->() ) }
5737 ▶ 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
5738 8 my @c;
5739 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
5740 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
5741 8 ▶ $end = ';' if $end eq '\\;';
Branch: 1 branch
BranchTrueFalseTotal
if $end eq "\\;" 0 8 8
5742 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
5743 8 push @exec, [ \@c, $end ];
5744 8 $act->( 'exec', $#exec );
5745 }
5746 3 elsif ( $x eq '-delete' ) { $act->('delete') }
5747 1 else { return ( "find: unknown predicate `$x'", 0 ) }
5748 }
5749 # Vorrang wie find: ( ) vor ! vor -a (auch ohne Wort) vor -o
5750 57 my $pos = 0;
5751 57 my ( $p_or, $p_and, $p_un );
5752 122 ▶ $p_un = sub {
Subroutine __ANON__: called CC=15 SCAR=28.0
5753 122 my $t = $tok[$pos];
5754 122 ▶ die "find: expected an expression at the end\n" unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 122 122
5755 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
5756 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
5757 6 $pos++;
5758 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
5759 6 my $e = $p_or->();
5760 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
5761 5 $pos++;
5762 5 return $e;
5763 }
5764 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
5765 110 ▶ die "find: invalid expression; you have too many ')'\n" if !ref $t;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $t 0 110 110
5766 110 $pos++;
5767 110 return $t;
5768 57 };
5769 72 ▶ $p_and = sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
5770 72 my @e = ( $p_un->() );
5771 70 ▶ while ( defined( my $t = $tok[$pos] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $t = $tok[$pos])) 62 53 115
5772 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
5773 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
5774 45 push @e, $p_un->();
5775 }
5776 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
5777 57 };
5778 60 ▶ $p_or = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
5779 60 my @e = ( $p_and->() );
5780 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
5781 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
5782 57 };
5783 57 ▶ my $expr = sub {1};
Subroutine __ANON__: called CC=1 SCAR=0.0
5784 57 ▶ if (@tok) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tok) 54 3 57
5785 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
5786 54 ▶ if ( my $err = $@ ) { $err =~ s/\s+\z//; return ( $err, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 2 52 54
5787 }
5788 55 my ( @hit, @err );
5789 55 for my $r (@roots) {
5790 55 ( my $root = $r ) =~ s{(?<=.)/+\z}{};
5791 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
5792 55 my @cand = ( [ $root, 0 ] );
5793 55 ▶ if ( !_file_entry( $dev, $root ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_file_entry($dev, $root)) 55 0 55
5794 55 my %seen;
5795 55 ▶ my $pre = $root eq '/' ? '/' : "$root/";
Branch: 1 branch
BranchTrueFalseTotal
$root eq '/' ? : 6 49 55
5796 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
5797 490 ▶ next unless index( $p, $pre ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless index($p, $pre) == 0 293 197 490
5798 197 my @seg = split m{/}, substr( $p, length $pre );
5799 197 $seen{ $pre . join( '/', @seg[ 0 .. $_ ] ) } = $_ + 1 for 0 .. $#seg;
5800 }
5801 55 push @cand, map { [ $_, $seen{$_} ] } sort keys %seen;
5802 }
5803 55 my @pruned; # Eltern stehen vor ihren Kindern (sortiert)
5804 55 for my $c (@cand) {
5805 355 my ( $p, $depth ) = @$c;
5806 355 ▶ next if grep { index( $p, "$_/" ) == 0 } @pruned;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($p, "$_/") == 0;} @pruned 3 352 355
5807 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
5808 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
5809 344 my $fe = _file_entry( $dev, $p );
5810 344 ▶ my $kind = $fe ? ( defined $fe->{link} ? 'l' : 'f' ) : 'd';
Branch: 2 branches
BranchTrueFalseTotal
$fe ? : 177 167 344
defined $$fe{'link'} ? : 0 177 177
5811 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
5812 344 local @FIND_ACT = ();
5813 344 local $FIND_PRUNE;
5814 344 my $match = $expr->( $p, $e, $kind );
5815 344 ▶ push @pruned, $p if $FIND_PRUNE;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::FIND_PRUNE 3 341 344
5816 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
5817 61 elsif ($match) { push @hit, [ $p, $e, $kind, [ ['print'] ] ] }
5818 }
5819 }
5820 55 my @out = @err;
5821 55 ▶ my $ok = @err ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
@err ? : 0 55 55
5822 55 my ( %exec_paths, @del, $txt );
5823 55 $txt = '';
5824 55 for my $h (@hit) {
5825 100 my ( $p, $e, $kind, $acts ) = @$h;
5826 100 for my $a (@$acts) {
5827 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
5828 3 elsif ( $a->[0] eq 'ls' ) { $txt .= _ls_line( $dev, $p, $p ) . "\n" }
5829 1 elsif ( $a->[0] eq 'printf' ) { $txt .= _find_printf( $dev, $a->[1], $p, $e, $kind ) }
5830 16 elsif ( $a->[0] eq 'exec' ) { push @{ $exec_paths{ $a->[1] } }, $p }
5831 5 elsif ( $a->[0] eq 'delete' ) { push @del, $p }
5832 }
5833 }
5834 55 $txt =~ s/\n\z//;
5835 55 ▶ push @out, $txt if length $txt;
Branch: 1 branch
BranchTrueFalseTotal
if length $txt 42 13 55
5836 55 for my $i ( 0 .. $#exec ) {
5837 8 my ( $c, $end ) = @{ $exec[$i] };
5838 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
5839 6 ▶ my @runs = $end eq '+' ? ( @paths ? [ map { $_ eq '{}' ? @paths : $_ } @$c ] : () )
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '{}' ? : 2 4 6
5840 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
5841 8 for my $argv (@runs) {
5842 14 my ( $o, $k ) = __PACKAGE__->_command( $dev, $argv, $ctx, undef );
5843 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
5844 14 ▶ $ok = 0 unless $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $k 2 12 14
5845 }
5846 }
5847 55 for my $p ( reverse @del ) {
5848 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
5849 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
5850 0 else { push @out, "find: cannot delete '$p': Directory not empty"; $ok = 0 }
5851 }
5852 55 return ( join( "\n", @out ), $ok );
5853 }
5854  
5855 # find -printf: %p %f %h %s %u %g %m %M %l %y %t %T+ %TY-%Tm-%Td, \n \t
5856 1 ▶sub _find_printf {
Subroutine _find_printf: called CC=9 SCAR=24.1
5857 1 my ( $dev, $fmt, $p, $e, $kind ) = @_;
5858 1 my $t = _mtime($e); # Ortszeit
5859 1 my @g = gmtime $t;
5860 1 my ( $base, $dir ) = ( $p =~ m{([^/]*)\z} )[0];
5861 1 ( $dir = $p ) =~ s{/[^/]*\z}{};
5862 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
5863 my %f = (
5864 p => $p, f => $base, h => length $dir ? $dir : '.', s => $kind eq 'd' ? 4096 : _file_size($e), u => $e->{owner} // 'root',
5865 g => $e->{group} // 'root', m => sprintf( '%o', $m & 07777 ), M => _mode_text( $m, $kind eq 'd', $kind eq 'l' ),
5866 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
5867 '%' => '%',
5868 );
5869 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] ),
5870 Y => sprintf( '%04d', $g[5] + 1900 ), m => sprintf( '%02d', $g[4] + 1 ), d => sprintf( '%02d', $g[3] ), H => sprintf( '%02d', $g[2] ),
5871 M => sprintf( '%02d', $g[1] ), S => sprintf( '%02d', $g[0] ), F => sprintf( '%04d-%02d-%02d', $g[5] + 1900, $g[4] + 1, $g[3] ),
5872 T => sprintf( '%02d:%02d:%02d', $g[2], $g[1], $g[0] ) );
5873 1 ( my $s = $fmt ) =~ s/\\n/\n/g;
5874 1 $s =~ s/\\t/\t/g;
5875 1 $s =~ s/%[TA]([+YmdHMSFT])/$T{$1}/g;
5876 1 ▶ $s =~ s/%(-?\d*)([pfhsugmMlyt%])/length $1 ? sprintf( "%$1s", $f{$2} ) : $f{$2}/ge;
Branch: 1 branch
BranchTrueFalseTotal
length $1 ? : 0 3 3
5877 1 return $s;
5878 }
5879  
5880 0 ▶sub _ls_names_empty { my ( $dev, $p ) = @_; return !%{ _ls_names( $dev, $p ) } }
Subroutine _ls_names_empty: not called CC=1 SCAR=6.9
5881  
5882 # -perm [-/]oktal | [-/]u=s,g+w… -> [ art, maske ]
5883 18 ▶sub _find_perm {
Subroutine _find_perm: called CC=11 SCAR=26.8
5884 18 my ($v) = @_;
5885 18 ▶ my ( $kind, $rest ) = $v =~ /\A([-\/]?)(.+)\z/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = $v =~ m[\A([-/]?)(.+)\z] or return undef 18 0 18
5886 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
5887 1 my $m = 0;
5888 1 for my $part ( split /,/, $rest ) {
5889 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
5890 2 ▶ $who = 'a' if $who eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $who eq "" 0 2 2
5891 2 ▶ for my $w ( $who =~ /a/ ? qw( u g o ) : split //, $who ) {
Branch: 1 branch
BranchTrueFalseTotal
$who =~ /a/ ? : 0 2 2
5892 2 my $sh = { u => 6, g => 3, o => 0 }->{$w};
5893 2 for ( split //, $p ) {
5894 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
5895 0 elsif ( $_ eq 't' ) { $m |= 01000 }
5896 0 else { $m |= { r => 4, w => 2, x => 1 }->{$_} << $sh }
5897 }
5898 }
5899 }
5900 1 return [ $kind, $m ];
5901 }
5902  
5903 1 ▶sub _lsof {
Subroutine _lsof: called CC=15 SCAR=40.6
5904 1 my ( $dev, $av ) = @_;
5905 1 my @l = ('COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME');
5906 1 my $pid = 1200;
5907 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
5908 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
5909 push @l, sprintf( '%-9s %5d %-6s %4s %4s %6s %12d %5d %7d %s (deleted)', substr( $d->{by} // '?', 0, 9 ), $pid++, $u,
5910 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
5911 }
5912 1 ▶ if ( !grep { /\+L1|-a|deleted/ } @$av ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {/\+L1|-a|deleted/;} @$av) 0 1 1
5913 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
5914 0 my $e = _file_entry( $dev, $p );
5915 0 ▶ next unless defined $e->{open_by};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$e{"open_by"} 0 0 0
5916 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
5917 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',
5918 _file_size($e), 1, 4243, $p );
5919 }
5920 }
5921 1 return ( join( "\n", @l ), 1 );
5922 }
5923  
5924 # Datenbank-Programme gibt es nur, wo die Datenbank laeuft
5925 176 our %NEEDS = ( ( map { $_ => 'redis' } qw( redis-cli redis-server ) ),
5926 88 ( map { $_ => 'mariadb' } qw( mysql mariadb mysqld mariadbd mysqladmin mariadb-admin mysqldump ) ) );
5927  
5928 # Zeitangabe fuer date -d: @EPOCHE, now/today/tomorrow/yesterday, [JJJJ-MM-TT][ |T][HH:MM[:SS]] [ZONE|+HH:MM],
5929 # [now] + N hours|minutes|days; $now ist die Uhr des Geraets
5930 17 ▶sub _date_parse {
Subroutine _date_parse: called CC=29 SCAR=36.9
5931 17 my ( $s, $tz, $C, $now ) = @_;
5932 17 $s =~ s/\A\s+|\s+\z//g;
5933 17 ▶ return $1 if $s =~ /\A\@(-?\d+)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ /\A\@(-?\d+)\z/ 1 16 17
5934 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
5935 # "20 days ago", "-3 days", "2 hours ago" (Monate/Jahre wie GNU als Kalenderschritt genaehert)
5936 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
5937 3 ▶ my ( $n, $u ) = defined $1 ? ( $1, lc $2 ) : ( $3, lc $4 );
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 3 0 3
5938 3 my %f = ( sec => 1, second => 1, seconds => 1, secs => 1, min => 60, mins => 60, minute => 60, minutes => 60, hour => 3600, hours => 3600,
5939 day => 86400, days => 86400, week => 604800, weeks => 604800, month => 2592000, months => 2592000, year => 31536000, years => 31536000 );
5940 3 ▶ return defined $f{$u} ? $now - $n * $f{$u} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $f{$u} ? : 3 0 3
5941 }
5942 13 my $fixed; # +02:00 am Ende: fester Versatz
5943 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
5944 13 my $zone = $tz;
5945 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
5946 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
5947 13 my @l = gmtime( $now + $C->can('offset')->( $now, $zone ) );
5948 13 my ( $y, $m, $d, $H, $M, $S ) = ( $l[5] + 1900, $l[4] + 1, $l[3], 0, 0, 0 );
5949 13 my $day = 0;
5950 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
5951 elsif ( $s =~ s/\A(today|tomorrow|yesterday)\b\s*//i ) {
5952 3 $day = { today => 0, tomorrow => 1, yesterday => -1 }->{ lc $1 };
5953 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
5954 }
5955 8 elsif ( $s =~ s/\A(\d{4})-(\d{1,2})-(\d{1,2})(?:[ T]+|\z)// ) { ( $y, $m, $d ) = ( $1, $2, $3 ) }
5956 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
5957 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
5958 11 require Time::Local;
5959 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
5960 11 $u += 86400 * $day;
5961 11 ▶ return $u - $fixed if defined $fixed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fixed 0 11 11
5962 11 my $off = $C->can('offset')->( $u - $C->can('offset')->( $u, $zone ), $zone );
5963 11 return $u - $off;
5964 }
5965  
5966 # redis-cli (ohne Redis-Zustand)/redis-server: nur mit einem Dienst redis-server (Langertha::Holmgang::Sim::Linux::RedisService)
5967 14 ▶sub _redis_cmd {
Subroutine _redis_cmd: called CC=6 SCAR=17.9
5968 14 my ( $how, $dev, $av, $ctx ) = @_;
5969 14 _part('RedisService');
5970 14 ▶ my $n = $how eq 'cli' ? 'redis-cli' : 'redis-server';
Branch: 1 branch
BranchTrueFalseTotal
$how eq 'cli' ? : 12 2 14
5971 14 ▶ if ( !Langertha::Holmgang::Sim::Linux::RedisService::installed($dev) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Langertha::Holmgang::Sim::Linux::RedisService::installed($dev)) 1 13 14
5972 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
5973 1 push @GAPS, join( ' ', $n, @$av );
5974 1 return ( '', 0 );
5975 }
5976 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
5977 13 ▶ push @GAPS, $gap if defined $gap;
Branch: 1 branch
BranchTrueFalseTotal
if defined $gap 1 12 13
5978 13 return ( $o, $k );
5979 }
5980  
5981 # Dateiargumente eines Filters (head -n 3 DATEI, awk PROG DATEI …): ohne Optionen und
5982 # ihre Werte, ohne das Programm von awk und ohne die Ausgabedatei von uniq; tr liest nur stdin
5983 88 my %FILTER_VALUE = (
5984 head => qr/\A(?:-[nc]|--lines|--bytes)\z/, tail => qr/\A(?:-[ncs]|--lines|--bytes|--pid|--sleep-interval)\z/,
5985 sort => qr/\A(?:-[ktoTS]|--key|--field-separator|--output|--buffer-size)\z/, uniq => qr/\A-[fsw]\z/,
5986 cut => qr/\A-[dfcb]\z/, awk => qr/\A-[Fvf]\z/, fold => qr/\A-w\z/, wc => qr/\A(?!)/,
5987 );
5988 33 ▶sub _filter_files {
Subroutine _filter_files: called CC=12 SCAR=26.2
5989 33 my ( $cmd, @a ) = @_;
5990 33 ▶ my $val = $FILTER_VALUE{$cmd} or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $val = $FILTER_VALUE{$cmd} or return () 33 0 33
5991 33 my ( @ops, $prog_f );
5992 33 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 65 33 98
5993 65 my $x = shift @a;
5994 0 ▶ if ( $x eq '--' ) { push @ops, @a; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "--") 0 65 65
5995 65 ▶ if ( $x =~ $val ) { $prog_f = 1 if $cmd eq 'awk' && $x eq '-f'; shift @a; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($x =~ /$val/) 9 56 65
if $cmd eq "awk" and $x eq "-f" 0 9 9
Condition33%1/3
$cmd eq "awk" and $x eq "-f"
!ll&&!rl&&r
900
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
5996 56 ▶ next if $x =~ /\A-./;
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /\A-./ 21 35 56
5997 35 push @ops, $x;
5998 }
5999 33 ▶ if ( $cmd eq 'awk' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "awk") 4 29 33
6000 4 ▶ shift @ops unless $prog_f; # das Programm
Branch: 1 branch
BranchTrueFalseTotal
unless $prog_f 4 0 4
6001 4 @ops = grep { !/\A[A-Za-z_]\w*=/ } @ops; # var=wert ist eine Zuweisung
6002 }
6003 33 ▶ @ops = @ops[ 0 .. 0 ] if $cmd eq 'uniq' && @ops > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "uniq" and @ops > 1 0 33 33
Condition66%2/3
$cmd eq "uniq" and @ops > 1
!ll&&!rl&&r
3210
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
6004 33 return @ops;
6005 }
6006  
6007 # od -c | -An | -t c [DATEI…]: Bytes als Zeichen wie GNU od (je Zeile 16, Breite 4,
6008 # \n \t … als Escapes, sonst oktal), Versatz oktal; anderes ist eine Luecke
6009 6 ▶sub _od {
Subroutine _od: called CC=40 SCAR=44.6
6010 6 my ( $dev, $av, $ctx, $stdin ) = @_;
6011 6 my ( $chars, $hex, $noaddr, @files );
6012 6 my @a = @$av;
6013 6 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 9 6 15
6014 9 my $x = shift @a;
6015 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
6016 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
6017 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
6018 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
6019 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
6020 0 elsif ( $x =~ /\A-/ ) { push @GAPS, join( ' ', 'od', @$av ); return ( '', 0 ) }
6021 1 else { push @files, $x }
6022 }
6023 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
6024 6 my $in = '';
6025 6 ▶ if (@files) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) { } 1 5 6
6026 1 for my $f (@files) {
6027 1 my $p = _absp($f);
6028 1 ▶ return ( "od: $f: Permission denied", 0 ) unless _read_ok( $dev, $p );
Branch: 1 branch
BranchTrueFalseTotal
unless _read_ok($dev, $p) 0 1 1
6029 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
6030 1 $in .= $t;
6031 }
6032 }
6033 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
6034 6 utf8::encode( my $b = $in );
6035 6 my %esc = ( 0 => '\0', 7 => '\a', 8 => '\b', 9 => '\t', 10 => '\n', 11 => '\v', 12 => '\f', 13 => '\r' );
6036 6 my ( @l, $prev, $star );
6037 6 ▶ for ( my $o = 0; $o < length $b; $o += 16 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o < length $b) 7 6 13
6038 7 my $chunk = substr( $b, $o, 16 );
6039 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
6040 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
6041 7 ( $prev, $star ) = ( $chunk, 0 );
6042 7 ▶ push @l, $noaddr ? $row : sprintf( '%07o', $o ) . $row;
Branch: 1 branch
BranchTrueFalseTotal
$noaddr ? : 2 5 7
6043 }
6044 6 ▶ push @l, sprintf '%07o', length $b unless $noaddr;
Branch: 1 branch
BranchTrueFalseTotal
unless $noaddr 4 2 6
6045 6 return ( join( "\n", @l ), 1 );
6046 }
6047  
6048 # flock [-n|-x|-s|-w N|-E N] FD | DATEI [-c BEFEHL | BEFEHL …]: gelingt (die Simulation
6049 # kennt keine nebenlaeufigen Laeufe, es haelt niemand die Sperre); die Sperrdatei wird
6050 # angelegt, ein Befehl laeuft
6051 3 ▶sub _flock {
Subroutine _flock: called CC=21 SCAR=35.6
6052 3 my ( $dev, $av, $ctx, $stdin ) = @_;
6053 3 my @a = @$av;
6054 3 my $c;
6055 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
6056 3 my $x = shift @a;
6057 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
6058 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
6059 elsif ( $x =~ /\A-[nxseuo]+\z|\A--(?:nonblock|exclusive|shared|unlock|close)\z/ ) { }
6060 0 else { return ( "flock: unrecognized option '$x'", 0 ) }
6061 }
6062 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
6063 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
6064 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
6065 2 my $p = _absp($t);
6066 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
6067 2 my ( $e, $wok ) = _write_path( $dev, $p, '', 0, $ctx );
6068 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
6069 }
6070 2 ▶ return __PACKAGE__->_run_inner( $dev, $c, $ctx ) if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 1 1 2
6071 1 ▶ return ( '', 1 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 1 1
6072 1 return __PACKAGE__->_command( $dev, \@a, $ctx, $stdin );
6073 }
6074  
6075 # Pruefsumme wie coreutils (md5, sha1, sha256) ueber die Bytes (UTF-8); hier fuer sha256sum
6076 # ohne Datei (stdin) — Dateien rechnet Sim::Backup, md5sum hat _md5sum; -c ist eine Luecke
6077 2 ▶sub _digest {
Subroutine _digest: called CC=17 SCAR=49.9
6078 2 my ( $alg, $dev, $av, $ctx, $stdin ) = @_;
6079 0 my @f = grep { !/\A-/ } @$av;
6080 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
6081 2 require Digest::MD5;
6082 2 require Digest::SHA;
6083 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
6084 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
6085 0 my ( @out, $ok ) = ();
6086 0 $ok = 1;
6087 0 for my $f (@f) {
6088 0 my $p = _absp($f);
6089 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
6090 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
6091 0 my $t = _file_text( $dev, $p );
6092 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
6093 0 my $e = _file_entry( $dev, $p );
6094 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
6095 0 push @out, $h->($t) . " $f";
6096 }
6097 0 return ( join( "\n", @out ), $ok );
6098 }
6099  
6100 # lsblk-Optionen: -o|--output LISTE (+LISTE ergaenzt die Vorgabe), -b, -n, -l, -p, -a, -f, -m,
6101 # Geraete als Argumente. Rueckgabe \%o; ( undef, Text ) bei Fehler wie lsblk; () bei Luecke
6102 88 our %LSBLK_COL = map { $_ => 1 } qw( NAME KNAME PATH MAJ:MIN RM SIZE RO TYPE MOUNTPOINT MOUNTPOINTS FSTYPE LABEL UUID FSAVAIL FSUSE% );
6103  
6104 7 ▶sub _lsblk_opts {
Subroutine _lsblk_opts: called CC=23 SCAR=34.3
6105 7 my ($av) = @_;
6106 7 my %o = ( dev => [] );
6107 7 my %long = ( all => 'a', bytes => 'b', noheadings => 'n', list => 'l', paths => 'p', fs => 'f', perms => 'm' );
6108 7 my @a = @$av;
6109 7 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 9 7 16
6110 9 my $x = shift @a;
6111 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
6112 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
6113 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
6114 ▶ 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
6115 8 my ( $fl, $oo, $rest ) = ( $1, $2, $3 );
6116 8 $o{$_} = 1 for split //, $fl;
6117 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
6118 }
6119 0 elsif ( $x =~ /\A-/ ) { return }
6120 1 else { push @{ $o{dev} }, $x }
6121 }
6122 7 ▶ return if $o{m};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"m"} 0 7 7
6123 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
6124 7 ▶ if ( defined $o{cols} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o{'cols'}) { } 4 3 7
6125 4 my $plus = $o{cols} =~ s/\A\+//;
6126 4 my @c = map {uc} grep {length} split /,/, $o{cols};
6127 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
6128 3 ▶ $o{list} = [ $plus ? ( @def, @c ) : @c ];
Branch: 1 branch
BranchTrueFalseTotal
$plus ? : 0 3 3
6129 }
6130 3 else { $o{list} = \@def }
6131 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
6132 6 return \%o;
6133 }
6134  
6135 # Zeilen -> Tabelle wie lsblk: Zeile { name, path, tree, majmin, size (Bytes), type, mps => [], fstype,
6136 # label, uuid, fsavail (Bytes), fsuse }; Zahlenspalten rechtsbuendig, eine Leerstelle dazwischen
6137 3 ▶sub _lsblk_table {
Subroutine _lsblk_table: called CC=5 SCAR=16.9
6138 3 my ( $rows, $o ) = @_;
6139 3 my %right = map { $_ => 1 } qw( RM SIZE RO FSAVAIL FSUSE% );
6140 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
6141 my %val = (
6142 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
6143 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
6144 0 ▶ PATH => sub { $_[0]{path} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
6145 0 ▶ 'MAJ:MIN' => sub { $_[0]{majmin} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
6146 0 ▶ RM => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
6147 0 ▶ RO => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
6148 2 ▶ SIZE => sub { $sz->( $_[0]{size} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
6149 2 ▶ TYPE => sub { $_[0]{type} },
Subroutine __ANON__: called CC=1 SCAR=0.0
6150 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
6151 0 ▶ MOUNTPOINTS => sub { join ' ', @{ $_[0]{mps} } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
6152 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
6153 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
6154 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
6155 0 ▶ FSAVAIL => sub { $sz->( $_[0]{fsavail} ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
6156 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
6157 3 );
6158 3 my @c = @{ $o->{list} };
6159 3 ▶ my @t = ( $o->{n} ? () : [@c], map { my $r = $_; [ map { $val{$_}->($r) } @c ] } @$rows );
Branch: 1 branch
BranchTrueFalseTotal
$$o{'n'} ? : 2 1 3
6160 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
6161 return join "\n", map {
6162 3 my $r = $_;
6163 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
6164 } @t;
6165 }
6166  
6167 # lsblk ohne Platten im Zustand: die Geraete der Einhaengepunkte (vda1 -> Platte vda);
6168 # LABEL, UUID und -f/-m kennt der Zustand hier nicht (Luecke)
6169 5 ▶sub _lsblk_basic {
Subroutine _lsblk_basic: called CC=28 SCAR=34.1
6170 5 my ( $dev, $av ) = @_;
6171 5 my ( $o, $err ) = _lsblk_opts($av);
6172 5 ▶ return ( $err, 0 ) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 1 4 5
6173 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
6174 3 my $m = _mounts($dev);
6175 3 my ( %disk, @order );
6176 3 my $minor = 0;
6177 3 for my $mp ( sort keys %$m ) {
6178 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
6179 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
6180 3 my $part = $1;
6181 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
6182 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
6183 3 ▶ push @order, $disk unless $disk{$disk};
Branch: 1 branch
BranchTrueFalseTotal
unless $disk{$disk} 3 0 3
6184 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
6185 }
6186 3 my %df = map { $_->{mount} => $_ } _df_rows($dev);
6187 3 my @rows;
6188 3 my $maj = 254;
6189 3 for my $dk (@order) {
6190 3 my $base = $minor;
6191 3 my @parts = grep { $_->[0] ne $dk } @{ $disk{$dk} };
6192 3 my ($whole) = grep { $_->[0] eq $dk } @{ $disk{$dk} };
6193 3 ▶ my $size = $whole ? $whole->[1] : $parts[0][1];
Branch: 1 branch
BranchTrueFalseTotal
$whole ? : 0 3 3
6194 3 my @r = ( [ $dk, "$maj:$base", $size, 'disk', $whole, '' ] );
6195 3 my $i = 0;
6196 3 for my $pt (@parts) {
6197 3 $i++;
6198 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
6199 }
6200 3 for (@r) {
6201 6 my ( $n, $mm, $sz, $type, $src, $tree ) = @$_;
6202 6 ▶ my $mp = $src ? $src->[2] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$src ? : 3 3 6
6203 6 ▶ my $df = defined $mp ? $df{$mp} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $mp ? : 3 3 6
6204 push @rows, { name => $n, path => "/dev/$n", tree => $tree, majmin => $mm, size => $sz, type => $type, mps => [ $mp // () ],
6205 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
6206 }
6207 3 $minor += 16;
6208 }
6209 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
6210 1 my @l = ( sprintf '%-8s %-7s %2s %5s %2s %-4s %s', 'NAME', 'MAJ:MIN', 'RM', 'SIZE', 'RO', 'TYPE', 'MOUNTPOINTS' );
6211 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;
6212 1 return ( join( "\n", @l ), 1 );
6213 }
6214  
6215 # Programm, das als ausfuehrbare Datei im Zustand liegt (z. B. /usr/bin/redis-cli)
6216 2428 ▶sub _prog_file {
Subroutine _prog_file: called CC=5 SCAR=16.3
6217 2428 my ( $dev, $n ) = @_;
6218 2428 ▶ return undef if $n =~ m{/};
Branch: 1 branch
BranchTrueFalseTotal
if $n =~ m[/] 0 2428 2428
6219 2428 for my $d (qw( /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin )) {
6220 14530 ▶ my $e = _file_entry( $dev, "$d/$n" ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $e = _file_entry($dev, "$d/$n") or next 18 14512 14530
6221 18 ▶ return "$d/$n" if _mode_of($e) & 0111;
Branch: 1 branch
BranchTrueFalseTotal
if _mode_of($e) & 73 18 0 18
6222 }
6223 2410 return undef;
6224 }
6225  
6226 # Shell-Skript im Zustand: Text mit sh/bash/dash-Shebang oder ohne Shebang (leer = Programm)
6227 19 ▶sub _shell_script {
Subroutine _shell_script: called CC=5 SCAR=16.1
6228 19 my ( $dev, $p ) = @_;
6229 19 ▶ return 0 unless _file_entry( $dev, $p );
Branch: 1 branch
BranchTrueFalseTotal
unless _file_entry($dev, $p) 7 12 19
6230 12 ▶ my $t = _file_text( $dev, $p ) // '';
Condition50%1/2
_file_text($dev, $p) // ""
l!l
120
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
6231 12 ▶ 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 4 12
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
138
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
6232 }
6233  
6234 # which/whereis/type/command -v: Pfad eines Programms, das es auf dem System gibt
6235 2365 ▶sub _which {
Subroutine _which: called CC=38 SCAR=36.6
6236 2365 my ( $how, $dev, $av, $ctx, $stdin ) = @_;
6237 2365 my @a = @$av;
6238 2365 ▶ if ( $how eq 'command' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($how eq "command") 2 2363 2365
6239 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
6240 1 shift @a;
6241 }
6242 2364 @a = grep { !/\A-/ } @a;
6243 2364 ▶ return ( '', 1 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 2364 2364
6244 2364 my ( @out, $ok );
6245 2364 $ok = 1;
6246 # Dienstprogramme aus ExecStart (exec); eine Datei des Falls gilt vor der Vorgabe
6247 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
6248 2364 for my $n (@a) {
6249 2372 my ($file) = grep { _file_entry( $dev, $_ ) } map {"$_/$n"} qw( /usr/local/bin /usr/bin /usr/sbin /bin );
6250 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
6251 || $n =~ /\A(?:ls|bash|sh|cat|cp|mv|rm|mkdir|tail|head|grep|sed|awk|find)\z/;
6252 2372 ▶ $have = 0 if $NOT_INSTALLED{$n};
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::NOT_INSTALLED{$n} 61 2311 2372
6253 2372 ▶ $have = 1 if _web_cmd( $dev, $n );
Branch: 1 branch
BranchTrueFalseTotal
if _web_cmd($dev, $n) 1 2371 2372
6254 # Zusatz-Simulatoren (BIND, Postfix, Platten, …) nur, wo ihr Paket im Zustand steht
6255 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
6256 2372 ▶ $have = 1 if $file;
Branch: 1 branch
BranchTrueFalseTotal
if $file 2 2370 2372
6257 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
6258 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
6259 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
6260 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
6261 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
6262 278 ▶ push @out, "bash: type: $n: not found" if $how eq 'type';
Branch: 1 branch
BranchTrueFalseTotal
if $how eq "type" 0 278 278
6263 278 $ok = 0;
6264 278 next;
6265 }
6266 2092 ▶ push @out, $how eq 'type' ? "$n is $path" : $path;
Branch: 1 branch
BranchTrueFalseTotal
$how eq 'type' ? : 1 2091 2092
6267 }
6268 2364 return ( join( "\n", @out ), $ok );
6269 }
6270  
6271 # --- Benutzer und Gruppen ------------------------------------------------------------
6272  
6273 7 ▶sub _id {
Subroutine _id: called CC=6 SCAR=19.2
6274 7 my ( $dev, $av ) = @_;
6275 7 my ($u) = grep { !/\A-/ } @$av;
6276 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
6277 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
6278 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
6279 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
6280 7 return ( "uid=$e->{uid}($u) gid=" . _gid( $dev, $g[0] ) . "($g[0]) groups=" . join( ',', map { _gid( $dev, $_ ) . "($_)" } @g ), 1 );
6281 }
6282  
6283 0 ▶sub _groups_cmd {
Subroutine _groups_cmd: not called CC=6 SCAR=37.4
6284 0 my ( $dev, $av ) = @_;
6285 0 my ($u) = @$av;
6286 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
6287 0 ▶ return ( 'root', 1 ) if $u eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $u eq "root" 0 0 0
6288 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
6289 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
6290 }
6291  
6292 7 ▶sub _usermod {
Subroutine _usermod: called CC=66 SCAR=53.1
6293 7 my ( $dev, $av ) = @_;
6294 7 my @a = @$av;
6295 7 my ( $add, $grps, $del, %set );
6296 7 ▶ while ( @a > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a > 1) 11 7 18
6297 11 my $x = shift @a;
6298 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
6299 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
6300 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
6301 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
6302 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
6303 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
6304 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
6305 0 ▶ elsif ( $x =~ /\A-[LU]+\z/ ) { $set{locked} = $x =~ /L/ ? 1 : 0 }
Branch: 1 branch
BranchTrueFalseTotal
$x =~ /L/ ? : 0 0 0
6306 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
6307 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
6308 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
6309 0 else { return ( "usermod: invalid option -- '$x'", 0 ) }
6310 }
6311 7 my $u = shift @a;
6312 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
6313 7 ▶ if ( defined $set{home} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set{"home"}) 1 6 7
6314 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
6315 1 my $new = delete $set{home};
6316 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
6317 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
6318 1 $e->{home} = $new;
6319 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
6320 }
6321 6 delete $set{move};
6322 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
6323 6 ▶ if ( exists $set{locked} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $set{"locked"}) 1 5 6
6324 1 ▶ my $want = $set{locked} ? JSON::MaybeXS::true() : JSON::MaybeXS::false();
Branch: 1 branch
BranchTrueFalseTotal
$set{'locked'} ? : 1 0 1
6325 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
6326 }
6327 6 ▶ if ( defined $set{shell} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set{"shell"}) 2 4 6
6328 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
6329 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
6330 }
6331 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
6332 1 my %rm = map { $_ => 1 } split /,/, $grps;
6333 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
6334 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
6335 1 return ( '', 1 );
6336 }
6337 5 ▶ return ( %set ? '' : "usermod: no changes", 1 ) unless defined $grps;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $grps 2 3 5
%set ? : 2 0 2
6338 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
6339 3 my @new = split /,/, $grps;
6340 3 ▶ for (@new) { return ( "usermod: group '$_' does not exist", 0 ) unless $known{$_} }
Branch: 1 branch
BranchTrueFalseTotal
unless $known{$_} 1 2 3
6341 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
6342 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
6343 2 ▶ $e->{groups} = \@g unless join( ',', @g ) eq join( ',', @cur );
Branch: 1 branch
BranchTrueFalseTotal
unless join(",", @g) eq join(",", @cur) 2 0 2
6344 2 return ( '', 1 );
6345 }
6346  
6347 # Naechste freie Nummer: Konten ab 1000 nach der hoechsten vergebenen, Systemkonten von 999
6348 # abwaerts (useradd/groupadd -r), adduser/addgroup --system ab 100 aufwaerts; $want zuerst
6349 9 ▶sub _free_id {
Subroutine _free_id: called CC=11 SCAR=24.7
6350 9 my ( $used, $sys, $want, $up ) = @_;
6351 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
6352 7 ▶ if ($sys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sys) 4 3 7
6353 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
6354 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
6355 }
6356 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
6357 3 ▶ return defined $max ? $max + 1 : 1000;
Branch: 1 branch
BranchTrueFalseTotal
defined $max ? : 3 0 3
6358 }
6359  
6360 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
6361  
6362 # groupadd [-r] [-g GID] name | addgroup [--system] [--gid GID] name
6363 4 ▶sub _groupadd {
Subroutine _groupadd: called CC=19 SCAR=36.1
6364 4 my ( $prog, $dev, $av ) = @_;
6365 4 my @a = @$av;
6366 4 my ( $sys, $gid, @n );
6367 4 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 6 4 10
6368 6 my $x = shift @a;
6369 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
6370 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
6371 ▶ 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
6372 0 elsif ( $x =~ /\A-/ ) { return ( "$prog: unrecognized option '$x'", 0 ) }
6373 4 else { push @n, $x }
6374 }
6375 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
6376 4 my $g = $n[0];
6377 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
6378 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
6379 3 my $used = _gids($dev);
6380 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
6381 3 $dev->{groups}{$g} = { gid => 0 + _free_id( $used, $sys, $gid, $prog eq 'addgroup' ) };
6382 3 return ( '', 1 );
6383 }
6384  
6385 # useradd [-m|-M] [-r] [-s S] [-d D] [-g G] [-G a,b] [-u UID] name;
6386 # adduser --system [--group|--ingroup G] [--no-create-home] [--home D] [--shell S] name;
6387 # adduser BENUTZER GRUPPE. Interaktives adduser (Passwort): Luecke der Simulation.
6388 8 ▶sub _useradd {
Subroutine _useradd: called CC=81 SCAR=55.4
6389 8 my ( $prog, $dev, $av ) = @_;
6390 8 my @a = @$av;
6391 8 my ( %o, @n );
6392 8 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 22 8 30
6393 22 my $x = shift @a;
6394 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
6395 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
6396 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
6397 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
6398 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
6399 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
6400 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
6401 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
6402 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
6403 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
6404 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
6405 ▶ 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
6406 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
6407 9 else { push @n, $x }
6408 }
6409 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
6410 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
6411 1 my ( $u, $g ) = @n;
6412 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
6413 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
6414 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
6415 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
6416 1 return ( "Adding user `$u' to group `$g' ...\nDone.", 1 );
6417 }
6418 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
6419 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
6420 6 my $u = $n[0];
6421 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
6422 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
6423 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
6424 5 ▶ my @extra = defined $o{groups} ? split /,/, $o{groups} : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $o{'groups'} ? : 2 3 5
6425 5 ▶ for ( ( defined $o{group} ? $o{group} : () ), @extra ) {
Branch: 1 branch
BranchTrueFalseTotal
defined $o{'group'} ? : 2 3 5
6426 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
6427 }
6428 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
6429 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
6430 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
6431 4 my $uid = _free_id( \%uids, $o{sys}, $o{uid}, $prog eq 'adduser' );
6432 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
6433 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
6434 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
6435 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
6436 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
6437 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
6438 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
6439 ( $home ne "/home/$u" ? ( home => $home ) : () ) };
6440 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
6441 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
6442 4 return ( '', 1 );
6443 }
6444  
6445 # install [-m MODUS] [-o BENUTZER] [-g GRUPPE] [-D] QUELLE… ZIEL | install -d [-m …] DIR…
6446 9 ▶sub _install {
Subroutine _install: called CC=52 SCAR=45.5
6447 9 my ( $dev, $av ) = @_;
6448 9 my @a = @$av;
6449 9 my ( %o, @p );
6450 9 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 35 9 44
6451 35 my $x = shift @a;
6452 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
6453 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
6454 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
6455 0 elsif ( $x =~ /\A--(mode|owner|group)=(.*)\z/ ) { $o{$1} = $2 }
6456 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
6457 1 elsif ( $x eq '-D' ) { $o{parents} = 1 }
6458 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
6459 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
6460 0 elsif ( $x =~ /\A-/ ) { return ( "install: invalid option -- '" . substr( $x, 1, 1 ) . "'\nTry 'install --help' for more information.", 0 ) }
6461 17 else { push @p, $x }
6462 }
6463 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
6464 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
6465 return ( "install: invalid group '$o{group}'", 0 )
6466 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
6467 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
6468 3 ▶ my $mkdirs = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
6469 3 my ($d) = @_;
6470 3 my @seg = split m{/}, $d;
6471 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
6472 7 };
6473 7 ▶ if ( $o{dir} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"dir"}) 2 5 7
6474 2 ▶ return ( "install: missing file operand\nTry 'install --help' for more information.", 0 ) unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 2 2
6475 2 for my $d ( map { _absp($_) =~ s{(?<=.)/+\z}{}r } @p ) { $mkdirs->($d); $dev->{dirs}{$d} = {%meta} }
6476 2 return ( '', 1 );
6477 }
6478 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
6479 5 my $to = _absp( pop @p ) =~ s{(?<=.)/+\z}{}r;
6480 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
6481 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
6482 5 for my $src (@p) {
6483 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
6484 5 ( my $base = $src ) =~ s{.*/}{};
6485 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
6486 5 ( my $dd = $dst ) =~ s{/[^/]+\z}{};
6487 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
6488 5 my %n = %$e;
6489 5 delete @n{qw( open_by link tar )};
6490 5 $dev->{files}{$dst} = { %n, %meta, mtime => 'Oct 20 12:00' };
6491 }
6492 4 return ( '', 1 );
6493 }
6494  
6495 2 ▶sub _gpasswd {
Subroutine _gpasswd: called CC=9 SCAR=37.4
6496 2 my ( $dev, $av ) = @_;
6497 2 my ( $o, $u, $g ) = @$av;
6498 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
6499 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
6500 0 my ( $out, $ok ) = _usermod( $dev, [ '-aG', $g, $u ] );
6501 0 ▶ return ( $ok ? "Adding user $u to group $g" : $out, $ok );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 0 0
6502 }
6503  
6504 14 ▶sub _getent {
Subroutine _getent: called CC=33 SCAR=41.5
6505 14 my ( $dev, $av ) = @_;
6506 14 my ( $db, @keys ) = @$av;
6507 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
6508 14 ▶ if ( $db eq 'passwd' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db eq "passwd") 3 11 14
6509 3 my @l;
6510 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
6511 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
6512 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
6513 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
6514 }
6515 3 return ( join( "\n", @l ), 1 );
6516 }
6517 11 ▶ if ( $db eq 'shadow' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db eq "shadow") 1 10 11
6518 1 my @l;
6519 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
6520 0 ▶ if ( $u eq 'root' ) { push @l, 'root:*:20332:0:99999:7:::'; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($u eq "root") 0 1 1
6521 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
6522 1 push @l, _acc()->can('shadow_line')->( $u, $e );
6523 }
6524 1 return ( join( "\n", @l ), 1 );
6525 }
6526 10 ▶ if ( $db eq 'group' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db eq "group") 4 6 10
6527 4 my %m;
6528 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
6529 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
6530 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
6531 4 ▶ return ( join( "\n", @l ), ( grep { !$known{$_} } @keys ) ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
grep({not $known{$_};} @keys) ? : 1 3 4
6532 }
6533 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
6534 6 my @l;
6535 6 for my $n (@keys) {
6536 6 my ($ip) = _resolve( $dev, $n );
6537 6 ▶ return ( join( "\n", @l ), 0 ) unless defined $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip 3 3 6
6538 3 push @l, sprintf( '%-15s %s', $ip, $n );
6539 }
6540 3 return ( join( "\n", @l ), 1 );
6541 }
6542 0 return ( "Unknown database: $db\nTry `getent --help' or `getent --usage' for more information.", 0 );
6543 }
6544  
6545 # --- Resolver ---------------------------------------------------------------------
6546  
6547 # Nameserver aus /etc/resolv.conf (bzw. dem Stub von systemd-resolved)
6548 22 ▶sub _nameservers {
Subroutine _nameservers: called CC=8 SCAR=21.0
6549 22 my ($dev) = @_;
6550 22 ▶ my $rc = _file_text( $dev, '/etc/resolv.conf' ) // '';
Condition100%2/2
_file_text($dev, "/etc/resolv.conf") // ""
l!l
166
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
6551 22 my @ns = $rc =~ /^\s*nameserver\s+(\S+)/mg;
6552 22 ▶ 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 20 22
Condition83%5/6
@ns == 1 and $ns[0] eq "127.0.0.53" and $$dev{"resolved"}
!ll&&!rl&&r
2002
@ns == 1 and $ns[0] eq "127.0.0.53"
!ll&&!rl&&r
6142
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
6553 2 my $r = $dev->{resolved};
6554 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
6555 }
6556 22 return @ns;
6557 }
6558  
6559 # Name -> Adresse: /etc/hosts, dann die Nameserver der Reihe nach (dns_servers:
6560 # { <adresse>: { <name>: <ip> } }; ein Server, der fehlt, antwortet nicht).
6561 139 ▶sub _resolve {
Subroutine _resolve: called CC=12 SCAR=24.9
6562 139 my ( $dev, $name ) = @_;
6563 139 ▶ for my $l ( split /\n/, _file_text( $dev, '/etc/hosts' ) // '' ) {
Condition100%2/2
_file_text($dev, "/etc/hosts") // ""
l!l
1327
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
6564 217 $l =~ s/#.*//;
6565 217 my ( $ip, @n ) = split ' ', $l;
6566 217 ▶ return ( $ip, 'hosts' ) if defined $ip && grep { $_ eq $name } @n;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ip and grep {$_ eq $name;} @n 126 91 217
Condition66%2/3
defined $ip and grep {$_ eq $name;} @n
!ll&&!rl&&r
091126
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
6567 }
6568 13 ▶ my $rc = _file_text( $dev, '/etc/resolv.conf' ) // '';
Condition100%2/2
_file_text($dev, "/etc/resolv.conf") // ""
l!l
76
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
6569 13 my @search = map { split ' ' } $rc =~ /^\s*(?:search|domain)\s+(.+)$/mg;
6570 13 for my $ns ( _nameservers($dev) ) {
6571 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
6572 7 ▶ for my $q ( $name, ( $name =~ /\./ ? () : map {"$name.$_"} @search ) ) {
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /\./ ? : 5 2 7
6573 9 ▶ return ( $zone->{$q}, $ns ) if defined $zone->{$q};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$zone{$q} 4 5 9
6574 }
6575 3 return ( undef, $ns ); # Server antwortet: NXDOMAIN
6576 }
6577 6 return ();
6578 }
6579  
6580 2 ▶sub _resolvectl {
Subroutine _resolvectl: called CC=46 SCAR=62.8
6581 2 my ( $dev, $av ) = @_;
6582 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
6583 2 my @a = @$av;
6584 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
6585 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
6586 1 my @l;
6587 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
6588 0 push @l, 'Global', ' Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported', 'resolv.conf mode: stub';
6589 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
6590 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
6591 }
6592 1 my $i = 1;
6593 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
6594 1 $i++;
6595 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
6596 1 my $k = $r->{links}{$n};
6597 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
6598 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
6599 1 push @l, '', "Link $i ($n)", ' Current Scopes: DNS', ' Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS';
6600 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
6601 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
6602 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
6603 }
6604 1 return ( join( "\n", @l ), 1 );
6605 }
6606 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
6607 1 my $if = shift @a;
6608 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
6609 1 ▶ $k->{ $verb eq 'dns' ? 'dns' : 'domains' } = [@a];
Branch: 1 branch
BranchTrueFalseTotal
$verb eq 'dns' ? : 1 0 1
6610 1 return ( '', 1 );
6611 }
6612 0 ▶ if ( $verb eq 'query' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "query") 0 0 0
6613 0 my @l;
6614 0 for my $n (@a) {
6615 0 my ( $ip, $src ) = _resolve( $dev, $n );
6616 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
6617 unless defined $ip;
6618 0 push @l, "$n: $ip", '', '-- Information acquired via protocol DNS in 1.2ms.';
6619 }
6620 0 return ( join( "\n", @l ), 1 );
6621 }
6622 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
6623 0 ▶ if ( $verb eq 'revert' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "revert") 0 0 0
6624 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
6625 0 delete @{$k}{qw( dns domains )};
6626 0 return ( '', 1 );
6627 }
6628 0 return ( "Unknown command verb '$verb'.", 0 );
6629 }
6630  
6631 8 ▶sub _ln {
Subroutine _ln: called CC=18 SCAR=30.0
6632 8 my ( $dev, $av ) = @_;
6633 8 my @a = grep { !/\A-/ } @$av;
6634 8 my $sym = grep {/s/} grep {/\A-/} @$av;
6635 8 ▶ return ( "ln: missing file operand", 0 ) unless @a == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @a == 2 0 8 8
6636 8 ▶ return ( "ln: failed to create hard link: Operation not permitted", 0 ) unless $sym;
Branch: 1 branch
BranchTrueFalseTotal
unless $sym 0 8 8
6637 8 my ( $target, $link ) = @a;
6638 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
6639 8 $link =~ s{(?<=.)/+\z}{};
6640 8 $link = _absp($link); # der Name gilt im aktuellen Verzeichnis, das Ziel bleibt Text (relativ zum Link)
6641 # Ein Verzeichnis (auch ein Symlink darauf, ohne -n/-T) als Ziel: der Link entsteht darin
6642 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
6643 3 ▶ my $e = ref $dev->{files} eq 'HASH' ? $dev->{files}{$link} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'} eq 'HASH' ? : 3 0 3
6644 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
6645 3 ( my $base = $target ) =~ s{/+\z}{};
6646 3 $base =~ s{.*/}{};
6647 3 $link = "$d/$base";
6648 }
6649 return ( "ln: failed to create symbolic link '$link': File exists", 0 )
6650 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
6651 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
6652 6 $dev->{files}{$link} = { link => $target };
6653 6 return ( '', 1 );
6654 }
6655  
6656 # ssh [-o …] [user@]ziel befehl: der Befehl laeuft auf dem Geraet mit diesem Namen oder
6657 # dieser Adresse (als root, Schluessel hinterlegt); ohne Befehl keine Sitzung; andere Ziele
6658 # sind eine Luecke
6659 13 ▶sub _ssh {
Subroutine _ssh: called CC=30 SCAR=37.1
6660 13 my ( $dev, $av, $ctx ) = @_;
6661 13 my @a = @$av;
6662 13 my $host;
6663 13 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 18 0 18
6664 18 my $x = shift @a;
6665 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
6666 elsif ( $x =~ /\A-/ ) { }
6667 13 else { $host = $x; last }
6668 }
6669 13 ▶ return ( 'usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] destination [command [argument ...]]', 0 ) unless defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 13 13
6670 13 my ($login) = $host =~ /\A([^@]+)@/;
6671 13 $host =~ s/\A[^@]*@//;
6672 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
6673 2 _part('Git');
6674 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
6675 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
6676 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
6677 1 push @GAPS, join( ' ', 'ssh', @$av );
6678 1 return ( '', 0 );
6679 }
6680 }
6681 # auf sich selbst (localhost, eigene Adresse, eigener Name): Anmeldung gegen die geladene
6682 # sshd-Konfiguration, wie sshd selbst sie prueft
6683 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
6684 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
6685 8 ▶ my $state = $CTX ? $CTX->{state} : {};
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 8 0 8
6686 my $other = ref $state->{$host} eq 'HASH' ? $state->{$host}
6687 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
6688 # ein Geraet, das der Fall nicht nachbildet: Luecke (es kann es geben)
6689 8 ▶ if ( !$other ) { push @GAPS, join( ' ', 'ssh', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($other) 5 3 8
6690 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
6691 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
6692 # wie echtes ssh: die Woerter mit Leerzeichen verbunden, drueben neu gelesen (im Heimatverzeichnis)
6693 3 local $CWD_DIR;
6694 3 my ( $o, $k ) = __PACKAGE__->_run_inner( $other, join( ' ', @a ), $ctx );
6695 3 return ( $o, $k );
6696 }
6697  
6698 # nginx als Webserver fuer statische Dateien: ( text, status, typ ) fuer GET auf PORT/PFAD
6699 # mit Host-Kopf, oder () wenn nicht nachgebildet (proxy_pass, kein passender server-Block).
6700 # Der server-Block nach Port und server_name (sonst der erste mit dem Port), root + Pfad,
6701 # index.html fuer ein Verzeichnis; 403, wenn der Arbeiter (user, Vorgabe www-data) ein
6702 # Verzeichnis auf dem Weg nicht betreten oder die Datei nicht lesen darf, 404, wenn es sie
6703 # nicht gibt. Status 0: nginx laeuft nicht oder lauscht nicht auf dem Port.
6704 14 ▶sub _nginx_http {
Subroutine _nginx_http: called CC=32 SCAR=35.4
6705 14 my ( $dev, $port, $vhost, $path ) = @_;
6706 14 ▶ my ( $name, $svc ) = map { ( $_, $dev->{services}{$_} ) } grep { ( $dev->{services}{$_}{exec} // $_ ) eq 'nginx' } sort keys %{ $dev->{services} || {} };
Condition60%3/5
$$dev{"services"}{$_}{"exec"} // $_
l!l&&r!l&&!r
950
$$dev{'services'} || {}
l!l
140
MC/DC0%0/2
$$dev{"services"}{$_}{"exec"} // $_
$$dev{"services"}{$_}{"exec"} $_
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table66%2/3
A // B
A= $$dev{"services"}{$_}{"exec"}B= $_
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
6707 14 ▶ 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) 6 8 14
Condition83%5/6
$svc and $$svc{"active"} and grep {/:\Q$port\E\z/;} _svc_listen($dev, $name, $svc)
!ll&&!rl&&r
608
$svc and $$svc{"active"}
!ll&&!rl&&r
518
MC/DC66%2/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 table75%3/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
6708 8 ▶ my $run = ref $svc->{running} eq 'HASH' ? $svc->{running} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'running'} eq 'HASH' ? : 0 8 8
6709 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
6710 8 my ($user) = $text->('/etc/nginx/nginx.conf') =~ /^\s*user\s+([^\s;]+)/m;
6711 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
6712 8 my @blocks;
6713 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
6714 8 ( my $t = $text->($p) ) =~ s/#[^\n]*//g;
6715 8 ▶ while ( $t =~ /\bserver\s*\{/g ) { # Block mit ausgeglichenen Klammern
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /\bserver\s*\{/g) 8 8 16
6716 8 my ( $start, $depth, $i ) = ( pos($t), 1, pos($t) );
6717 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
6718 8 my $body = substr( $t, $start, $i - $start - 1 );
6719 8 pos($t) = $i;
6720 8 ( my $top = $body ) =~ s/\blocation\b[^{]*\{(?:[^{}]|\{[^{}]*\})*\}//g;
6721 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
6722 8 names => [ map { split ' ' } $top =~ /^\s*server_name\s+([^;]+);/mg ] };
6723 }
6724 }
6725 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
6726 8 my @on = grep { grep { $_ == $port } @{ $_->{ports} } } @blocks;
6727 8 my ($blk) = ( ( grep { my $x = $_; grep { $_ eq $vhost } @{ $x->{names} } } @on ), @on );
6728 8 ▶ return () unless $blk;
Branch: 1 branch
BranchTrueFalseTotal
unless $blk 0 8 8
6729 8 $path =~ s/[?#].*//s;
6730 # eine location mit proxy_pass, die den Pfad betrifft: nicht nachgebildet
6731 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
6732 7 my ($root) = $blk->{top} =~ /^\s*root\s+([^;\s]+)\s*;/m;
6733 7 ▶ return () unless defined $root;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root 0 7 7
6734 7 my $f = $root =~ s{/+\z}{}r . $path;
6735 7 ▶ $f .= 'index.html' if $f =~ m{/\z};
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ m[/\z] 1 6 7
6736 7 my @parts = split m{/}, $f;
6737 7 for my $i ( 1 .. $#parts - 1 ) {
6738 25 my $d = join '/', @parts[ 0 .. $i ];
6739 25 ▶ next unless length $d;
Branch: 1 branch
BranchTrueFalseTotal
unless length $d 0 25 25
6740 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
6741 unless _is_dir( $dev, $d );
6742 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
6743 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
6744 unless _can( $dev, $user, $d, 'x' );
6745 }
6746 6 my $body = _file_text( $dev, $f );
6747 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
6748 unless defined $body;
6749 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
6750 unless _can( $dev, $user, $f, 'r' );
6751 4 my %type = ( css => 'text/css', js => 'application/javascript', html => 'text/html', svg => 'image/svg+xml', json => 'application/json', txt => 'text/plain' );
6752 4 my ($ext) = $f =~ /\.(\w+)\z/;
6753 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
6754 }
6755  
6756 # /dev/tcp/HOST/PORT der bash: Verbindung wie _tcp_probe; UDP und Unbekanntes sind eine Luecke
6757 16 ▶sub _dev_tcp {
Subroutine _dev_tcp: called CC=9 SCAR=22.3
6758 16 my ( $dev, $path, $dir ) = @_;
6759 16 my ( $proto, $h, $p ) = $path =~ m{\A/dev/(tcp|udp)/([^/]+)/(\d+)\z};
6760 16 ▶ my $st = defined $p && $proto eq 'tcp' ? _tcp_probe( $dev, $h, $p ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $p && $proto eq 'tcp' ? : 16 0 16
Condition33%1/3
defined $p and $proto eq "tcp"
!ll&&!rl&&r
0016
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
6761 16 ▶ if ( !defined $st ) { push @GAPS, "$dir $path"; return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 7 9 16
6762 9 ▶ return ( '', 1 ) if $st eq 'open';
Branch: 1 branch
BranchTrueFalseTotal
if $st eq "open" 3 6 9
6763 6 ▶ 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" 2 4 6
6764 4 ▶ 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 3 4
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
301
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
6765 3 my $m = { refused => 'Connection refused', timeout => 'Connection timed out', unreach => 'Network is unreachable', nohost => 'No route to host' }->{$st};
6766 3 return ( "bash: connect: $m\nbash: $path: $m", 0 );
6767 }
6768  
6769 # --- Anmeldungen (wtmp) ------------------------------------------------------------------
6770 # Laufender Start des Geraets (Epoche): der frueheste since eines Dienstes, sonst die Vorgabe
6771 48 ▶sub _boot_epoch {
Subroutine _boot_epoch: called CC=6 SCAR=18.3
6772 48 my ($dev) = @_;
6773 39 ▶ 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
10330
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
6774 48 ▶ grep { ref eq 'HASH' && ( $_->{active} || defined $_->{since} ) } values %{ $dev->{services} || {} };
Condition75%6/8
ref $_ eq 'HASH' && ($$_{'active'} || defined $$_{'since'})
!ll&&!rl&&r
0343
$$_{"active"} or defined $$_{"since"}
l!l&&r!l&&!r
4303
$$dev{'services'} || {}
l!l
1632
MC/DC33%1/3
ref $_ eq 'HASH' && ($$_{'active'} || defined $$_{'since'})
ref $_ eq 'HASH' $$_{"active"} defined $$_{"since"}
MC/DC100%1/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%2/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
6775 48 ▶ return $t // _parse_stamp($BOOT_STAMP);
Condition66%2/3
$t // _parse_stamp($Langertha::Holmgang::Sim::Linux::BOOT_STAMP)
l!l&&r!l&&!r
16320
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
6776 }
6777  
6778 # Anmeldungen aus dem Zustand (logins: [ { user, tty, from, start: "Mon Oct 19 16:02",
6779 # end: "16:40"|"still logged in", duration } ]) und der laufende Start: [ epoche, zeile, -a-zeile, user, tty ]
6780 7 ▶sub _wtmp {
Subroutine _wtmp: called CC=17 SCAR=31.2
6781 7 my ($dev) = @_;
6782 7 require POSIX;
6783 7 require Time::Local;
6784 7 my @r;
6785 7 my $boot = _boot_epoch($dev);
6786 7 my $bs = POSIX::strftime( '%a %b %e %H:%M', _local_tm($boot) );
6787 7 my $kern = '6.1.0-26-amd64';
6788 7 push @r, [ $boot, sprintf( '%-8s %-12s %-16s %-16s still running', 'reboot', 'system boot', $kern, $bs ),
6789 sprintf( '%-8s %-12s %-37s %s', 'reboot', 'system boot', "$bs still running", $kern ), 'reboot', 'system boot' ];
6790 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
6791 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
6792 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
6793 5 $t -= Langertha::Holmgang::Sim::Linux::Calendar::offset( $t - 3600 );
6794 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
6795 5 my $dur = $l->{duration};
6796 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
6797 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
6798 5 my $start = sprintf '%-16s', $l->{start};
6799 push @r, [ $t, sprintf( '%-8s %-12s %-16s %s %s', $l->{user}, $l->{tty} // 'pts/0', $l->{from} // '', $start, $rest ),
6800 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
6801 }
6802 7 return sort { $b->[0] <=> $a->[0] } @r;
6803 }
6804  
6805 # uptime [-p|-s]: seit dem laufenden Start (_boot_epoch) an der Uhr des Geraets; ein
6806 # Benutzer (die Sitzung des Modells), ruhige Last
6807 36 ▶sub _uptime {
Subroutine _uptime: called CC=16 SCAR=32.4
6808 36 my ( $dev, $av ) = @_;
6809 36 require POSIX;
6810 36 my ( $boot, $now ) = ( _boot_epoch($dev), _dev_now($dev) );
6811 36 my $up = $now - $boot;
6812 36 ▶ $up = 60 if $up < 60;
Branch: 1 branch
BranchTrueFalseTotal
if $up < 60 0 36 36
6813 36 my ( $d, $h, $m ) = ( int( $up / 86400 ), int( $up % 86400 / 3600 ), int( $up % 3600 / 60 ) );
6814 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
6815 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
6816 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
6817 1 my @p;
6818 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
6819 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
6820 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
6821 1 return ( 'up ' . join( ', ', @p ), 1 );
6822 }
6823 0 ▶ if ( length $opt ) { push @GAPS, join( ' ', 'uptime', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (length $opt) 0 34 34
6824 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
6825 34 return ( POSIX::strftime( ' %H:%M:%S', _local_tm($now) ) . " up $t, 1 user, load average: 0.08, 0.03, 0.01", 1 );
6826 }
6827  
6828 # last [-a] [-n N] [-F] [-x] [BENUTZER|reboot|TTY …]
6829 6 ▶sub _last {
Subroutine _last: called CC=15 SCAR=31.1
6830 6 my ( $dev, $av ) = @_;
6831 6 my ( $a, $n, @who );
6832 6 my @x = @$av;
6833 6 ▶ while (@x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@x) 4 6 10
6834 4 my $o = shift @x;
6835 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
6836 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
6837 1 ▶ elsif ( $o =~ /\A-([aFxwiR]+)\z/ ) { $a = 1 if $1 =~ /a/ }
Branch: 1 branch
BranchTrueFalseTotal
if $1 =~ /a/ 1 0 1
6838 0 elsif ( $o =~ /\A-/ ) { push @GAPS, join( ' ', 'last', @$av ); return ( '', 0 ) }
6839 3 else { push @who, $o }
6840 }
6841 6 my @r = _wtmp($dev);
6842 6 my $first = $r[-1][0];
6843 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
6844 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
6845 6 require POSIX;
6846 6 ▶ my @l = map { ( $a ? $_->[2] : $_->[1] ) =~ s/\s+\z//r } @r;
Branch: 1 branch
BranchTrueFalseTotal
$a ? : 2 6 8
6847 6 return ( join( "\n", @l, '', 'wtmp begins ' . POSIX::strftime( '%a %b %e %H:%M:%S %Y', _local_tm($first) ) ), 1 );
6848 }
6849  
6850 # lastlog [-u BENUTZER]: letzte Anmeldung je Konto (root und die Konten im Zustand)
6851 1 ▶sub _lastlog {
Subroutine _lastlog: called CC=16 SCAR=34.0
6852 1 my ( $dev, $av ) = @_;
6853 1 my @a = @$av;
6854 1 my $only;
6855 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
6856 1 my %last;
6857 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
6858 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
6859 1 require POSIX;
6860 1 my @l = ( sprintf '%-16s %-8s %-16s %s', 'Username', 'Port', 'From', 'Latest' );
6861 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
6862 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
6863 2 my $r = $last{$u};
6864 2 ▶ if ( !$r ) { push @l, sprintf '%-43s%s', $u, '**Never logged in**'; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 1 1 2
6865 1 my $lg = $login{$u};
6866 1 my $t = $r->[0];
6867 1 my $off = Langertha::Holmgang::Sim::Linux::Calendar::offset($t);
6868 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
6869 POSIX::strftime( '%a %b %e %H:%M:%S', gmtime( $t + $off ) ) . sprintf( ' %+03d%02d %d', $off / 3600, 0, ( gmtime( $t + $off ) )[5] + 1900 );
6870 }
6871 1 return ( join( "\n", @l ), 1 );
6872 }
6873  
6874 # --- TCP zwischen Geraeten -------------------------------------------------------------
6875 # Wo laufende Dienste ohne listen im Zustand lauschen (Debian-Vorgaben nach exec bzw. Name);
6876 # Dienste, die nie lauschen. Ein anderer laufender Dienst macht die Ports des Geraets
6877 # unbekannt (dann ist eine geschlossene Antwort nicht sicher: Luecke).
6878 88 our %SVC_PORT = ( sshd => [22], postgres => [5432], 'redis-server' => [6379], mariadbd => [3306], mysqld => [3306],
6879 prometheus => [9090], alertmanager => [9093], 'prometheus-node-exporter' => [9100], node_exporter => [9100],
6880 named => [53], dnsmasq => [53], 'systemd-resolved' => [], unbound => [53], postfix => [25], master => [25],
6881 dovecot => [ 143, 993 ], 'grafana-server' => [3000], apache2 => [80], gunicorn => [8000] );
6882 88 our %NO_LISTEN = map { $_ => 1 } qw( cron rsyslogd rsyslog systemd-journald nftables chronyd chrony unattended-upgrades
6883 systemd-timesyncd systemd-networkd networking auditd logrotate e2scrub_all fstrim apt-daily wg-quick smartd mdmonitor );
6884  
6885 # Lauscher eines Geraets auf PORT: ( [ adresse, … ], vollstaendig? )
6886 21 ▶sub _listeners {
Subroutine _listeners: called CC=29 SCAR=39.4
6887 21 my ( $dev, $port ) = @_;
6888 21 my @addr;
6889 21 for my $line ( split /\n/, ( _ss( $dev, [] ) )[0] ) {
6890 57 ▶ 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 14 43 57
6891 14 push @addr, $a;
6892 }
6893 21 my $complete = 1;
6894 21 ▶ my $s = $dev->{services} || {};
Condition50%1/2
$$dev{'services'} || {}
l!l
210
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
6895 21 for my $n ( sort keys %$s ) {
6896 37 my $v = $s->{$n};
6897 37 ▶ 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 37 37
Condition33%2/6
ref $v eq "HASH" and $$v{"active"} and not $n =~ /\.(?:timer|socket|target|mount|path)\z/
!ll&&!rl&&r
0037
ref $v eq "HASH" and $$v{"active"}
!ll&&!rl&&r
0037
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
6898 37 ▶ 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" 20 17 37
Condition77%7/9
$$v{"listen"} or ($$v{"exec"} // $n) eq "nginx" or $n eq "ssh"
l!l&&r!l&&!r
41617
$$v{"listen"} or ($$v{"exec"} // $n) eq "nginx"
l!l&&r!l&&!r
4033
$$v{"exec"} // $n
l!l&&r!l&&!r
3030
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
6899 17 ▶ 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 17 17
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
0017
defined $$v{"run"} or $Langertha::Holmgang::Sim::Linux::NO_LISTEN{$$v{"exec"} // $n}
l!l&&r!l&&!r
0017
$$v{"exec"} // $n
l!l&&r!l&&!r
1610
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
6900 17 ▶ 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 17 17
Condition42%3/7
$n eq (($$dev{"redis"} || {})->{"service"} // "redis-server") and $$dev{"redis"}
!ll&&!rl&&r
1700
($$dev{"redis"} || {})->{"service"} // "redis-server"
l!l
017
$$dev{'redis'} || {}
l!l
017
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
6901 17 ▶ 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 17 17
Condition42%3/7
$n eq (($$dev{"mariadb"} || {})->{"service"} // "mariadb") and $$dev{"mariadb"}
!ll&&!rl&&r
1700
($$dev{"mariadb"} || {})->{"service"} // "mariadb"
l!l
017
$$dev{'mariadb'} || {}
l!l
017
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
6902 17 ▶ 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
809
(split(' ', $$v{"exec"} // "", 0))[0] // ""
l!l
161
$$v{"exec"} // ""
l!l
161
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
6903 17 ▶ if ( !$ports ) { $complete = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ports) 9 8 17
6904 8 ▶ push @addr, '0.0.0.0' if grep { $_ == $port } @$ports;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == $port;} @$ports 4 4 8
6905 }
6906 21 return ( \@addr, $complete );
6907 }
6908  
6909 # Urteil der Firewall (nft, Ketten mit hook input) fuer ein neues TCP-Paket von $src an
6910 # $dst:$port ueber $iif: 'accept', 'drop', 'reject' oder undef (Regel nicht nachgebildet)
6911 18 ▶sub _nft_verdict {
Subroutine _nft_verdict: called CC=16 SCAR=36.3
6912 18 my ( $dev, $src, $dst, $port, $iif ) = @_;
6913 18 ▶ my $T = ref $dev->{nft} eq 'HASH' ? $dev->{nft} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'nft'} eq 'HASH' ? : 7 11 18
6914 18 my @chains;
6915 18 for my $tn ( sort keys %$T ) {
6916 7 ▶ next unless $tn =~ /\A(?:inet|ip) /;
Branch: 1 branch
BranchTrueFalseTotal
unless $tn =~ /\A(?:inet|ip) / 0 7 7
6917 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
6918 7 my $c = $T->{$tn}{chains}{$cn};
6919 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
6920 }
6921 }
6922 30 ▶ my $inset = sub { # Wert gegen "X", "{ a, b }", "a-b", "!= X"
Subroutine __ANON__: called CC=13 SCAR=29.0
6923 30 my ( $spec, $v, $kind ) = @_;
6924 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
6925 30 for my $a (@alt) {
6926 34 $a =~ s/\A"|"\z//g;
6927 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
6928 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
6929 7 ▶ else { return 1 if $a eq $v }
Branch: 1 branch
BranchTrueFalseTotal
if $a eq $v 0 7 7
6930 }
6931 19 return 0;
6932 18 };
6933 18 my $rule;
6934 7 ▶ $rule = sub {
Subroutine __ANON__: called CC=67 SCAR=63.3
6935 7 my ( $tn, $c, $depth ) = @_;
6936 7 ▶ return undef if $depth > 5;
Branch: 1 branch
BranchTrueFalseTotal
if $depth > 5 0 7 7
6937 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
6938 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
6939 33 $t =~ s/\s+comment\s+"[^"]*"//g;
6940 33 $t =~ s/\blog(?:\s+(?:prefix\s+"[^"]*"|level\s+\S+|flags\s+\S+))*//g;
6941 33 $t =~ s/\bcounter(?:\s+packets\s+\d+\s+bytes\s+\d+)?//g;
6942 33 $t =~ s/\blimit rate\s+\S+(?:\s+burst\s+\d+\s+packets)?//g; # Grenze: ein einzelnes Paket liegt darunter
6943 33 my @w = $t =~ /(\{[^}]*\}|"[^"]*"|\S+)/g;
6944 33 my $verdict;
6945 33 ▶ while (@w) {
Branch: 1 branch
BranchTrueFalseTotal
if (@w) 44 0 44
6946 44 my $x = shift @w;
6947 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
6948 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
6949 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
6950 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
6951 7 my $which = shift @w;
6952 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
6953 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
6954 7 ▶ next RULE if $neg ? $m : !$m;
Branch: 2 branches
BranchTrueFalseTotal
if $neg ? $m : !$m 0 7 7
$neg ? : 0 7 7
6955 7 next;
6956 }
6957 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
6958 16 my $which = shift @w;
6959 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
6960 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
6961 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
6962 16 ▶ next RULE if $neg ? $m : !$m;
Branch: 2 branches
BranchTrueFalseTotal
if $neg ? $m : !$m 12 4 16
$neg ? : 0 16 16
6963 4 next;
6964 }
6965 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
6966 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
6967 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
6968 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
6969 1 ▶ if ( $x eq 'reject' ) { $verdict = 'reject'; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "reject") 1 0 1
6970 0 ▶ if ( $x eq 'return' ) { return 'return' }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "return") 0 0 0
6971 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
6972 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
6973 0 my $v = $rule->( $tn, $sub, $depth + 1 );
6974 0 ▶ return undef unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6975 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
6976 0 return $v;
6977 }
6978 0 return undef; # anderes: nicht nachgebildet
6979 }
6980 7 ▶ return $verdict if $verdict;
Branch: 1 branch
BranchTrueFalseTotal
if $verdict 7 0 7
6981 }
6982 0 return 'none';
6983 18 };
6984 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
6985 7 my $v = $rule->( $ch->[0], $ch->[1], 0 );
6986 7 ▶ return undef unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 7 7
6987 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
6988 7 ▶ return $v unless $v eq 'accept';
Branch: 1 branch
BranchTrueFalseTotal
unless $v eq "accept" 4 3 7
6989 }
6990 14 return 'accept';
6991 }
6992  
6993 # Geschlossene Welt im eigenen Netz (ADR 0012): Eine Adresse in einem direkt angeschlossenen
6994 # Netz, die kein Geraet des Zustands traegt und die der Zustand nirgends nennt (Datei, Route,
6995 # Nameserver, Gegenstelle), gibt es nicht: 'nohost'. Hinter einem Gateway weiss die Welt es
6996 # nicht (undef), ebenso bei einer Adresse, die irgendwo im Zustand steht.
6997 # Liegt die Adresse in einem Netz, an dem das Geraet selbst haengt? (auch ohne Eintrag in routes:
6998 # die Route des Kerns fuer das eigene Netz gibt es immer)
6999 27 ▶sub _onlink {
Subroutine _onlink: called CC=6 SCAR=19.0
7000 27 my ( $dev, $ip ) = @_;
7001 27 ▶ return scalar grep { m{/} && _in( $ip, $_ ) } map { @{ $_->{addr} || [] } } grep { ref eq 'HASH' && ( $_->{state} // 'UP' ) ne 'DOWN' } values %{ $dev->{interfaces} || {} };
Condition58%7/12
m[/] && _in($ip, $_)
!ll&&!rl&&r
0321
$$_{'addr'} || []
l!l
240
ref $_ eq 'HASH' && ($$_{'state'} // 'UP') ne 'DOWN'
!ll&&!rl&&r
0024
$$_{"state"} // "UP"
l!l
240
$$dev{'interfaces'} || {}
l!l
243
MC/DC50%1/2
m[/] && _in($ip, $_)
m[/] _in($ip, $_)
MC/DC0%0/1
$$_{'addr'} || []
$$_{'addr'}
MC/DC0%0/2
ref $_ eq 'HASH' && ($$_{'state'} // 'UP') ne 'DOWN'
ref $_ eq 'HASH' $$_{"state"}
MC/DC100%1/1
$$dev{'interfaces'} || {}
$$dev{'interfaces'}
Truth table66%2/3
A && B
A= m[/]B= _in($ip, $_)
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$_{'addr'}
Aresult
11
00
Truth table33%1/3
A && B
A= ref $_ eq 'HASH'B= $$_{"state"}
ABresult
0X0
100
111
Truth table100%2/2
A
A= $$dev{'interfaces'}
Aresult
11
00
7002 }
7003  
7004 25 ▶sub _absent {
Subroutine _absent: called CC=10 SCAR=24.8
7005 25 my ( $dev, $ip ) = @_;
7006 25 ▶ return undef unless defined $ip && defined _ip2n($ip);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip and defined _ip2n($ip) 0 25 25
Condition33%1/3
defined $ip and defined _ip2n($ip)
!ll&&!rl&&r
0025
MC/DC0%0/2
defined $ip and defined _ip2n($ip)
defined $ip defined _ip2n($ip)
Truth table33%1/3
A and B
A= defined $ipB= defined _ip2n($ip)
ABresult
0X0
100
111
7007 25 ▶ if ( !_onlink( $dev, $ip ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_onlink($dev, $ip)) 6 19 25
7008 6 my ( $r ) = _lookup( $dev, $ip );
7009 # keine Route, obwohl das Geraet Routen hat: nicht erreichbar; sonst weiss die Welt es nicht
7010 6 ▶ return !$r && @{ $dev->{routes} || [] } ? 'unreach' : undef;
Branch: 1 branch
BranchTrueFalseTotal
!$r && @{$$dev{'routes'} or [];} ? : 0 6 6
Condition60%3/5
not $r and @{$$dev{"routes"} or [];}
!ll&&!rl&&r
240
$$dev{'routes'} || []
l!l
04
MC/DC0%0/2
not $r and @{$$dev{"routes"} or [];}
not $r @{$$dev{"routes"} or [];}
MC/DC0%0/1
$$dev{'routes'} || []
$$dev{'routes'}
Truth table66%2/3
not(A) and B
A= not $rB= @{$$dev{"routes"} or [];}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$dev{'routes'}
Aresult
11
00
7011 }
7012 19 ▶ my $state = $CTX ? $CTX->{state} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 19 0 19
7013 19 ▶ return undef unless ref $state eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $state eq "HASH" 0 19 19
7014 19 ▶ return undef if $CLONE_JSON->encode($state) =~ /(?<![0-9.])\Q$ip\E(?![0-9.])/;
Branch: 1 branch
BranchTrueFalseTotal
if $CLONE_JSON->encode($state) =~ /(?<![0-9.])\Q$ip\E(?![0-9.])/ 13 6 19
7015 6 return 'nohost';
7016 }
7017  
7018 # Neue TCP-Verbindung von diesem Geraet zu HOST:PORT: 'open', 'refused', 'timeout',
7019 # 'unreach', 'nohost' (im eigenen Netz gibt es die Adresse nicht, _absent) oder undef (Ziel
7020 # oder Regel nicht nachgebildet)
7021 43 ▶sub _tcp_probe {
Subroutine _tcp_probe: called CC=38 SCAR=42.0
7022 43 my ( $dev, $host, $port ) = @_;
7023 43 ▶ my $state = $CTX ? $CTX->{state} || {} : {};
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 43 0 43
Condition50%1/2
$$Langertha::Holmgang::Sim::Linux::CTX{"state"} or {}
l!l
430
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
7024 43 my @own = _own_addrs($dev);
7025 43 ▶ 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"} // ()) 7 36 43
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
7036
$$dev{"hostname"} // ()
l!l&&r!l&&!r
0342
($Langertha::Holmgang::Sim::Linux::CTX || {})->{"host"} // ()
l!l&&r!l&&!r
3600
$Langertha::Holmgang::Sim::Linux::CTX || {}
l!l
360
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
7026 7 my ( $addr, $complete ) = _listeners( $dev, $port );
7027 7 ▶ my $ip = _ip2n($host) ? $host : '127.0.0.1';
Branch: 1 branch
BranchTrueFalseTotal
_ip2n($host) ? : 3 4 7
7028 7 ▶ 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 6 1 7
Condition33%3/9
$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ || $_ eq $ip || $ip =~ /\A127\./ && $_ =~ /\A127\./
l!l&&r!l&&!r
700
$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ or $_ eq $ip
l!l&&r!l&&!r
610
$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
7029 1 ▶ return $complete ? 'refused' : undef;
Branch: 1 branch
BranchTrueFalseTotal
$complete ? : 0 1 1
7030 }
7031 37 ▶ my $find = sub {
Subroutine __ANON__: called CC=8 SCAR=23.1
7032 37 my ($h) = @_;
7033 18 ▶ my ($t) = grep { ref $_ eq 'HASH' && ( $_->{type} // '' ) eq 'linux' && $_ != $dev }
Branch: 1 branch
BranchTrueFalseTotal
ref $$state{$h} eq 'HASH' ? : 1 36 37
Condition37%3/8
ref $_ eq 'HASH' && ($$_{'type'} // '') eq 'linux' && $_ != $dev
!ll&&!rl&&r
0018
ref $_ eq "HASH" and ($$_{"type"} // "") eq "linux"
!ll&&!rl&&r
0018
$$_{"type"} // ""
l!l
180
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
7034 ( ref $state->{$h} eq 'HASH' ? $state->{$h} : () ),
7035 37 ▶ 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
08917
($$state{$_}{"hostname"} // "") eq $h or grep {$_ eq $h;} _own_addrs($$state{$_})
l!l&&r!l&&!r
01789
$$state{$_}{"hostname"} // ""
l!l
0106
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
7036 37 return $t;
7037 36 };
7038 36 my $tgt = $find->($host);
7039 36 my $ip;
7040 36 ▶ if ( !$tgt && !_ip2n($host) ) { # Name: wie getent hosts (/etc/hosts, Nameserver); unbekannt: nicht aufloesbar
Branch: 1 branch
BranchTrueFalseTotal
unless ($tgt or _ip2n($host)) 5 31 36
Condition100%3/3
$tgt or _ip2n($host)
l!l&&r!l&&!r
18135
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
7041 5 my ($r) = _resolve( $dev, $host );
7042 5 ▶ return 'noname' unless defined $r;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r 4 1 5
7043 1 ▶ $tgt = $find->($r) or return _absent( $dev, $r );
Branch: 1 branch
BranchTrueFalseTotal
$tgt = &$find($r) or return _absent($dev, $r) 0 1 1
7044 0 $ip = $r;
7045 }
7046 31 ▶ return _absent( $dev, $host ) unless $tgt;
Branch: 1 branch
BranchTrueFalseTotal
unless $tgt 13 18 31
7047 18 ▶ $ip //= _ip2n($host) ? $host : ( _own_addrs($tgt) )[0] // return undef;
Branch: 1 branch
BranchTrueFalseTotal
_ip2n($host) ? : 17 1 18
Condition40%2/5
$ip //= _ip2n($host) ? $host : (_own_addrs($tgt))[0] // (return undef)
l!l&&r!l&&!r
0180
(_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
7048 18 ▶ return 'unreach' unless _lookup( $dev, $ip ) || _onlink( $dev, $ip );
Branch: 1 branch
BranchTrueFalseTotal
unless _lookup($dev, $ip) or _onlink($dev, $ip) 0 18 18
Condition66%2/3
_lookup($dev, $ip) or _onlink($dev, $ip)
l!l&&r!l&&!r
1710
MC/DC0%0/2
_lookup($dev, $ip) or _onlink($dev, $ip)
_lookup($dev, $ip) _onlink($dev, $ip)
Truth table66%2/3
A or B
A= _lookup($dev, $ip)B= _onlink($dev, $ip)
ABresult
1X1
011
000
7049 18 ▶ my ($src) = grep { my $s = $_; grep { _in( $s, $_ ) } map { @{ $_->{addr} || [] } } values %{ $tgt->{interfaces} || {} } } @own;
Condition50%2/4
$$_{'addr'} || []
l!l
180
$$tgt{'interfaces'} || {}
l!l
180
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
7050 18 ▶ $src //= $own[0] // return undef;
Condition25%1/4
$src //= $own[0] // (return undef)
l!l
180
$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
7051 18 ▶ my ($iif) = grep { grep { m{/} && _in( $src, $_ ) } @{ $tgt->{interfaces}{$_}{addr} || [] } } sort keys %{ $tgt->{interfaces} || {} };
Condition42%3/7
m[/] && _in($src, $_)
!ll&&!rl&&r
0018
$$tgt{'interfaces'}{$_}{'addr'} || []
l!l
180
$$tgt{'interfaces'} || {}
l!l
180
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
7052 18 ▶ 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
180
$iif // "eth0"
l!l
180
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
7053 18 ▶ return 'timeout' if $v eq 'drop';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "drop" 3 15 18
7054 15 ▶ return 'refused' if $v eq 'reject';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "reject" 1 14 15
7055 14 my ( $addr, $complete ) = _listeners( $tgt, $port );
7056 14 ▶ 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 5 9 14
Condition66%2/3
$_ =~ /\A(?:0\.0\.0\.0|\*|\[::\])\z/ || $_ eq $ip
l!l&&r!l&&!r
1001
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
7057 9 ▶ return $complete ? 'refused' : undef;
Branch: 1 branch
BranchTrueFalseTotal
$complete ? : 8 1 9
7058 }
7059  
7060 # nc [-z] [-v] [-w N] [-n] HOST PORT[-PORT]…: Verbindungsprobe (netcat-openbsd), nur wenn
7061 # installiert (Programmdatei im Zustand); Daten senden (ohne -z) und UDP sind eine Luecke
7062 14 ▶sub _nc {
Subroutine _nc: called CC=20 SCAR=31.1
7063 14 my ( $dev, $av, $ctx ) = @_;
7064 14 my ($me) = grep { _prog_file( $dev, $_ ) } qw( nc netcat ncat );
7065 14 ▶ return ( 'bash: nc: command not found', 0 ) unless $me;
Branch: 1 branch
BranchTrueFalseTotal
unless $me 1 13 14
7066 13 my ( $z, $v, @pos );
7067 13 my @a = @$av;
7068 13 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 40 13 53
7069 40 my $x = shift @a;
7070 40 ▶ if ( $x =~ /\A-[wWiqpsTX]\z/ ) { shift @a }
Branch: 3 branches
BranchTrueFalseTotal
if ($x =~ /\A-[wWiqpsTX]\z/) { } 1 39 40
elsif ($x =~ /\A-([zvnNw0-9]+)\z/) { } 13 26 39
elsif ($x =~ /\A-/) { } 0 26 26
7071 13 ▶ 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/ 13 0 13
if $f =~ /v/ 12 1 13
if $f =~ /w\z/ 0 13 13
7072 0 elsif ( $x =~ /\A-/ ) { push @GAPS, join( ' ', 'nc', @$av ); return ( '', 0 ) } # -u, -l, …
7073 26 else { push @pos, $x }
7074 }
7075 13 my ( $host, @ports ) = @pos;
7076 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 13 13
Condition33%2/6
$z and defined $host and @ports
!ll&&!rl&&r
0013
$z and defined $host
!ll&&!rl&&r
0013
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
7077 13 my %svc = ( 22 => 'ssh', 25 => 'smtp', 53 => 'domain', 80 => 'http', 443 => 'https', 3306 => 'mysql', 5432 => 'postgresql', 6379 => '*' );
7078 13 my ( @out, $any );
7079 13 ▶ for my $p ( map { /\A(\d+)-(\d+)\z/ ? ( $1 .. $2 ) : $_ } @ports ) {
Branch: 1 branch
BranchTrueFalseTotal
/\A(\d+)-(\d+)\z/ ? : 0 13 13
7080 13 my $st = _tcp_probe( $dev, $host, $p );
7081 13 ▶ if ( !defined $st ) { push @GAPS, join( ' ', 'nc', @$av ); return ( join( "\n", @out ), 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 1 12 13
7082 12 ▶ 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") 4 8 12
if $v 3 1 4
Condition50%1/2
$svc{$p} // "*"
l!l
30
MC/DC0%0/1
$svc{$p} // "*"
$svc{$p}
Truth table50%1/2
A
A= $svc{$p}
Aresult
11
00
7083 8 ▶ 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 7 8
7084 push @out, "nc: connect to $host port $p (tcp) "
7085 7 . { refused => 'failed: Connection refused', timeout => 'timed out: Operation now in progress', unreach => 'failed: Network is unreachable', nohost => 'failed: No route to host' }->{$st};
7086 }
7087 12 ▶ return ( join( "\n", @out ), $any ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$any ? : 4 8 12
7088 }
7089  
7090 # curl (nur wenn installiert): eigene Maschine mit nginx wie wget; andere Geraete: nur das
7091 # Scheitern der Verbindung (7 refused, 28 timeout); eine gelungene Verbindung zu einem
7092 # anderen Geraet ist eine Luecke (dort antwortet kein nachgebildeter Dienst)
7093 3 ▶sub _curl {
Subroutine _curl: called CC=53 SCAR=67.6
7094 3 my ( $dev, $av, $ctx ) = @_;
7095 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
7096 2 my ( $url, $silent, $show, $head, $out, $wfmt, $vhost );
7097 2 my @a = @$av;
7098 2 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 4 2 6
7099 4 my $x = shift @a;
7100 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
7101 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
7102 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
7103 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
7104 0 elsif ( $x =~ /\A(?:-m|--max-time|--connect-timeout)\z/ ) { shift @a }
7105 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
7106 0 elsif ( $x =~ /\A-/ ) { push @GAPS, join( ' ', 'curl', @$av ); return ( '', 0 ) }
7107 2 else { $url = $x }
7108 }
7109 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
7110 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
7111 2 my $st = _tcp_probe( $dev, $h, $port );
7112 0 ▶ if ( !defined $st ) { push @GAPS, join( ' ', 'curl', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 0 2 2
7113 2 ▶ if ( $st ne 'open' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($st ne "open") 2 0 2
7114 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: 4 branches
BranchTrueFalseTotal
$st eq 'noname' ? : 0 2 2
$st eq 'timeout' ? : 0 2 2
$st eq 'unreach' ? : 0 2 2
$st eq 'nohost' ? : 0 2 2
7115 : $st eq 'unreach' ? ( 7, "Failed to connect to $h port $port after 0 ms: Couldn't connect to server" )
7116 : $st eq 'nohost' ? ( 7, "Failed to connect to $h port $port after 3066 ms: Couldn't connect to server" )
7117 : ( 7, "Failed to connect to $h port $port after 0 ms: Couldn't connect to server" );
7118 2 ▶ $SH->{code} = $code if $SH;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH 2 0 2
7119 2 my @o;
7120 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
7121 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
7122 2 return ( join( "\n", @o ), 0 );
7123 }
7124 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
7125 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
7126 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
7127 0 my %reason = ( 200 => 'OK', 403 => 'Forbidden', 404 => 'Not Found' );
7128 0 my @o;
7129 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
7130 ▶ 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
7131 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
7132 }
7133 0 else { push @o, $body =~ s/\n\z//r }
7134 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
7135 0 return ( join( "\n", @o ), 1 );
7136 }
7137  
7138 # env [NAME=wert …] [befehl …]: ohne Befehl die Umgebung der Shell (exportierte Variablen,
7139 # Vorgaben der Anmeldung), sonst den Befehl mit diesen Variablen
7140 8 ▶sub _env {
Subroutine _env: called CC=16 SCAR=29.3
7141 8 my ( $dev, $av, $ctx, $stdin ) = @_;
7142 8 my @a = @$av;
7143 8 my %set;
7144 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
7145 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
7146 8 ▶ if (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 1 7 8
7147 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
7148 1 return __PACKAGE__->_command( $dev, \@a, $ctx, $stdin );
7149 }
7150 7 my $u = _who();
7151 my %e = ( PATH => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', HOME => $u eq 'root' ? '/root' : "/home/$u",
7152 USER => $u, LOGNAME => $u, SHELL => '/bin/bash', PWD => $CWD_DIR // ( $u eq 'root' ? '/root' : "/home/$u" ), LANG => 'C.UTF-8', SHLVL => 1,
7153 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' ) : () ),
7154 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
7155 7 return ( join( "\n", ( map {"$_=$e{$_}"} sort keys %e ), '_=/usr/bin/env' ), 1 );
7156 }
7157  
7158 # wget gegen die eigene Maschine: Prometheus/Alertmanager (Sim::Monitoring), auf dem Port
7159 # von nginx dessen statische Dateien (_nginx_http): -O -|DATEI, -q, -S, --spider,
7160 # --header='Host: …'; anderes ist eine Luecke
7161 51 ▶sub _wget {
Subroutine _wget: called CC=93 SCAR=52.5
7162 51 my ( $dev, $av, $ctx ) = @_;
7163 51 my ( $url, $out, $post, $quiet, $show, $spider, $vhost );
7164 51 my @a = @$av;
7165 51 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 115 51 166
7166 115 my $x = shift @a;
7167 115 ▶ 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') { } 12 103 115
elsif ($x =~ /\A-([qS]*)O(.+)\z/) { } 36 67 103
elsif ($x =~ /\A--output-document=(.*)\z/) { } 0 67 67
elsif ($x =~ /\A--post-data=/ or $x =~ /\A--method=POST\z/i) { } 3 64 67
elsif ($x eq '--post-data') { } 0 64 64
elsif ($x eq '--header') { } 0 64 64
elsif ($x =~ /\A--header=Host:\s*(\S+)\z/i) { } 1 63 64
elsif ($x eq '--spider') { } 2 61 63
elsif ($x =~ /\A-([qSv]+)\z/ or $x eq '--quiet' or $x eq '--server-response') { } 10 51 61
elsif ($x =~ /\A-/) { } 0 51 51
Condition66%2/3
$x =~ /\A-([qS]*)O\z/ or $x eq "--output-document"
l!l&&r!l&&!r
120103
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
7168 12 ▶ my $f = $x =~ /\A-([qS]*)O\z/ ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$x =~ /\A-([qS]*)O\z/ ? : 12 0 12
7169 12 $out = shift @a;
7170 12 ▶ $quiet = 1 if $f =~ /q/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /q/ 1 11 12
7171 12 ▶ $show = 1 if $f =~ /S/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /S/ 0 12 12
7172 }
7173 36 ▶ 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/ 30 6 36
if $f =~ /S/ 0 36 36
7174 0 elsif ( $x =~ /\A--output-document=(.*)\z/ ) { $out = $1 }
7175 3 ▶ 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
3064
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
7176 0 elsif ( $x eq '--post-data' ) { shift @a; $post = 1 }
7177 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
7178 1 elsif ( $x =~ /\A--header=Host:\s*(\S+)\z/i ) { $vhost = $1 }
7179 2 elsif ( $x eq '--spider' ) { $spider = 1 }
7180 ▶ 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
10051
$x =~ /\A-([qSv]+)\z/ or $x eq "--quiet"
l!l&&r!l&&!r
10051
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
7181 10 ▶ 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
100
MC/DC0%0/1
$1 // ($x eq "--quiet" ? "q" : "S")
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
7182 10 ▶ $quiet = 1 if $f =~ /q/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /q/ 8 2 10
7183 10 ▶ $show = 1 if $f =~ /S/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /S/ 2 8 10
7184 }
7185 elsif ( $x =~ /\A-/ ) { }
7186 51 else { $url = $x }
7187 }
7188 51 ▶ my ( $h80, $port80, $path80 ) = ( $url // '' ) =~ m{\A(?:http://)?([^/:]+)(?::(\d+))?(/.*)?\z};
Condition50%1/2
$url // ""
l!l
510
MC/DC0%0/1
$url // ""
$url
Truth table50%1/2
A
A= $url
Aresult
11
00
7189 51 ▶ 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
0744
$h80 =~ /\A(?:localhost|127\.0\.0\.1)\z/ or grep {$_ eq $h80;} _own_addrs($dev), $$dev{"hostname"} // (), $$ctx{"host"} // ()
l!l&&r!l&&!r
4407
$$dev{"hostname"} // ()
l!l&&r!l&&!r
052
$$ctx{"host"} // ()
l!l&&r!l&&!r
700
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
7190 51 ▶ 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/) 14 37 51
Condition100%8/8
$self80 and not $post and not +($port80 // 80) =~ /\A(?:9090|9093)\z/
!ll&&!rl&&r
102714
$self80 and not $post
!ll&&!rl&&r
7341
$port80 // 80
l!l
329
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
7191 14 ▶ my ( $body, $st, $type ) = _nginx_http( $dev, $port80 // 80, $vhost // $h80, $path80 // '/' );
Condition71%5/7
$port80 // 80
l!l
59
$vhost // $h80
l!l&&r!l&&!r
1130
$path80 // "/"
l!l
140
MC/DC100%1/1
$port80 // 80
$port80
MC/DC0%0/2
$vhost // $h80
$vhost $h80
MC/DC0%0/1
$path80 // "/"
$path80
Truth table100%2/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
7192 # nginx lauscht dort nicht, aber ein anderer Dienst: nicht nachgebildet
7193 14 ▶ my $pn = $port80 // 80;
Condition100%2/2
$port80 // 80
l!l
59
MC/DC100%1/1
$port80 // 80
$port80
Truth table100%2/2
A
A= $port80
Aresult
11
00
7194 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 14 14
Condition83%5/6
defined $st and not $st and (_ss($dev, scalar []))[0] =~ /:\Q$pn\E\s/
!ll&&!rl&&r
860
defined $st and not $st
!ll&&!rl&&r
176
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
7195 14 ▶ if ( !defined $st ) { push @GAPS, join( ' ', 'wget', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 1 13 14
7196 13 require POSIX;
7197 13 my $stamp = POSIX::strftime( '%Y-%m-%d %H:%M:%S', _local_tm( _dev_now($dev) ) );
7198 13 ▶ my $hp = $h80 . ( defined $port80 ? ":$port80" : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $port80 ? : 5 8 13
7199 13 ▶ my $addr = $h80 eq 'localhost' ? '127.0.0.1' : $h80;
Branch: 1 branch
BranchTrueFalseTotal
$h80 eq 'localhost' ? : 2 11 13
7200 13 my @err;
7201 13 ▶ 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 7 6 13
$st ? : 2 5 7
Condition75%3/4
$path80 // "/"
l!l
70
$port80 // 80
l!l
43
MC/DC0%0/1
$path80 // "/"
$path80
MC/DC100%1/1
$port80 // 80
$port80
Truth table50%1/2
A
A= $path80
Aresult
11
00
Truth table100%2/2
A
A= $port80
Aresult
11
00
7202 13 ▶ return ( join( "\n", @err ), 0 ) unless $st;
Branch: 1 branch
BranchTrueFalseTotal
unless $st 6 7 13
7203 7 my %reason = ( 200 => 'OK', 403 => 'Forbidden', 404 => 'Not Found' );
7204 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
7205 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
7206 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
7207 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
7208 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
7209 3 ▶ return ( join( "\n", @err, $body =~ s/\n\z//r ), 1 ) if $file eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $file eq "-" 2 1 3
7210 1 ▶ if ( $file ne '/dev/null' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file ne "/dev/null") 1 0 1
7211 1 my ( $e, $wok ) = _write_path( $dev, $file, $body, 0, $ctx );
7212 1 ▶ return ( $e, 0 ) unless $wok;
Branch: 1 branch
BranchTrueFalseTotal
unless $wok 0 1 1
7213 }
7214 1 ▶ push @err, "Saving to: '$file'", '', "'$file' saved [" . length($body) . ']' unless $quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet 0 1 1
7215 1 return ( join( "\n", @err ), 1 );
7216 }
7217 # ein anderes Geraet: nur das Scheitern der Verbindung ist nachgebildet
7218 37 ▶ if ( defined $h80 && !$self80 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h80 and not $self80) 7 30 37
Condition66%2/3
defined $h80 and not $self80
!ll&&!rl&&r
0307
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
7219 7 ▶ my $pn = $port80 // ( ( $url // '' ) =~ m{\Ahttps://} ? 443 : 80 );
Branch: 1 branch
BranchTrueFalseTotal
($url // '') =~ m[\Ahttps://] ? : 0 5 5
Condition75%3/4
$port80 // (($url // "") =~ m[\Ahttps://] ? 443 : 80)
l!l
25
$url // ""
l!l
50
MC/DC100%1/1
$port80 // (($url // "") =~ m[\Ahttps://] ? 443 : 80)
$port80
Truth table100%2/2
A
A= $port80
Aresult
11
00
7220 7 my $st = _tcp_probe( $dev, $h80, $pn );
7221 7 ▶ if ( defined $st && $st ne 'open' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $st and $st ne "open") 5 2 7
Condition66%2/3
defined $st and $st ne "open"
!ll&&!rl&&r
205
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
7222 5 require POSIX;
7223 5 my $stamp = POSIX::strftime( '%Y-%m-%d %H:%M:%S', _local_tm( _dev_now($dev) ) );
7224 5 my $why = { refused => 'Connection refused', timeout => 'Connection timed out', unreach => 'Network is unreachable', nohost => 'No route to host' }->{$st};
7225 5 ▶ $SH->{code} = 4 if $SH;
Branch: 1 branch
BranchTrueFalseTotal
if $Langertha::Holmgang::Sim::Linux::SH 5 0 5
7226 5 ▶ 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 4 5
Condition66%4/6
$quiet or $st eq "timeout" and $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT
l!l&&r!l&&!r
104
$st eq "timeout" and $Langertha::Holmgang::Sim::Linux::IN_TIMEOUT
!ll&&!rl&&r
310
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
7227 4 ▶ return ( "wget: unable to resolve host address '$h80'", 0 ) if $st eq 'noname';
Branch: 1 branch
BranchTrueFalseTotal
if $st eq "noname" 1 3 4
7228 3 ▶ my $ip = _ip2n($h80) ? $h80 : ( _own_addrs( ( $ctx->{state} || {} )->{$h80} || {} ) )[0] // $h80;
Branch: 1 branch
BranchTrueFalseTotal
_ip2n($h80) ? : 3 0 3
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
7229 3 return ( "--$stamp-- $url\nConnecting to $h80 ($ip:$pn)... failed: $why.", 0 );
7230 }
7231 }
7232 32 ▶ my ( $host, $port, $path ) = ( $url // '' ) =~ m{\A(?:http://)?([^/:]+):(\d+)(/.*)?\z};
Condition50%1/2
$url // ""
l!l
320
MC/DC0%0/1
$url // ""
$url
Truth table50%1/2
A
A= $url
Aresult
11
00
7233 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
1130
$host =~ /\A(?:localhost|127\.0\.0\.1)\z/ or grep {$_ eq $host;} _own_addrs($dev)
l!l&&r!l&&!r
3001
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
7234 32 ▶ if ( !$local || ( $out // '' ) ne '-' ) { push @GAPS, join( ' ', 'wget', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (not $local or ($out // "") ne "-") 2 30 32
Condition60%3/5
not $local or ($out // "") ne "-"
l!l&&r!l&&!r
2030
$out // ""
l!l
300
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
7235 30 _part('Monitoring');
7236 my ( $body, $st ) = Langertha::Holmgang::Sim::Linux::Monitoring::http( $dev, $post ? 'POST' : 'GET', $port, $path // '/',
7237 1 ▶ sub { my ( $o, $k ) = __PACKAGE__->_run_inner( $dev, $_[0], $ctx ); return ( $o, $k ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
7238 30 ▶ sub { _tcp_probe( $dev, @_ ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$post ? : 3 27 30
Condition50%1/2
$path // "/"
l!l
300
MC/DC0%0/1
$path // "/"
$path
Truth table50%1/2
A
A= $path
Aresult
11
00
7239 30 ▶ if ( !defined $st ) { push @GAPS, join( ' ', 'wget', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $st) 5 25 30
7240 25 ▶ return ( "failed: Connection refused.", 0 ) if !$st;
Branch: 1 branch
BranchTrueFalseTotal
unless $st 1 24 25
7241 24 ▶ return ( $body, 1 ) if $st == 200;
Branch: 1 branch
BranchTrueFalseTotal
if $st == 200 22 2 24
7242 2 my %reason = ( 400 => 'Bad Request', 403 => 'Forbidden', 405 => 'Method Not Allowed', 500 => 'Internal Server Error' );
7243 2 ▶ return ( "ERROR $st: " . ( $reason{$st} // 'Error' ) . '.', 0 );
Condition50%1/2
$reason{$st} // "Error"
l!l
20
MC/DC0%0/1
$reason{$st} // "Error"
$reason{$st}
Truth table50%1/2
A
A= $reason{$st}
Aresult
11
00
7244 }
7245  
7246 # nginx -t|-T (Klammern und Semikolons je Datei pruefen: nginx.conf, conf.d/*.conf, sites-enabled/*),
7247 # -v|-V, -s reload|stop|quit (wie systemctl); ohne nginx-Dienst nicht installiert
7248 6 ▶sub _nginx {
Subroutine _nginx: called CC=29 SCAR=36.6
7249 6 my ( $dev, $av, $ctx ) = @_;
7250 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
7251 4 my %o;
7252 4 my @a = @$av;
7253 4 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 4 4 8
7254 4 my $x = shift @a;
7255 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
7256 3 elsif ( $x =~ /\A-([tTvVq]+)\z/ ) { $o{$_} = 1 for split //, $1 }
7257 0 else { push @GAPS, join( ' ', 'nginx', @$av ); return ( '', 0 ) }
7258 }
7259 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
7260 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
7261 4 ▶ if ( defined $o{s} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o{"s"}) 1 3 4
7262 1 my %verb = ( reload => 'reload', stop => 'stop', quit => 'stop', reopen => 'reload' );
7263 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
7264 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
7265 1 my ( $out, $k ) = _systemctl( $dev, [ $v, 'nginx' ], $ctx );
7266 1 ▶ return ( $k ? '' : $out, $k );
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 1 0 1
7267 }
7268 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
7269 6 my @f = grep { defined _file_text( $dev, $_ ) } '/etc/nginx/nginx.conf',
7270 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
7271 3 for my $f (@f) {
7272 6 my $t = _file_text( $dev, $f );
7273 6 ( my $c = $t ) =~ s/#[^\n]*//g;
7274 6 $c =~ s/"[^"\n]*"|'[^'\n]*'//g;
7275 6 my ( $depth, $line ) = ( 0, 0 );
7276 6 for my $l ( split /\n/, $c, -1 ) {
7277 25 $line++;
7278 25 for my $ch ( $l =~ /([{}])/g ) {
7279 18 ▶ $depth += $ch eq '{' ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$ch eq '{' ? : 10 8 18
7280 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
7281 }
7282 25 ( my $st = $l ) =~ s/\A\s+|\s+\z//g;
7283 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
7284 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
7285 1 ▶ next if $next =~ /\A\s*[{;]/; # Fortsetzung auf der naechsten Zeile
Branch: 1 branch
BranchTrueFalseTotal
if $next =~ /\A\s*[{;]/ 0 1 1
7286 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 );
7287 }
7288 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
7289 }
7290 1 my @out = ( 'nginx: the configuration file /etc/nginx/nginx.conf syntax is ok', 'nginx: configuration file /etc/nginx/nginx.conf test is successful' );
7291 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
7292 1 return ( join( "\n", @out ), 1 );
7293 }
7294 0 push @GAPS, join( ' ', 'nginx', @$av );
7295 0 return ( '', 0 );
7296 }
7297  
7298  
7299 # diff a b (Normalformat) und diff -u (vereinheitlicht, 3 Zeilen Kontext);
7300 # gleich: leer und Erfolg, verschieden: Ausgabe und Exit 1
7301 12 ▶sub _diff {
Subroutine _diff: called CC=25 SCAR=34.1
7302 12 my ( $dev, $av ) = @_;
7303 12 my @f = grep { !/\A-/ } @$av;
7304 12 my $u = grep {/\A-[a-zA-Z]*u|\A--unified/} @$av;
7305 12 my $r = grep {/\A-[a-zA-Z]*r|\A--recursive/} @$av;
7306 12 my $q = grep {/\A-[a-zA-Z]*q|\A--brief/} @$av;
7307 12 ▶ return ( 'diff: missing operand', 0 ) if @f < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @f < 2 0 12 12
7308 12 my ( $fa, $fb ) = map { _absp( s{(?<=.)/+\z}{}r ) } @f[ 0, 1 ];
7309 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
7310 2 my %rel;
7311 2 for my $d ( $fa, $fb ) {
7312 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
7313 4 for my $p ( _under( $dev, $real ) ) {
7314 10 my $x = substr $p, length($real) + 1;
7315 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
7316 7 $rel{$x}{$d} = 1;
7317 }
7318 }
7319 2 my @out;
7320 2 for my $x ( sort keys %rel ) {
7321 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
7322 1 ▶ my $d = $rel{$x}{$fa} ? $fa : $fb;
Branch: 1 branch
BranchTrueFalseTotal
$rel{$x}{$fa} ? : 0 1 1
7323 1 my ( $sub, $n ) = $x =~ m{\A(?:(.*)/)?([^/]+)\z};
7324 1 ▶ push @out, "Only in $d" . ( defined $sub ? "/$sub" : '' ) . ": $n";
Branch: 1 branch
BranchTrueFalseTotal
defined $sub ? : 1 0 1
7325 1 next;
7326 }
7327 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
7328 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
7329 }
7330 2 return ( join( "\n", @out ), !@out );
7331 }
7332 10 my @t;
7333 10 for my $p ( $fa, $fb ) {
7334 20 my $x = _file_text( $dev, $p );
7335 20 ▶ return ( "diff: $p: No such file or directory", 0 ) if !defined $x;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x 1 19 20
7336 19 push @t, [ split /\n/, $x ];
7337 }
7338 9 my @out = _diff_text( @t, $u, @f[ 0, 1 ] );
7339 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
7340 9 return ( join( "\n", @out ), !@out );
7341 }
7342  
7343 12 ▶sub _diff_text {
Subroutine _diff_text: called CC=14 SCAR=26.4
7344 12 my ( $a, $b, $u, $fa, $fb ) = @_;
7345 12 my @ops = _lcs_ops( $a, $b );
7346 12 ▶ return () if !grep { $_->[0] ne '=' } @ops;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$$_[0] ne "=";} @ops 4 8 12
7347 8 ▶ return _diff_unified( \@ops, $fa, $fb ) if $u;
Branch: 1 branch
BranchTrueFalseTotal
if $u 2 6 8
7348 6 my @out;
7349 6 my ( $i, $j ) = ( 0, 0 );
7350 6 my $k = 0;
7351 6 ▶ while ( $k < @ops ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k < @ops) 28 6 34
7352 28 ▶ if ( $ops[$k][0] eq '=' ) { $i++; $j++; $k++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($ops[$k][0] eq "=") 20 8 28
7353 8 my ( @d, @a );
7354 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
7355 13 ▶ push @d, $ops[$k][1] if $ops[$k][0] eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $ops[$k][0] eq "-" 5 8 13
7356 13 ▶ push @a, $ops[$k][1] if $ops[$k][0] eq '+';
Branch: 1 branch
BranchTrueFalseTotal
if $ops[$k][0] eq "+" 8 5 13
7357 13 $k++;
7358 }
7359 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
7360 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
7361 : @d ? $r->( $i + 1, scalar @d ) . 'd' . $j
7362 : $i . 'a' . $r->( $j + 1, scalar @a );
7363 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
7364 8 $i += @d;
7365 8 $j += @a;
7366 }
7367 6 return @out;
7368 }
7369  
7370 12 ▶sub _lcs_ops {
Subroutine _lcs_ops: called CC=14 SCAR=26.4
7371 12 my ( $a, $b ) = @_;
7372 12 my ( $n, $m ) = ( scalar @$a, scalar @$b );
7373 12 my @L;
7374 12 for my $i ( reverse 0 .. $n ) {
7375 63 for my $j ( reverse 0 .. $m ) {
7376 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
7377 : $a->[$i] eq $b->[$j] ? $L[ $i + 1 ][ $j + 1 ] + 1
7378 : _max( $L[ $i + 1 ][$j], $L[$i][ $j + 1 ] );
7379 }
7380 }
7381 12 my ( $i, $j, @ops ) = ( 0, 0 );
7382 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
7383 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
7384 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
7385 7 else { push @ops, [ '-', $a->[ $i++ ] ] }
7386 }
7387 12 return @ops;
7388 }
7389  
7390 493 ▶sub _max { $_[0] > $_[1] ? $_[0] : $_[1] }
Subroutine _max: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] > $_[1] ? : 228 265 493
7391  
7392 2 ▶sub _diff_unified {
Subroutine _diff_unified: called CC=12 SCAR=26.5
7393 2 my ( $ops, $fa, $fb ) = @_;
7394 2 my @out = ( "--- $fa", "+++ $fb" );
7395 2 my @chg = grep { $ops->[$_][0] ne '=' } 0 .. $#$ops;
7396 # Bereiche: Aenderungen, die hoechstens 6 Zeilen auseinander liegen, gehoeren zusammen
7397 2 my @h;
7398 2 for my $c (@chg) {
7399 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
7400 2 else { push @h, [ $c, $c ] }
7401 }
7402 2 for my $h (@h) {
7403 2 my $s = _max( 0, $h->[0] - 3 );
7404 2 ▶ my $e = $h->[1] + 3 > $#$ops ? $#$ops : $h->[1] + 3;
Branch: 1 branch
BranchTrueFalseTotal
$$h[1] + 3 > $ops->$#* ? : 2 0 2
7405 2 my ( $ia, $ib ) = ( 1, 1 );
7406 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
7407 2 ▶ my @l = map { ( $_->[0] eq '=' ? ' ' : $_->[0] ) . $_->[1] } @$ops[ $s .. $e ];
Branch: 1 branch
BranchTrueFalseTotal
$$_[0] eq '=' ? : 3 5 8
7408 2 my $na = grep { !/\A\+/ } @l;
7409 2 my $nb = grep { !/\A-/ } @l;
7410 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
7411 }
7412 2 return @out;
7413 }
7414  
7415 1 ▶sub _cmp {
Subroutine _cmp: called CC=7 SCAR=20.1
7416 1 my ( $dev, $av ) = @_;
7417 1 my @f = grep { !/\A-/ } @$av;
7418 1 my @t = map { _file_text( $dev, $_ ) } @f[ 0, 1 ];
7419 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
7420 1 ▶ return ( '', 1 ) if $t[0] eq $t[1];
Branch: 1 branch
BranchTrueFalseTotal
if $t[0] eq $t[1] 0 1 1
7421 1 my $i = 0;
7422 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
7423 1 my $line = 1 + ( () = substr( $t[0], 0, $i ) =~ /\n/g );
7424 1 return ( "$f[0] $f[1] differ: byte " . ( $i + 1 ) . ", line $line", 0 );
7425 }
7426  
7427 7 ▶sub _readlink {
Subroutine _readlink: called CC=10 SCAR=23.3
7428 7 my ( $dev, $av ) = @_;
7429 7 my $canon = grep {/\A-\w*[fem]/} @$av;
7430 7 my @out;
7431 7 for my $p ( grep { !/\A-/ } @$av ) {
7432 7 ( my $q = $p ) =~ s{(?<=.)/+\z}{};
7433 7 ▶ my $e = ref $dev->{files} eq 'HASH' ? $dev->{files}{$q} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'files'} eq 'HASH' ? : 7 0 7
7434 7 ▶ if ( !$canon ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($canon) 3 4 7
7435 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
7436 2 push @out, $e->{link};
7437 2 next;
7438 }
7439 4 my $t = $q;
7440 4 for ( 1 .. 6 ) {
7441 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
7442 7 my $x = $dev->{files}{$t};
7443 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
7444 3 $t = _link_target( $t, $x->{link} );
7445 }
7446 4 push @out, $t;
7447 }
7448 6 return ( join( "\n", @out ), 1 );
7449 }
7450  
7451 # --- systemd ----------------------------------------------------------------------
7452  
7453 # Startbedingungen eines Dienstes (needs): erste nicht erfuellte oder undef.
7454 # { can: { user, read|write|exec: pfad } } Benutzer darf die Datei …
7455 # { free: { mount, min } } mindestens so viel frei
7456 # { state: [pfad im Geraet], <Erwartungen> } Zustand (wie Regeln)
7457 # Jede Bedingung traegt log: [ Zeilen ] fuer das Journal beim Scheitern.
7458 125 ▶sub _failing_need {
Subroutine _failing_need: called CC=25 SCAR=34.3
7459 125 my ( $dev, $svc ) = @_;
7460 # ohne Benutzer in der Bedingung: User= der geladenen Unit, sonst user des Dienstes
7461 125 ▶ my ($uu) = ( $svc->{unit_loaded} // '' ) =~ /^\s*User\s*=\s*(\S+)/m;
Condition100%2/2
$$svc{"unit_loaded"} // ""
l!l
4679
MC/DC100%1/1
$$svc{"unit_loaded"} // ""
$$svc{"unit_loaded"}
Truth table100%2/2
A
A= $$svc{"unit_loaded"}
Aresult
11
00
7462 125 ▶ for my $n ( @{ $svc->{needs} || [] } ) {
Condition100%2/2
$$svc{'needs'} || []
l!l
3590
MC/DC100%1/1
$$svc{'needs'} || []
$$svc{'needs'}
Truth table100%2/2
A
A= $$svc{'needs'}
Aresult
11
00
7463 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
7464 6 my ($what) = grep { exists $c->{$_} } qw( read write exec );
7465 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
7466 }
7467 elsif ( my $f = $n->{free} ) {
7468 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
7469 9 ▶ return $n if $free < _bytes( $f->{min} );
Branch: 1 branch
BranchTrueFalseTotal
if $free < _bytes($$f{"min"}) 3 6 9
7470 }
7471 elsif ( my $want = $n->{env} ) { # Umgebung des Prozesses: VAR => Muster
7472 6 my ( $env, $miss ) = _unit_env( $dev, $svc );
7473 6 ▶ if ( defined $miss ) { # EnvironmentFile ohne - fehlt: systemd startet den Prozess gar nicht
Branch: 1 branch
BranchTrueFalseTotal
if (defined $miss) 2 4 6
7474 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
7475 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
7476 2 my $c = _clock($dev);
7477 2 return { log => [ "$c:03 $h systemd[1]: $u: Failed to load environment files: No such file or directory",
7478 "$c:03 $h systemd[1]: $u: Failed to spawn 'start' task: No such file or directory" ] };
7479 }
7480 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
7481 }
7482 elsif ( exists $n->{state} ) {
7483 14 my %c = %$n;
7484 14 delete @c{qw( state log )};
7485 14 my ($ok) = _condition( $dev, { %c, path => $n->{state} } );
7486 14 ▶ return $n unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 7 7 14
7487 }
7488 }
7489 108 return undef;
7490 }
7491  
7492 # Umgebung eines Dienstes aus der geladenen Unit: Environment=, dann EnvironmentFile= (in dieser
7493 # Reihenfolge, die Datei gewinnt; Zeilen VAR=wert, Anfuehrungszeichen weg, Kommentare und
7494 # Zeilen ohne VAR= uebergangen; ein vorangestelltes export ist erlaubt). ( \%env, $fehlende_datei )
7495 6 ▶sub _unit_env {
Subroutine _unit_env: called CC=12 SCAR=25.2
7496 6 my ( $dev, $svc ) = @_;
7497 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
7498 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
7499 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
7500 3 my $opt = $f =~ s/\A-//;
7501 3 my $t = _file_text( $dev, $f );
7502 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
7503 1 for my $l ( split /\n/, $t ) {
7504 3 ▶ next if $l =~ /\A\s*(?:[#;]|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\A\s*(?:[#;]|\z)/ 1 2 3
7505 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
7506 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
7507 2 $env{$k} = $v;
7508 }
7509 }
7510 4 return ( \%env, undef );
7511 }
7512  
7513 # Konten und Gruppen eines frischen Debian 12 (und gaengiger Pakete), die kein Fall nennen muss
7514 88 our %BASE_USERS = map { $_ => 1 } qw( root daemon bin sys sync games man lp mail news uucp proxy www-data backup list irc _apt
7515 nobody systemd-network systemd-timesync messagebus sshd postgres redis mysql prometheus bind _chrony postfix nginx );
7516 88 our %BASE_GROUPS = map { $_ => 1 } qw( root daemon bin sys adm tty disk lp mail news uucp man proxy kmem dialout fax voice cdrom
7517 floppy tape sudo audio dip www-data backup operator list irc src shadow utmp video sasl plugdev staff games users nogroup
7518 systemd-journal systemd-network systemd-timesync input sgx kvm render crontab messagebus ssl-cert postgres redis mysql
7519 prometheus bind _chrony postfix postdrop nginx );
7520  
7521 # User=/Group= der Unit, die es auf dem Geraet nicht gibt: 'user' bzw. 'group' oder undef. Nur
7522 # auf Geraeten mit check_accounts (der Fall nennt alle Konten); Nummern und Grundkonten zaehlen
7523 # immer als vorhanden.
7524 88 ▶sub _cred_missing {
Subroutine _cred_missing: called CC=13 SCAR=26.3
7525 88 my ( $dev, $u, $g ) = @_;
7526 88 ▶ return undef unless $dev->{check_accounts};
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{"check_accounts"} 76 12 88
7527 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
7528 return 'group' if defined $g && $g !~ /\A\d+\z/ && !$BASE_GROUPS{$g} && !( $dev->{groups} || {} )->{$g}
7529 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
7530 10 return undef;
7531 }
7532  
7533 407 ▶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
158249
MC/DC100%1/1
$$svc{"unit"} // '/lib/systemd/system/' . _uname($n)
$$svc{"unit"}
Truth table100%2/2
A
A= $$svc{"unit"}
Aresult
11
00
7534  
7535 # Voller Unit-Name: "app" -> "app.service", "backup.timer" bleibt
7536 1083 ▶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 1043 1083
7537  
7538 # Text der Unit, wie systemd sie geladen hat (sonst Datei und Drop-ins)
7539 212 ▶sub _unit_loaded_text {
Subroutine _unit_loaded_text: called CC=2 SCAR=6.9
7540 212 my ( $dev, $n, $svc ) = @_;
7541 212 ▶ 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
932594
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
7542 }
7543  
7544 # Ganze Unit ohne [Install]: "static", enable/disable wirken nicht
7545 58 ▶sub _static {
Subroutine _static: called CC=4 SCAR=13.9
7546 58 my ( $dev, $n, $svc ) = @_;
7547 58 my $t = _unit_loaded_text( $dev, $n, $svc );
7548 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
7549 }
7550  
7551 78 ▶sub _oneshot {
Subroutine _oneshot: called CC=4 SCAR=13.9
7552 78 my ( $dev, $n, $svc ) = @_;
7553 78 ▶ my $t = _unit_loaded_text( $dev, $n, $svc ) // '';
Condition100%2/2
_unit_loaded_text($dev, $n, $svc) // ""
l!l
3840
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
7554 78 ▶ 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 71 78
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
7107
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
7555 }
7556  
7557 # Timer aus dem geladenen Text: gueltige und ungueltige OnCalendar=, andere
7558 # Ausloeser, ausgeloeste Unit.
7559 32 ▶sub _timer_info {
Subroutine _timer_info: called CC=9 SCAR=22.0
7560 32 my ( $dev, $n, $svc ) = @_;
7561 32 require Langertha::Holmgang::Sim::Linux::Calendar;
7562 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
7563 32 my ( @cal, @bad, $other );
7564 32 my $line = 0;
7565 32 for my $l ( split /\n/, $t ) {
7566 265 $line++;
7567 265 ▶ if ( $l =~ /^\s*OnCalendar\s*=\s*(.*?)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /^\s*OnCalendar\s*=\s*(.*?)\s*$/) 40 225 265
7568 40 my $e = $1;
7569 # leere Zuweisung setzt die Liste zurueck (systemd.timer(5), z. B. im Drop-in)
7570 40 ▶ if ( $e eq '' ) { @cal = (); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq "") 4 36 40
7571 36 my $c = Langertha::Holmgang::Sim::Linux::Calendar::parse($e);
7572 36 ▶ if ($c) { push @cal, $c } else { push @bad, [ $line, $e ] }
Branch: 1 branch
BranchTrueFalseTotal
if ($c) { } 31 5 36
7573 }
7574 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
7575 }
7576 32 ( my $base = $n ) =~ s/\.timer\z//;
7577 32 my ($unit) = $t =~ /^\s*Unit\s*=\s*(\S+)\s*$/m;
7578 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
7579 persistent => $t =~ /^\s*Persistent\s*=\s*(?:yes|true|1|on)\s*$/m ? 1 : 0 };
7580 }
7581  
7582 # Abgeleitete Felder eines Timers im Zustand (fuer Regeln): Normalformen der
7583 # gueltigen OnCalendar= und die ausgeloeste Unit. Nur wenn sich die geladene
7584 # Unit aendert.
7585 33 ▶sub _timer_derive {
Subroutine _timer_derive: called CC=2 SCAR=6.9
7586 33 my ( $dev, $n, $svc ) = @_;
7587 33 ▶ return unless $n =~ /\.timer\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $n =~ /\.timer\z/ 25 8 33
7588 8 my $i = _timer_info( $dev, $n, $svc );
7589 8 $svc->{triggers} = [ map { $_->{normalized} } @{ $i->{cal} } ];
7590 8 $svc->{activates} = $i->{activates};
7591 8 return;
7592 }
7593  
7594 # Unit aus ihrer Datei laden, wenn systemd sie noch nicht kennt (wie beim ersten
7595 # Zugriff auf eine neue Unit-Datei)
7596 22 ▶sub _load_unit {
Subroutine _load_unit: called CC=5 SCAR=16.1
7597 22 my ( $dev, $n, $peek ) = @_;
7598 22 for my $dir (qw( /etc/systemd/system /lib/systemd/system )) {
7599 28 my $p = "$dir/" . _uname($n);
7600 28 my $t = _file_text( $dev, $p );
7601 28 ▶ next unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 12 16 28
7602 16 my ($desc) = $t =~ /^\s*Description\s*=\s*(.*?)\s*$/m;
7603 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
7604 ( defined $desc ? ( description => $desc ) : () ) };
7605 16 _timer_derive( $dev, $n, $svc );
7606 16 ▶ $dev->{services}{$n} = $svc unless $peek; # Lesen (status, is-*) laedt nur zur Ansicht
Branch: 1 branch
BranchTrueFalseTotal
unless $peek 12 4 16
7607 16 return $svc;
7608 }
7609 6 return undef;
7610 }
7611  
7612 # Drop-ins <unit>.service.d/*.conf: gleichnamige unter /etc ueberdecken /run und /lib,
7613 # gelesen nach Namen sortiert; ein Link auf /dev/null schaltet einen ab
7614 395 ▶sub _dropins {
Subroutine _dropins: called CC=7 SCAR=19.7
7615 395 my ( $dev, $n ) = @_;
7616 395 my $u = _uname($n);
7617 395 my %by;
7618 395 for my $base (qw( /lib/systemd/system /usr/lib/systemd/system /run/systemd/system /etc/systemd/system )) {
7619 1580 for my $p ( _under( $dev, "$base/$u.d" ) ) {
7620 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
7621 52 my $e = $dev->{files}{$p};
7622 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
7623 }
7624 }
7625 395 return map { $by{$_} } grep { defined $by{$_} } sort keys %by;
7626 }
7627  
7628 # Unit, wie systemd sie liest: Hauptdatei, dann die Drop-ins (mit Kopfzeile); undef ohne beides
7629 353 ▶sub _unit_text {
Subroutine _unit_text: called CC=4 SCAR=14.0
7630 353 my ( $dev, $n, $svc ) = @_;
7631 353 my $main = _file_text( $dev, _unit_file( $n, $svc ) );
7632 353 my @d = _dropins( $dev, $n );
7633 353 ▶ return $main unless @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 324 29 353
7634 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
7635 }
7636  
7637 # Wirksame Einstellungen einer Unit-Fassung (nur innerhalb eines Abschnitts, wie systemd;
7638 # ein Drop-in ohne [Service] wirkt nicht): die letzte Zuweisung gilt; ExecStart*,
7639 # EnvironmentFile sind Listen, die eine leere Zuweisung leert; Environment ist { VAR => wert }.
7640 189 ▶sub _unit_props {
Subroutine _unit_props: called CC=21 SCAR=31.2
7641 189 my ($text) = @_;
7642 189 my %p;
7643 my $sec;
7644 189 ▶ for my $l ( split /\n/, $text // '' ) {
Condition100%2/2
$text // ""
l!l
17910
MC/DC100%1/1
$text // ""
$text
Truth table100%2/2
A
A= $text
Aresult
11
00
7645 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
7646 671 ▶ if ( $l =~ /\A\s*\[(\w+)\]/ ) { $sec = $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A\s*\[(\w+)\]/) 211 460 671
7647 460 ▶ next if $l =~ /\A\s*(?:[#;]|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\A\s*(?:[#;]|\z)/ 101 359 460
7648 359 ▶ next unless defined $sec; # ausserhalb eines Abschnitts: systemd ignoriert die Zeile
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sec 2 357 359
7649 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
7650 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
7651 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
7652 178 ▶ push @{ $p{$k} }, $v if $v ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $v ne "" 169 9 178
7653 }
7654 elsif ( $k eq 'Environment' ) {
7655 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
7656 17 ▶ while ( $v =~ /\G\s*(?:"([^"]*)"|'([^']*)'|(\S+))/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /\G\s*(?:"([^"]*)"|'([^']*)'|(\S+))/cg) 31 17 48
7657 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
7658 31 my ( $a, $b ) = split /=/, $w, 2;
7659 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
7660 }
7661 }
7662 162 else { $p{$k} = $v }
7663 }
7664 189 return \%p;
7665 }
7666  
7667 # Fehler beim Laden der Unit (bad-setting) oder undef
7668 162 ▶sub _unit_bad {
Subroutine _unit_bad: called CC=7 SCAR=19.5
7669 162 my ( $n, $props ) = @_;
7670 return _uname($n) . ": Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing."
7671 162 ▶ 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 159 162
Condition71%5/7
@{$$props{"ExecStart"} or [];} > 1 and ($$props{"Type"} // "simple") ne "oneshot"
!ll&&!rl&&r
15903
$$props{'ExecStart'} || []
l!l
7884
$$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
7672 # ExecStart= geleert und nichts mehr gesetzt
7673 return _uname($n) . ": Service has no ExecStart=, ExecStop=, or SuccessAction=. Refusing."
7674 159 ▶ if $props->{ExecStart} && !@{ $props->{ExecStart} };
Branch: 1 branch
BranchTrueFalseTotal
if $$props{"ExecStart"} and not @{$$props{"ExecStart"};} 2 157 159
Condition100%3/3
$$props{"ExecStart"} and not @{$$props{"ExecStart"};}
!ll&&!rl&&r
84732
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
7675 157 return undef;
7676 }
7677  
7678 93 ▶sub _systemd_start {
Subroutine _systemd_start: called CC=125 SCAR=62.2
7679 93 my ( $dev, $n, $svc, $verb ) = @_;
7680 93 my $u = _uname($n);
7681 93 ▶ return ( "Failed to $verb $u: Unit $u is masked.", 0 ) if $svc->{masked};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"masked"} 0 93 93
7682 93 my @warn;
7683 93 ▶ if ( defined $svc->{unit_loaded} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$svc{"unit_loaded"}) 34 59 93
7684 34 my $now = _unit_text( $dev, $n, $svc );
7685 push @warn, "Warning: The unit file, source configuration file or drop-ins of $u changed on disk. Run 'systemctl daemon-reload' to reload units."
7686 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
7687 }
7688 93 ▶ if ( $n =~ /\.timer\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /\.timer\z/) 6 87 93
7689 6 my $i = _timer_info( $dev, $n, $svc );
7690 return ( join( "\n", @warn, "Failed to $verb $u: Unit $u has a bad unit file setting.",
7691 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
7692 4 my $act = _unit( $i->{activates} );
7693 return ( join( "\n", @warn, "Failed to $verb $u: Unit $i->{activates} not found." ), 0 )
7694 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
7695 }
7696 # RuntimeDirectory=/StateDirectory=/LogsDirectory= der geladenen Unit legt systemd beim Start an
7697 90 ▶ my $ut = $svc->{unit_loaded} // _unit_text( $dev, $n, $svc ) // '';
Condition100%5/5
($$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)) // ""
l!l
4644
$$svc{"unit_loaded"} // _unit_text($dev, $n, $svc)
l!l&&r!l&&!r
311544
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
7698 90 my $props = _unit_props($ut);
7699 # bad-setting: systemd nimmt den Auftrag gar nicht an — ein laufender Prozess laeuft weiter
7700 90 ▶ if ( _unit_bad( $n, $props ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_unit_bad($n, $props)) 2 88 90
7701 2 return ( join( "\n", @warn, "Failed to $verb $u: Unit $u has a bad unit file setting.",
7702 "See system logs and 'systemctl status $u' for details." ), 0 );
7703 }
7704 88 my ($uuser) = $ut =~ /^\s*User\s*=\s*(\S+)/m;
7705 88 my ($ugrp) = $ut =~ /^\s*Group\s*=\s*(\S+)/m;
7706 # User=/Group= der Unit, die es nicht gibt (Geraet mit check_accounts): 217/USER bzw. 216/GROUP wie systemd
7707 88 ▶ if ( my $miss = _cred_missing( $dev, $uuser, $ugrp ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $miss = _cred_missing($dev, $uuser, $ugrp)) 2 86 88
7708 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
7709 2 $prog =~ s/\s.*//s;
7710 2 ( my $short = $n ) =~ s/\A(.{1,15}).*/$1/;
7711 2 my $W = uc $miss;
7712 2 _log( $dev, $n, $svc, "($short)[3001]: $u: Failed to determine $miss credentials: No such process",
7713 "($short)[3001]: $u: Failed at step $W spawning $prog: No such process" );
7714 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
7715 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
7716 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
7717 return ( join( "\n", @warn, "Job for $u failed because the control process exited with error code.",
7718 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
7719 }
7720 86 for ( [ RuntimeDirectory => '/run' ], [ StateDirectory => '/var/lib' ], [ LogsDirectory => '/var/log' ], [ CacheDirectory => '/var/cache' ] ) {
7721 344 my ( $k, $base ) = @$_;
7722 344 for my $d ( map { split /\s+/ } $ut =~ /^\s*\Q$k\E\s*=\s*(.+?)\s*$/mg ) {
7723 2 my $p = "$base/$d";
7724 2 ▶ next if _is_dir( $dev, $p );
Branch: 1 branch
BranchTrueFalseTotal
if _is_dir($dev, $p) 1 1 2
7725 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
7726 }
7727 }
7728 # Neustart gibt geloeschte, noch offene Dateien frei
7729 86 ▶ if ( $dev->{deleted_open} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"deleted_open"}) 1 85 86
7730 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
7731 1 ▶ $dev->{deleted_open} = \@keep if @keep != @{ $dev->{deleted_open} };
Branch: 1 branch
BranchTrueFalseTotal
if @keep != @{$$dev{"deleted_open"};} 1 0 1
7732 }
7733 86 my $conf_bad = _app_conf_error( $dev, $n );
7734 86 ▶ if ($conf_bad) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf_bad) 4 82 86
7735 4 ▶ _app_event( $dev, $n, 'stop' ) if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 4 0 4
7736 4 _log( $dev, $n, $svc, @$conf_bad );
7737 }
7738 86 ▶ if ( $conf_bad || ( my $bad = _failing_need( $dev, $svc ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf_bad or my $bad = _failing_need($dev, $svc)) 11 75 86
Condition100%3/3
$conf_bad or my $bad = _failing_need($dev, $svc)
l!l&&r!l&&!r
4775
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
7739 11 _app_log( $dev, $n, $svc, 'fail' );
7740 11 ▶ $svc->{active} = JSON::MaybeXS::false() if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 5 6 11
7741 11 ▶ $svc->{failed} = JSON::MaybeXS::true() unless $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"failed"} 8 3 11
7742 11 return ( join( "\n", @warn, "Job for $u failed because the control process exited with error code.",
7743 "See \"systemctl status $u\" and \"journalctl -xeu $u\" for details." ), 0 );
7744 }
7745 75 ▶ 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 75 75
7746 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
7747 0 local $CWD_DIR = '/';
7748 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
7749 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
7750 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
7751 $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";
7752 0 ▶ $svc->{active} = JSON::MaybeXS::false() if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 0 0 0
7753 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
7754 0 ▶ $svc->{failed} = JSON::MaybeXS::true() unless $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"failed"} 0 0 0
7755 0 return ( join( "\n", @warn, "Job for $u failed because the control process exited with error code.",
7756 "See \"systemctl status $u\" and \"journalctl -xeu $u\" for details." ), 0 );
7757 }
7758 # Geraet mit oneshot_scripts: Type=oneshot mit Shell-Skripten als ExecStart (ohne creates)
7759 # fuehrt die Skripte als User= der Unit aus; ihr Exit-Status entscheidet, ihre Ausgabe
7760 # steht im Journal
7761 75 ▶ 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 71 75
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
7104
$$dev{"oneshot_scripts"} and not $$svc{"creates"} and _oneshot($dev, $n, $svc)
!ll&&!rl&&r
6834
$$dev{"oneshot_scripts"} and not $$svc{"creates"}
!ll&&!rl&&r
6807
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
7762 4 my ( @o, $k );
7763 {
7764 4 local $CWD_DIR = '/';
7765 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
7766 4 local $AS_USER;
7767 4 for my $st (@steps) {
7768 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
7769 1 push @o, "$u: Failed to execute $st->[1]: Permission denied", "$u: Failed at step EXEC spawning $st->[1]: Permission denied";
7770 1 $k = 0;
7771 1 last;
7772 }
7773 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
7774 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
7775 3 $k = $kk;
7776 3 ▶ last unless $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $k 2 1 3
7777 }
7778 }
7779 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
7780 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
7781 $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";
7782 4 ▶ $svc->{active} = JSON::MaybeXS::false() if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 0 4 4
7783 4 ▶ if ($k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k) 1 3 4
7784 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
7785 1 ▶ $svc->{failed} = JSON::MaybeXS::false() if $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"failed"} 0 1 1
7786 1 return ( join( "\n", @warn ), 1 );
7787 }
7788 3 ▶ $svc->{failed} = JSON::MaybeXS::true() unless $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"failed"} 3 0 3
7789 3 return ( join( "\n", @warn, "Job for $u failed because the control process exited with error code.",
7790 "See \"systemctl status $u\" and \"journalctl -xeu $u\" for details." ), 0 );
7791 }
7792 71 ▶ if ( _oneshot( $dev, $n, $svc ) ) { # laeuft einmal durch und ist danach wieder inactive
Branch: 1 branch
BranchTrueFalseTotal
if (_oneshot($dev, $n, $svc)) 3 68 71
7793 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
7794 # was ein erfolgreicher Lauf anlegt (creates: { pfad => eintrag })
7795 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
7796 3 ▶ $svc->{failed} = JSON::MaybeXS::false() if $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"failed"} 0 3 3
7797 3 ▶ $svc->{active} = JSON::MaybeXS::false() if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 0 3 3
7798 3 return ( join( "\n", @warn ), 1 );
7799 }
7800 68 my $was = $svc->{active};
7801 68 ▶ if ( defined( my $e = _svc_hook( $dev, $n, $verb ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $e = _svc_hook($dev, $n, $verb))) 1 67 68
7802 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
7803 1 ▶ $svc->{active} = JSON::MaybeXS::false() if $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"active"} 1 0 1
7804 1 ▶ $svc->{failed} = JSON::MaybeXS::true() unless $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"failed"} 1 0 1
7805 1 $svc->{last_error} = $e;
7806 1 return ( join( "\n", @warn, "Job for $n.service failed because the control process exited with error code.",
7807 "See \"systemctl status $n.service\" and \"journalctl -xeu $n.service\" for details." ), 0 );
7808 }
7809 67 ▶ $svc->{restarts} = ( $svc->{restarts} // 0 ) + 1 if $was && $verb =~ /restart/;
Branch: 1 branch
BranchTrueFalseTotal
if $was and $verb =~ /restart/ 47 20 67
Condition80%4/5
$was and $verb =~ /restart/
!ll&&!rl&&r
20047
$$svc{"restarts"} // 0
l!l
740
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
7810 67 _restart_effect( $dev, $n, $verb );
7811 64 ▶ _app_event( $dev, $n, $was ? 'restart' : 'start' ) unless $was && $verb !~ /restart/;
Branch: 2 branches
BranchTrueFalseTotal
unless $was and not $verb =~ /restart/ 64 0 64
$was ? : 45 19 64
Condition66%2/3
$was and not $verb =~ /restart/
!ll&&!rl&&r
19450
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
7812 # journal_start: was der Dienst beim (Neu-)Start ins Journal schreibt
7813 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 64 64
Condition16%1/6
ref $$svc{"journal_start"} eq "ARRAY" and not $verb eq "start" && $was
!ll&&!rl&&r
6400
$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
7814 64 ▶ $svc->{active} = JSON::MaybeXS::true() unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 19 45 64
7815 64 ▶ $svc->{failed} = JSON::MaybeXS::false() if $svc->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"failed"} 6 58 64
7816 # Laufzeitdateien (Socket, PID-Datei) legt der laufende Dienst an — sofern es das Verzeichnis gibt
7817 64 ▶ for my $rf ( @{ $svc->{runtime_files} || [] } ) {
Condition100%2/2
$$svc{'runtime_files'} || []
l!l
163
MC/DC100%1/1
$$svc{'runtime_files'} || []
$$svc{'runtime_files'}
Truth table100%2/2
A
A= $$svc{'runtime_files'}
Aresult
11
00
7818 1 ( my $d = $rf->{path} ) =~ s{/[^/]+\z}{};
7819 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
7820 $dev->{files}{ $rf->{path} } = { content => '', owner => $rf->{owner} // $svc->{user} // $uuser // 'root',
7821 group => $rf->{group} // $ugrp // $svc->{user} // $uuser // 'root',
7822 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
7823 }
7824 64 ▶ if ( !$was || $verb =~ /restart/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $was or $verb =~ /restart/) 64 0 64
Condition66%2/3
not $was or $verb =~ /restart/
l!l&&r!l&&!r
19450
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
7825 64 ▶ $svc->{_started} = $props if length $ut; # womit der Prozess laeuft
Branch: 1 branch
BranchTrueFalseTotal
if length $ut 28 36 64
7826 64 ▶ _log( $dev, $n, $svc, $was ? ( "systemd[1]: Stopping $u" . _desc($svc) . '...', "systemd[1]: $u: Deactivated successfully." ) : (),
Branch: 1 branch
BranchTrueFalseTotal
$was ? : 45 19 64
7827 "systemd[1]: Started $u" . _desc($svc) . '.' );
7828 # neuer Prozess: neue Haupt-PID (die der Startmeldungen), Startzeit = Zeit der Zeile "Started"
7829 64 ▶ my $pid = $svc->{_pid} = 50000 + ( $dev->{_tick} // 0 );
Condition50%1/2
$$dev{"_tick"} // 0
l!l
640
MC/DC0%0/1
$$dev{"_tick"} // 0
$$dev{"_tick"}
Truth table50%1/2
A
A= $$dev{"_tick"}
Aresult
11
00
7830 64 require Time::Local;
7831 64 $svc->{_since} = _jtime( $svc->{_log}[-1] );
7832 # wo der neue Prozess lauscht (wie er die Datei gelesen hat), Zeilen in seinem Log
7833 64 ▶ $svc->{_listen} = [ _svc_listen( $dev, $n, $svc ) ] if ref $svc->{listen} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $$svc{"listen"} eq "HASH" 1 63 64
7834 64 _app_log( $dev, $n, $svc, 'start', $svc->{_since} );
7835 # Startmeldungen des Dienstes (Kolon, duerfen vom Zustand abhaengen)
7836 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
7837 64 ▶ @{ $svc->{start_log} || [] } );
Condition100%2/2
$$svc{'start_log'} || []
l!l
361
MC/DC100%1/1
$$svc{'start_log'} || []
$$svc{'start_log'}
Truth table100%2/2
A
A= $$svc{'start_log'}
Aresult
11
00
7838 64 ▶ if ( $n eq 'systemd-journald' && exists $svc->{_journald_flushed} ) { # der neue journald meldet, wohin er schreibt
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "systemd-journald" and exists $$svc{"_journald_flushed"}) 4 60 64
Condition66%2/3
$n eq "systemd-journald" and exists $$svc{"_journald_flushed"}
!ll&&!rl&&r
6004
MC/DC50%1/2
$n eq "systemd-journald" and exists $$svc{"_journald_flushed"}
$n eq "systemd-journald" exists $$svc{"_journald_flushed"}
Truth table66%2/3
A and B
A= $n eq "systemd-journald"B= exists $$svc{"_journald_flushed"}
ABresult
0X0
100
111
7839 4 my $flush = delete $svc->{_journald_flushed};
7840 4 ▶ my ($id) = map { m{\A/var/log/journal/([0-9a-f]{32})/} ? $1 : () } _under( $dev, '/var/log/journal' );
Branch: 1 branch
BranchTrueFalseTotal
m[\A/var/log/journal/([0-9a-f]{32})/] ? : 4 2 6
7841 4 ▶ _log( $dev, $n, $svc, map {"systemd-journald[$pid]: $_"} 'Journal started', _journald_msgs($dev),
Branch: 1 branch
BranchTrueFalseTotal
$flush && defined $id ? : 4 0 4
Condition33%1/3
$flush and defined $id
!ll&&!rl&&r
004
MC/DC0%0/2
$flush and defined $id
$flush defined $id
Truth table33%1/3
A and B
A= $flushB= defined $id
ABresult
0X0
100
111
7842 $flush && defined $id ? "Time spent on flushing to /var/log/journal/$id is 9.871ms for 1520 entries." : () );
7843 }
7844 }
7845 64 ▶ _reopen_logs( $dev, $n ) unless $verb eq 'start' && $was;
Branch: 1 branch
BranchTrueFalseTotal
unless $verb eq "start" and $was 64 0 64
Condition66%2/3
$verb eq "start" and $was
!ll&&!rl&&r
47170
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
7846 64 ▶ _pg_event( $dev, $n, $verb =~ /restart/ ? 'restart' : $verb ) unless $verb eq 'start' && $was;
Branch: 2 branches
BranchTrueFalseTotal
unless $verb eq "start" and $was 64 0 64
$verb =~ /restart/ ? : 47 17 64
Condition66%2/3
$verb eq "start" and $was
!ll&&!rl&&r
47170
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
7847 64 return ( join( "\n", @warn ), 1 );
7848 }
7849  
7850 # ExecStart= einer Unit als Shell-Skripte im Zustand: ( [ skript, argumente … ], … ) —
7851 # leer, wenn eine Zeile kein Skript startet (dann wie bisher ohne Ausfuehrung)
7852 4 ▶sub _script_steps {
Subroutine _script_steps: called CC=11 SCAR=28.6
7853 4 my ( $dev, $props ) = @_;
7854 4 my @steps;
7855 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
7856 4 my @w = split ' ', $line =~ s/\A[-@+!:]+//r;
7857 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
7858 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
7859 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
7860 }
7861 4 return @steps;
7862 }
7863  
7864 229 ▶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 164 229
7865  
7866 # Uhr der Simulation fuer neue Journalzeilen (clock am Geraet, z. B. "Oct 24 09:12")
7867 327 ▶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
122205
MC/DC100%1/1
$$dev{"clock"} // "Oct 20 09:12"
$$dev{"clock"}
Truth table100%2/2
A
A= $$dev{"clock"}
Aresult
11
00
7868  
7869 # Journalzeilen anhaengen (unter _log: Laufzeitspur, „sonst nichts geaendert" sieht sie nicht)
7870 194 ▶sub _log {
Subroutine _log: called CC=6 SCAR=19.3
7871 194 my ( $dev, $n, $svc, @lines ) = @_;
7872 194 ▶ return unless @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 61 133 194
7873 133 ▶ 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'} ? : 133 0 133
Condition20%1/5
$Langertha::Holmgang::Sim::Linux::CTX and $$Langertha::Holmgang::Sim::Linux::CTX{"host"}
!ll&&!rl&&r
00133
$$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
7874 133 for my $l (@lines) {
7875 307 my $t = ++$dev->{_tick};
7876 307 push @{ $svc->{_log} }, sprintf( '%s:%02d %s %s', _clock($dev), 3 + $t % 57, $host, $l );
7877 }
7878 133 return;
7879 }
7880  
7881 79 ▶sub _journal_lines {
Subroutine _journal_lines: called CC=30 SCAR=36.1
7882 79 my ( $dev, $n, $svc, $host ) = @_;
7883 79 ▶ $host //= $dev->{hostname} // 'localhost';
Condition25%1/4
$host //= $$dev{"hostname"} // "localhost"
l!l
790
$$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
7884 79 my $u = _uname($n);
7885 79 ▶ _journald_boot( $dev, $svc, $host ) if $n eq 'systemd-journald';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "systemd-journald" 13 66 79
7886 79 ▶ my @l = ( @{ $svc->{journal} || $svc->{_boot} || [] }, @{ $svc->{_log} || [] } );
Condition100%7/7
$$svc{'journal'} || $$svc{'_boot'} || []
l!l
3544
$$svc{"journal"} or $$svc{"_boot"}
l!l&&r!l&&!r
221344
$$svc{'_log'} || []
l!l
2158
MC/DC100%2/2
$$svc{'journal'} || $$svc{'_boot'} || []
$$svc{"journal"} $$svc{"_boot"}
MC/DC100%1/1
$$svc{'_log'} || []
$$svc{'_log'}
Truth table100%3/3
A or B
A= $$svc{"journal"}B= $$svc{"_boot"}
ABresult
1X1
011
000
Truth table100%2/2
A
A= $$svc{'_log'}
Aresult
11
00
7887 # eigene Simulation (nginx): Meldung des letzten gescheiterten Starts bzw. reload
7888 79 ▶ 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 78 79
7889 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 79 79
Condition14%1/7
$$dev{"bind"} and $n eq ($$dev{"bind"}{"service"} // "named")
!ll&&!rl&&r
7900
$$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
7890 79 ▶ 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 77 79
Condition83%5/6
$n eq "ssh" || $n eq "sshd" and $$dev{"ssh_tries"}
!ll&&!rl&&r
7252
$n eq "ssh" or $n eq "sshd"
l!l&&r!l&&!r
7072
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
7891 79 ▶ if ( $n =~ /\.timer\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /\.timer\z/) 2 77 79
7892 2 my $i = _timer_info( $dev, $n, $svc );
7893 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} };
7894 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
7895 }
7896 79 ▶ 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 65 79
Condition83%5/6
not $$svc{"active"} and $$svc{"failed"} || _failing_need($dev, $svc)
!ll&&!rl&&r
541114
$$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
7897 14 my $bad = _failing_need( $dev, $svc );
7898 14 my $c = _clock($dev);
7899 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
7900 push @l, "$c:03 $host systemd[1]: $u: Main process exited, code=exited, status=1/FAILURE",
7901 "$c:03 $host systemd[1]: $u: Failed with result 'exit-code'.",
7902 "$c:03 $host systemd[1]: Failed to start $u" . _desc($svc) . '.'
7903 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
7904 }
7905 79 ▶ for my $r ( 1 .. ( $svc->{runs} // 0 ) ) {
Condition100%2/2
$$svc{"runs"} // 0
l!l
376
MC/DC100%1/1
$$svc{"runs"} // 0
$$svc{"runs"}
Truth table100%2/2
A
A= $$svc{"runs"}
Aresult
11
00
7906 3 ▶ my $d = defined $svc->{description} ? " - $svc->{description}" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $$svc{'description'} ? : 2 1 3
7907 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
7908 sprintf( "Oct 20 14:%02d:01 $host systemd[1]: $u: Deactivated successfully.", $r ),
7909 sprintf( "Oct 20 14:%02d:01 $host systemd[1]: Finished $u$d.", $r );
7910 }
7911 79 return @l;
7912 }
7913  
7914 59 ▶sub _journalctl {
Subroutine _journalctl: called CC=86 SCAR=59.4
7915 59 my ( $dev, $av, $ctx ) = @_;
7916 59 my $host = $ctx->{host};
7917 59 my @a = @$av;
7918 59 my ( @units, $n, $grep, $since, $until, $out, $reverse, $file, $boots, $all_units, $kernel, @ident, $header );
7919 59 ▶ 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 10 10
7920 59 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 90 55 145
7921 90 my $x = shift @a;
7922 90 ▶ if ( $x eq '-u' || $x eq '--unit' ) { push @units, _unit( shift(@a) // '' ) }
Branch: 31 branches
BranchTrueFalseTotal
if ($x eq '-u' or $x eq '--unit') { } 40 50 90
elsif ($x =~ /\A--unit=(.+)\z/) { } 0 50 50
elsif ($x eq '-n' or $x eq '--lines') { } 17 33 50
elsif ($x =~ /\A(?:-n|--lines=)(\d+)\z/) { } 0 33 33
elsif ($x eq '-e' or $x eq '--pager-end') { } 0 33 33
elsif ($x eq '-g' or $x eq '--grep') { } 1 32 33
elsif ($x =~ /\A--grep=(.+)\z/) { } 0 32 32
elsif ($x =~ /\A(?:-S|--since)(?:=.*)?\z/) { } 8 24 32
elsif ($x =~ /\A(?:-U|--until)(?:=.*)?\z/) { } 0 24 24
elsif ($x =~ /\A(?:-o|--output)(?:=.*)?\z/) { } 1 23 24
elsif ($x =~ /\A--file(?:=.*)?\z/) { } 0 23 23
elsif ($x eq '-r' or $x eq '--reverse') { } 0 23 23
elsif ($x eq '--list-boots') { } 2 21 23
elsif ($x eq '-k' or $x eq '--dmesg') { } 2 19 21
elsif ($x eq '-p' or $x eq '--priority') { } 0 19 19
elsif ($x =~ /\A(?:-t|--identifier)(?:=.*)?\z/) { } 1 18 19
elsif ($x =~ /\A_SYSTEMD_UNIT=(.+)\z/) { } 1 17 18
elsif ($x =~ /\A(_COMM|SYSLOG_IDENTIFIER)=(.*)\z/) { } 3 14 17
elsif ($x eq '--header') { } 2 12 14
elsif ($x =~ /\A-(?:b|-boot)\z/) { } 2 10 12
elsif ($x eq '-f' or $x eq '--follow') { } 0 10 10
elsif ($x eq '--flush') { } 1 9 10
elsif ($x =~ /\A--(?:rotate|sync|relinquish-var)\z/) { } 0 9 9
elsif ($x eq '--verify') { } 0 9 9
elsif ($x =~ /\A-\w*u\z/) { } 0 9 9
elsif ($x eq '--disk-usage') { } 1 8 9
elsif ($x =~ /\A--vacuum-(size|time|files)=(.+)\z/) { } 0 8 8
elsif ($x =~ /\A-(?:x|-no-pager|-no-hostname|-quiet|q|-catalog|a|-all|-merge|m|-system|-utc|-no-full|l|-full)\z/) { } 7 1 8
elsif ($x =~ /\A(?:-F|--field|--facility|--cursor|--after-cursor|--cursor-file|-D|--directory|--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
40050
shift @a // ""
l!l
400
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
7923 0 elsif ( $x =~ /\A--unit=(.+)\z/ ) { push @units, _unit($1) }
7924 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
17033
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
7925 0 elsif ( $x =~ /\A(?:-n|--lines=)(\d+)\z/ ) { $n = $1 }
7926 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
0033
$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
7927 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
1032
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
7928 0 elsif ( $x =~ /\A--grep=(.+)\z/ ) { $grep = $1 }
7929 8 elsif ( $x =~ /\A(?:-S|--since)(?:=.*)?\z/ ) { $since = $val->($x) }
7930 0 elsif ( $x =~ /\A(?:-U|--until)(?:=.*)?\z/ ) { $until = $val->($x) }
7931 1 elsif ( $x =~ /\A(?:-o|--output)(?:=.*)?\z/ ) { $out = $val->($x) }
7932 0 elsif ( $x =~ /\A--file(?:=.*)?\z/ ) { $file = $val->($x) }
7933 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
0023
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
7934 2 elsif ( $x eq '--list-boots' ) { $boots = 1 }
7935 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
1119
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
7936 0 ▶ elsif ( $x eq '-p' || $x eq '--priority' ) { shift @a } # Prioritaeten nicht nachgebildet: alles
Condition33%1/3
$x eq "-p" or $x eq "--priority"
l!l&&r!l&&!r
0019
MC/DC0%0/2
$x eq "-p" or $x eq "--priority"
$x eq "-p" $x eq "--priority"
Truth table33%1/3
A or B
A= $x eq "-p"B= $x eq "--priority"
ABresult
1X1
011
000
7937 1 ▶ elsif ( $x =~ /\A(?:-t|--identifier)(?:=.*)?\z/ ) { push @ident, [ SYSLOG_IDENTIFIER => $val->($x) // '' ] }
Condition50%1/2
&$val($x) // ""
l!l
10
MC/DC0%0/1
&$val($x) // ""
&$val($x)
Truth table50%1/2
A
A= &$val($x)
Aresult
11
00
7938 1 elsif ( $x =~ /\A_SYSTEMD_UNIT=(.+)\z/ ) { push @units, _unit($1) }
7939 3 elsif ( $x =~ /\A(_COMM|SYSLOG_IDENTIFIER)=(.*)\z/ ) { push @ident, [ $1, $2 ] }
7940 2 elsif ( $x eq '--header' ) { $header = 1 }
7941 elsif ( $x =~ /\A-(?:b|-boot)\z/ ) { # nachgebildet ist nur der laufende Start (--list-boots: einer)
7942 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
7943 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
7944 }
7945 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
0010
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
7946 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
7947 0 elsif ( $x =~ /\A--(?:rotate|sync|relinquish-var)\z/ ) { return ( '', 1 ) }
7948 elsif ( $x eq '--verify' ) {
7949 0 return ( join( "\n", map {"PASS: $_"} grep {/\.journal~?\z/} _under( $dev, '/var/log/journal' ), _under( $dev, '/run/log/journal' ) ), 1 );
7950 }
7951 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
7952 elsif ( $x eq '--disk-usage' ) {
7953 1 my $t = 0;
7954 1 $t += _file_size( _file_entry( $dev, $_ ) ) for _under( $dev, '/var/log/journal' ), _under( $dev, '/run/log/journal' );
7955 1 return ( 'Archived and active journals take up ' . _human($t) . ' in the file system.', 1 );
7956 }
7957 elsif ( $x =~ /\A--vacuum-(size|time|files)=(.+)\z/ ) {
7958 0 my ( $kind, $v ) = ( $1, $2 );
7959 0 my $freed;
7960 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
7961 elsif ( $kind eq 'time' ) {
7962 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
7963 0 $freed = _journal_vacuum( $dev, age => $age );
7964 }
7965 0 else { push @GAPS, "journalctl --vacuum-files=$v"; return ( '', 0 ) }
7966 0 return ( 'Vacuuming done, freed ' . _human($freed) . ' of archived journals from /var/log/journal.', 1 );
7967 }
7968 elsif ( $x =~ /\A-(?:x|-no-pager|-no-hostname|-quiet|q|-catalog|a|-all|-merge|m|-system|-utc|-no-full|l|-full)\z/ ) { }
7969 elsif ( $x =~ /\A(?:-F|--field|--facility|--cursor|--after-cursor|--cursor-file|-D|--directory|--namespace|-M|--machine|--output-fields|--show-cursor|--user|--user-unit|-I|-N|--fields)(?:=.*)?\z/ ) {
7970 0 push @GAPS, join( ' ', 'journalctl', @$av ); # echte Optionen ohne Nachbildung
7971 0 return ( '', 0 );
7972 }
7973 1 elsif ( $x =~ /\A--/ ) { ( my $o = $x ) =~ s/=.*//s; return ( "journalctl: unrecognized option '$o'", 0 ) }
7974 0 elsif ( $x =~ /\A-(.)/ ) { return ( "journalctl: invalid option -- '$1'", 0 ) }
7975 0 else { push @GAPS, join( ' ', 'journalctl', @$av ); return ( '', 0 ) } # Treffer wie _SYSTEMD_UNIT=…
7976 }
7977 55 ▶ return ( '-- No entries --', 1 ) if $kernel;
Branch: 1 branch
BranchTrueFalseTotal
if $kernel 2 53 55
7978 53 ▶ return _journal_header( $dev, $host ) if $header;
Branch: 1 branch
BranchTrueFalseTotal
if $header 2 51 53
7979 # Zeilen mit Zeitpunkt: [ epoche, text ]
7980 51 my @l;
7981 51 ▶ if ( defined $file ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $file) { } 0 51 51
elsif (@units) { } 41 10 51
7982 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
7983 0 @l = grep { $_->[2] eq $file } _journal_file_lines( $dev, $host );
7984 }
7985 elsif (@units) {
7986 41 for my $u (@units) {
7987 41 ▶ my $svc = ( $dev->{services} || {} )->{$u} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $svc = ($$dev{"services"} || {})->{$u} or next 41 0 41
Condition50%1/2
$$dev{'services'} || {}
l!l
410
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
7988 41 push @l, map { [ _jtime($_), $_ ] } _journal_lines( $dev, $u, $svc, $host );
7989 }
7990 }
7991 else {
7992 10 ▶ @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
100
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
7993 _journal_file_lines( $dev, $host ) );
7994 }
7995 # _COMM= (Prozessname, vom Kernel auf 15 Zeichen gekuerzt), SYSLOG_IDENTIFIER=/-t: der Name vor [pid]:
7996 51 ▶ if (@ident) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ident) 4 47 51
7997 @l = grep {
7998 4 my ($id) = $_->[1] =~ /\A\w{3}\s+\d+ \d\d:\d\d:\d\d \S+ ([^\s\[:]+)(?:\[\d+\])?:/;
7999 12 ▶ defined $id && grep { $_->[1] eq ( $_->[0] eq '_COMM' ? substr( $id, 0, 15 ) : $id ) } @ident
Branch: 1 branch
BranchTrueFalseTotal
$$_[0] eq '_COMM' ? : 6 6 12
Condition66%2/3
defined $id && grep({$$_[1] eq ($$_[0] eq '_COMM' ? substr($id, 0, 15) : $id);} @ident)
!ll&&!rl&&r
066
MC/DC50%1/2
defined $id && grep({$$_[1] eq ($$_[0] eq '_COMM' ? substr($id, 0, 15) : $id);} @ident)
defined $id grep({$$_[1] eq ($$_[0] eq '_COMM' ? substr($id, 0, 15) : $id);} @ident)
Truth table66%2/3
A && B
A= defined $idB= grep({$$_[1] eq ($$_[0] eq '_COMM' ? substr($id, 0, 15) : $id);} @ident)
ABresult
0X0
100
111
8000 } @l;
8001 }
8002 51 @l = sort { $a->[0] <=> $b->[0] } @l;
8003 51 ▶ if ($boots) {
Branch: 1 branch
BranchTrueFalseTotal
if ($boots) 2 49 51
8004 3 my @all = sort { $a->[0] <=> $b->[0] } ( _journal_file_lines( $dev, $host ),
8005 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
8006 2 ▶ return ( 'No boots found.', 0 ) unless @all;
Branch: 1 branch
BranchTrueFalseTotal
unless @all 0 2 2
8007 2 my $f = Langertha::Holmgang::Sim::Linux::Calendar::format_local( $all[0][0] );
8008 2 my $t = Langertha::Holmgang::Sim::Linux::Calendar::format_local( _dev_now($dev) );
8009 2 return ( " 0 7f3e9c2b5a1d4e8f9b0c6a2d4e8f1a3c $f\x{2014}$t", 1 );
8010 }
8011 49 for my $b ( [ $since, 1 ], [ $until, 0 ] ) {
8012 97 ▶ next unless defined $b->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$b[0] 89 8 97
8013 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
8014 7 ▶ @l = grep { $b->[1] ? $_->[0] >= $t : $_->[0] <= $t } @l;
Branch: 1 branch
BranchTrueFalseTotal
$$b[1] ? : 9 0 9
8015 }
8016 48 my @txt = map { $_->[1] } @l;
8017 48 ▶ if ( defined $grep ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grep) 1 47 48
8018 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
8019 0 @txt = grep { $_ =~ $re } @txt;
8020 }
8021 48 ▶ @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 32 48
@txt > $n ? : 11 5 16
Condition66%2/3
defined $n and $n =~ /\A\d+\z/
!ll&&!rl&&r
32016
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
8022 48 ▶ @txt = reverse @txt if $reverse;
Branch: 1 branch
BranchTrueFalseTotal
if $reverse 0 48 48
8023 48 ▶ if ( defined $out ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $out) 1 47 48
8024 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
8025 @txt = map {
8026 1 my $l = $_;
8027 1 my $t = _jtime($l);
8028 1 my $off = Langertha::Holmgang::Sim::Linux::Calendar::offset($t);
8029 1 my @g = gmtime( $t + $off );
8030 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;
8031 1 $l
8032 } @txt;
8033 }
8034 0 elsif ( $out eq 'cat' ) { s/\A\w{3}\s+\d+ \d\d:\d\d:\d\d \S+ [^:]+: // for @txt }
8035 0 elsif ( $out !~ /\A(?:short|short-full|short-precise|with-unit)\z/ ) { push @GAPS, "journalctl -o $out"; return ( '', 0 ) }
8036 }
8037 48 ▶ return ( '-- No entries --', 1 ) unless @txt;
Branch: 1 branch
BranchTrueFalseTotal
unless @txt 5 43 48
8038 43 return ( join( "\n", @txt ), 1 );
8039 }
8040  
8041 # "Oct 20 14:00:01 host …" -> Epoche (Ortszeit, Jahr 2026)
8042 270 ▶sub _jtime {
Subroutine _jtime: called CC=4 SCAR=14.9
8043 270 my ($l) = @_;
8044 270 ▶ 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() 270 0 270
Condition50%1/2
$l // ""
l!l
2700
MC/DC0%0/1
$l // ""
$l
Truth table50%1/2
A
A= $l
Aresult
11
00
8045 270 ▶ my $lt = Time::Local::timegm( $s, $mi, $h, $d, $MON{$mon} // 9, 2026 );
Condition50%1/2
$MON{$mon} // 9
l!l
2700
MC/DC0%0/1
$MON{$mon} // 9
$MON{$mon}
Truth table50%1/2
A
A= $MON{$mon}
Aresult
11
00
8046 270 return $lt - Langertha::Holmgang::Sim::Linux::Calendar::offset( $lt - 3600 );
8047 }
8048  
8049 # --since/--until: 2026-10-01[ 12:00[:00]], 06:00[:00] (heute), today, yesterday, now, -2d,
8050 # "2 days ago", "1 hour ago"; $now: die Uhr des Geraets (Vorgabe: die der Simulation)
8051 9 ▶sub _parse_since {
Subroutine _parse_since: called CC=16 SCAR=28.8
8052 9 my ( $v, $now ) = @_;
8053 9 require Time::Local;
8054 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
8055 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
8056 9 my @g = gmtime( $now + Langertha::Holmgang::Sim::Linux::Calendar::offset($now) );
8057 9 ▶ return $now if $v eq 'now';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "now" 0 9 9
8058 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
8059 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
8060 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
8061 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
8062 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
8063 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
8064 1 return undef;
8065 }
8066  
8067 # Je Journal-Datei eine unauffaellige Zeile zu ihrer Zeit (damit das Journal so weit
8068 # zurueckreicht wie seine Dateien): [ epoche, text, datei ]
8069 14 ▶sub _journal_file_lines {
Subroutine _journal_file_lines: called CC=6 SCAR=18.2
8070 14 my ( $dev, $host ) = @_;
8071 14 ▶ $host //= $dev->{hostname} // 'localhost';
Condition25%1/4
$host //= $$dev{"hostname"} // "localhost"
l!l
140
$$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
8072 14 my @msg = ( 'CRON[%d]: pam_unix(cron:session): session closed for user root', 'systemd[1]: Starting systemd-tmpfiles-clean.service - Cleanup of Temporary Directories...',
8073 'systemd[1]: logrotate.service: Deactivated successfully.', 'sshd[%d]: Received disconnect from 10.0.0.5 port 52114:11: disconnected by user' );
8074 14 my @r;
8075 14 my $i = 0;
8076 14 for my $p ( grep {/\.journal~?\z/} _under( $dev, '/var/log/journal' ), _under( $dev, '/run/log/journal' ) ) {
8077 12 my $fe = _file_entry( $dev, $p );
8078 12 ▶ 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'} ? : 1 11 12
8079 12 my @g = gmtime $lt;
8080 12 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];
8081 12 my $m = $msg[ $i++ % @msg ];
8082 12 ▶ $m = sprintf $m, 1000 + 37 * $i if $m =~ /%d/;
Branch: 1 branch
BranchTrueFalseTotal
if $m =~ /%d/ 12 0 12
8083 12 push @r, [ $lt - Langertha::Holmgang::Sim::Linux::Calendar::offset( $lt - 3600 ), "$stamp $host $m", $p ];
8084 }
8085 14 return @r;
8086 }
8087  
8088 # Was journald beim Start ueber seine Dateien meldet: "Runtime Journal (/run/log/journal/ID) is
8089 # 24.0M, max 195.2M, 171.2M free." bzw. "System Journal (/var/log/journal/ID) …" — Groesse aus den
8090 # Dateien, max aus SystemMaxUse=/RuntimeMaxUse= oder der Vorgabe (10 % des Dateisystems, hoechstens 4G)
8091 8 ▶sub _journald_msgs {
Subroutine _journald_msgs: called CC=18 SCAR=30.2
8092 8 my ($dev) = @_;
8093 8 ▶ my $svc = ( $dev->{services} || {} )->{'systemd-journald'} || {};
Condition50%2/4
($$dev{'services'} || {})->{'systemd-journald'} || {}
l!l
80
$$dev{'services'} || {}
l!l
80
MC/DC0%0/1
($$dev{'services'} || {})->{'systemd-journald'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
8094 8 ▶ 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
80
$$svc{"running"} // _file_text($dev, "/etc/systemd/journald.conf")
l!l&&r!l&&!r
800
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
8095 8 ▶ $t = '' if ref $t;
Branch: 1 branch
BranchTrueFalseTotal
if ref $t 0 8 8
8096 0 ▶ my $fmt = sub { my $b = shift; for my $u (qw( G M K )) { return sprintf '%.1f%s', $b / $UNIT{$u}, $u if $b >= $UNIT{$u} } return "${b}B" };
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
if $b >= $UNIT{$u} 18 11 29
8097 8 my @m;
8098 8 for my $k ( [ 'System', '/var/log/journal', 'SystemMaxUse' ], [ 'Runtime', '/run/log/journal', 'RuntimeMaxUse' ] ) {
8099 16 my @f = grep { m{\A\Q$k->[1]\E/[0-9a-f]{32}/[^/]+\.journal~?\z} } _under( $dev, $k->[1] );
8100 16 ▶ next unless @f;
Branch: 1 branch
BranchTrueFalseTotal
unless @f 10 6 16
8101 6 my ($id) = $f[0] =~ m{/([0-9a-f]{32})/};
8102 6 my $size = 0;
8103 6 $size += _file_size( _file_entry( $dev, $_ ) ) for @f;
8104 6 my ($max) = $t =~ /^\s*$k->[2]\s*=\s*(\S+)\s*$/m;
8105 6 ▶ my $mb = defined $max ? _bytes($max) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $max ? : 1 5 6
8106 6 ▶ if ( !defined $mb && $k->[0] eq 'System' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $mb and $$k[0] eq "System") 3 3 6
Condition100%3/3
not defined $mb and $$k[0] eq "System"
!ll&&!rl&&r
123
MC/DC100%2/2
not defined $mb and $$k[0] eq "System"
not defined $mb $$k[0] eq "System"
Truth table100%3/3
not(A) and B
A= not defined $mbB= $$k[0] eq "System"
ABresult
0X0
100
111
8107 3 ▶ my $fs = ( ( $dev->{mounts} || {} )->{'/'} || {} )->{size};
Condition50%2/4
($$dev{'mounts'} || {})->{'/'} || {}
l!l
03
$$dev{'mounts'} || {}
l!l
03
MC/DC0%0/1
($$dev{'mounts'} || {})->{'/'} || {}
$$dev{'mounts'}
Truth table50%1/2
A
A= $$dev{'mounts'}
Aresult
11
00
8108 3 ▶ $mb = defined $fs ? _bytes($fs) / 10 : 4 * $UNIT{G};
Branch: 1 branch
BranchTrueFalseTotal
defined $fs ? : 0 3 3
8109 3 ▶ $mb = 4 * $UNIT{G} if $mb > 4 * $UNIT{G};
Branch: 1 branch
BranchTrueFalseTotal
if $mb > 4 * $UNIT{"G"} 0 3 3
8110 }
8111 6 ▶ $mb //= 195.2 * $UNIT{M};
Condition100%2/2
$mb //= "195.2" * $UNIT{"M"}
l!l
42
MC/DC100%1/1
$mb //= "195.2" * $UNIT{"M"}
$mb
Truth table100%2/2
A
A= $mb
Aresult
11
00
8112 6 ▶ push @m, "$k->[0] Journal ($k->[1]/$id) is " . $fmt->($size) . ', max ' . $fmt->($mb) . ', ' . $fmt->( $mb > $size ? $mb - $size : 0 ) . ' free.';
Branch: 1 branch
BranchTrueFalseTotal
$mb > $size ? : 6 0 6
8113 }
8114 8 return @m;
8115 }
8116  
8117 # Die Meldungen von journald beim Start des Systems (einmal festgehalten, unter _boot)
8118 17 ▶sub _journald_boot {
Subroutine _journald_boot: called CC=6 SCAR=19.4
8119 17 my ( $dev, $svc, $host ) = @_;
8120 17 ▶ return if !$svc || $svc->{journal} || $svc->{_boot};
Branch: 1 branch
BranchTrueFalseTotal
if not $svc or $$svc{"journal"} or $$svc{"_boot"} 13 4 17
Condition50%3/6
not $svc or $$svc{"journal"} or $$svc{"_boot"}
l!l&&r!l&&!r
0134
not $svc or $$svc{"journal"}
l!l&&r!l&&!r
0017
MC/DC33%1/3
not $svc or $$svc{"journal"} or $$svc{"_boot"}
not $svc $$svc{"journal"} $$svc{"_boot"}
Truth table50%2/4
not(A) or B or C
A= not $svcB= $$svc{"journal"}C= $$svc{"_boot"}
ABCresult
1XX1
01X1
0011
0000
8121 4 ▶ $host //= $dev->{hostname} // 'localhost';
Condition25%1/4
$host //= $$dev{"hostname"} // "localhost"
l!l
40
$$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
8122 4 require POSIX;
8123 4 my $st = POSIX::strftime( '%b %e %H:%M:%S', _local_tm( _boot_epoch($dev) ) ); # der laufende Start (wie uptime, last)
8124 4 $svc->{_boot} = [ map {"$st $host systemd-journald[231]: $_"} 'Journal started', _journald_msgs($dev) ];
8125 4 return;
8126 }
8127  
8128 # journalctl --header: der Kopf jeder Journaldatei (die Felder, die eine Fachkraft liest: Pfad,
8129 # Zustand, Zeitraum, Groesse); IDs aus dem Pfad abgeleitet
8130 2 ▶sub _journal_header {
Subroutine _journal_header: called CC=8 SCAR=21.6
8131 2 my ( $dev, $host ) = @_;
8132 2 require Digest::MD5;
8133 2 my %t = map { $_->[2] => $_->[0] } _journal_file_lines( $dev, $host );
8134 2 my @out;
8135 2 for my $p ( grep {/\.journal~?\z/} _under( $dev, '/var/log/journal' ), _under( $dev, '/run/log/journal' ) ) {
8136 2 my ($mid) = $p =~ m{/([0-9a-f]{32})/};
8137 2 my $h = Digest::MD5::md5_hex($p);
8138 2 my $size = _file_size( _file_entry( $dev, $p ) );
8139 2 ▶ my $from = Langertha::Holmgang::Sim::Linux::Calendar::format_local( $p =~ m{\A/run/} ? _boot_epoch($dev) : $t{$p} // _dev_now($dev) );
Branch: 1 branch
BranchTrueFalseTotal
$p =~ m[\A/run/] ? : 1 1 2
Condition33%1/3
$t{$p} // _dev_now($dev)
l!l&&r!l&&!r
100
MC/DC0%0/2
$t{$p} // _dev_now($dev)
$t{$p} _dev_now($dev)
Truth table33%1/3
A // B
A= $t{$p}B= _dev_now($dev)
ABresult
1X1
011
000
8140 2 my $to = Langertha::Holmgang::Sim::Linux::Calendar::format_local( _dev_now($dev) );
8141 2 ▶ push @out, join( "\n", "File path: $p", 'File ID: ' . substr( $h, 0, 32 ), 'Machine ID: ' . ( $mid // '' ),
Branch: 2 branches
BranchTrueFalseTotal
$p =~ /~\z/ ? : 0 2 2
$size > 256 ? : 2 0 2
Condition50%1/2
$mid // ""
l!l
20
MC/DC0%0/1
$mid // ""
$mid
Truth table50%1/2
A
A= $mid
Aresult
11
00
8142 'Boot ID: 7f3e9c2b5a1d4e8f9b0c6a2d4e8f1a3c', 'Sequential number ID: ' . substr( Digest::MD5::md5_hex("seq$p"), 0, 32 ),
8143 'State: ' . ( $p =~ /~\z/ ? 'OFFLINE' : 'ONLINE' ), 'Compatible flags: TAIL_ENTRY_BOOT_ID', 'Incompatible flags: COMPRESSED-ZSTD KEYED-HASH',
8144 'Header size: 256', 'Arena size: ' . ( $size > 256 ? $size - 256 : 0 ), 'Rotate suggested: no',
8145 "Head realtime timestamp: $from", "Tail realtime timestamp: $to", 'Disk usage: ' . _human($size) );
8146 }
8147 2 ▶ return ( 'No journal files were found.', 0 ) unless @out;
Branch: 1 branch
BranchTrueFalseTotal
unless @out 0 2 2
8148 2 return ( join( "\n\n", @out ), 1 );
8149 }
8150  
8151 # Speichert journald dauerhaft? (Storage=persistent, oder auto mit /var/log/journal)
8152 1 ▶sub _journal_persistent {
Subroutine _journal_persistent: called CC=9 SCAR=26.5
8153 1 my ($dev) = @_;
8154 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
8155 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
8156 1 my ($st) = $t =~ /^\s*Storage\s*=\s*(\S+)\s*$/m;
8157 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
8158 1 ▶ return 1 if $st eq 'persistent';
Branch: 1 branch
BranchTrueFalseTotal
if $st eq "persistent" 0 1 1
8159 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
8160 }
8161  
8162 # Laufzeit-Journal (/run/log/journal/<id>) nach /var/log/journal/<id> uebernehmen
8163 5 ▶sub _journal_flush {
Subroutine _journal_flush: called CC=11 SCAR=24.2
8164 5 my ($dev) = @_;
8165 5 my @run = grep {/\.journal\z/} _under( $dev, '/run/log/journal' );
8166 5 ▶ 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})/] ? : 3 0 3
8167 5 ▶ ($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 3 5
m[\A/var/log/journal/([0-9a-f]{32})/] ? : 0 2 2
8168 5 ▶ $id //= '3b1f5c7e9a2d4c6e8f0a1b3d5e7f9a1c';
Condition100%2/2
$id //= "3b1f5c7e9a2d4c6e8f0a1b3d5e7f9a1c"
l!l
32
MC/DC100%1/1
$id //= "3b1f5c7e9a2d4c6e8f0a1b3d5e7f9a1c"
$id
Truth table100%2/2
A
A= $id
Aresult
11
00
8169 5 ▶ $dev->{dirs}{'/var/log/journal'} //= {} unless _is_dir( $dev, '/var/log/journal' );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_dir($dev, "/var/log/journal") 3 2 5
Condition50%1/2
$$dev{"dirs"}{"/var/log/journal"} //= {}
l!l
03
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
8170 5 my $dst = "/var/log/journal/$id/system.journal";
8171 5 ▶ if ( !_file_entry( $dev, $dst ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_file_entry($dev, $dst)) 5 0 5
8172 5 my $size = 0;
8173 5 $size += _file_size( _file_entry( $dev, $_ ) ) for @run;
8174 5 ▶ $dev->{files}{$dst} = { size => _human( $size || 8 * 1024 * 1024 ), owner => 'root', group => 'systemd-journal', mode => '0640',
Condition100%2/2
$size || 8388608
l!l
32
MC/DC100%1/1
$size || 8388608
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
8175 content => '', open_by => 'systemd-journald', mtime => 'Oct 20 14:00' };
8176 }
8177 5 delete $dev->{files}{$_} for @run;
8178 5 return;
8179 }
8180  
8181 42 ▶sub _unit_changed {
Subroutine _unit_changed: called CC=4 SCAR=13.9
8182 42 my ( $dev, $n, $svc ) = @_;
8183 42 ▶ return 0 unless defined $svc->{unit_loaded};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$svc{"unit_loaded"} 30 12 42
8184 12 my $now = _unit_text( $dev, $n, $svc );
8185 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
8186 }
8187  
8188 # Naechster Ablauf eines Timers (Epoche) oder undef
8189 7 ▶sub _timer_next {
Subroutine _timer_next: called CC=1 SCAR=0.0
8190 7 my ( $dev, $n, $svc ) = @_;
8191 7 my $i = _timer_info( $dev, $n, $svc );
8192 0 my ($t) = sort { $a <=> $b } grep {defined} map { Langertha::Holmgang::Sim::Linux::Calendar::next_elapse( $_, _sim_now() ) } @{ $i->{cal} };
8193 7 return $t;
8194 }
8195  
8196 # "Tue 2026-10-20 02:00:04 CEST" -> Epoche
8197 151 ▶sub _parse_stamp {
Subroutine _parse_stamp: called CC=3 SCAR=11.0
8198 151 my ($s) = @_;
8199 151 ▶ 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 98 53 151
Condition100%2/2
$s // ""
l!l
9853
MC/DC100%1/1
$s // ""
$s
Truth table100%2/2
A
A= $s
Aresult
11
00
8200 98 require Time::Local;
8201 98 return Time::Local::timegm( $se, $mi, $h, $d, $m - 1, $y ) - { CEST => 7200, CET => 3600, UTC => 0 }->{$tz};
8202 }
8203  
8204 10 ▶sub _systemctl_status {
Subroutine _systemctl_status: called CC=32 SCAR=36.5
8205 10 my ( $dev, $n, $svc, $host ) = @_;
8206 10 my $u = _uname($n);
8207 10 my $uf = _unit_file( $n, $svc );
8208 10 my $timer = $n =~ /\.timer\z/;
8209 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
8210 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
8211 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
8212 my $act = $svc->{active} ? ( $timer ? 'active (waiting)' : 'active (running)' ) . ' since '
8213 . Langertha::Holmgang::Sim::Linux::Calendar::format_local($since) . '; ' . _ago( $dev, $since )
8214 : $svc->{failed} ? "failed (Result: exit-code) since Tue 2026-10-20 09:12:03 CEST; 4h 47min ago"
8215 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
8216 : 'inactive (dead)';
8217 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
8218 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
8219 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
8220 : $bad ? " Loaded: bad-setting (Reason: Unit $u has a bad unit file setting.)"
8221 : " Loaded: loaded ($uf; $en; preset: enabled)" );
8222 10 my @d = _dropins( $dev, $n );
8223 10 ▶ if (@d) {
Branch: 1 branch
BranchTrueFalseTotal
if (@d) 3 7 10
8224 3 my %dir;
8225 3 for (@d) { my ( $dd, $f ) = m{\A(.*)/([^/]+)\z}; push @{ $dir{$dd} }, $f }
8226 3 my $first = 1;
8227 3 for my $dd ( sort keys %dir ) {
8228 3 ▶ push @l, ( $first ? ' Drop-In: ' : ' ' ) . $dd, ' └─' . join( ', ', @{ $dir{$dd} } );
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 3 0 3
8229 3 $first = 0;
8230 }
8231 }
8232 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
8233 if _unit_changed( $dev, $n, $svc );
8234 10 push @l, " Active: $act";
8235 10 ▶ if ($timer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timer) 1 9 10
8236 1 ▶ my $next = $svc->{active} ? _timer_next( $dev, $n, $svc ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$svc{'active'} ? : 1 0 1
8237 1 ▶ push @l, ' Trigger: ' . ( defined $next ? Langertha::Holmgang::Sim::Linux::Calendar::format_local($next) . '; '
Branch: 1 branch
BranchTrueFalseTotal
defined $next ? : 1 0 1
8238 . Langertha::Holmgang::Sim::Linux::Calendar::left( $next - _sim_now() ) . ' left' : 'n/a' );
8239 1 push @l, ' Triggers: ● ' . _timer_info( $dev, $n, $svc )->{activates};
8240 }
8241 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
8242 10 my @j = _journal_lines( $dev, $n, $svc, $host );
8243 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
8244 10 return @l;
8245 }
8246  
8247 # Ein Dienst oeffnet seine Logdateien neu (Neustart, reload): schrieb er nach einer
8248 # Rotation noch in die umbenannte Datei (opened_as), schreibt er jetzt wieder in die
8249 # Originaldatei; fehlt sie, legt er sie an.
8250 102 ▶sub _reopen_logs {
Subroutine _reopen_logs: called CC=11 SCAR=27.1
8251 102 my ( $dev, $n ) = @_;
8252 102 ▶ my $files = $dev->{files} || {};
Condition100%2/2
$$dev{'files'} || {}
l!l
993
MC/DC100%1/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table100%2/2
A
A= $$dev{'files'}
Aresult
11
00
8253 102 ▶ 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
56574
ref $$files{$_} eq "HASH" and ($$files{$_}{"open_by"} // "") eq $n
!ll&&!rl&&r
39616911
$$files{$_}{"open_by"} // ""
l!l
42138
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
8254 4 my $e = $files->{$p};
8255 4 my $orig = delete $e->{opened_as};
8256 4 delete $e->{open_by};
8257 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
8258 elsif ( !exists $files->{$orig} ) {
8259 $files->{$orig} = { content => '', size => '0', mode => $e->{mode} // '0644', owner => $e->{owner} // 'root',
8260 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
8261 }
8262 }
8263 102 return;
8264 }
8265  
8266 # systemctl list-timers [--all]
8267 2 ▶sub _list_timers {
Subroutine _list_timers: called CC=20 SCAR=32.2
8268 2 my ( $dev, $all, $pat ) = @_; # $pat: Muster hinter dem Verb (export*)
8269 2 require Langertha::Holmgang::Sim::Linux::Calendar;
8270 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
8271 2 my @rows;
8272 2 for my $n ( sort grep {/\.timer\z/} keys %$svcs ) {
8273 3 my $svc = $svcs->{$n};
8274 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
8275 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
8276 3 ▶ my $next = $svc->{active} ? _timer_next( $dev, $n, $svc ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$svc{'active'} ? : 3 0 3
8277 3 my $last = _parse_stamp( $svc->{last} );
8278 push @rows, [ $next // 9e12,
8279 defined $next ? Langertha::Holmgang::Sim::Linux::Calendar::format_local($next) : '-',
8280 defined $next ? Langertha::Holmgang::Sim::Linux::Calendar::left( $next - _sim_now() ) . ' left' : '-',
8281 defined $last ? $svc->{last} : '-',
8282 defined $last ? Langertha::Holmgang::Sim::Linux::Calendar::left( _sim_now() - $last ) . ' ago' : '-',
8283 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
8284 }
8285 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
8286 2 my @w = ( 0, 4, 4, 4, 6, 4, 9 );
8287 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
8288 2 my $fmt = join( ' ', map {"%-$w[$_]s"} 1 .. 6 );
8289 2 my @l = ( sprintf( $fmt, qw( NEXT LEFT LAST PASSED UNIT ACTIVATES ) ) =~ s/\s+\z//r );
8290 2 push @l, sprintf( $fmt, @{$_}[ 1 .. 6 ] ) =~ s/\s+\z//r for @rows;
8291 2 push @l, '', scalar(@rows) . ' timers listed.';
8292 2 ▶ push @l, 'Pass --all to see loaded but inactive timers, too.' unless $all;
Branch: 1 branch
BranchTrueFalseTotal
unless $all 2 0 2
8293 2 return join "\n", @l;
8294 }
8295  
8296 # Zeitspanne wie systemd (format_timespan): 1800 -> "30min", 90 -> "1min 30s"
8297 6 ▶sub _timespan {
Subroutine _timespan: called CC=4 SCAR=13.9
8298 6 my ($s) = @_;
8299 6 ▶ return '0' unless $s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s 3 3 6
8300 3 my @p;
8301 3 for my $u ( [ 'w', 604800 ], [ 'd', 86400 ], [ 'h', 3600 ], [ 'min', 60 ], [ 's', 1 ] ) {
8302 15 ▶ next if $s < $u->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $s < $$u[1] 12 3 15
8303 3 my $n = int( $s / $u->[1] );
8304 3 $s -= $n * $u->[1];
8305 3 push @p, "$n$u->[0]";
8306 }
8307 3 return join ' ', @p;
8308 }
8309  
8310 # ExecStart=… -> Form von systemctl show
8311 9 ▶sub _exec_prop {
Subroutine _exec_prop: called CC=1 SCAR=0.0
8312 9 my ($cmd) = @_;
8313 9 $cmd =~ s/\A[-\@:+!]+//;
8314 9 my ($path) = split /\s+/, $cmd;
8315 9 return "{ path=$path ; argv[]=$cmd ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }";
8316 }
8317  
8318 # systemctl show UNIT… [-p A,B | --property=A,B]… [--value]
8319 35 ▶sub _systemctl_show {
Subroutine _systemctl_show: called CC=71 SCAR=45.3
8320 35 my ( $dev, $av ) = @_;
8321 35 require Langertha::Holmgang::Sim::Linux::Calendar;
8322 35 my ( @want, @units, $value );
8323 35 my @a = @$av;
8324 35 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 134 35 169
8325 134 my $x = shift @a;
8326 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
8327 0 elsif ( $x =~ /\A--property=(.*)\z/ ) { push @want, split /,/, $1 }
8328 0 elsif ( $x =~ /\A-p(.+)\z/ ) { push @want, split /,/, $1 }
8329 29 elsif ( $x eq '--value' ) { $value = 1 }
8330 ▶ 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
8331 35 else { push @units, _unit($x) }
8332 }
8333 35 ▶ return ( 'Too few arguments.', 0 ) unless @units; # ohne Unit: Eigenschaften des Managers (nicht nachgebildet)
Branch: 1 branch
BranchTrueFalseTotal
unless @units 0 35 35
8334 35 my @blocks;
8335 35 for my $n (@units) {
8336 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
8337 35 my $u = _uname($n);
8338 35 my %p = ( Id => $u, Names => $u );
8339 35 ▶ if ( !$svc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $svc) { } 1 34 35
8340 1 %p = ( %p, LoadState => 'not-found', ActiveState => 'inactive', SubState => 'dead', UnitFileState => '', Description => $u );
8341 }
8342 else {
8343 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
8344 34 my $timer = $n =~ /\.timer\z/;
8345 34 ▶ my $i = $timer ? _timer_info( $dev, $n, $svc ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$timer ? : 3 31 34
8346 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
8347 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
8348 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
8349 34 ▶ $p{ActiveState} = $svc->{active} ? 'active' : $svc->{failed} ? 'failed' : 'inactive';
Branch: 2 branches
BranchTrueFalseTotal
$$svc{'active'} ? : 31 3 34
$$svc{'failed'} ? : 0 3 3
8350 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
8351 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
8352 34 $p{FragmentPath} = _unit_file( $n, $svc );
8353 34 ▶ if ($timer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timer) { } 3 31 34
8354 3 ▶ my $next = $svc->{active} ? _timer_next( $dev, $n, $svc ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$svc{'active'} ? : 3 0 3
8355 $p{TimersCalendar} = join "\n", map {
8356 3 my $ne = Langertha::Holmgang::Sim::Linux::Calendar::next_elapse( $_, _sim_now() );
8357 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
8358 3 } @{ $i->{cal} };
8359 3 ▶ $p{NextElapseUSecRealtime} = defined $next ? Langertha::Holmgang::Sim::Linux::Calendar::format_local($next) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $next ? : 3 0 3
8360 3 ▶ $p{LastTriggerUSec} = defined _parse_stamp( $svc->{last} ) ? $svc->{last} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined _parse_stamp($$svc{'last'}) ? : 1 2 3
8361 3 ▶ $p{Persistent} = $i->{persistent} ? 'yes' : 'no';
Branch: 1 branch
BranchTrueFalseTotal
$$i{'persistent'} ? : 3 0 3
8362 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
8363 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
8364 3 $p{Unit} = $i->{activates};
8365 }
8366 else {
8367 # wirksame Werte der geladenen Fassung samt Drop-ins (letzte Zuweisung gilt)
8368 31 my $up = _unit_props($t);
8369 31 my %extra = %$up;
8370 31 delete @extra{qw( ExecStart ExecStartPre ExecStartPost ExecReload EnvironmentFile Environment )};
8371 31 %p = ( %extra, %p );
8372 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
8373 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
8374 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
8375 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
8376 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
8377 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
8378 31 ▶ $p{Environment} = $up->{Environment} ? join( ' ', map {"$_=$up->{Environment}{$_}"} sort keys %{ $up->{Environment} } ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$$up{'Environment'} ? : 2 29 31
8379 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
8380 31 ( $p{LimitNOFILE}, $p{LimitNOFILESoft} ) = ( '524288', '1024' );
8381 31 ▶ if ( defined( my $l = $up->{LimitNOFILE} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = $$up{"LimitNOFILE"})) 2 29 31
8382 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
8383 }
8384 31 $p{MainPID} = _main_pid( $dev, $n );
8385 31 $p{ExecMainPID} = $p{MainPID};
8386 # Startzeit des laufenden Prozesses; NRestarts zaehlt wie systemd nur
8387 # automatische Neustarts (Restart= nach einem Signal, _signal)
8388 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
8389 31 ▶ $p{ExecMainStartTimestamp} = $p{ActiveEnterTimestamp} = defined $st ? Langertha::Holmgang::Sim::Linux::Calendar::format_local($st) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $st ? : 29 2 31
8390 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
8391 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
8392 31 $p{DropInPaths} = join ' ', _dropins( $dev, $n );
8393 31 ▶ $p{NeedDaemonReload} = _unit_changed( $dev, $n, $svc ) ? 'yes' : 'no';
Branch: 1 branch
BranchTrueFalseTotal
_unit_changed($dev, $n, $svc) ? : 1 30 31
8394 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
8395 }
8396 }
8397 # Reihenfolge wie systemctl show (systemd 257); unbekannte Eigenschaften gibt es nicht aus
8398 35 my @order = qw( Unit TimersCalendar NextElapseUSecRealtime LastTriggerUSec AccuracyUSec RandomizedDelayUSec Persistent
8399 Type Restart NRestarts MainPID ExecMainStartTimestamp ExecMainPID ExecStart Environment EnvironmentFiles WorkingDirectory
8400 LimitNOFILE LimitNOFILESoft Id Names Description LoadState ActiveState SubState ActiveEnterTimestamp FragmentPath DropInPaths UnitFileState NeedDaemonReload CanReload User Group );
8401 35 my %known = map { $_ => 1 } @order;
8402 35 push @order, sort grep { !$known{$_} } keys %p;
8403 35 my %w = map { $_ => 1 } @want;
8404 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
8405 35 my @l;
8406 35 for my $k (@keys) {
8407 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
8408 54 ▶ @v = ('') unless @v;
Branch: 1 branch
BranchTrueFalseTotal
unless @v 1 53 54
8409 54 ▶ push @l, map { $value ? $_ : "$k=$_" } @v;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 30 24 54
8410 }
8411 35 push @blocks, join "\n", @l;
8412 }
8413 35 return ( join( "\n\n", @blocks ), 1 );
8414 }
8415  
8416 # --- Dienste ---------------------------------------------------------------------------
8417  
8418 269 ▶sub _unit { my ($n) = @_; $n =~ s/\.service\z//; return $n }
Subroutine _unit: called CC=1 SCAR=0.0
8419  
8420 108 ▶sub _restart_effect {
Subroutine _restart_effect: called CC=81 SCAR=58.9
8421 108 my ( $dev, $name, $verb ) = @_;
8422 108 my $svc = $dev->{services}{$name};
8423 108 ▶ 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 104 108
Condition66%2/3
$name =~ /\Awg-quick\@(wg\d+)\z/ and $verb ne "reload"
!ll&&!rl&&r
10404
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
8424 # start/restart wie die Unit: wg-quick down (falls oben), dann wg-quick up
8425 4 my $n = $1;
8426 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
8427 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
8428 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
8429 # von Hand hochgefahren: die Unit scheitert an der vorhandenen Schnittstelle
8430 0 ▶ $svc->{failed} = JSON::MaybeXS::true() if $svc;
Branch: 1 branch
BranchTrueFalseTotal
if $svc 0 0 0
8431 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
8432 0 die "Job for $name.service failed because the control process exited with error code.\n"
8433 . "See \"systemctl status $name.service\" and \"journalctl -xeu $name.service\" for details.\n";
8434 }
8435 4 my $copy = Langertha::Holmgang::Sim::Linux::clone_state($dev);
8436 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
8437 4 my $down = Langertha::Holmgang::Sim::Linux::clone_state($copy);
8438 4 ▶ if ( !eval { _wg_up( $copy, $n ); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { _wg_up($copy, $n); 1 } }) 1 3 4
8439 1 my $e = $@;
8440 1 %$dev = %$down;
8441 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
8442 1 ▶ $s->{active} = JSON::MaybeXS::false() if $s->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$s{"active"} 0 1 1
8443 1 $s->{failed} = JSON::MaybeXS::true();
8444 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
8445 1 die "Job for $name.service failed because the control process exited with error code.\n"
8446 . "See \"systemctl status $name.service\" and \"journalctl -xeu $name.service\" for details.\n";
8447 }
8448 3 my $s = $copy->{services}{$name};
8449 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
8450 3 %$dev = %$copy;
8451 3 return;
8452 }
8453 104 ▶ if ( $name =~ /\Awg-quick\@(wg\d+)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\Awg-quick\@(wg\d+)\z/) 0 104 104
8454 0 my $n = $1;
8455 0 my $t = _file_text( $dev, "/etc/wireguard/$n.conf" );
8456 0 ▶ if ( defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) 0 0 0
8457 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
8458 0 my $new = _wg_parse( $t, $old );
8459 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
8460 0 $new->{$_} = $old->{$_} for grep { exists $old->{$_} } qw( address mtu );
8461 0 ▶ delete $new->{mtu} unless exists $old->{mtu};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$old{"mtu"} 0 0 0
8462 0 ▶ delete $new->{address} unless exists $old->{address};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$old{"address"} 0 0 0
8463 }
8464 ▶ 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
8465 0 $dev->{interfaces}{$n}{mtu} = $new->{mtu};
8466 }
8467 0 $dev->{wg}{$n} = $new;
8468 }
8469 }
8470 104 ▶ 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 103 104
Condition66%4/6
$name eq "nftables" and ref $$dev{"files"} eq "HASH" and exists $$dev{"files"}{"/etc/nftables.conf"}
!ll&&!rl&&r
10301
$name eq "nftables" and ref $$dev{"files"} eq "HASH"
!ll&&!rl&&r
10301
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
8471 1 my ( $o, $ok ) = _nft_load( $dev, _file_text( $dev, '/etc/nftables.conf' ), '/etc/nftables.conf' );
8472 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
8473 }
8474 104 ▶ 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 95 104
Condition66%4/6
$name eq "ssh" || $name eq "sshd" and _sshd_sim()->can("active")->($dev)
!ll&&!rl&&r
9509
$name eq "ssh" or $name eq "sshd"
l!l&&r!l&&!r
9095
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
8475 9 ▶ _sshd_sim()->can('load')->( $dev, $name, $verb, $CTX ? $CTX->{host} : undef );
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 9 0 9
8476 7 _ssh_access()->can('loaded')->($dev); # was sshd jetzt geladen hat (Match, AuthorizedKeysFile …)
8477 }
8478 102 ▶ if ( $name eq 'systemd-journald' && $verb ne 'reload' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "systemd-journald" and $verb ne "reload") 4 98 102
Condition66%2/3
$name eq "systemd-journald" and $verb ne "reload"
!ll&&!rl&&r
9804
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
8479 4 ▶ 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'} ? : 4 0 4
Condition33%1/3
$svc and defined $$svc{"config"}
!ll&&!rl&&r
004
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
8480 4 ▶ 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) 1 3 4
Condition66%2/3
defined $t and $t =~ /^\s*SystemMaxUse\s*=\s*(\S+)/m
!ll&&!rl&&r
031
MC/DC50%1/2
defined $t and $t =~ /^\s*SystemMaxUse\s*=\s*(\S+)/m
defined $t $t =~ /^\s*SystemMaxUse\s*=\s*(\S+)/m
Truth table66%2/3
A and B
A= defined $tB= $t =~ /^\s*SystemMaxUse\s*=\s*(\S+)/m
ABresult
0X0
100
111
8481 4 ▶ 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 3 4
Condition66%4/6
defined $t and $t =~ /^\s*MaxRetentionSec\s*=\s*(\S+)/m and defined(my $age = _secs($1))
!ll&&!rl&&r
301
defined $t and $t =~ /^\s*MaxRetentionSec\s*=\s*(\S+)/m
!ll&&!rl&&r
031
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
8482 # dauerhaft (Storage=persistent, oder auto mit /var/log/journal): legt das Verzeichnis
8483 # an und uebernimmt das Laufzeit-Journal aus /run/log/journal
8484 4 ▶ my ($st) = ( $t // '' ) =~ /^\s*Storage\s*=\s*(\S+)\s*$/m;
Condition50%1/2
$t // ""
l!l
40
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
Aresult
11
00
8485 4 ▶ _journald_boot( $dev, $svc, $CTX ? $CTX->{host} : undef ); # was beim Systemstart galt, vor dem Umzug
Branch: 1 branch
BranchTrueFalseTotal
$Langertha::Holmgang::Sim::Linux::CTX ? : 4 0 4
8486 4 ▶ my $flush = ( $st // 'auto' ) eq 'persistent' || ( $st // 'auto' ) eq 'auto' && _is_dir( $dev, '/var/log/journal' );
Condition20%2/10
($st // 'auto') eq 'persistent' || ($st // 'auto') eq 'auto' && _is_dir($dev, '/var/log/journal')
l!l&&r!l&&!r
400
$st // "auto"
l!l
40
($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' || ($st // 'auto') eq 'auto' && _is_dir($dev, '/var/log/journal')
$st $st _is_dir($dev, "/var/log/journal")
Truth table25%1/4
A || B and C
A= $stB= $stC= _is_dir($dev, "/var/log/journal")
ABCresult
1XX1
0111
00X0
0100
8487 4 ▶ _journal_flush($dev) if $flush;
Branch: 1 branch
BranchTrueFalseTotal
if $flush 4 0 4
8488 4 ▶ $svc->{_journald_flushed} = $flush if $svc && $verb =~ /start/; # Meldungen nach "Started" (_journald_started)
Branch: 1 branch
BranchTrueFalseTotal
if $svc and $verb =~ /start/ 4 0 4
Condition33%1/3
$svc and $verb =~ /start/
!ll&&!rl&&r
004
MC/DC0%0/2
$svc and $verb =~ /start/
$svc $verb =~ /start/
Truth table33%1/3
A and B
A= $svcB= $verb =~ /start/
ABresult
0X0
100
111
8489 }
8490 102 ▶ 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 99 102
Condition54%6/11
$$dev{"bind"} and $name eq ($$dev{"bind"}{"service"} // "named") and not $verb eq "start" && $$svc{"active"}
!ll&&!rl&&r
9903
$$dev{"bind"} and $name eq ($$dev{"bind"}{"service"} // "named")
!ll&&!rl&&r
9903
$$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
8491 3 _part('Dns');
8492 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
8493 }
8494 101 ▶ 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 99 101
Condition55%5/9
$$dev{"postfix"} and $name eq "postfix" and not $verb eq "start" && $$svc{"active"}
!ll&&!rl&&r
9902
$$dev{"postfix"} and $name eq "postfix"
!ll&&!rl&&r
9902
$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
8495 2 _part('Postfix');
8496 2 Langertha::Holmgang::Sim::Linux::Postfix::service_event( $dev, $verb );
8497 }
8498 # dnsmasq & Co.: reload (SIGHUP) liest nur Hosts-Dateien neu, nicht die
8499 # Konfiguration — die wirkt erst nach restart. Dienste mit reload_config
8500 # (gunicorn, prometheus, …) lesen sie auch beim reload.
8501 # Mehrere Dateien (config: [ … ]): running ist { pfad => text }; reload_config
8502 # true liest alle, eine Liste nur diese (z. B. prometheus.yml, nicht die
8503 # Startoptionen in /etc/default). Mit config_check prueft der Dienst vorher;
8504 # beim reload bleibt bei einem Fehler alles, wie es lief (Fehler im Journal).
8505 100 ▶ if ( ref $svc->{config} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$svc{"config"} eq "ARRAY") 22 78 100
8506 22 my $rc = $svc->{reload_config};
8507 22 ▶ return if $verb eq 'reload' && !$rc;
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "reload" and not $rc 0 22 22
Condition66%2/3
$verb eq "reload" and not $rc
!ll&&!rl&&r
1840
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
8508 22 ▶ 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
3622
$verb ne "reload" or ref $rc ne "ARRAY"
l!l&&r!l&&!r
3244
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
8509 22 my ( $err, $extra ) = _config_check( $dev, $svc );
8510 22 ▶ if (@$err) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$err) 1 21 22
8511 1 _log( $dev, $name, $svc, @$err );
8512 1 return;
8513 }
8514 21 ▶ my %run = ref $svc->{running} eq 'HASH' ? %{ $svc->{running} } : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'running'} eq 'HASH' ? : 21 0 21
8515 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) { } 36 0 36
8516 # Dateien, die die Hauptdatei nachlaedt (Regeldateien), kommen mit ihr neu
8517 21 ▶ 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) 21 0 21
defined $$svc{'config_main'} ? : 21 0 21
8518 21 my %cfg = map { $_ => 1 } @{ $svc->{config} };
8519 21 delete @run{ grep { !$cfg{$_} } keys %run };
8520 21 %run = ( %run, %$extra );
8521 }
8522 21 $svc->{running} = \%run;
8523 21 return;
8524 }
8525 78 ▶ 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"}) 14 64 78
Condition100%6/6
defined $$svc{"config"} and $verb ne "reload" || $$svc{"reload_config"}
!ll&&!rl&&r
61314
$verb ne "reload" or $$svc{"reload_config"}
l!l&&r!l&&!r
1133
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
8526 14 my $t = _file_text( $dev, $svc->{config} );
8527 14 ▶ die "Job for $name.service failed because the control process exited with error code.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 14 14
8528 . "See \"systemctl status $name.service\" and \"journalctl -xeu $name.service\" for details.\n"
8529 unless defined $t;
8530 14 $svc->{running} = $t;
8531 }
8532 78 return;
8533 }
8534  
8535 # Muster einer Unit (Shell-Glob) als regulaerer Ausdruck; ohne Endung passt es
8536 # auch auf NAME.service (systemctl status 'billing*')
8537 1 ▶sub _unit_glob {
Subroutine _unit_glob: called CC=1 SCAR=0.0
8538 1 my ($g) = @_;
8539 1 ( my $r = quotemeta $g ) =~ s/\\\*/.*/g;
8540 1 $r =~ s/\\\?/./g;
8541 1 $r =~ s/\\\[/[/g;
8542 1 $r =~ s/\\\]/]/g;
8543 1 return qr/\A$r(?:\.service)?\z/;
8544 }
8545  
8546 # systemctl list-unit-files: UNIT FILE, STATE, VENDOR PRESET (systemd 252)
8547 0 ▶sub _list_unit_files {
Subroutine _list_unit_files: not called CC=8 SCAR=42.8
8548 0 my ( $dev, $names ) = @_;
8549 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
8550 my @r = map {
8551 0 my $v = $svcs->{$_};
8552 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
8553 } @$names;
8554 0 my ( $w1, $w2 ) = ( length 'UNIT FILE', length 'STATE' );
8555 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
8556 return join "\n", sprintf( '%-*s %-*s %s', $w1, 'UNIT FILE', $w2, 'STATE', 'VENDOR PRESET' ),
8557 0 ( map { sprintf( '%-*s %-*s %s', $w1, $_->[0], $w2, $_->[1], 'enabled' ) } @r ), '', scalar(@r) . ' unit files listed.';
8558 }
8559  
8560 236 ▶sub _systemctl {
Subroutine _systemctl: called CC=164 SCAR=70.8
8561 236 my ( $dev, $av, $ctx ) = @_;
8562 { # systemctl [-p A] show …: erstes Wort ohne Option (Werte von -p uebersprungen)
8563 236 my @x = @$av;
8564 236 ▶ while (@x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@x) 236 0 236
8565 236 my $y = shift @x;
8566 0 ▶ if ( $y eq '-p' || $y eq '--property' ) { shift @x; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($y eq "-p" or $y eq "--property") 0 236 236
Condition33%1/3
$y eq "-p" or $y eq "--property"
l!l&&r!l&&!r
00236
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
8567 236 ▶ next if $y =~ /\A-/;
Branch: 1 branch
BranchTrueFalseTotal
if $y =~ /\A-/ 0 236 236
8568 236 ▶ return _systemctl_show( $dev, $av ) if $y eq 'show';
Branch: 1 branch
BranchTrueFalseTotal
if $y eq "show" 35 201 236
8569 201 last;
8570 }
8571 }
8572 201 my $now = grep { $_ eq '--now' } @$av;
8573 201 ▶ my $failed = grep { $_ eq '--failed' || $_ eq '--state=failed' } @$av;
Condition33%1/3
$_ eq '--failed' || $_ eq '--state=failed'
l!l&&r!l&&!r
00400
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
8574 # systemctl kill [-s SIG] dienst…: SIGHUP wirkt wie reload; TERM, KILL, INT treffen den
8575 # laufenden Dienst wie kill (Restart= der Unit gilt); nicht geladen, stehend, anderes: Luecke
8576 201 ▶ if ( ( $av->[0] // '' ) eq 'kill' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($$av[0] // "") eq "kill") 6 195 201
Condition50%1/2
$$av[0] // ""
l!l
2010
MC/DC0%0/1
$$av[0] // ""
$$av[0]
Truth table50%1/2
A
A= $$av[0]
Aresult
11
00
8577 6 my ( @rest, $sig ) = ();
8578 6 my @k = @{$av}[ 1 .. $#$av ];
8579 6 ▶ while (@k) {
Branch: 1 branch
BranchTrueFalseTotal
if (@k) 10 6 16
8580 10 my $x = shift @k;
8581 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
8582 1 elsif ( $x =~ /\A--signal=(.+)\z/ ) { $sig = $1 }
8583 elsif ( $x =~ /\A--kill-whom=(?:all|main)\z/ ) { }
8584 6 elsif ( $x !~ /\A-/ ) { push @rest, $x }
8585 0 else { push @GAPS, join( ' ', 'systemctl', @$av ); return ( '', 0 ) }
8586 }
8587 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
8588 6 ▶ return _systemctl( $dev, [ 'reload', @rest ], $ctx ) if $s eq 'HUP';
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "HUP" 1 5 6
8589 5 my @units = map { _unit($_) } @rest;
8590 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
8591 2 push @GAPS, join( ' ', 'systemctl', @$av );
8592 2 return ( '', 0 );
8593 }
8594 3 _signal( $dev, $_, $s ) for @units;
8595 3 return ( '', 1 );
8596 }
8597 195 ▶ my $all = grep { $_ eq '--all' || $_ eq '-a' } @$av;
Condition33%1/3
$_ eq '--all' || $_ eq '-a'
l!l&&r!l&&!r
00381
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
8598 195 ▶ my ($type) = map { /\A--type=(\w+)\z/ ? $1 : () } @$av;
Branch: 1 branch
BranchTrueFalseTotal
/\A--type=(\w+)\z/ ? : 0 381 381
8599 195 ▶ my @a = grep { !/\A--/ && !/\A-[qlfa]\z/ } @$av;
Condition66%2/3
/\A--/ || /\A-[qlfa]\z/
l!l&&r!l&&!r
20379
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
8600 195 ▶ my $verb = shift(@a) // 'list-units';
Condition50%1/2
shift @a // "list-units"
l!l
1950
MC/DC0%0/1
shift @a // "list-units"
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
8601 195 my @names = map { _unit($_) } @a;
8602 195 ▶ my $svcs = $dev->{services} //= {};
Condition100%2/2
$$dev{"services"} //= {}
l!l
1914
MC/DC100%1/1
$$dev{"services"} //= {}
$$dev{"services"}
Truth table100%2/2
A
A= $$dev{"services"}
Aresult
11
00
8603 # Debian: postgresql.service fasst die Cluster zusammen (ReloadPropagatedFrom=, PartOf=)
8604 195 ▶ 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 188 195
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
18807
ref $$dev{"postgres"} eq "HASH" and not $$svcs{"postgresql"}
!ll&&!rl&&r
18807
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
8605 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
8606 }
8607 # systemctl status 'billing*': die passenden geladenen Units, ohne Treffer nichts
8608 195 ▶ if ( $verb eq 'status' && grep {/[*?[]/} @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "status" and grep {/[*?[]/;} @a) 0 195 195
Condition66%2/3
$verb eq "status" and grep {/[*?[]/;} @a
!ll&&!rl&&r
184110
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
8609 0 ▶ @names = map { my $p = $_; /[*?[]/ ? ( grep { _uname($_) =~ _unit_glob($p) } sort keys %$svcs ) : _unit($p) } @a;
Branch: 1 branch
BranchTrueFalseTotal
/[*?[]/ ? : 0 0 0
8610 0 ▶ return ( '', 1 ) unless @names;
Branch: 1 branch
BranchTrueFalseTotal
unless @names 0 0 0
8611 }
8612 195 ▶ return ( _list_timers( $dev, $all, \@a ), 1 ) if $verb eq 'list-timers';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "list-timers" 2 193 195
8613 193 ▶ 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 193 193
Condition33%1/3
$verb eq "list-units" or $verb eq "list-unit-files"
l!l&&r!l&&!r
00193
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
8614 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
8615 # Muster hinter dem Verb (billing*, *.timer) wie systemd: gegen den Namen der Unit
8616 0 ▶ @n = grep { my $u = _uname($_); grep { $u =~ _unit_glob($_) } @a } @n if @a;
Branch: 1 branch
BranchTrueFalseTotal
if @a 0 0 0
8617 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
8618 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
8619 return ( join( "\n", sprintf( ' %-30s %-6s %-8s %-8s %s', qw( UNIT LOAD ACTIVE SUB DESCRIPTION ) ),
8620 0 map { my $v = $svcs->{$_};
8621 sprintf( '%s %-30s loaded %-8s %-8s %s', $v->{failed} ? '●' : ' ', _uname($_),
8622 $v->{active} ? 'active' : $v->{failed} ? 'failed' : 'inactive',
8623 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
8624 }
8625 193 ▶ if ( $verb eq 'daemon-reload' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "daemon-reload") 15 178 193
8626 15 ▶ if ( $dev->{storage} ) { # systemd liest die fstab neu (Mount-Units)
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"storage"}) 1 14 15
8627 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
8628 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
8629 }
8630 15 for my $n ( keys %$svcs ) {
8631 29 my $svc = $svcs->{$n};
8632 29 ▶ next unless exists $svc->{unit_loaded};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$svc{"unit_loaded"} 2 27 29
8633 27 my $t = _unit_text( $dev, $n, $svc );
8634 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
8635 17 $svc->{unit_loaded} = $t;
8636 17 _timer_derive( $dev, $n, $svc );
8637 # Fehler der Unit meldet systemd beim Laden
8638 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
8639 }
8640 15 return ( '', 1 );
8641 }
8642 178 ▶ return ( "Too few arguments.", 0 ) unless @names;
Branch: 1 branch
BranchTrueFalseTotal
unless @names 0 178 178
8643 178 my @out;
8644 178 my $ok = 1;
8645 178 for my $n (@names) {
8646 183 my $svc = $svcs->{$n};
8647 183 ▶ if ( !$svc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($svc) 16 167 183
8648 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
8649 16 ▶ ( $n, $svc ) = ( $real, $svcs->{$real} ) if defined $real;
Branch: 1 branch
BranchTrueFalseTotal
if defined $real 0 16 16
8650 }
8651 183 ▶ $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
167124
$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
8652 183 my $u = _uname($n);
8653 183 ▶ if ( !$svc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($svc) 4 179 183
8654 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
8655 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
8656 2 push @out, "Failed to $verb $u: Unit $u not found.";
8657 2 $ok = 0;
8658 2 next;
8659 }
8660 179 ▶ if ( $verb eq 'status' ) {
Branch: 12 branches
BranchTrueFalseTotal
if ($verb eq 'status') { } 10 169 179
elsif ($verb eq 'is-active') { } 9 160 169
elsif ($verb eq 'is-failed') { } 0 160 160
elsif ($verb eq 'is-enabled') { } 5 155 160
elsif ($verb eq 'cat') { } 1 154 155
elsif ($verb =~ /\A(?:restart|reload|start|reload-or-restart|try-restart)\z/) { } 133 21 154
elsif ($verb eq 'stop') { } 15 6 21
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
8661 10 push @out, _systemctl_status( $dev, $n, $svc, $ctx->{host} );
8662 10 ▶ $ok = 0 unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 1 9 10
8663 }
8664 elsif ( $verb eq 'is-active' ) {
8665 9 ▶ push @out, $svc->{active} ? 'active' : $svc->{failed} ? 'failed' : 'inactive';
Branch: 2 branches
BranchTrueFalseTotal
$$svc{'active'} ? : 7 2 9
$$svc{'failed'} ? : 1 1 2
8666 9 ▶ $ok = 0 unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 2 7 9
8667 }
8668 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
8669 elsif ( $verb eq 'is-enabled' ) {
8670 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
8671 5 push @out, $e;
8672 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
8673 }
8674 elsif ( $verb eq 'cat' ) {
8675 1 my $uf = _unit_file( $n, $svc );
8676 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
8677 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
8678 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
8679 "# This output shows the current version of the unit's original fragment and drop-in files.",
8680 "# If fragments or drop-ins were added or removed, they are not properly reflected in this output.",
8681 "# Run 'systemctl daemon-reload' to reload units." if _unit_changed( $dev, $n, $svc );
8682 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
8683 }
8684 elsif ( $verb =~ /\A(?:restart|reload|start|reload-or-restart|try-restart)\z/ ) {
8685 133 ▶ next if $verb eq 'try-restart' && !$svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "try-restart" and not $$svc{"active"} 0 133 133
Condition33%1/3
$verb eq "try-restart" and not $$svc{"active"}
!ll&&!rl&&r
13300
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
8686 # reload-or-restart: laeuft der Dienst und kann er neu laden, laedt er nur neu
8687 133 my $verb = $verb;
8688 133 ▶ if ( $verb eq 'reload-or-restart' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "reload-or-restart") 1 132 133
8689 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
8690 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
8691 }
8692 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 133 133
8693 133 ▶ my $uft = $verb eq 'reload' ? $svc->{unit_loaded} // _unit_text( $dev, $n, $svc ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$verb eq 'reload' ? : 44 89 133
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
8694 # Units ohne ExecReload (in der Unit, systemd-journald, oder reload: false im Zustand)
8695 133 ▶ 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 130 133
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
89413
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
8696 || ( defined $uft && $uft !~ /^\s*ExecReload\s*=/m ) ) ) {
8697 3 push @out, "Failed to reload $u: Job type reload is not applicable for unit $u.";
8698 3 $ok = 0;
8699 3 next;
8700 }
8701 130 ▶ if ( $verb eq 'reload' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "reload") 41 89 130
8702 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
8703 1 $svc->{last_error} = $e;
8704 1 push @out, "Job for $n.service failed because the control process exited with error code.",
8705 "See \"systemctl status $n.service\" and \"journalctl -xeu $n.service\" for details.";
8706 1 $ok = 0;
8707 1 next;
8708 }
8709 40 _restart_effect( $dev, $n, 'reload' );
8710 38 _reopen_logs( $dev, $n );
8711 38 _pg_event( $dev, $n, 'reload' );
8712 _log( $dev, $n, $svc, "systemd[1]: Reloading $u" . _desc($svc) . '...',
8713 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
8714 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
8715 "systemd[1]: Reloaded $u" . _desc($svc) . '.' );
8716 38 next;
8717 }
8718 89 my ( $o, $k ) = _systemd_start( $dev, $n, $svc, $verb );
8719 86 ▶ push @out, $o if length $o;
Branch: 1 branch
BranchTrueFalseTotal
if length $o 23 63 86
8720 86 ▶ $ok = 0 unless $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $k 22 64 86
8721 }
8722 elsif ( $verb eq 'stop' ) {
8723 15 ▶ if ( $svc->{active} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$svc{"active"}) 15 0 15
8724 15 ▶ $svc->{restarts} = ( $svc->{restarts} // 0 ) + 1;
Condition100%2/2
$$svc{"restarts"} // 0
l!l
78
MC/DC100%1/1
$$svc{"restarts"} // 0
$$svc{"restarts"}
Truth table100%2/2
A
A= $$svc{"restarts"}
Aresult
11
00
8725 15 $svc->{active} = JSON::MaybeXS::false();
8726 15 _pg_event( $dev, $n, 'stop' );
8727 15 _app_event( $dev, $n, 'stop' );
8728 15 _log( $dev, $n, $svc, "systemd[1]: Stopping $u" . _desc($svc) . '...', "systemd[1]: $u: Deactivated successfully.",
8729 "systemd[1]: Stopped $u" . _desc($svc) . '.' );
8730 }
8731 0 ▶ $dev->{deleted_open} = [ grep { ( $_->{by} // '' ) ne $n } @{ $dev->{deleted_open} } ] if $dev->{deleted_open};
Branch: 1 branch
BranchTrueFalseTotal
if $$dev{"deleted_open"} 0 15 15
Condition0%0/2
$$_{"by"} // ""
l!l
00
MC/DC0%0/1
$$_{"by"} // ""
$$_{"by"}
Truth table0%0/2
A
A= $$_{"by"}
Aresult
11
00
8732 15 ▶ 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 14 15
Condition62%5/8
$n =~ /\Awg-quick\@(wg\d+)\z/ and $$dev{"interfaces"}{$1} and ($$dev{"interfaces"}{$1}{"state"} // "") ne "DOWN"
!ll&&!rl&&r
1401
$n =~ /\Awg-quick\@(wg\d+)\z/ and $$dev{"interfaces"}{$1}
!ll&&!rl&&r
1401
$$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
8733 1 my $w = $1;
8734 1 my $copy = Langertha::Holmgang::Sim::Linux::clone_state($dev);
8735 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
8736 0 else { $dev->{interfaces}{$w}{state} = 'DOWN' }
8737 1 $dev->{services}{$n}{active} = JSON::MaybeXS::false();
8738 }
8739 }
8740 ▶ 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
8741 6 ▶ my $want = $verb eq 'enable' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$verb eq 'enable' ? : 3 3 6
8742 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
8743 0 push @out, "Failed to enable unit: Unit file /etc/systemd/system/$u is masked.";
8744 0 $ok = 0;
8745 0 next;
8746 }
8747 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
8748 1 push @out, 'The unit files have no installation config (WantedBy=, RequiredBy=, UpheldBy=,',
8749 'Also=, or Alias= settings in the [Install] section, and DefaultInstance= for',
8750 'template units). This means they are not meant to be enabled or disabled using systemctl.', ' ',
8751 'Possible reasons for having these kinds of units are:',
8752 "\x{2022} A unit may be statically enabled by being symlinked from another unit's",
8753 ' .wants/, .requires/, or .upholds/ directory.',
8754 "\x{2022} A unit's purpose may be to act as a helper for some other unit which has",
8755 ' a requirement dependency on it.',
8756 "\x{2022} A unit may be started when needed via activation (socket, path, timer,",
8757 ' D-Bus, udev, scripted systemctl call, ...).',
8758 "\x{2022} In case of template units, the unit is meant to be enabled with some",
8759 ' instance name specified.';
8760 }
8761 else {
8762 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
8763 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
8764 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
8765 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
8766 : "Removed \"/etc/systemd/system/$wb.wants/$u\".";
8767 }
8768 6 ▶ if ($now) {
Branch: 1 branch
BranchTrueFalseTotal
if ($now) 2 4 6
8769 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
8770 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
8771 }
8772 }
8773 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
8774 0 elsif ( $verb eq 'unmask' ) { delete $svc->{masked}; push @out, "Removed \"/etc/systemd/system/$u\"." }
8775 0 ▶ elsif ( $verb eq 'reset-failed' ) { $svc->{failed} = JSON::MaybeXS::false() if $svc->{failed} }
Branch: 1 branch
BranchTrueFalseTotal
if $$svc{"failed"} 0 0 0
8776 0 elsif ( $verb eq 'edit' ) { push @GAPS, "systemctl edit $n"; push @out, 'Error opening terminal: unknown.'; $ok = 0 }
8777 0 else { return ( "Unknown command verb $verb.", 0 ) }
8778 }
8779 173 return ( join( "\n", @out ), $ok );
8780 }
8781  
8782 # systemd-analyze calendar AUSDRUCK… | verify DATEI… | cat-config PFAD…; anderes ist eine Luecke
8783 9 ▶sub _systemd_analyze {
Subroutine _systemd_analyze: called CC=24 SCAR=33.9
8784 9 my ( $dev, $av ) = @_;
8785 9 my @a = grep { !/\A--(?:iterations|base-time)=/ } @$av;
8786 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
8787 9 require Langertha::Holmgang::Sim::Linux::Calendar;
8788 9 ▶ if ( $sub eq 'calendar' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "calendar") 4 5 9
8789 4 ▶ return ( 'Too few arguments.', 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 4 4
8790 4 my ( @out, $ok );
8791 4 $ok = 1;
8792 4 for my $e (@a) {
8793 4 my $c = Langertha::Holmgang::Sim::Linux::Calendar::parse($e);
8794 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
8795 3 my $t = Langertha::Holmgang::Sim::Linux::Calendar::next_elapse( $c, _sim_now() );
8796 3 ▶ push @out, '' if @out;
Branch: 1 branch
BranchTrueFalseTotal
if @out 0 3 3
8797 3 push @out, " Original form: $e", "Normalized form: $c->{normalized}";
8798 3 ▶ if ( defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) { } 3 0 3
8799 3 push @out, ' Next elapse: ' . Langertha::Holmgang::Sim::Linux::Calendar::format_local($t);
8800 3 push @out, ' (in UTC): ' . Langertha::Holmgang::Sim::Linux::Calendar::format_local( $t, 1 );
8801 3 push @out, ' From now: ' . Langertha::Holmgang::Sim::Linux::Calendar::left( $t - _sim_now() ) . ' left';
8802 }
8803 0 else { push @out, ' Next elapse: never' }
8804 }
8805 4 return ( join( "\n", @out ), $ok );
8806 }
8807 5 ▶ if ( $sub eq 'verify' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "verify") 1 4 5
8808 1 my ( @out, $ok );
8809 1 $ok = 1;
8810 1 for my $p (@a) {
8811 1 my $t = _file_text( $dev, $p );
8812 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
8813 1 ( my $n = $p ) =~ s{.*/}{};
8814 1 ▶ next unless $n =~ /\.timer\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $n =~ /\.timer\z/ 0 1 1
8815 1 my $i = _timer_info( $dev, $n, { unit => $p } );
8816 1 push @out, map {"$p:$_->[0]: Failed to parse calendar specification, ignoring: $_->[1]"} @{ $i->{bad} };
8817 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
8818 1 push @out, "$n: Timer unit lacks value setting. Refusing.", "Unit $n has a bad unit file setting.";
8819 1 $ok = 0;
8820 }
8821 }
8822 1 return ( join( "\n", @out ), $ok );
8823 }
8824 4 ▶ if ( $sub eq 'cat-config' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "cat-config") 3 1 4
8825 3 my @p = grep { !/\A-/ } @a;
8826 3 ▶ return ( 'Too few arguments.', 0 ) unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 3 3
8827 3 my @out;
8828 3 for my $p (@p) {
8829 3 ( my $rel = $p ) =~ s{\A/(?:etc|run|usr/local/lib|usr/lib|lib)/}{};
8830 0 ▶ if ( $rel =~ m{\A/} ) { push @GAPS, join( ' ', 'systemd-analyze', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($rel =~ m[\A/]) 0 3 3
8831 3 my @roots = qw( /etc /run /usr/local/lib /usr/lib );
8832 3 my ($main) = grep { defined _file_text( $dev, $_ ) } map {"$_/$rel"} @roots;
8833 3 my %drop; # Dateiname -> Pfad, das erste Verzeichnis gewinnt
8834 3 for my $r ( reverse @roots ) {
8835 12 my $d = "$r/$rel.d/";
8836 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
8837 }
8838 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
8839 0 ▶ if ( !@f ) { push @GAPS, join( ' ', 'systemd-analyze', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (@f) 0 3 3
8840 3 push @out, map { "# $_\n" . ( _file_text( $dev, $_ ) =~ s/\n+\z//r ) } @f;
8841 }
8842 3 return ( join( "\n\n", @out ), 1 );
8843 }
8844 1 push @GAPS, join( ' ', 'systemd-analyze', @$av );
8845 1 return ( '', 0 );
8846 }
8847  
8848 # bash -c '…' / sh -c '…': die Zeile im Simulator ausfuehren
8849 0 ▶sub _shell_c {
Subroutine _shell_c: not called CC=6 SCAR=37.4
8850 0 my ( $dev, $av, $ctx ) = @_;
8851 0 my @a = @$av;
8852 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
8853 0 ▶ return ( '', 1 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 0 0
8854 0 ▶ if ( $a[0] eq '-c' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a[0] eq "-c") 0 0 0
8855 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
8856 0 my ( $o, $k ) = __PACKAGE__->_run_inner( $dev, $line, $ctx );
8857 0 return ( $o, $k );
8858 }
8859 0 push @GAPS, join( ' ', 'bash', @a ); # Skript ausfuehren: nicht nachgebildet
8860 0 return ( '', 0 );
8861 }
8862  
8863 # timedatectl [status|show|set-timezone Z|list-timezones|timesync-status]
8864 4 ▶sub _timedatectl {
Subroutine _timedatectl: called CC=18 SCAR=30.7
8865 4 my ( $dev, $av ) = @_;
8866 4 require Langertha::Holmgang::Sim::Linux::Calendar;
8867 4 my $C = 'Langertha::Holmgang::Sim::Linux::Calendar';
8868 4 my @a = grep { !/\A--(?:no-pager|no-ask-password)\z/ } @$av;
8869 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
8870 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
8871 4 my $now = _sim_now();
8872 4 my $off = $C->can('offset')->( $now, $tz );
8873 4 ▶ if ( $verb eq 'status' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "status") 2 2 4
8874 2 my $loc = $C->can('format_local')->( $now, $tz );
8875 2 ( my $abbr = $loc ) =~ s/.* //;
8876 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
8877 2 ( my $rtc = $C->can('format_local')->( $now, 1 ) ) =~ s/ UTC\z//;
8878 2 return ( join( "\n", " Local time: $loc", ' Universal time: ' . $C->can('format_local')->( $now, 1 ),
8879 " RTC time: $rtc", " Time zone: $tz ($abbr, $o)", 'System clock synchronized: yes',
8880 ' NTP service: active', ' RTC in local TZ: no' ), 1 );
8881 }
8882 2 ▶ if ( $verb eq 'show' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "show") 1 1 2
8883 1 my %p = ( Timezone => $tz, LocalRTC => 'no', CanNTP => 'yes', NTP => 'yes', NTPSynchronized => 'yes',
8884 TimeUSec => $C->can('format_local')->( $now, $tz ), RTCTimeUSec => $C->can('format_local')->( $now, $tz ) );
8885 1 ▶ my @want = map { /\A--property=(.*)\z/ ? split( /,/, $1 ) : () } @a;
Branch: 1 branch
BranchTrueFalseTotal
/\A--property=(.*)\z/ ? : 0 3 3
8886 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
8887 1 my $value = grep { $_ eq '--value' } @a;
8888 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
8889 1 ▶ return ( join( "\n", map { $value ? $p{$_} : "$_=$p{$_}" } @k ), 1 );
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 1 0 1
8890 }
8891 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
8892 1 ▶ if ( $verb eq 'set-timezone' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "set-timezone") 1 0 1
8893 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
8894 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
8895 1 ▶ $dev->{timezone} = $z unless $z eq $tz;
Branch: 1 branch
BranchTrueFalseTotal
unless $z eq $tz 1 0 1
8896 1 return ( '', 1 );
8897 }
8898 0 push @GAPS, join( ' ', 'timedatectl', @$av );
8899 0 return ( '', 0 );
8900 }
8901  
8902 # file PFAD…: Art einer Datei aus dem Zustand
8903 5 ▶sub _file_cmd {
Subroutine _file_cmd: called CC=20 SCAR=32.8
8904 5 my ( $dev, $av ) = @_;
8905 5 my @out;
8906 5 for my $p ( grep { !/\A-/ } @$av ) {
8907 7 my $e = _file_entry( $dev, $p );
8908 # ein Programm, das which an diesem Pfad findet (git, kubectl …): ausfuehrbare Datei
8909 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
8910 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";
8911 1 next;
8912 }
8913 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
8914 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
8915 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
8916 my $kind = $p =~ /\.gz\z/ ? 'gzip compressed data, from Unix'
8917 : $p =~ /\.journal(?:~)?\z/ ? 'Journal file'
8918 : $t =~ /\A#!\s*\S*\b(?:ba|da)?sh\b/ ? 'POSIX shell script, ASCII text executable'
8919 : $t =~ /BEGIN OPENSSH PRIVATE KEY/ ? 'OpenSSH private key'
8920 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
8921 : length $t ? ( $t =~ /[^\x00-\x7f]/ ? 'Unicode text, UTF-8 text' : 'ASCII text' )
8922 : _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'
8923 : _file_size($e) > 0 ? 'data' : 'empty';
8924 4 push @out, "$p: $kind";
8925 }
8926 5 return ( join( "\n", @out ), 1 );
8927 }
8928  
8929 # Pakete, deren Dateien der Simulator kennt (dpkg -L/-S/-l/-s); weitere ueber
8930 # packages: { name: [ pfade ] } im Zustand
8931 88 our %PACKAGES = (
8932 'openssh-server' => { version => '1:9.2p1-2+deb12u3', files => [], desc => 'secure shell (SSH) server, for secure access from remote machines' },
8933 'openssh-client' => { version => '1:9.2p1-2+deb12u3', files => [], desc => 'secure shell (SSH) client, for secure access to remote machines' },
8934 nftables => { version => '1.0.6-2+deb12u2', files => [], desc => 'Program to control packet filtering rules by Netfilter project' },
8935 logrotate => { version => '3.21.0-1', files => [ qw( /etc/cron.daily/logrotate /etc/logrotate.conf /etc/logrotate.d/btmp
8936 /etc/logrotate.d/wtmp /lib/systemd/system/logrotate.service /lib/systemd/system/logrotate.timer /usr/sbin/logrotate
8937 /usr/share/doc/logrotate/changelog.Debian.gz /usr/share/man/man5/logrotate.conf.5.gz /usr/share/man/man8/logrotate.8.gz
8938 /var/lib/logrotate ) ], desc => 'Log rotation utility' },
8939 cron => { version => '3.0pl1-162', files => [ qw( /etc/cron.d /etc/cron.d/.placeholder /etc/cron.daily /etc/crontab
8940 /etc/init.d/cron /lib/systemd/system/cron.service /usr/sbin/cron /usr/bin/crontab ) ], desc => 'process scheduling daemon' },
8941 );
8942  
8943 4 ▶sub _dpkg {
Subroutine _dpkg: called CC=17 SCAR=30.0
8944 4 my ( $dev, $av ) = @_;
8945 4 my @a = @$av;
8946 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
8947 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
8948 4 ▶ my $known = sub { my ($n) = @_; $pk{$n} };
Subroutine __ANON__: called CC=1 SCAR=0.0
8949 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
8950 3 my @out;
8951 3 my $ok = 1;
8952 3 for my $n (@a) {
8953 3 my $p = $known->($n);
8954 3 ▶ if ( !$p ) { push @GAPS, "dpkg $op $n"; return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($p) 1 2 3
8955 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
8956 0 elsif ( $op =~ /\A-(?:s|-status)\z/ ) { push @out, "Package: $n", 'Status: install ok installed', "Version: $p->{version}" }
8957 1 else { push @out, sprintf( 'ii %-14s %-15s amd64 %s', $n, $p->{version}, $p->{desc} ) }
8958 }
8959 2 return ( join( "\n", @out ), $ok );
8960 }
8961 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
8962 1 my @out;
8963 1 for my $f (@a) {
8964 1 my ($n) = grep { my $x = $_; grep { $_ eq $f } @{ $pk{$x}{files} } } sort keys %pk;
8965 0 ▶ if ( !$n ) { push @GAPS, "dpkg -S $f"; return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($n) 0 1 1
8966 1 push @out, "$n: $f";
8967 }
8968 1 return ( join( "\n", @out ), 1 );
8969 }
8970 0 push @GAPS, join( ' ', 'dpkg', @$av );
8971 0 return ( '', 0 );
8972 }
8973  
8974 # PostgreSQL und seine Clients: Wirkung von Start, Neustart, reload, Stopp.
8975 117 ▶sub _pg_event {
Subroutine _pg_event: called CC=11 SCAR=24.9
8976 117 my ( $dev, $n, $verb ) = @_;
8977 117 ▶ my $svc = ( $dev->{services} || {} )->{$n} || {};
Condition50%2/4
($$dev{'services'} || {})->{$n} || {}
l!l
1170
$$dev{'services'} || {}
l!l
1170
MC/DC0%0/1
($$dev{'services'} || {})->{$n} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
8978 117 ▶ return unless $dev->{postgres} || $svc->{pg_connect};
Branch: 1 branch
BranchTrueFalseTotal
unless $$dev{"postgres"} or $$svc{"pg_connect"} 108 9 117
Condition100%3/3
$$dev{"postgres"} or $$svc{"pg_connect"}
l!l&&r!l&&!r
72108
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
8979 _pg()->can('service_event')->( $dev, $n, $verb eq 'start' || $verb eq 'restart' || $verb eq 'reload' || $verb eq 'stop' ? $verb : 'restart',
8980 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
8981 9 return;
8982 }
8983  
8984 1 ▶sub _service {
Subroutine _service: called CC=2 SCAR=7.0
8985 1 my ( $dev, $av, $ctx ) = @_;
8986 1 my ( $n, $verb ) = @$av;
8987 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
8988 1 return _systemctl( $dev, [ $verb, $n ], $ctx );
8989 }
8990  
8991 1 ▶sub _reboot {
Subroutine _reboot: called CC=2 SCAR=7.1
8992 1 my ( $dev, $av, $ctx ) = @_;
8993 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
8994 1 return ( "Connection to $ctx->{host} closed by remote host.", 0 );
8995 }
8996  
8997 # --- NetworkManager ----------------------------------------------------------------
8998  
8999 2 ▶sub _nmcli {
Subroutine _nmcli: called CC=45 SCAR=62.1
9000 2 my ( $dev, $av ) = @_;
9001 2 my @a;
9002 2 ▶ for ( my $i = 0; $i < @$av; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$av) 8 2 10
9003 8 my $x = $av->[$i];
9004 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
9005 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
9006 8 push @a, $x;
9007 }
9008 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
9009 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
9010 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
9011 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
9012 // ( $obj eq 'c' || $obj eq 'con' ? 'connection' : $obj eq 'd' || $obj eq 'dev' ? 'device' : undef )
9013 // return ( "Error: argument '$obj' not understood. Try passing --help instead.", 0 );
9014 2 ▶ if ( $o eq 'connection' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "connection") 2 0 2
9015 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
9016 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
9017 2 ▶ if ( $verb eq 'show' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "show") 0 2 2
9018 0 my $n = shift @a;
9019 0 ▶ if ( !defined $n ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $n) 0 0 0
9020 return ( join( "\n", sprintf( '%-20s %-38s %-10s %s', qw( NAME UUID TYPE DEVICE ) ),
9021 0 map { sprintf( '%-20s %-38s %-10s %s', $_, $cons->{$_}{uuid} // '00000000-0000-0000-0000-000000000000',
9022 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
9023 }
9024 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
9025 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
9026 0 return ( join( "\n", map { sprintf( '%-40s%s', "$_:", $p{$_} ) } sort keys %p ), 1 );
9027 }
9028 2 ▶ if ( $verb eq 'modify' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "modify") 1 1 2
9029 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
9030 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
9031 1 ▶ return ( "Error: '$n' - no properties to modify.", 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 1 1
9032 1 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 1 1 2
9033 1 my $k = shift @a;
9034 1 $k =~ s/\A\+|\A-//;
9035 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
9036 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
9037 unless $k =~ /\A(?:ipv4|ipv6|connection|802-3-ethernet|gsm)\.[\w-]+\z/;
9038 1 $c->{props}{$k} = $v;
9039 }
9040 1 return ( '', 1 );
9041 }
9042 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
9043 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
9044 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
9045 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
9046 1 _nm_apply( $dev, $c );
9047 1 return ( "Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)", 1 );
9048 }
9049 0 return ( "Error: argument '$verb' not understood. Try passing --help instead.", 0 );
9050 }
9051 0 ▶ if ( $o eq 'device' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "device") 0 0 0
9052 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
9053 0 ▶ if ( $verb eq 'reapply' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "reapply") 0 0 0
9054 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
9055 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
9056 0 ▶ return ( "Error: Device '$d' not found.", 0 ) unless $c;
Branch: 1 branch
BranchTrueFalseTotal
unless $c 0 0 0
9057 0 _nm_apply( $dev, $c );
9058 0 return ( "Connection successfully reapplied to device '$d'.", 1 );
9059 }
9060 return ( join( "\n", sprintf( '%-10s %-10s %-10s %s', qw( DEVICE TYPE STATE CONNECTION ) ),
9061 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
9062 sort keys %$cons ), 1 );
9063 }
9064 0 return ( "STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN\nconnected full missing enabled enabled enabled", 1 );
9065 }
9066  
9067 # Metrik einer Verbindung auf ihre (nicht-Kernel-)Routen anwenden.
9068 1 ▶sub _nm_apply {
Subroutine _nm_apply: called CC=12 SCAR=28.8
9069 1 my ( $dev, $c ) = @_;
9070 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
9071 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
9072 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
9073 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
9074 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
9075 1 $r->{metric} = 0 + $m;
9076 }
9077 1 return;
9078 }
9079  
9080 # --- ping (ohne Beobachtung des Falls) ---------------------------------------------
9081  
9082 12 ▶sub _ping {
Subroutine _ping: called CC=32 SCAR=41.3
9083 12 my ( $dev, $av ) = @_;
9084 12 my @a = @$av;
9085 12 my ( $count, $from, $to ) = (4);
9086 12 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 25 12 37
9087 25 my $x = shift @a;
9088 25 ▶ if ( $x eq '-c' ) { $count = shift @a }
Branch: 5 branches
BranchTrueFalseTotal
if ($x eq '-c') { } 11 14 25
elsif ($x =~ /\A-c(\d+)\z/) { } 1 13 14
elsif ($x eq '-I' or $x eq '-S') { } 0 13 13
elsif ($x =~ /\A-[WwisMt]\z/) { } 0 13 13
elsif ($x =~ /\A-/) { } 1 12 13
9089 1 elsif ( $x =~ /\A-c(\d+)\z/ ) { $count = $1 } # -c1 zusammengeschrieben
9090 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
0013
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
9091 0 elsif ( $x =~ /\A-[WwisMt]\z/ ) { shift @a }
9092 elsif ( $x =~ /\A-/ ) { }
9093 12 else { $to = $x }
9094 }
9095 12 ▶ return ( "ping: usage error: Destination address required", 0 ) unless defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to 0 12 12
9096 12 my $name;
9097 12 ▶ if ( !defined _ip2n($to) ) { # Name: ueber /etc/hosts und die Nameserver aufloesen
Branch: 1 branch
BranchTrueFalseTotal
unless (defined _ip2n($to)) 3 9 12
9098 3 my ($ip) = _resolve( $dev, $to );
9099 3 ▶ 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 2 3
Condition66%2/3
defined $ip and defined _ip2n($ip)
!ll&&!rl&&r
102
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
9100 2 ( $name, $to ) = ( $to, $ip );
9101 }
9102 11 ▶ $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 11 11
Condition33%3/9
defined $count and $count =~ /\A\d+\z/ and $count > 0 and $count < 20
!ll&&!rl&&r
0011
defined $count and $count =~ /\A\d+\z/ and $count > 0
!ll&&!rl&&r
0011
defined $count and $count =~ /\A\d+\z/
!ll&&!rl&&r
0011
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
9103 11 ▶ my $src = defined $from && defined _ip2n($from) ? $from : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $from && defined _ip2n($from) ? : 0 11 11
Condition33%1/3
defined $from and defined _ip2n($from)
!ll&&!rl&&r
1100
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
9104 11 my ($r) = _lookup( $dev, $to, $src );
9105 11 ▶ return ( "ping: connect: Network is unreachable", 0 ) unless $r || _onlink( $dev, $to );
Branch: 1 branch
BranchTrueFalseTotal
unless $r or _onlink($dev, $to) 0 11 11
Condition66%2/3
$r or _onlink($dev, $to)
l!l&&r!l&&!r
1010
MC/DC0%0/2
$r or _onlink($dev, $to)
$r _onlink($dev, $to)
Truth table66%2/3
A or B
A= $rB= _onlink($dev, $to)
ABresult
1X1
011
000
9106 11 ▶ if ( ( _absent( $dev, $to ) // q{} ) eq 'nohost' ) { # im eigenen Netz gibt es die Adresse nicht (ADR 0012)
Branch: 1 branch
BranchTrueFalseTotal
if ((_absent($dev, $to) // "") eq "nohost") 1 10 11
Condition100%2/2
_absent($dev, $to) // ""
l!l
110
MC/DC100%1/1
_absent($dev, $to) // ""
_absent($dev, $to)
Truth table100%2/2
A
A= _absent($dev, $to)
Aresult
11
00
9107 1 ▶ my ( $own ) = defined $src ? $src : map { s{/\d+\z}{}r } grep { m{/} && _in( $to, $_ ) } map { @{ $_->{addr} || [] } } values %{ $dev->{interfaces} || {} };
Branch: 1 branch
BranchTrueFalseTotal
defined $src ? : 0 1 1
Condition42%3/7
m[/] && _in($to, $_)
!ll&&!rl&&r
001
$$_{'addr'} || []
l!l
10
$$dev{'interfaces'} || {}
l!l
10
MC/DC0%0/2
m[/] && _in($to, $_)
m[/] _in($to, $_)
MC/DC0%0/1
$$_{'addr'} || []
$$_{'addr'}
MC/DC0%0/1
$$dev{'interfaces'} || {}
$$dev{'interfaces'}
Truth table33%1/3
A && B
A= m[/]B= _in($to, $_)
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$_{'addr'}
Aresult
11
00
Truth table50%1/2
A
A= $$dev{'interfaces'}
Aresult
11
00
9108 1 ▶ $own //= ( _own_addrs($dev) )[0] // $to;
Condition16%1/6
$own //= (_own_addrs($dev))[0] // $to
l!l&&r!l&&!r
100
(_own_addrs($dev))[0] // $to
l!l&&r!l&&!r
000
MC/DC0%0/3
$own //= (_own_addrs($dev))[0] // $to
$own (_own_addrs($dev))[0] $to
Truth table0%0/4
A //= B // C
A= $ownB= (_own_addrs($dev))[0]C= $to
ABCresult
1XX1
01X1
0011
0000
9109 1 ▶ my @l = ( "PING " . ( $name // $to ) . " ($to) 56(84) bytes of data." );
Condition33%1/3
$name // $to
l!l&&r!l&&!r
010
MC/DC0%0/2
$name // $to
$name $to
Truth table33%1/3
A // B
A= $nameB= $to
ABresult
1X1
011
000
9110 1 push @l, "From $own icmp_seq=$_ Destination Host Unreachable" for 1 .. $count;
9111 1 push @l, q{}, "--- $to ping statistics ---", "$count packets transmitted, 0 received, +$count errors, 100% packet loss, time " . ( $count - 1 ) . '057ms';
9112 1 return ( join( "\n", @l ), 0 );
9113 }
9114 10 ▶ my @l = ( "PING " . ( $name // $to ) . " ($to) 56(84) bytes of data." );
Condition66%2/3
$name // $to
l!l&&r!l&&!r
280
MC/DC0%0/2
$name // $to
$name $to
Truth table66%2/3
A // B
A= $nameB= $to
ABresult
1X1
011
000
9115 10 push @l, "64 bytes from $to: icmp_seq=$_ ttl=64 time=0.4" . $_ . ' ms' for 1 .. $count;
9116 10 push @l, '', "--- $to ping statistics ---", "$count packets transmitted, $count received, 0% packet loss, time " . ( $count - 1 ) . '003ms';
9117 10 return ( join( "\n", @l ), 1 );
9118 }
9119  
9120 88 __PACKAGE__->meta->make_immutable;
9121  
9122 __END__
« blib/lib/Langertha/Holmgang/Shell/Filter.pm ↑ Summary blib/lib/Langertha/Holmgang/Structure.pm »