line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Umlmgr; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
29665
|
use 5.010000; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
39
|
|
6
|
1
|
|
|
1
|
|
5
|
use base qw(Config::IniFiles); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1337
|
|
7
|
1
|
|
|
1
|
|
45052
|
use Umlmgr::Uml; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
33
|
|
8
|
1
|
|
|
1
|
|
7
|
use Sys::Syslog; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
68
|
|
9
|
1
|
|
|
1
|
|
5
|
use IPC::Open3; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
778
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
1
|
16
|
my ($class, %options) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
4
|
my ($config) = grep { |
17
|
1
|
|
33
|
|
|
6
|
$_ |
18
|
|
|
|
|
|
|
} ($options{config} || ($> != 0 ? "$ENV{HOME}/.umlmgr/config" : '/etc/umlmgr.cfg')); |
19
|
1
|
|
|
|
|
3
|
my $self; |
20
|
1
|
|
|
|
|
1
|
eval { |
21
|
1
|
50
|
|
|
|
37
|
$self = $class->SUPER::new( |
22
|
|
|
|
|
|
|
(-f $config ? (-file => $config) : ()), |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
1
|
50
|
|
|
|
1048
|
$self or return; |
27
|
1
|
|
|
|
|
5
|
bless($self, $class); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub machinesdir { |
31
|
2
|
|
|
2
|
0
|
3
|
my ($self) = @_; |
32
|
2
|
|
|
|
|
14
|
$self->val('machines', 'dir', "$ENV{HOME}/.umlmgr/"); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub list_machines_config { |
36
|
1
|
|
|
1
|
0
|
675
|
my ($self) = @_; |
37
|
1
|
50
|
|
|
|
6
|
if (opendir(my $dh, $self->machinesdir)) { |
38
|
1
|
|
|
|
|
77
|
my @list; |
39
|
1
|
|
|
|
|
23
|
while(my $f = readdir($dh)) { |
40
|
4
|
100
|
|
|
|
19
|
$f =~ /(.+)\.uml$/ or next; |
41
|
1
|
|
|
|
|
5
|
push(@list, $1); |
42
|
|
|
|
|
|
|
} |
43
|
1
|
|
|
|
|
12
|
closedir($dh); |
44
|
1
|
|
|
|
|
8
|
return(@list); |
45
|
|
|
|
|
|
|
} else {} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_machine { |
49
|
1
|
|
|
1
|
0
|
578
|
my ($self, $name) = @_; |
50
|
1
|
|
|
|
|
4
|
return Umlmgr::Uml->new( |
51
|
|
|
|
|
|
|
$self->machinesdir . "/$name.uml", |
52
|
|
|
|
|
|
|
user => $self->val('env', 'user'), |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub setup_network { |
57
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
0
|
|
|
|
if ($> == 0 && ! $self->val('env', 'user')) { |
60
|
0
|
|
|
|
|
|
warn "No user defined, running vm as root is a bad idea\n"; |
61
|
0
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
Sys::Syslog::openlog('umlmgr', 'pid', 'daemon'); |
65
|
0
|
0
|
|
|
|
|
if (my $tap = $self->val('network', 'tap')) { |
66
|
0
|
0
|
|
|
|
|
my $id = $self->val('env', 'user') |
67
|
|
|
|
|
|
|
? Umlmgr::Utils::get_id($self->val('env', 'user')) |
68
|
|
|
|
|
|
|
: undef; |
69
|
0
|
0
|
|
|
|
|
system( |
70
|
|
|
|
|
|
|
'tunctl', |
71
|
|
|
|
|
|
|
($id ? ('-u', $id) : ()), |
72
|
|
|
|
|
|
|
'-t', $tap |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
} |
75
|
0
|
0
|
|
|
|
|
if ($self->val('network', 'switch')) { |
76
|
0
|
|
|
|
|
|
my $pid = fork; |
77
|
0
|
0
|
|
|
|
|
return if(!defined $pid); |
78
|
0
|
0
|
|
|
|
|
if ($pid) { |
79
|
|
|
|
|
|
|
} else { |
80
|
0
|
0
|
|
|
|
|
Umlmgr::Utils::become_user($self->val('env', 'user')) |
81
|
|
|
|
|
|
|
if ($self->val('env', 'user')); |
82
|
0
|
|
|
|
|
|
close(STDIN); |
83
|
|
|
|
|
|
|
#close(STDOUT); |
84
|
0
|
0
|
|
|
|
|
exec(join(' ', map { quotemeta($_) } |
|
0
|
0
|
|
|
|
|
|
85
|
|
|
|
|
|
|
('uml_switch', |
86
|
|
|
|
|
|
|
($self->val('network', 'hub') ? ('-hub') : ()), |
87
|
|
|
|
|
|
|
($self->val('network', 'tap') |
88
|
|
|
|
|
|
|
? ('-tap', $self->val('network', 'tap')) |
89
|
|
|
|
|
|
|
: ()), |
90
|
|
|
|
|
|
|
)) . ' < /dev/null > /dev/null' |
91
|
|
|
|
|
|
|
); |
92
|
0
|
|
|
|
|
|
exit(0); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub start { |
98
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
99
|
0
|
|
|
|
|
|
foreach my $m ($self->list_machines_config) { |
100
|
0
|
|
|
|
|
|
my $ma = $self->get_machine($m); |
101
|
0
|
0
|
|
|
|
|
$ma->onboot or next; |
102
|
0
|
0
|
|
|
|
|
$ma->status and next; |
103
|
0
|
|
|
|
|
|
$ma->start; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub stop { |
108
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
109
|
0
|
|
|
|
|
|
foreach my $m ($self->list_machines_config) { |
110
|
0
|
|
|
|
|
|
my $ma = $self->get_machine($m); |
111
|
0
|
|
|
|
|
|
$ma->stop; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Preloaded methods go here. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
__END__ |