line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Command::Runner::Timeout; |
2
|
10
|
|
|
10
|
|
64
|
use strict; |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
251
|
|
3
|
10
|
|
|
10
|
|
44
|
use warnings; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
314
|
|
4
|
10
|
|
|
10
|
|
40
|
use Time::HiRes (); |
|
10
|
|
|
|
|
88
|
|
|
10
|
|
|
|
|
2758
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $_USE_CLOCK_MONOTONIC = 0; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my $time; |
9
|
|
|
|
|
|
|
{ |
10
|
|
|
|
|
|
|
local $SIG{__DIE__} = 'DEFAULT'; |
11
|
|
|
|
|
|
|
local $@; |
12
|
|
|
|
|
|
|
if (eval 'Time::HiRes::clock_gettime( Time::HiRes::CLOCK_MONOTONIC() )') { |
13
|
|
|
|
|
|
|
$time = sub { Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC()) }; |
14
|
|
|
|
|
|
|
$_USE_CLOCK_MONOTONIC = 1; |
15
|
|
|
|
|
|
|
} else { |
16
|
|
|
|
|
|
|
$time = \&Time::HiRes::time; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
4
|
|
|
4
|
0
|
84
|
my ($class, $at, $kill) = @_; |
22
|
4
|
|
|
|
|
63
|
my $now = $time->(); |
23
|
4
|
|
|
|
|
164
|
bless { signaled => 0, at => $now + $at, at_kill => $now + $at + $kill }, $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub signal { |
27
|
180
|
|
|
180
|
0
|
435
|
my $self = shift; |
28
|
180
|
50
|
66
|
|
|
958
|
return if !$self->{at} && !$self->{at_kill}; |
29
|
180
|
|
|
|
|
535
|
my $now = $time->(); |
30
|
180
|
100
|
100
|
|
|
2330
|
if ($self->{at} and $now >= $self->{at}) { |
31
|
4
|
|
|
|
|
67
|
$self->{at} = undef; |
32
|
4
|
|
|
|
|
21
|
$self->{signaled} = 1; |
33
|
4
|
|
|
|
|
33
|
return 'TERM'; |
34
|
|
|
|
|
|
|
} |
35
|
176
|
100
|
|
|
|
508
|
if ($now >= $self->{at_kill}) { |
36
|
1
|
|
|
|
|
18
|
$self->{at_kill} = undef; |
37
|
1
|
|
|
|
|
19
|
$self->{signaled} = 1; |
38
|
1
|
|
|
|
|
13
|
return 'KILL'; |
39
|
|
|
|
|
|
|
} |
40
|
175
|
|
|
|
|
857
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub signaled { |
44
|
4
|
|
|
4
|
0
|
34
|
my $self = shift; |
45
|
4
|
|
|
|
|
71
|
$self->{signaled}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |