lib/IO/Trace.pm

filter: Statementstmt 93.8% 182 / 194 Branchbran 78.7% 74 / 94 Conditioncond 67.3% 35 / 52 MC/DCmcdc 48.3% 15 / 31 Subroutinesub 100% 23 / 23 Podpod 0.0% 0 / 13 totaltotal 80.8% 329 / 407 CC 66 SCAR 25.4
CC
66
Cov
86%
io_loop
26.1
finish_child
16.9
spawn
11.2
CRAP 12.7
↑ Summary script/iotrace »
1 package IO::Trace;
2  
3 46 ▶use 5.006000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 46 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 46 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 46 ▶use Getopt::Long qw(GetOptionsFromArray Configure);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 46 ▶use IPC::Open3 qw(open3);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 46 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 46 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 46 ▶use IO::File qw(O_WRONLY O_TRUNC O_CREAT SEEK_CUR);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 46 our @EXPORT = qw(iotrace);
14 46 our $VERSION = '0.023';
15  
16 # Magic Timer Settings
17 46 our $has_hires = eval { require Time::HiRes; 1 };
18 46 our $patience_idle = 8000; # Seconds to wait for I/O while process is still running
19 46 ▶our $patience_kill_mute = $has_hires ? 5.2 : 6; # Seconds to wait for "mute" process to terminate. If all its handles are closed, then force SIGTERM and SIGKILL if still running after waiting this long.
Branch: 1 branch
BranchTrueFalseTotal
$has_hires ? : 46 0 46
20 46 our $heartbeat_grind_mute = 0.2; # Interval Seconds between SIGCHLD check to test if "mute" child died yet.
21 46 our $implicit_close_before_chld = 0.08; # Maximum Seconds to wait for SIGCHLD after all handles have been closed in order to consider it an implicit close instead of explicit close.
22 46 ▶our $implicit_chld_before_close = $has_hires ? 0.25 : 1; # Maximum Seconds after receiving SIGCHLD to consider a close to be implicit. Any longer is considered an explicit close.
Branch: 1 branch
BranchTrueFalseTotal
$has_hires ? : 46 0 46
23 46 ▶our $patience_zombie_breather = $has_hires ? 5.6 : 7; # Maximum Seconds of uninterrupted silence after receiving SIGCHLD to wait for the process to close all handles. Any longer, then all open pipes are implicitly slapped closed to sufficate the zombie process. Then it is reaped to log the correct exit status, and the descent process should receive a SIGPIPE if ever attempting to write to its output handle in the future.
Branch: 1 branch
BranchTrueFalseTotal
$has_hires ? : 46 0 46
24  
25 308 ▶sub now { $has_hires ? Time::HiRes::time() : time }
Subroutine now: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$IO::Trace::has_hires ? : 308 0 308
26  
27 sub usage {
28 2 ▶ $0 =~ /([^\/]+)$/ and return "Usage> $1 -o <output_log> CMD [ARGS]\n";
Subroutine usage: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$0 =~ m[([^/]+)$] and return "Usage> $1 -o <output_log> CMD [ARGS]\n" 2 0 2
29 }
30  
31 sub iotrace {
32 45 ▶ my $self = __PACKAGE__->new;
Subroutine iotrace: called CC=7 SCAR=20.0
Pod undocumented
33 45 ▶ my @args = @_ ? @_ : @ARGV or die usage; # No args is Error
Branch: 2 branches
BranchTrueFalseTotal
my(@args) = @_ ? @_ : @ARGV or die usage() 1 44 45
@_ ? : 0 45 45
34 44 ▶ $self->parse_commandline(@args) or die usage; # Broken args parsing is Error
Branch: 1 branch
BranchTrueFalseTotal
$self->parse_commandline(@args) or die usage() 0 44 44
35 44 ▶ $self->{help} and print usage and exit; # Showing --help usage is not Error
Branch: 1 branch
BranchTrueFalseTotal
$self->{"help"} and print usage() and exit 1 43 44
Condition66%2/3
$self->{"help"} and print usage()
!ll&&!rl&&r
4301
MC/DC50%1/2
$self->{"help"} and print usage()
$self->{"help"} print usage()
Truth table66%2/3
A and B
A= $self->{"help"}B= print usage()
ABresult
0X0
100
111
36 43 $self->{child_died} = 0;
37 43 ▶ local $SIG{CHLD} = sub { $self->{child_died} = now; };
Subroutine __ANON__: called CC=1 SCAR=0.0
38 43 $self->run_trace;
39 41 my $exit_status = $self->finish_child;
40 41 ▶ if (defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 0 41 41
41 0 return $exit_status;
42 }
43 41 exit $exit_status;
44 }
45  
46 sub new {
47 45 ▶ my $self = shift;
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
48 45 ▶ my $args = shift || {};
Condition50%1/2
shift() || {}
l!l
045
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
49 45 return bless $args, $self;
50 }
51  
52 sub parse_commandline {
53 44 ▶ my $self = shift;
Subroutine parse_commandline: called CC=1 SCAR=0.0
Pod undocumented
54 44 Configure("require_order");
55 44 Configure("bundling");
56 return GetOptionsFromArray
57 $self->{run} = \@_,
58 "o=s" => \($self->{output_log_file}),
59 "v+" => \($self->{verbose} = 0),
60 "x+" => \($self->{heX_ify} = 0),
61 "t+" => \($self->{timing} = 0),
62 "f+" => \($self->{follow_fork} = 0),
63 "q+" => \($self->{quiet} = 0), # Ignored
64 "s=i" => \($self->{size_of_strings}), # Ignored
65 "e=s" => \($self->{events}), # Ignored
66 44 "help|h"=> \($self->{help}),
67 }
68  
69 sub t {
70 235 ▶ my $self = shift;
Subroutine t: called CC=5 SCAR=16.1
Pod undocumented
71 235 my $h = "";
72 235 ▶ if ($self->{follow_fork} == 1) { $h .= "$self->{pid} "; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"follow_fork"} == 1) 12 223 235
73 235 ▶ if ($self->{timing}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"timing"}) 85 150 235
74 85 ▶ my $now = $self->{timing} > 1 ? now : time;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'timing'} > 1 ? : 81 4 85
75 85 my @t = localtime $now;
76 85 $h .= sprintf "%02d:%02d:%02d", $t[2], $t[1], $t[0];
77 85 ▶ $h .= sprintf ".%06d", 1000000*($now - int($now)) if $self->{timing} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"timing"} > 1 81 4 85
78 85 $h .= " ";
79 }
80 235 return $h;
81 }
82  
83 sub log {
84 235 ▶ my $self = shift;
Subroutine log: called CC=1 SCAR=0.0
Pod undocumented
85 235 my $line = join "", @_;
86 235 $line =~ s/\s*$/\n/;
87 235 $self->{log}->print($self->t().$line);
88 }
89  
90 # Escape strings like strace does
91 sub e {
92 282 ▶ my $self = shift;
Subroutine e: called CC=3 SCAR=12.4
Pod undocumented
93 282 my $chars = shift;
94 282 ▶ if ($self->{heX_ify} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'heX_ify'} > 1) { } 0 282 282
95 # -xx: Super Hex Encode everything
96 0 $chars =~ s/([\s\S])/sprintf "\\x%02x", ord($1)/eg;
97 }
98 else {
99 # Both \\ and \" really need to be escaped
100 # But add other helpful chars to make it easier for Perl to read too.
101 282 $chars =~ s/([\\\"\'\$\@])/\\$1/g;
102 # Special backslash escape chars for easy legibility
103 282 $chars =~ s/\t/\\t/g;
104 282 $chars =~ s/\r/\\r/g;
105 282 $chars =~ s/\n/\\n/g;
106 282 ▶ if ($self->{heX_ify}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'heX_ify'}) { } 0 282 282
107 # -x: Hex Encode only non-ascii chars
108 0 $chars =~ s/([^\ -\~])/sprintf "\\x%02x", ord $1/eg;
109 }
110 else {
111 # Default is octal encoding non-ascii only
112 282 $chars =~ s/([^\ -\~])/sprintf "\\%03o", ord $1/eg;
113 }
114 }
115 282 return qq{"$chars"};
116 }
117  
118 sub run_trace {
119 43 ▶ my $self = shift;
Subroutine run_trace: called CC=4 SCAR=14.1
Pod undocumented
120 43 ▶ if ($self->{timing} > 1 and not $has_hires) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"timing"} > 1 and not $IO::Trace::has_hires) 0 43 43
Condition66%2/3
$self->{"timing"} > 1 and not $IO::Trace::has_hires
!ll&&!rl&&r
32110
MC/DC0%0/2
$self->{"timing"} > 1 and not $IO::Trace::has_hires
$self->{"timing"} > 1 not $IO::Trace::has_hires
Truth table66%2/3
A and not(B)
A= $self->{"timing"} > 1B= not $IO::Trace::has_hires
ABresult
0X0
100
111
121 # If requesting to log high precision, but without HiRes, then just change "-tt" to "-t" to show integer time
122 0 $self->{timing} = 1;
123 }
124 43 $self->spawn;
125 41 $self->open_output_log;
126 115 ▶ $self->log("execve(".$self->e($self->{full}).", [".join(', ', map { $self->e($_) } @{ $self->{run} }).'], '.(
Branch: 1 branch
BranchTrueFalseTotal
$self->{'verbose'} ? : 1 40 41
127 $self->{verbose} ? (
128 41 '['.join(', ', map { $self->e("$_=$ENV{$_}") } sort keys %ENV).']'
129 ) :
130 \%ENV.' /* '.(scalar keys %ENV).' vars */'
131 ).") = 0");
132 41 $self->io_loop;
133 }
134  
135 sub spawn {
136 43 ▶ my $self = shift;
Subroutine spawn: called CC=11 SCAR=24.2
Pod undocumented
137 43 my $full = $self->{run}->[0];
138 43 ▶ if (eval { require File::Which; 1; } and $full =~ m{^([\w\-\.]+)$}) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require File::Which; 1 } } and $full =~ /^([\w\-\.]+)$/) 5 38 43
Condition66%2/3
eval { do { require File::Which; 1 } } and $full =~ /^([\w\-\.]+)$/
!ll&&!rl&&r
0385
MC/DC50%1/2
eval { do { require File::Which; 1 } } and $full =~ /^([\w\-\.]+)$/
eval { do { require File::Which; 1 } } $full =~ /^([\w\-\.]+)$/
Truth table66%2/3
A and B
A= eval { do { require File::Which; 1 } }B= $full =~ /^([\w\-\.]+)$/
ABresult
0X0
100
111
139 5 $full = File::Which::which($1);
140 }
141 43 ▶ if (!$full or $full =~ m{^/} && !-x $full) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $full or $full =~ m[^/] and not -x $full) 2 41 43
Condition83%5/6
not $full or $full =~ m[^/] and not -x $full
l!l&&r!l&&!r
1141
$full =~ m[^/] and not -x $full
!ll&&!rl&&r
0411
MC/DC66%2/3
not $full or $full =~ m[^/] and not -x $full
not $full $full =~ m[^/] not -x $full
Truth table75%3/4
not(A) or B and not(C)
A= not $fullB= $full =~ m[^/]C= not -x $full
ABCresult
1XX1
0111
00X0
0100
142 2 die "$self->{run}->[0]: No such file or directory\n";
143 }
144 41 $self->{in} = IO::Handle->new;
145 41 $self->{out} = IO::Handle->new;
146 41 $self->{err} = IO::Handle->new;
147 # open3 can't vivify STDERR from undef for some reason
148 41 my @r = @{ $self->{run} };
149 41 ▶ $r[0] = $full if $full;
Branch: 1 branch
BranchTrueFalseTotal
if $full 41 0 41
150 41 ▶ $self->{full} = $full // $r[0];
Condition33%1/3
$full // $r[0]
l!l&&r!l&&!r
4100
MC/DC0%0/2
$full // $r[0]
$full $r[0]
Truth table33%1/3
A // B
A= $fullB= $r[0]
ABresult
1X1
011
000
151 # Launch target program
152 41 ▶ $self->{pid} = open3 $self->{in}, $self->{out}, $self->{err}, @r or die "$r[0]: fork exec failure: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"pid"} = open3($self->{"in"}, $self->{"out"}, $self->{"err"}, @r) or die "$r[0]: fork exec failure: $!\n" 0 41 41
153 # Map each handle to its corresponding handle
154 $self->{proxy} = {
155 fileno($self->{in}) => *STDIN,
156 fileno($self->{out}) => *STDOUT,
157 fileno($self->{err}) => *STDERR,
158  
159 fileno(*STDIN) => $self->{in},
160 fileno(*STDOUT) => $self->{out},
161 fileno(*STDERR) => $self->{err},
162 41 };
163 41 $self->{implicitly_closed} = {};
164 41 $self->{sel} = IO::Select->new(values %{ $self->{proxy} });
165 41 $self->{writers} = IO::Select->new($self->{in}, \*STDOUT, \*STDERR);
166 41 foreach my $fh ($self->{writers}->handles) {
167 # Test if writer handle is seek()able
168 123 ▶ if (seek $fh, 0, SEEK_CUR) { # Offset +0 from Current Position doesn't actually move the pointer
Branch: 1 branch
BranchTrueFalseTotal
if (seek $fh, 0, 1) 3 120 123
169 # YUP! Must be a real file. Don't monitor it since nobody will be able to close() the "other end" anyways.
170 # We must remove it from the Select loop to prevent super grinding since we always "can_read" a real file.
171 3 $self->{sel}->remove($fh);
172 3 $self->{writers}->remove($fh);
173 }
174 }
175 41 return $self->{pid};
176 }
177  
178 sub open_output_log {
179 41 ▶ my $self = shift;
Subroutine open_output_log: called CC=4 SCAR=13.9
Pod undocumented
180 41 my $output_log_file = $self->{output_log_file};
181 41 ▶ if (defined $output_log_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_log_file) { } 38 3 41
182 38 ▶ $output_log_file .= ".$self->{pid}" if $self->{follow_fork} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"follow_fork"} > 1 1 37 38
183 38 ▶ $self->{log} = IO::File->new($output_log_file, O_WRONLY | O_TRUNC | O_CREAT ) or die "$output_log_file: open failure: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"log"} = "IO::File"->new($output_log_file, 577) or die "${output_log_file}: open failure: $!\n" 0 38 38
184 }
185 else {
186 # Spew all the trace info mixed in with the normal STDERR stream if no -o option provided:
187 3 $self->{log} = IO::Handle->new_from_fd(fileno(STDERR), ">");
188 }
189 41 $self->{log}->autoflush(1);
190 41 return $self->{log};
191 }
192  
193 sub io_loop {
194 41 ▶ my $self = shift;
Subroutine io_loop: called CC=26 SCAR=32.6
Pod undocumented
195 # Loop while still open handles or during brief implicit close detection
196 41 ▶ while ($self->{sel}->handles or keys %{ $self->{implicitly_closed} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sel"}->handles or keys %{$$self{"implicitly_closed"};}) 188 8 196
Condition100%3/3
$self->{"sel"}->handles or keys %{$$self{"implicitly_closed"};}
l!l&&r!l&&!r
153358
MC/DC100%2/2
$self->{"sel"}->handles or keys %{$$self{"implicitly_closed"};}
$self->{"sel"}->handles keys %{$$self{"implicitly_closed"};}
Truth table100%3/3
A or B
A= $self->{"sel"}->handlesB= keys %{$$self{"implicitly_closed"};}
ABresult
1X1
011
000
197 my $maximum_timeout =
198 188 ▶ keys %{ $self->{implicitly_closed} } ? $implicit_close_before_chld :
Branch: 1 branch
BranchTrueFalseTotal
$self->{'child_died'} ? : 9 136 145
199 188 ▶ $self->{child_died} ? $patience_zombie_breather :
Branch: 1 branch
BranchTrueFalseTotal
keys %{$$self{'implicitly_closed'};} ? : 43 145 188
200 $patience_idle;
201 188 ▶ my @ready = $self->{sel}->count ? $self->{sel}->can_read($maximum_timeout) : do {select undef,undef,undef, $maximum_timeout; ()};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'sel'}->count ? : 153 35 188
202 188 foreach my $fh (@ready) {
203 189 ▶ my $fn = fileno($fh) // next;
Condition100%2/2
fileno $fh // (next)
l!l
1854
MC/DC100%1/1
fileno $fh // (next)
fileno $fh
Truth table100%2/2
A
A= fileno $fh
Aresult
11
00
204 185 ▶ my $pr = $self->{proxy}->{$fn} or die "Fileno $fn: Impossible Implementation Crash! $!\n";;
Branch: 1 branch
BranchTrueFalseTotal
my $pr = $self->{"proxy"}{$fn} or die "Fileno ${fn}: Impossible Implementation Crash! $!\n" 0 185 185
205 # Find original fileno (STDIN=0, STDOUT=1, STDERR=2):
206 185 ▶ my $real_fileno = $fn < 3 ? $fn : fileno($pr);
Branch: 1 branch
BranchTrueFalseTotal
$fn < 3 ? : 69 116 185
207 185 ▶ if ($self->{writers}->exists($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"writers"}->exists($fh)) 18 167 185
208 # $fh should only be written to, so if it's suddenly "READABLE",
209 # that means it woke up due to the pipe being close()d on the other end.
210 # Never attempt to actually read from a "writers" handle.
211 # Only log explicit close(). Don't bother if it's probably just an implicit close() upon exit.
212 18 ▶ $self->log("close($real_fileno) = 0") if !$self->{child_died};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"child_died"} 14 4 18
213 # Close both sides since there's nowhere for any data to go anymore:
214 18 $self->{sel}->remove($fh);
215 18 $self->{sel}->remove($pr);
216 18 $self->{writers}->remove($fh);
217 18 close $fh;
218 18 close $pr;
219 18 next;
220 }
221 167 my $bytes = sysread($fh, (my $buffer), 16384);
222 # Only STDIN (fileno = 0) is "read", otherwise "write"
223 167 ▶ my $op = $real_fileno ? "write" : "read";
Branch: 1 branch
BranchTrueFalseTotal
$real_fileno ? : 109 58 167
224 167 ▶ $self->log("$op($real_fileno, ".$self->e($buffer).", $bytes) = $bytes") if $bytes or $op eq "read";
Branch: 1 branch
BranchTrueFalseTotal
if $bytes or $op eq "read" 96 71 167
Condition100%3/3
$bytes or $op eq "read"
l!l&&r!l&&!r
623471
MC/DC100%2/2
$bytes or $op eq "read"
$bytes $op eq "read"
Truth table100%3/3
A or B
A= $bytesB= $op eq "read"
ABresult
1X1
011
000
225 167 ▶ if ($bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes) { } 62 105 167
226 # Forward non-empty packet to the proxy file handle
227 62 syswrite($pr, $buffer, $bytes);
228 }
229 else {
230 # Getting ZERO bytes always means the file handle just closed.
231 # Quit listening to this anymore:
232 105 $self->{sel}->remove($fh);
233 # And then close the file handle for real:
234 105 close($fh);
235  
236 # And quit listening on the corresponding handle too:
237 105 $self->{sel}->remove($pr);
238  
239 105 ▶ if ($real_fileno == 0 # Immediately close corresponding handle for STDIN immediately in order to signal target program its input stream has ended.
Branch: 1 branch
BranchTrueFalseTotal
if ($real_fileno == 0 or $self->{'child_died'} and now() > $self->{'child_died'} + $implicit_chld_before_close) { } 34 71 105
Condition66%4/6
$real_fileno == 0 or $self->{"child_died"} and now() > $self->{"child_died"} + $implicit_chld_before_close
l!l&&r!l&&!r
34071
$self->{"child_died"} and now() > $self->{"child_died"} + $implicit_chld_before_close
!ll&&!rl&&r
8630
MC/DC33%1/3
$real_fileno == 0 or $self->{"child_died"} and now() > $self->{"child_died"} + $implicit_chld_before_close
$real_fileno == 0 $self->{"child_died"} now() > $self->{"child_died"} + $implicit_chld_before_close
Truth table75%3/4
A or B and C
A= $real_fileno == 0B= $self->{"child_died"}C= now() > $self->{"child_died"} + $implicit_chld_before_close
ABCresult
1XX1
0111
00X0
0100
240 or $self->{child_died} && now > $self->{child_died} + $implicit_chld_before_close) { # Or if it exited long enough ago, then this must have been an explicit output handle close from a backgrounded process, and it's safe to log, (even if it was implicitly closed by the grandchild or descendent process).
241 34 close($pr);
242  
243 # If it was STDIN (fd 0), then the invoker probably closed it before the target program. But just log the close acting like the target program called close itself (even if STDIN is being ignored by the target program).
244 34 $self->log("close($real_fileno) = 0");
245 }
246 else {
247 # An output handle (STDOUT fd 1 or STDERR fd 2) was just closed, but it might have just been an implicit close since the process is still running or exited too recently.
248 # So don't log it yet. Just flag it for now. Then keep a close eye on the {child_died} timer to determine which way it was.
249 # The goal is to mimic the same behavior as the target process whether to do an implicit or explicit close.
250 71 $self->{implicitly_closed}->{$real_fileno} = $pr;
251 }
252 }
253 }
254 188 ▶ if (!@ready and keys %{ $self->{implicitly_closed} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @ready and keys %{$$self{"implicitly_closed"};}) 42 146 188
Condition100%3/3
not @ready and keys %{$$self{"implicitly_closed"};}
!ll&&!rl&&r
145142
MC/DC100%2/2
not @ready and keys %{$$self{"implicitly_closed"};}
not @ready keys %{$$self{"implicitly_closed"};}
Truth table100%3/3
not(A) and B
A= not @readyB= keys %{$$self{"implicitly_closed"};}
ABresult
0X0
100
111
255 # Implicit detection timeout exceeded. No more waiting allowed.
256 # All implicitly_closed file handles must be imminently closed!
257 42 ▶ if (!$self->{sel}->count and $self->{child_died}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"sel"}->count and $self->{"child_died"}) 33 9 42
Condition100%3/3
not $self->{"sel"}->count and $self->{"child_died"}
!ll&&!rl&&r
7233
MC/DC100%2/2
not $self->{"sel"}->count and $self->{"child_died"}
not $self->{"sel"}->count $self->{"child_died"}
Truth table100%3/3
not(A) and B
A= not $self->{"sel"}->countB= $self->{"child_died"}
ABresult
0X0
100
111
258 # Must exit immediately in order to implicitly close any implicitly_closed handles
259 33 last;
260 }
261 # Otherwise, must explicitly close them all now and log it, then continue the select loop.
262 9 foreach my $fileno (keys %{ $self->{implicitly_closed} }) {
263 9 close(delete $self->{implicitly_closed}->{$fileno});
264 9 $self->log("close($fileno) = 0");
265 }
266 }
267 155 ▶ if ($self->{child_died}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"child_died"}) 40 115 155
268 40 ▶ if (now > $self->{child_died} + $patience_zombie_breather) {
Branch: 1 branch
BranchTrueFalseTotal
if (now() > $self->{'child_died'} + $patience_zombie_breather) { } 0 40 40
269 # Ran out of patience. Just leave to implicitly close all handles.
270 0 last;
271 }
272 else {
273 # Zombie handle said something, so restart the timer, and start the waiting all over again..
274 40 $self->{child_died} = now;
275 }
276 }
277 }
278 }
279  
280 sub finish_child {
281 41 ▶ my $self = shift;
Subroutine finish_child: called CC=10 SCAR=28.3
Pod undocumented
282 41 ▶ if (!$self->{child_died}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"child_died"}) 8 33 41
283 # If process still running, then all handles must have already been closed. So just wait a little bit for termination.
284 8 my $patient = $patience_kill_mute + now;
285 8 ▶ select undef,undef,undef,$heartbeat_grind_mute while !$self->{child_died} and $patient > now;
Branch: 1 branch
BranchTrueFalseTotal
not $self->{"child_died"} and $patient > now() and do { select undef, undef, undef, $heartbeat_grind_mute } 35 8 43
Condition66%2/3
not $self->{"child_died"} and $patient > now()
!ll&&!rl&&r
8035
MC/DC50%1/2
not $self->{"child_died"} and $patient > now()
not $self->{"child_died"} $patient > now()
Truth table66%2/3
not(A) and B
A= not $self->{"child_died"}B= $patient > now()
ABresult
0X0
100
111
286  
287 # If STILL running, then offer a little bit more help to terminate
288 8 ▶ !$self->{child_died} and kill TERM => $self->{pid} and sleep 1 and kill KILL => $self->{pid};
Branch: 1 branch
BranchTrueFalseTotal
not $self->{"child_died"} and kill "TERM", $self->{"pid"} and sleep 1 and kill "KILL", $self->{"pid"} 0 8 8
Condition33%2/6
not $self->{"child_died"} and kill "TERM", $self->{"pid"} and sleep 1
!ll&&!rl&&r
800
not $self->{"child_died"} and kill "TERM", $self->{"pid"}
!ll&&!rl&&r
800
MC/DC0%0/3
not $self->{"child_died"} and kill "TERM", $self->{"pid"} and sleep 1
not $self->{"child_died"} kill "TERM", $self->{"pid"} sleep 1
Truth table25%1/4
not(A) and B and C
A= not $self->{"child_died"}B= kill "TERM", $self->{"pid"}C= sleep 1
ABCresult
0XX0
10X0
1100
1111
289 }
290  
291 # Block waiting for process to exit
292 41 waitpid( $self->{pid}, 0 );
293 41 $self->{child_error} = $?;
294 41 my $signal = $self->{child_error} & 127;
295 41 my $child_exit_status = $self->{child_error} >> 8;
296 41 ▶ if ($signal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signal) 0 41 41
297 0 ▶ my $sig_name = eval { require Config; %Config::Config and [split / /, $Config::Config{sig_name}]->[$signal] } || $signal;
Branch: 1 branch
BranchTrueFalseTotal
%Config::Config and [split(/ /, $Config::Config{"sig_name"}, 0)]->[$signal] 0 0 0
Condition0%0/3
eval { do { require Config; %Config::Config and [split(/ /, $Config::Config{'sig_name'}, 0)]->[$signal] } } || $signal
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { require Config; %Config::Config and [split(/ /, $Config::Config{'sig_name'}, 0)]->[$signal] } } || $signal
eval { do { require Config; %Config::Config and [split(/ /, $Config::Config{'sig_name'}, 0)]->[$signal] } } $signal
Truth table0%0/3
A || B
A= eval { do { require Config; %Config::Config and [split(/ /, $Config::Config{'sig_name'}, 0)]->[$signal] } }B= $signal
ABresult
1X1
011
000
298 0 $self->log("--- GOT SIG$sig_name ($signal) ---");
299 }
300 41 $self->log("+++ exited with $child_exit_status +++");
301 41 $self->{log}->close;
302 41 return $child_exit_status;
303 }
304  
305 46 1;
306 __END__
↑ Summary script/iotrace »