blib/lib/Langertha/Holmgang/Sandbox/Docker.pm

filter: Statementstmt 22.9% 44 / 192 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 71 MC/DCmcdc 0.0% 0 / 35 Subroutinesub 45.0% 9 / 20 Podpod 100% 3 / 3 totaltotal 14.3% 56 / 391 CC 71 SCAR 77.0
CC
71
Cov
13%
run
3422.0
available
56.0
__ANON__
20.0
CRAP 2211.4
↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/MariaDB.pm »
1 package Langertha::Holmgang::Sandbox::Docker;
2 # ABSTRACT: Runs one real program on a copy of a device's files in a locked-down container
3  
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Archive::Tar ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Archive::Tar::Constant ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 our $VERSION = '0.002';
15  
16  
17 1 my $JSON = JSON::MaybeXS->new( utf8 => 1, canonical => 1 );
18  
19 1 has image => ( is => 'ro', isa => 'Str', default => 'langertha-holmgang-sandbox:1' );
20  
21  
22 0 ▶has docker => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { ['docker'] } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
23  
24  
25 1 has timeout => ( is => 'ro', isa => 'Int', default => 10 );
26  
27  
28 1 has memory => ( is => 'ro', isa => 'Str', default => '512m' );
29 1 has cpus => ( is => 'ro', isa => 'Str', default => '1' );
30 1 has pids => ( is => 'ro', isa => 'Int', default => 128 );
31  
32  
33 1 has max_output => ( is => 'ro', isa => 'Int', default => 262144 );
34 1 has max_file => ( is => 'ro', isa => 'Int', default => 1048576 );
35 1 has max_new => ( is => 'ro', isa => 'Int', default => 200 );
36  
37  
38 0 ▶has log => ( is => 'ro', isa => 'ArrayRef', default => sub { [] } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
39  
40  
41 0 ▶sub take_log {
Subroutine take_log: not called CC=1 SCAR=6.9
Pod documented
42 0 my ( $self ) = @_;
43 0 my @l = splice @{ $self->log };
44 0 return @l;
45 }
46  
47  
48 # the scan roots for new files: where a program of a server writes, never the
49 # system directories of the image
50 1 my @SCAN = qw( /etc /srv /opt /home /root /tmp /var /usr/local /run /mnt /data );
51  
52 # The driver inside the container. Plain perl of perl-base: no module beyond
53 # the core of a minimal Debian.
54 1 my $DRIVER = <<'DRIVER';
55 use strict; use warnings;
56 my %J; { open my $h, q{<}, q{/.hg/job} or die "job: $!"; while (<$h>) { chomp; my ( $k, $v ) = split /=/, $_, 2; $J{$k} = pack q{H*}, $v // q{} } }
57 my @argv = split /\0/, $J{argv};
58 my @scan = grep { -d } split /\0/, $J{scan};
59 my %sent = map { $_ => 1 } split /\0/, ( $J{sent} // '' );
60 sub listing {
61 my %f; my @todo = @scan;
62 while ( defined( my $d = shift @todo ) ) {
63 opendir my $dh, $d or next;
64 for my $n ( readdir $dh ) {
65 next if $n eq '.' || $n eq '..';
66 my $p = "$d/$n";
67 if ( -l $p ) { $f{$p} = 'l' } elsif ( -d _ ) { push @todo, $p } elsif ( -f _ ) { $f{$p} = 'f' }
68 }
69 }
70 return \%f;
71 }
72 sub finish {
73 my (%r) = @_;
74 open my $h, '>', '/.hg/result' or die "result: $!";
75 print $h map { "$_=" . unpack( q{H*}, $r{$_} // q{} ) . "\n" } grep { !/\A_/ } sort keys %r;
76 close $h;
77 my @list = ( '/.hg/result', ( -e '/.hg/out' ? '/.hg/out' : () ), @{ $r{_files} || [] } );
78 open my $l, '>', '/.hg/list' or die "list: $!";
79 print $l join( "\0", @list );
80 close $l;
81 exec 'tar', '-cf', '-', '--null', '-P', '--no-recursion', '-T', '/.hg/list';
82 die "tar: $!";
83 }
84 my ($prog) = $argv[0] =~ m{/} ? ( -x $argv[0] ? $argv[0] : () ) : grep { -x && !-d _ } map { "$_/$argv[0]" } split /:/, $J{path};
85 finish( unavailable => "$argv[0] is not in the image" ) unless defined $prog;
86 my $pre = listing();
87 my ($fake) = glob '/usr/lib/*/faketime/libfaketime.so.1';
88 my $pid = fork // die "fork: $!";
89 if ( !$pid ) {
90 chdir $J{cwd} or chdir '/';
91 open STDIN, '<', '/.hg/stdin' or die "stdin: $!";
92 open STDOUT, '>', '/.hg/out' or die "out: $!";
93 open STDERR, '>&', \*STDOUT or die "err: $!";
94 %ENV = ( PATH => $J{path}, HOME => '/root', USER => 'root', LOGNAME => 'root', SHELL => '/bin/bash', LANG => q{C.UTF-8}, PYTHONUNBUFFERED => 1,
95 HOSTNAME => $J{host}, TZ => $J{tz}, map { split /=/, $_, 2 } grep { /=/ } split /\0/, ( $J{env} // '' ) );
96 if ( defined $fake && length $J{now} ) { $ENV{LD_PRELOAD} = $fake; $ENV{FAKETIME} = '@' . $J{now}; $ENV{FAKETIME_DONT_RESET} = 1 }
97 exec {$prog} @argv or do { print "bash: $argv[0]: cannot execute\n"; exit 126 };
98 }
99 my $rc;
100 my $done = eval {
101 local $SIG{ALRM} = sub { die "timeout\n" };
102 alarm $J{timeout};
103 waitpid $pid, 0;
104 alarm 0;
105 $rc = $? & 127 ? 128 + ( $? & 127 ) : $? >> 8;
106 1;
107 };
108 if ( !$done ) { kill 'KILL', $pid; waitpid $pid, 0; $rc = 124 }
109 my $post = listing();
110 my ( @files, @deleted, $new );
111 for my $p ( sort keys %$post ) {
112 next unless $sent{$p} || !$pre->{$p};
113 $new++ unless $sent{$p};
114 finish( unavailable => "the program left more than $J{max_new} new files" ) if ( $new // 0 ) > $J{max_new};
115 finish( unavailable => "the program left a file of more than $J{max_file} bytes: $p" ) if $post->{$p} eq 'f' && -s $p > $J{max_file};
116 push @files, $p;
117 }
118 @deleted = grep { !-e $_ && !-l $_ } sort keys %sent;
119 finish( rc => $rc, deleted => join( "\0", @deleted ), clock => ( defined $fake && length $J{now} ? 'sim' : 'real' ), _files => \@files );
120 DRIVER
121  
122 0 ▶sub _job {
Subroutine _job: not called CC=1 SCAR=6.9
123 0 my (%j) = @_;
124 0 return join( q{}, map { $_.q{=}.unpack( q{H*}, _bytes( $j{$_} ) )."\n" } sort keys %j );
125 }
126  
127 0 ▶sub _unjob {
Subroutine _unjob: not called CC=2 SCAR=17.9
128 0 my ( $t ) = @_;
129 0 ▶ return map { my ( $k, $v ) = split /=/, $_, 2; ( $k => pack( q{H*}, $v // q{} ) ) } split /\n/, $t;
Condition0%0/2
$v // ""
l!l
00
MC/DC0%0/1
$v // ""
$v
Truth table0%0/2
A
A= $v
Aresult
11
00
130 }
131  
132 0 ▶sub _bytes { my ( $s ) = @_; $s = '' unless defined $s; utf8::encode($s) if utf8::is_utf8($s); return $s }
Subroutine _bytes: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
unless defined $s 0 0 0
if utf8::is_utf8($s) 0 0 0
133  
134 0 ▶sub _chars { my ( $s ) = @_; my $c = $s; return utf8::decode($c) ? $c : $s }
Subroutine _chars: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
utf8::decode($c) ? : 0 0 0
135  
136 1 my $SEQ = 0;
137  
138 0 ▶sub run {
Subroutine run: not called CC=58 SCAR=81.4
Pod documented
139 0 my ( $self, %a ) = @_;
140 0 ▶ my @argv = @{ $a{argv} || [] };
Condition0%0/2
$a{'argv'} || []
l!l
00
MC/DC0%0/1
$a{'argv'} || []
$a{'argv'}
Truth table0%0/2
A
A= $a{'argv'}
Aresult
11
00
141 0 ▶ croak __PACKAGE__.'->run needs argv' unless @argv;
Branch: 1 branch
BranchTrueFalseTotal
unless @argv 0 0 0
142 0 ▶ return ( undef, 'an argument holds a NUL byte' ) if grep { /\0/ } @argv;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/\0/;} @argv 0 0 0
143 0 ▶ my $files = $a{files} || {};
Condition0%0/2
$a{'files'} || {}
l!l
00
MC/DC0%0/1
$a{'files'} || {}
$a{'files'}
Truth table0%0/2
A
A= $a{'files'}
Aresult
11
00
144 0 ▶ my $dirs = $a{dirs} || {};
Condition0%0/2
$a{'dirs'} || {}
l!l
00
MC/DC0%0/1
$a{'dirs'} || {}
$a{'dirs'}
Truth table0%0/2
A
A= $a{'dirs'}
Aresult
11
00
145 0 my $now = $a{now};
146 0 ▶ my $mtime = defined $now ? $now - 3600 : time - 3600;
Branch: 1 branch
BranchTrueFalseTotal
defined $now ? : 0 0 0
147  
148 0 my $tar = Archive::Tar->new;
149 0 ▶ my $dir = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
150 0 my ( $p, $o ) = @_;
151 $tar->add_data( substr( $p, 1 ).'/', '', { type => Archive::Tar::Constant::DIR(), mode => $o->{mode} // 0755,
152 0 ▶ uid => $o->{uid} // 0, gid => $o->{gid} // 0, mtime => $mtime } );
Condition0%0/6
$o->{"mode"} // 493
l!l
00
$o->{"uid"} // 0
l!l
00
$o->{"gid"} // 0
l!l
00
MC/DC0%0/1
$o->{"mode"} // 493
$o->{"mode"}
MC/DC0%0/1
$o->{"uid"} // 0
$o->{"uid"}
MC/DC0%0/1
$o->{"gid"} // 0
$o->{"gid"}
Truth table0%0/2
A
A= $o->{"mode"}
Aresult
11
00
Truth table0%0/2
A
A= $o->{"uid"}
Aresult
11
00
Truth table0%0/2
A
A= $o->{"gid"}
Aresult
11
00
153 0 };
154 0 ▶ $dir->( $_, $dirs->{$_} || {} ) for sort grep { m{\A/[^\0]+\z} } keys %$dirs;
Condition0%0/2
$dirs->{$_} || {}
l!l
00
MC/DC0%0/1
$dirs->{$_} || {}
$dirs->{$_}
Truth table0%0/2
A
A= $dirs->{$_}
Aresult
11
00
155 0 my @sent;
156 0 for my $p ( sort keys %$files ) {
157 0 ▶ next unless $p =~ m{\A/[^\0]+\z} && $p !~ m{\A/\.hg(?:/|\z)};
Branch: 1 branch
BranchTrueFalseTotal
unless $p =~ m[\A/[^\0]+\z] and not $p =~ m[\A/\.hg(?:/|\z)] 0 0 0
Condition0%0/3
$p =~ m[\A/[^\0]+\z] and not $p =~ m[\A/\.hg(?:/|\z)]
!ll&&!rl&&r
000
MC/DC0%0/2
$p =~ m[\A/[^\0]+\z] and not $p =~ m[\A/\.hg(?:/|\z)]
$p =~ m[\A/[^\0]+\z] not $p =~ m[\A/\.hg(?:/|\z)]
Truth table0%0/3
A and not(B)
A= $p =~ m[\A/[^\0]+\z]B= not $p =~ m[\A/\.hg(?:/|\z)]
ABresult
0X0
100
111
158 0 my $e = $files->{$p};
159 0 ▶ my %o = ( uid => $e->{uid} // 0, gid => $e->{gid} // 0, mtime => $e->{mtime} // $mtime );
Condition0%0/7
$e->{"uid"} // 0
l!l
00
$e->{"gid"} // 0
l!l
00
$e->{"mtime"} // $mtime
l!l&&r!l&&!r
000
MC/DC0%0/1
$e->{"uid"} // 0
$e->{"uid"}
MC/DC0%0/1
$e->{"gid"} // 0
$e->{"gid"}
MC/DC0%0/2
$e->{"mtime"} // $mtime
$e->{"mtime"} $mtime
Truth table0%0/2
A
A= $e->{"uid"}
Aresult
11
00
Truth table0%0/2
A
A= $e->{"gid"}
Aresult
11
00
Truth table0%0/3
A // B
A= $e->{"mtime"}B= $mtime
ABresult
1X1
011
000
160 0 ▶ if ( defined $e->{link} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e->{'link'}) { } 0 0 0
161 0 $tar->add_data( substr( $p, 1 ), '', { %o, type => Archive::Tar::Constant::SYMLINK(), linkname => $e->{link}, mode => 0777 } );
162 }
163 else {
164 0 ▶ $tar->add_data( substr( $p, 1 ), _bytes( $e->{content} ), { %o, mode => $e->{mode} // 0644 } );
Condition0%0/2
$e->{"mode"} // 420
l!l
00
MC/DC0%0/1
$e->{"mode"} // 420
$e->{"mode"}
Truth table0%0/2
A
A= $e->{"mode"}
Aresult
11
00
165 }
166 0 push @sent, $p;
167 }
168 my %job = (
169 argv => join( "\0", @argv ), cwd => $a{cwd} // '/root', host => $a{host} // 'localhost', tz => $a{tz} // 'Europe/Berlin',
170 path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', timeout => $self->timeout,
171 scan => join( "\0", @SCAN ), sent => join( "\0", @sent ), max_new => $self->max_new, max_file => $self->max_file,
172 0 ▶ env => join( "\0", map { $_.'='.$a{env}{$_} } sort grep { /\A[A-Za-z_]\w*\z/ } keys %{ $a{env} || {} } ),
Branch: 1 branch
BranchTrueFalseTotal
defined $now ? : 0 0 0
Condition0%0/8
$a{"cwd"} // "/root"
l!l
00
$a{"host"} // "localhost"
l!l
00
$a{"tz"} // "Europe/Berlin"
l!l
00
$a{'env'} || {}
l!l
00
MC/DC0%0/1
$a{"cwd"} // "/root"
$a{"cwd"}
MC/DC0%0/1
$a{"host"} // "localhost"
$a{"host"}
MC/DC0%0/1
$a{"tz"} // "Europe/Berlin"
$a{"tz"}
MC/DC0%0/1
$a{'env'} || {}
$a{'env'}
Truth table0%0/2
A
A= $a{"cwd"}
Aresult
11
00
Truth table0%0/2
A
A= $a{"host"}
Aresult
11
00
Truth table0%0/2
A
A= $a{"tz"}
Aresult
11
00
Truth table0%0/2
A
A= $a{'env'}
Aresult
11
00
173 now => defined $now ? POSIX::strftime( '%Y-%m-%d %H:%M:%S', gmtime $now ) : '',
174 );
175 # libfaketime reads FAKETIME in the zone of TZ: hand it the simulation's local time
176 0 ▶ if ( defined $now ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $now) 0 0 0
177 0 local $ENV{TZ} = $job{tz};
178 0 POSIX::tzset();
179 0 $job{now} = POSIX::strftime( '%Y-%m-%d %H:%M:%S', localtime $now );
180 }
181 0 POSIX::tzset();
182 0 $tar->add_data( '.hg/', '', { type => Archive::Tar::Constant::DIR(), mode => 0700 } );
183 0 $tar->add_data( '.hg/job', _job(%job), { mode => 0600 } );
184 0 $tar->add_data( '.hg/stdin', _bytes( $a{stdin} ), { mode => 0600 } );
185 0 $tar->add_data( '.hg/driver', $DRIVER, { mode => 0600 } );
186  
187 0 my $in = File::Temp->new( TEMPLATE => 'holmgang-sandbox-in-XXXXXX', TMPDIR => 1 );
188 0 my $out = File::Temp->new( TEMPLATE => 'holmgang-sandbox-out-XXXXXX', TMPDIR => 1 );
189 0 my $err = File::Temp->new( TEMPLATE => 'holmgang-sandbox-err-XXXXXX', TMPDIR => 1 );
190 0 ▶ $tar->write( $in->filename ) or return ( undef, 'the input archive did not write: '.( $tar->error // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
$tar->write($in->filename) or return undef, 'the input archive did not write: ' . ($tar->error // "") 0 0 0
Condition0%0/2
$tar->error // ""
l!l
00
MC/DC0%0/1
$tar->error // ""
$tar->error
Truth table0%0/2
A
A= $tar->error
Aresult
11
00
191  
192 0 ( my $host = $job{host} ) =~ s/[^A-Za-z0-9.-]/-/g;
193 0 ▶ $host = 'localhost' unless $host =~ /\A[A-Za-z0-9]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $host =~ /\A[A-Za-z0-9]/ 0 0 0
194 0 my $name = sprintf 'holmgang-sandbox-%d-%d', $$, ++$SEQ;
195 0 my @cmd = ( @{ $self->docker }, 'run', '--rm', '-i', '--name', $name,
196 '--network', 'none', '--hostname', substr( $host, 0, 63 ),
197 0 '--cap-drop', 'ALL', ( map { ( '--cap-add', $_ ) } qw( CHOWN DAC_OVERRIDE FOWNER ) ),
198 '--security-opt', 'no-new-privileges', '--pids-limit', $self->pids,
199 '--memory', $self->memory, '--cpus', $self->cpus,
200 '--entrypoint', 'sh', $self->image, '-c', 'cd / && tar --overwrite -xf - && exec perl /.hg/driver' );
201  
202 0 my $t0 = Time::HiRes::time();
203 0 my $pid = fork;
204 0 ▶ return ( undef, 'fork failed: '.$! ) unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 0 0
205 0 ▶ if ( !$pid ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 0 0 0
206 0 ▶ open STDIN, '<', $in->filename or POSIX::_exit(125);
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, "<", $in->filename or POSIX::_exit(125) 0 0 0
207 0 ▶ open STDOUT, '>', $out->filename or POSIX::_exit(125);
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">", $out->filename or POSIX::_exit(125) 0 0 0
208 0 ▶ open STDERR, '>', $err->filename or POSIX::_exit(125);
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">", $err->filename or POSIX::_exit(125) 0 0 0
209 0 ▶ exec { $cmd[0] } @cmd or POSIX::_exit(127);
Branch: 1 branch
BranchTrueFalseTotal
exec {$cmd[0];} @cmd or POSIX::_exit(127) 0 0 0
210 }
211 0 my $status;
212 0 my $done = eval {
213 0 ▶ local $SIG{ALRM} = sub { die "timeout\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
214 0 alarm $self->timeout + 20;
215 0 waitpid $pid, 0;
216 0 $status = $?;
217 0 alarm 0;
218 0 1;
219 };
220 0 ▶ if ( !$done ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($done) 0 0 0
221 0 system { $self->docker->[0] } @{ $self->docker }, 'kill', $name;
222 0 kill 'KILL', $pid;
223 0 waitpid $pid, 0;
224 0 return ( undef, 'the container did not end in time' );
225 }
226 0 my $ms = int( 1000 * ( Time::HiRes::time() - $t0 ) + 0.5 );
227 0 ▶ if ( $status ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status) 0 0 0
228 0 ▶ my $why = do { local $/; open my $h, '<', $err->filename; scalar <$h> } // '';
Condition0%0/2
do { local $/; open my $h, "<", $err->filename; scalar readline $h } // ""
l!l
00
MC/DC0%0/1
do { local $/; open my $h, "<", $err->filename; scalar readline $h } // ""
do { local $/; open my $h, "<", $err->filename; scalar readline $h }
Truth table0%0/2
A
A= do { local $/; open my $h, "<", $err->filename; scalar readline $h }
Aresult
11
00
229 0 $why =~ s/\s+/ /g;
230 0 return ( undef, 'the container failed ('.( $status >> 8 ).'): '.substr( $why, 0, 300 ) );
231 }
232  
233 0 my $back = Archive::Tar->new;
234 0 ▶ $back->read( $out->filename ) or return ( undef, 'the result archive did not read: '.( $back->error // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
$back->read($out->filename) or return undef, 'the result archive did not read: ' . ($back->error // "") 0 0 0
Condition0%0/2
$back->error // ""
l!l
00
MC/DC0%0/1
$back->error // ""
$back->error
Truth table0%0/2
A
A= $back->error
Aresult
11
00
235 0 my %got = map { ( '/'.( $_->full_path =~ s{\A/+}{}r ) => $_ ) } $back->get_files;
236 0 ▶ my $res = $got{'/.hg/result'} or return ( undef, 'the container gave no result' );
Branch: 1 branch
BranchTrueFalseTotal
my $res = $got{"/.hg/result"} or return undef, "the container gave no result" 0 0 0
237 0 ▶ my %r = _unjob( $res->get_content // '' );
Condition0%0/2
$res->get_content // ""
l!l
00
MC/DC0%0/1
$res->get_content // ""
$res->get_content
Truth table0%0/2
A
A= $res->get_content
Aresult
11
00
238 0 ▶ return ( undef, $r{unavailable} ) if length( $r{unavailable} // '' );
Branch: 1 branch
BranchTrueFalseTotal
if length($r{"unavailable"} // "") 0 0 0
Condition0%0/2
$r{"unavailable"} // ""
l!l
00
MC/DC0%0/1
$r{"unavailable"} // ""
$r{"unavailable"}
Truth table0%0/2
A
A= $r{"unavailable"}
Aresult
11
00
239  
240 0 ▶ my $output = $got{'/.hg/out'} ? $got{'/.hg/out'}->get_content // '' : '';
Branch: 1 branch
BranchTrueFalseTotal
$got{'/.hg/out'} ? : 0 0 0
Condition0%0/2
$got{"/.hg/out"}->get_content // ""
l!l
00
MC/DC0%0/1
$got{"/.hg/out"}->get_content // ""
$got{"/.hg/out"}->get_content
Truth table0%0/2
A
A= $got{"/.hg/out"}->get_content
Aresult
11
00
241 0 ▶ $output = substr( $output, 0, $self->max_output ) if length $output > $self->max_output;
Branch: 1 branch
BranchTrueFalseTotal
if length $output > $self->max_output 0 0 0
242 0 my %changed;
243 0 for my $p ( sort grep { !m{\A/\.hg/} } keys %got ) {
244 0 my $f = $got{$p};
245 0 my $old = $files->{$p};
246 0 ▶ if ( $f->is_symlink ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->is_symlink) 0 0 0
247 0 ▶ next if $old && defined $old->{link} && $old->{link} eq $f->linkname;
Branch: 1 branch
BranchTrueFalseTotal
if $old and defined $old->{"link"} and $old->{"link"} eq $f->linkname 0 0 0
Condition0%0/6
$old and defined $old->{"link"} and $old->{"link"} eq $f->linkname
!ll&&!rl&&r
000
$old and defined $old->{"link"}
!ll&&!rl&&r
000
MC/DC0%0/3
$old and defined $old->{"link"} and $old->{"link"} eq $f->linkname
$old defined $old->{"link"} $old->{"link"} eq $f->linkname
Truth table0%0/4
A and B and C
A= $oldB= defined $old->{"link"}C= $old->{"link"} eq $f->linkname
ABCresult
0XX0
10X0
1100
1111
248 0 $changed{$p} = { link => $f->linkname };
249 0 next;
250 }
251 0 ▶ next unless $f->is_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $f->is_file 0 0 0
252 0 ▶ my $content = $f->get_content // '';
Condition0%0/2
$f->get_content // ""
l!l
00
MC/DC0%0/1
$f->get_content // ""
$f->get_content
Truth table0%0/2
A
A= $f->get_content
Aresult
11
00
253 0 my $mode = $f->mode & 07777;
254 0 ▶ next if $old && !defined $old->{link} && _bytes( $old->{content} ) eq $content && ( $old->{mode} // 0644 ) == $mode;
Branch: 1 branch
BranchTrueFalseTotal
if $old and not defined $old->{"link"} and _bytes($old->{"content"}) eq $content and ($old->{"mode"} // 420) == $mode 0 0 0
Condition0%0/11
$old and not defined $old->{"link"} and _bytes($old->{"content"}) eq $content and ($old->{"mode"} // 420) == $mode
!ll&&!rl&&r
000
$old and not defined $old->{"link"} and _bytes($old->{"content"}) eq $content
!ll&&!rl&&r
000
$old and not defined $old->{"link"}
!ll&&!rl&&r
000
$old->{"mode"} // 420
l!l
00
MC/DC0%0/4
$old and not defined $old->{"link"} and _bytes($old->{"content"}) eq $content and ($old->{"mode"} // 420) == $mode
$old not defined $old->{"link"} _bytes($old->{"content"}) eq $content $old->{"mode"}
Truth table0%0/5
A and not(B) and C and D
A= $oldB= not defined $old->{"link"}C= _bytes($old->{"content"}) eq $contentD= $old->{"mode"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
255 0 ▶ $changed{$p} = { content => _chars($content), mode => $mode, ( $old ? () : ( new => 1 ) ) };
Branch: 1 branch
BranchTrueFalseTotal
$old ? : 0 0 0
256 }
257 0 ▶ my @deleted = grep { length } split /\0/, $r{deleted} // '';
Condition0%0/2
$r{"deleted"} // ""
l!l
00
MC/DC0%0/1
$r{"deleted"} // ""
$r{"deleted"}
Truth table0%0/2
A
A= $r{"deleted"}
Aresult
11
00
258 0 push @{ $self->log }, { host => $job{host}, argv => [@argv], exit => 0 + $r{rc}, ms => $ms, clock => $r{clock} };
259 0 return { output => _chars($output), exit => 0 + $r{rc}, changed => \%changed, deleted => \@deleted, ms => $ms, clock => $r{clock} };
260 }
261  
262  
263 0 ▶sub available {
Subroutine available: not called CC=7 SCAR=40.3
Pod documented
264 0 my ( $self ) = @_;
265 0 my $out = File::Temp->new;
266 0 my $pid = fork;
267 0 ▶ return ( 0, 'fork failed: '.$! ) unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 0 0
268 0 ▶ if ( !$pid ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 0 0 0
269 0 open STDIN, '<', '/dev/null';
270 0 open STDOUT, '>', $out->filename;
271 0 open STDERR, '>&', \*STDOUT;
272 0 ▶ exec { $self->docker->[0] } @{ $self->docker }, 'image', 'inspect', '--format', '{{.Id}}', $self->image
Branch: 1 branch
BranchTrueFalseTotal
exec {$self->docker->[0];} @{$self->docker;}, "image", "inspect", "--format", "{{.Id}}", $self->image or POSIX::_exit(127) 0 0 0
273 or POSIX::_exit(127);
274 }
275 0 waitpid $pid, 0;
276 0 ▶ my $text = do { local $/; open my $h, '<', $out->filename; scalar <$h> } // '';
Condition0%0/2
do { local $/; open my $h, "<", $out->filename; scalar readline $h } // ""
l!l
00
MC/DC0%0/1
do { local $/; open my $h, "<", $out->filename; scalar readline $h } // ""
do { local $/; open my $h, "<", $out->filename; scalar readline $h }
Truth table0%0/2
A
A= do { local $/; open my $h, "<", $out->filename; scalar readline $h }
Aresult
11
00
277 0 $text =~ s/\s+\z//;
278 0 ▶ return ( 1, $text ) unless $?;
Branch: 1 branch
BranchTrueFalseTotal
unless $? 0 0 0
279 0 ▶ return ( 0, $? >> 8 == 127 ? $self->docker->[0].' is not installed' : 'the image '.$self->image.' is not there: '.substr( $text =~ s/\s+/ /gr, 0, 200 ) );
Branch: 1 branch
BranchTrueFalseTotal
$? >> 8 == 127 ? : 0 0 0
280 }
281  
282  
283 1 __PACKAGE__->meta->make_immutable;
284  
285 1 1;
286  
287 __END__
↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/MariaDB.pm »