line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::IOLoop::ReadWriteProcess::CGroup; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
27035
|
use Mojo::Base -base; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
103
|
|
4
|
15
|
|
|
15
|
|
2859
|
use Mojo::File 'path'; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
645
|
|
5
|
|
|
|
|
|
|
|
6
|
15
|
|
|
15
|
|
6425
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1; |
|
15
|
|
|
|
|
33
|
|
|
15
|
|
|
|
|
754
|
|
7
|
15
|
|
|
15
|
|
6167
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2; |
|
15
|
|
|
|
|
42
|
|
|
15
|
|
|
|
|
729
|
|
8
|
15
|
|
|
15
|
|
122
|
use File::Spec::Functions 'splitdir'; |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
964
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(cgroupv2 cgroupv1); |
11
|
15
|
|
|
15
|
|
90
|
use Exporter 'import'; |
|
15
|
|
|
|
|
18
|
|
|
15
|
|
|
|
|
694
|
|
12
|
|
|
|
|
|
|
|
13
|
15
|
|
100
|
15
|
|
80
|
use constant CGROUP_FS => $ENV{MOJO_CGROUP_FS} // '/sys/fs/cgroup'; |
|
15
|
|
|
|
|
33
|
|
|
15
|
|
|
|
|
983
|
|
14
|
15
|
|
|
15
|
|
78
|
use constant DEBUG => $ENV{MOJO_PROCESS_DEBUG}; |
|
15
|
|
|
|
|
29
|
|
|
15
|
|
|
|
|
16204
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has '_vfs' => sub { CGROUP_FS() }; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has [qw(name parent)]; |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
5
|
0
|
4973
|
sub cgroupv2 { Mojo::IOLoop::ReadWriteProcess::CGroup::v2->new(@_)->create } |
21
|
29
|
|
|
29
|
0
|
55119
|
sub cgroupv1 { Mojo::IOLoop::ReadWriteProcess::CGroup::v1->new(@_)->create } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub from { |
24
|
4
|
|
|
4
|
0
|
96
|
my ($self, $string) = @_; |
25
|
4
|
|
|
|
|
10
|
my $g = $self->_vfs; |
26
|
4
|
|
|
|
|
41
|
$string =~ s/$g//; |
27
|
4
|
|
|
|
|
42
|
my @p = splitdir($string); |
28
|
4
|
|
|
|
|
39
|
my $pre = substr $string, 0, 1; |
29
|
4
|
100
|
|
|
|
25
|
shift @p if $pre eq '/'; |
30
|
4
|
|
|
|
|
8
|
my $name = shift @p; |
31
|
4
|
|
|
|
|
12
|
return $_[0]->new(name => $name, parent => path(@p)); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _cgroup { |
35
|
107
|
100
|
50
|
107
|
|
16413
|
path($_[0]->parent |
|
|
|
100
|
|
|
|
|
36
|
|
|
|
|
|
|
? path($_[0]->_vfs, $_[0]->name // '', $_[0]->parent) |
37
|
|
|
|
|
|
|
: path($_[0]->_vfs, $_[0]->name // '')); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
208
|
100
|
|
208
|
0
|
5539
|
sub create { $_[0]->_cgroup->make_path unless -d $_[0]->_cgroup; $_[0] } |
|
207
|
|
|
|
|
46830
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# TODO: Make sure there aren't pid belonging to cgroup before removing |
43
|
|
|
|
|
|
|
# This is done in Container class, but we might want to warn in case this is hit |
44
|
87
|
|
|
87
|
0
|
13726
|
sub remove { rmdir $_[0]->_cgroup->to_string } #->remove_tree() } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub child { |
47
|
1
|
50
|
|
1
|
0
|
762
|
return $_[0]->new( |
48
|
|
|
|
|
|
|
name => $_[0]->name, |
49
|
|
|
|
|
|
|
parent => $_[0]->parent ? path($_[0]->parent, $_[1]) : $_[1])->create; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
70
|
|
|
70
|
0
|
10236
|
sub exists { -d $_[0]->_cgroup } |
53
|
|
|
|
|
|
|
|
54
|
48
|
|
|
48
|
|
821
|
sub _append { my $h = $_[0]->_cgroup->child($_[1])->open('>>'); print $h pop() } |
|
48
|
|
|
|
|
28730
|
|
55
|
4
|
|
|
4
|
|
39
|
sub _write { my $h = $_[0]->_cgroup->child($_[1])->open('>'); print $h pop() } |
|
4
|
|
|
|
|
951
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _flag { |
58
|
18
|
|
|
18
|
|
124
|
my $f = pop; |
59
|
18
|
|
|
|
|
48
|
my $h = $_[0]->_cgroup->child($_[1])->open('>'); |
60
|
18
|
100
|
|
|
|
4594
|
print $h ($f == 0 ? 0 : 1); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
48
|
|
|
48
|
|
561
|
sub _appendln { shift->_append(shift() => pop() . "\n") } |
64
|
352
|
100
|
|
352
|
|
2198
|
sub _list { my $c = shift->_cgroup->child(pop); $c->slurp if -e $c } |
|
352
|
|
|
|
|
35677
|
|
65
|
146
|
|
|
146
|
|
547
|
sub _listarray { split(/\n/, shift->_list(@_)) } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _contains { |
68
|
79
|
|
|
79
|
|
219
|
my $p = pop; |
69
|
79
|
|
|
|
|
623
|
my $i = pop; |
70
|
79
|
|
|
|
|
481
|
grep { $p eq $_ } shift->_listarray($i); |
|
103
|
|
|
|
|
9946
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _setget { |
74
|
64
|
100
|
|
64
|
|
444
|
$_[2] |
75
|
|
|
|
|
|
|
? shift->_cgroup->child($_[0])->spurt($_[1]) |
76
|
|
|
|
|
|
|
: shift->_cgroup->child($_[0])->slurp; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=encoding utf-8 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Mojo::IOLoop::ReadWriteProcess::CGroup - Base object for CGroups implementations. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SYNOPSIS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
use Mojo::IOLoop::ReadWriteProcess::CGroup; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $cgroup = Mojo::IOLoop::ReadWriteProcess::CGroup->new( name => "test" ); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$cgroup->create; |
94
|
|
|
|
|
|
|
$cgroup->exists; |
95
|
|
|
|
|
|
|
my $child = $cgroup->child('bar'); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 DESCRIPTION |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This module uses features that are only available on Linux, |
100
|
|
|
|
|
|
|
and requires cgroups and capability for unshare syscalls to achieve pid isolation. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 METHODS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
L inherits all methods from L and implements |
105
|
|
|
|
|
|
|
the following new ones. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 LICENSE |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Copyright (C) Ettore Di Giacinto. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
112
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Ettore Di Giacinto Eedigiacinto@suse.comE |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |