line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Eixo::Zone::Artifact::PSInit; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Abstraction of a init process |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
2274
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
62
|
|
6
|
2
|
|
|
2
|
|
1427
|
use parent qw(Eixo::Zone::Artifact); |
|
2
|
|
|
|
|
795
|
|
|
2
|
|
|
|
|
18
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new{ |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
0
|
32
|
return bless({ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
code=>$_[1], |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
resume=>$_[2], |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
ctl=>$_[3], |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
pid=>undef, |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
SELF_NETWORK=>undef, |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
SELF_USER=>undef, |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
f_created=>undef, |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
}); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub start{ |
30
|
1
|
|
|
1
|
0
|
7
|
my ($self, %opts) = @_; |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
8
|
my $flags = $self->__setFlags(%opts); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $pid = $self->{ctl}->clone( |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
$self->__createStartCode(), |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$flags |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
$self->{pid} = $pid; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
$self->{f_created} = 1; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
$self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub clear{ |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
0
|
0
|
0
|
$_[0]->end; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub end{ |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
0
|
0
|
0
|
return unless($_[0]->{f_created}); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
kill("TERM", $_[0]->{pid}); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
waitpid($_[0]->{pid}, 0); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
$_[0]->{f_created} = undef; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub integrity{ |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
0
|
0
|
0
|
($_[0]->{f_created}) ? kill(0, $_[0]->{pid}) : 1; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub __setFlags{ |
71
|
1
|
|
|
1
|
|
4
|
my ($self, %opts) = @_; |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
182
|
my $flags = 0 | $self->{ctl}->CLONE_NEWPID | 17; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# new mount? |
76
|
|
|
|
|
|
|
$flags |= $self->{ctl}->CLONE_NEWNS if( |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$opts{MOUNTS} |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# new net |
83
|
|
|
|
|
|
|
$flags |= $self->{ctl}->CLONE_NEWNET if( |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$opts{NETWORK} || $self->{SELF_NETWORK} |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
0
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# new user namespace |
90
|
|
|
|
|
|
|
$flags |= $self->{ctl}->CLONE_NEWUSER if( |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$opts{USER} || $self->{SELF_USER} |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
0
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$flags; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub __createStartCode{ |
100
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# a process should always be able to get its own zone::resume |
103
|
0
|
|
|
|
|
|
my $resume = $self->{resume}; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $init = $self->{code}; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub { |
108
|
|
|
|
|
|
|
|
109
|
2
|
|
|
2
|
|
904
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
161
|
|
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
*{"main::zone_resume"} = sub { |
112
|
0
|
|
|
|
|
|
return $resume; |
113
|
0
|
|
|
0
|
|
|
}; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$init->(); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
118
|
0
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |