| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Cinnamon::HandleManager; |
|
2
|
2
|
|
|
2
|
|
13
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
66
|
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
68
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
9
|
use Cinnamon::Logger; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
139
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1656
|
use AnyEvent; |
|
|
2
|
|
|
|
|
9100
|
|
|
|
2
|
|
|
|
|
88
|
|
|
8
|
2
|
|
|
2
|
|
1326
|
use AnyEvent::Handle; |
|
|
2
|
|
|
|
|
20121
|
|
|
|
2
|
|
|
|
|
90
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
24
|
use POSIX; |
|
|
2
|
|
|
|
|
28
|
|
|
|
2
|
|
|
|
|
15
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
0
|
|
|
0
|
0
|
|
my ($class, %args) = @_; |
|
14
|
0
|
|
|
|
|
|
bless \%args, $class; |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub register_fh { |
|
18
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $fh) = @_; |
|
19
|
0
|
|
0
|
|
|
|
my $handle_container = $self->{handle_container} ||= {}; |
|
20
|
0
|
|
|
|
|
|
$handle_container->{$name} = { |
|
21
|
|
|
|
|
|
|
fh => $fh, |
|
22
|
|
|
|
|
|
|
output_lines => [], |
|
23
|
|
|
|
|
|
|
}; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub start_async_read { |
|
27
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
28
|
0
|
0
|
|
|
|
|
my $handle_container = $self->{handle_container} or return; |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $cv = AnyEvent->condvar; |
|
31
|
0
|
|
|
|
|
|
my $handles = []; |
|
32
|
0
|
|
|
|
|
|
for my $name (keys %$handle_container) { |
|
33
|
0
|
|
|
|
|
|
my $info = $handle_container->{$name}; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$cv->begin; |
|
36
|
0
|
|
|
|
|
|
my $handle; $handle = AnyEvent::Handle->new( |
|
37
|
|
|
|
|
|
|
fh => $info->{fh}, |
|
38
|
|
|
|
|
|
|
on_read => sub { |
|
39
|
|
|
|
|
|
|
$handle->push_read(line => sub { |
|
40
|
0
|
|
|
|
|
|
my $line = $_[1]; |
|
41
|
0
|
|
|
|
|
|
push @{$info->{output_lines}}, $line; |
|
|
0
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
log info => sprintf "[%s :: %s] %s", |
|
43
|
0
|
|
|
|
|
|
$self->{host}, $name, $line; |
|
44
|
0
|
|
|
0
|
|
|
}); |
|
45
|
|
|
|
|
|
|
}, |
|
46
|
|
|
|
|
|
|
on_eof => sub { |
|
47
|
0
|
|
|
0
|
|
|
$cv->end; |
|
48
|
|
|
|
|
|
|
}, |
|
49
|
|
|
|
|
|
|
on_error => sub { |
|
50
|
0
|
|
|
0
|
|
|
my $msg = $_[2]; |
|
51
|
0
|
0
|
|
|
|
|
log error => sprintf "[%s :: %s] %s", $self->{host}, $name, $msg |
|
52
|
|
|
|
|
|
|
unless $! == POSIX::EPIPE; |
|
53
|
0
|
|
|
|
|
|
$cv->end; |
|
54
|
|
|
|
|
|
|
}, |
|
55
|
0
|
|
|
|
|
|
); |
|
56
|
0
|
|
|
|
|
|
push @$handles, $handle; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$cv->recv; |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
for my $h (@$handles) { |
|
62
|
0
|
|
|
|
|
|
$h->destroy; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub captured_str { |
|
67
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
|
68
|
0
|
0
|
|
|
|
|
my $hinfo = $self->{handle_container}->{$name} or return ''; |
|
69
|
0
|
|
|
|
|
|
my $str = join("\n", @{$hinfo->{output_lines}}); |
|
|
0
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return $str; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |