| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Ubic::PortMap; |
|
2
|
|
|
|
|
|
|
$Ubic::PortMap::VERSION = '1.60'; |
|
3
|
1
|
|
|
1
|
|
1669
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
22
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: update and read mapping of ports to service names. |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
3
|
use Try::Tiny; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
40
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use Params::Validate qw(:all); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
113
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
228
|
use Ubic::Logger; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
40
|
|
|
13
|
1
|
|
|
1
|
|
4
|
use Ubic::Persistent; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
14
|
|
|
14
|
1
|
|
|
1
|
|
3
|
use Ubic; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
302
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _portmap_file { |
|
17
|
0
|
|
|
0
|
|
|
my $ubic_dir = Ubic->get_data_dir; |
|
18
|
0
|
|
|
|
|
|
my $PORTMAP_FILE = $ubic_dir.'/portmap'; |
|
19
|
0
|
|
|
|
|
|
return $PORTMAP_FILE; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub update { |
|
23
|
0
|
|
|
0
|
1
|
|
validate_pos(@_); |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $portmap = Ubic::Persistent->new(_portmap_file()); |
|
26
|
0
|
|
|
|
|
|
my %port2service; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $process_tree; |
|
29
|
|
|
|
|
|
|
$process_tree = sub { |
|
30
|
0
|
|
0
|
0
|
|
|
my $service = shift() || Ubic->root_service; |
|
31
|
0
|
|
|
|
|
|
for $_ ($service->services) { |
|
32
|
0
|
0
|
|
|
|
|
if ($_->isa('Ubic::Multiservice')) { |
|
33
|
|
|
|
|
|
|
# multiservice |
|
34
|
0
|
|
|
|
|
|
$process_tree->($_); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
else { |
|
37
|
|
|
|
|
|
|
try { |
|
38
|
0
|
|
|
|
|
|
my $port = $_->port; |
|
39
|
0
|
0
|
|
|
|
|
if ($port) { |
|
40
|
0
|
|
|
|
|
|
push @{ $portmap->{$port} }, $_->full_name; |
|
|
0
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
catch { |
|
44
|
0
|
|
|
|
|
|
ERROR $_; |
|
45
|
0
|
|
|
|
|
|
}; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
0
|
|
|
|
|
|
return; |
|
49
|
0
|
|
|
|
|
|
}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
for (keys %{$portmap}) { |
|
|
0
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
next unless /^\d+$/; |
|
53
|
0
|
|
|
|
|
|
delete $portmap->{$_}; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
0
|
|
|
|
|
|
$process_tree->(); |
|
56
|
0
|
|
|
|
|
|
$portmap->commit(); |
|
57
|
0
|
|
|
|
|
|
undef $portmap; # fighting memory leaks - closure doesn't allow local variable to be destroyed |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub port2name($) { |
|
63
|
0
|
|
|
0
|
1
|
|
my ($port) = validate_pos(@_, { regex => qr/^\d+$/ }); |
|
64
|
0
|
|
|
|
|
|
my $portmap = Ubic::Persistent->load(_portmap_file()); |
|
65
|
0
|
0
|
|
|
|
|
return unless $portmap->{$port}; |
|
66
|
0
|
|
|
|
|
|
my @names = @{ $portmap->{$port} }; |
|
|
0
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
while (my $name = shift @names) { |
|
68
|
0
|
0
|
|
|
|
|
return $name unless @names; # return last service even if it's disabled |
|
69
|
0
|
0
|
|
|
|
|
return $name if Ubic->is_enabled($name); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |