line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::IOLoop::ReadWriteProcess::CGroup; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
27060
|
use Mojo::Base -base; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
140
|
|
4
|
15
|
|
|
15
|
|
2585
|
use Mojo::File 'path'; |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
713
|
|
5
|
|
|
|
|
|
|
|
6
|
15
|
|
|
15
|
|
6606
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1; |
|
15
|
|
|
|
|
35
|
|
|
15
|
|
|
|
|
718
|
|
7
|
15
|
|
|
15
|
|
6830
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2; |
|
15
|
|
|
|
|
44
|
|
|
15
|
|
|
|
|
715
|
|
8
|
15
|
|
|
15
|
|
107
|
use File::Spec::Functions 'splitdir'; |
|
15
|
|
|
|
|
19
|
|
|
15
|
|
|
|
|
939
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(cgroupv2 cgroupv1); |
11
|
15
|
|
|
15
|
|
90
|
use Exporter 'import'; |
|
15
|
|
|
|
|
21
|
|
|
15
|
|
|
|
|
620
|
|
12
|
|
|
|
|
|
|
|
13
|
15
|
|
100
|
15
|
|
89
|
use constant CGROUP_FS => $ENV{MOJO_CGROUP_FS} // '/sys/fs/cgroup'; |
|
15
|
|
|
|
|
18
|
|
|
15
|
|
|
|
|
944
|
|
14
|
15
|
|
|
15
|
|
79
|
use constant DEBUG => $ENV{MOJO_PROCESS_DEBUG}; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
17230
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has '_vfs' => sub { CGROUP_FS() }; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has [qw(name parent)]; |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
5
|
0
|
4987
|
sub cgroupv2 { Mojo::IOLoop::ReadWriteProcess::CGroup::v2->new(@_)->create } |
21
|
29
|
|
|
29
|
0
|
67155
|
sub cgroupv1 { Mojo::IOLoop::ReadWriteProcess::CGroup::v1->new(@_)->create } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub from { |
24
|
4
|
|
|
4
|
0
|
100
|
my ($self, $string) = @_; |
25
|
4
|
|
|
|
|
12
|
my $g = $self->_vfs; |
26
|
4
|
|
|
|
|
42
|
$string =~ s/$g//; |
27
|
4
|
|
|
|
|
46
|
my @p = splitdir($string); |
28
|
4
|
|
|
|
|
38
|
my $pre = substr $string, 0, 1; |
29
|
4
|
100
|
|
|
|
18
|
shift @p if $pre eq '/'; |
30
|
4
|
|
|
|
|
8
|
my $name = shift @p; |
31
|
4
|
|
|
|
|
11
|
return $_[0]->new(name => $name, parent => path(@p)); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _cgroup { |
35
|
107
|
100
|
50
|
107
|
|
16989
|
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
|
6201
|
sub create { $_[0]->_cgroup->make_path unless -d $_[0]->_cgroup; $_[0] } |
|
207
|
|
|
|
|
50741
|
|
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
|
13887
|
sub remove { rmdir $_[0]->_cgroup->to_string } #->remove_tree() } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub child { |
47
|
1
|
50
|
|
1
|
0
|
728
|
return $_[0]->new( |
48
|
|
|
|
|
|
|
name => $_[0]->name, |
49
|
|
|
|
|
|
|
parent => $_[0]->parent ? path($_[0]->parent, $_[1]) : $_[1])->create; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
70
|
|
|
70
|
0
|
10879
|
sub exists { -d $_[0]->_cgroup } |
53
|
|
|
|
|
|
|
|
54
|
48
|
|
|
48
|
|
917
|
sub _append { my $h = $_[0]->_cgroup->child($_[1])->open('>>'); print $h pop() } |
|
48
|
|
|
|
|
30505
|
|
55
|
4
|
|
|
4
|
|
38
|
sub _write { my $h = $_[0]->_cgroup->child($_[1])->open('>'); print $h pop() } |
|
4
|
|
|
|
|
1033
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _flag { |
58
|
18
|
|
|
18
|
|
128
|
my $f = pop; |
59
|
18
|
|
|
|
|
53
|
my $h = $_[0]->_cgroup->child($_[1])->open('>'); |
60
|
18
|
100
|
|
|
|
4903
|
print $h ($f == 0 ? 0 : 1); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
48
|
|
|
48
|
|
885
|
sub _appendln { shift->_append(shift() => pop() . "\n") } |
64
|
352
|
100
|
|
352
|
|
2365
|
sub _list { my $c = shift->_cgroup->child(pop); $c->slurp if -e $c } |
|
352
|
|
|
|
|
39540
|
|
65
|
146
|
|
|
146
|
|
786
|
sub _listarray { split(/\n/, shift->_list(@_)) } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _contains { |
68
|
79
|
|
|
79
|
|
348
|
my $p = pop; |
69
|
79
|
|
|
|
|
360
|
my $i = pop; |
70
|
79
|
|
|
|
|
392
|
grep { $p eq $_ } shift->_listarray($i); |
|
103
|
|
|
|
|
10396
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _setget { |
74
|
64
|
100
|
|
64
|
|
473
|
$_[2] |
75
|
|
|
|
|
|
|
? shift->_cgroup->child($_[0])->spew($_[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 |