line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ControlFreak::Util; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
60
|
use strict; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
321
|
|
4
|
8
|
|
|
8
|
|
45
|
use warnings; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
264
|
|
5
|
8
|
|
|
8
|
|
9391
|
use IO::Socket::UNIX(); |
|
8
|
|
|
|
|
124608
|
|
|
8
|
|
|
|
|
203
|
|
6
|
8
|
|
|
8
|
|
71
|
use IO::Socket::INET(); |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
127
|
|
7
|
8
|
|
|
8
|
|
9372
|
use POSIX(); |
|
8
|
|
|
|
|
66397
|
|
|
8
|
|
|
|
|
259
|
|
8
|
8
|
|
|
8
|
|
75
|
use Socket qw(SOCK_STREAM); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
6139
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub parse_unix { |
11
|
0
|
|
0
|
0
|
0
|
0
|
my $address = shift || ""; |
12
|
|
|
|
|
|
|
|
13
|
0
|
0
|
0
|
|
|
0
|
if ($address =~ m!^unix:(.+)!) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
14
|
0
|
|
|
|
|
0
|
return $1; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
elsif ($address =~ m!^/!) { |
17
|
0
|
|
|
|
|
0
|
return $address; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
## relative path to a socket. This is bad, maybe I'd better ignore it? |
20
|
|
|
|
|
|
|
elsif ($address =~ m!^\w.*/! && $address !~ m!:!) { |
21
|
0
|
|
|
|
|
0
|
return $address; |
22
|
|
|
|
|
|
|
} |
23
|
0
|
|
|
|
|
0
|
return; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub get_sock_from_addr { |
27
|
0
|
|
|
0
|
0
|
0
|
my $address = shift; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
my $unix = parse_unix($address); |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
0
|
if ($unix) { |
32
|
0
|
|
|
|
|
0
|
return IO::Socket::UNIX->new( |
33
|
|
|
|
|
|
|
Type => SOCK_STREAM, |
34
|
|
|
|
|
|
|
Peer => $unix, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
0
|
$address =~ s{/+$}{}; |
39
|
0
|
|
|
|
|
0
|
my $sock = IO::Socket::INET->new( |
40
|
|
|
|
|
|
|
PeerAddr => $address, |
41
|
|
|
|
|
|
|
Proto => 'tcp', |
42
|
|
|
|
|
|
|
); |
43
|
0
|
0
|
|
|
|
0
|
return unless $sock; |
44
|
0
|
|
|
|
|
0
|
$sock->autoflush(1); |
45
|
0
|
|
|
|
|
0
|
return $sock; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
## conveniently, log to the "log" priority, |
49
|
|
|
|
|
|
|
## and call the error callback if one is specified. |
50
|
|
|
|
|
|
|
sub error { |
51
|
3
|
|
|
3
|
0
|
52
|
my $object = shift; |
52
|
3
|
|
|
|
|
6
|
my $err_msg = pop; |
53
|
3
|
|
|
|
|
10
|
my %param = @_; |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
72
|
my $log = $object->{ctrl}->log; |
56
|
3
|
|
|
|
|
25
|
$log->error($err_msg); |
57
|
3
|
|
50
|
0
|
|
466
|
my $err_cb = $param{err_cb} || sub {}; |
|
0
|
|
|
|
|
0
|
|
58
|
3
|
|
|
|
|
9
|
return $err_cb->($err_msg); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub exit_reason { |
62
|
21
|
|
|
21
|
0
|
59
|
my $status = shift; |
63
|
|
|
|
|
|
|
|
64
|
21
|
|
|
|
|
86
|
my $exit_status = POSIX::WEXITSTATUS($status); |
65
|
21
|
|
|
|
|
70
|
my $signal = POSIX::WTERMSIG($status); |
66
|
|
|
|
|
|
|
|
67
|
21
|
|
|
|
|
34
|
my ($exit, $sig); |
68
|
21
|
100
|
|
|
|
109
|
if (POSIX::WIFEXITED($status)) { |
69
|
14
|
50
|
|
|
|
171
|
$exit = $exit_status |
70
|
|
|
|
|
|
|
? "Exited with error $exit_status" |
71
|
|
|
|
|
|
|
: "Exited successfuly"; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
21
|
100
|
|
|
|
292
|
$sig = "Received signal $signal" if POSIX::WIFSIGNALED($status); |
75
|
21
|
|
|
|
|
76
|
return join " - ", grep { $_ } ($exit, $sig); |
|
42
|
|
|
|
|
323
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |