line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::IOLoop::ReadWriteProcess::CGroup; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
17970
|
use Mojo::Base -base; |
|
15
|
|
|
|
|
29
|
|
|
15
|
|
|
|
|
114
|
|
4
|
15
|
|
|
15
|
|
3162
|
use Mojo::File 'path'; |
|
15
|
|
|
|
|
29
|
|
|
15
|
|
|
|
|
702
|
|
5
|
|
|
|
|
|
|
|
6
|
15
|
|
|
15
|
|
6734
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1; |
|
15
|
|
|
|
|
41
|
|
|
15
|
|
|
|
|
790
|
|
7
|
15
|
|
|
15
|
|
6342
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2; |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
743
|
|
8
|
15
|
|
|
15
|
|
115
|
use File::Spec::Functions 'splitdir'; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
1025
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(cgroupv2 cgroupv1); |
11
|
15
|
|
|
15
|
|
101
|
use Exporter 'import'; |
|
15
|
|
|
|
|
19
|
|
|
15
|
|
|
|
|
1100
|
|
12
|
|
|
|
|
|
|
|
13
|
15
|
|
100
|
15
|
|
174
|
use constant CGROUP_FS => $ENV{MOJO_CGROUP_FS} // '/sys/fs/cgroup'; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
1127
|
|
14
|
15
|
|
|
15
|
|
91
|
use constant DEBUG => $ENV{MOJO_PROCESS_DEBUG}; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
16947
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has '_vfs' => sub { CGROUP_FS() }; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has [qw(name parent)]; |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
5
|
0
|
4233
|
sub cgroupv2 { Mojo::IOLoop::ReadWriteProcess::CGroup::v2->new(@_)->create } |
21
|
29
|
|
|
29
|
0
|
46891
|
sub cgroupv1 { Mojo::IOLoop::ReadWriteProcess::CGroup::v1->new(@_)->create } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub from { |
24
|
4
|
|
|
4
|
0
|
95
|
my ($self, $string) = @_; |
25
|
4
|
|
|
|
|
11
|
my $g = $self->_vfs; |
26
|
4
|
|
|
|
|
49
|
$string =~ s/$g//; |
27
|
4
|
|
|
|
|
45
|
my @p = splitdir($string); |
28
|
4
|
|
|
|
|
39
|
my $pre = substr $string, 0, 1; |
29
|
4
|
100
|
|
|
|
22
|
shift @p if $pre eq '/'; |
30
|
4
|
|
|
|
|
8
|
my $name = shift @p; |
31
|
4
|
|
|
|
|
13
|
return $_[0]->new(name => $name, parent => path(@p)); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _cgroup { |
35
|
107
|
100
|
50
|
107
|
|
14662
|
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
|
5558
|
sub create { $_[0]->_cgroup->make_path unless -d $_[0]->_cgroup; $_[0] } |
|
207
|
|
|
|
|
46487
|
|
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
|
14113
|
sub remove { rmdir $_[0]->_cgroup->to_string } #->remove_tree() } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub child { |
47
|
1
|
50
|
|
1
|
0
|
558
|
return $_[0]->new( |
48
|
|
|
|
|
|
|
name => $_[0]->name, |
49
|
|
|
|
|
|
|
parent => $_[0]->parent ? path($_[0]->parent, $_[1]) : $_[1])->create; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
70
|
|
|
70
|
0
|
10226
|
sub exists { -d $_[0]->_cgroup } |
53
|
|
|
|
|
|
|
|
54
|
48
|
|
|
48
|
|
596
|
sub _append { my $h = $_[0]->_cgroup->child($_[1])->open('>>'); print $h pop() } |
|
48
|
|
|
|
|
28563
|
|
55
|
4
|
|
|
4
|
|
37
|
sub _write { my $h = $_[0]->_cgroup->child($_[1])->open('>'); print $h pop() } |
|
4
|
|
|
|
|
933
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _flag { |
58
|
18
|
|
|
18
|
|
135
|
my $f = pop; |
59
|
18
|
|
|
|
|
48
|
my $h = $_[0]->_cgroup->child($_[1])->open('>'); |
60
|
18
|
100
|
|
|
|
4415
|
print $h ($f == 0 ? 0 : 1); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
48
|
|
|
48
|
|
576
|
sub _appendln { shift->_append(shift() => pop() . "\n") } |
64
|
352
|
100
|
|
352
|
|
1868
|
sub _list { my $c = shift->_cgroup->child(pop); $c->slurp if -e $c } |
|
352
|
|
|
|
|
39432
|
|
65
|
146
|
|
|
146
|
|
644
|
sub _listarray { split(/\n/, shift->_list(@_)) } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _contains { |
68
|
79
|
|
|
79
|
|
364
|
my $p = pop; |
69
|
79
|
|
|
|
|
587
|
my $i = pop; |
70
|
79
|
|
|
|
|
598
|
grep { $p eq $_ } shift->_listarray($i); |
|
103
|
|
|
|
|
9513
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _setget { |
74
|
64
|
100
|
|
64
|
|
482
|
$_[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 |