Perl/prlimit.pm

filter: Statementstmt 100% 44 / 44 Branchbran 100% 4 / 4 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 100% 65 / 65 CC 4 SCAR 4.3
CC
4
Cov
100%
_prlimit64
3.0
set
2.0
BEGIN
1.0
CRAP 1.5
« Perl/signalfd.pm ↑ Summary Perl/Base.pm »
1 package Linux::Perl::prlimit;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Linux::Perl::prlimit
8  
9 =head1 SYNOPSIS
10  
11 my ($soft, $hard) = Linux::Perl::prlimit->get(
12 0,
13 Linux::Perl::prlimit::NUMBER()->{'NPROC'}
14 );
15  
16 my ($old_soft, $old_hard) = Linux::Perl::prlimit->get(
17 0,
18 Linux::Perl::prlimit::NUMBER()->{'NPROC'},
19 $new_soft,
20 $new_hard,
21 );
22  
23 =head1 DESCRIPTION
24  
25 This module provides access to Linux’s facility for getting and setting
26 an arbitrary process’s rlimits.
27  
28 =cut
29  
30 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 5 ▶use Call::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use Linux::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 5 ▶use parent (
Subroutine BEGIN: called CC=1 SCAR=0.0
37 5 'Linux::Perl::Base',
38 'Linux::Perl::Base::BitsTest',
39 5 );
40  
41 #----------------------------------------------------------------------
42  
43 =head1 CONSTANTS
44  
45 =head2 INFINITY
46  
47 Equivalent to the kernel’s RLIM_INFINITY constant.
48  
49 =cut
50  
51 5 ▶use constant INFINITY => ~0;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 =head2 NAMES
54  
55 A list of resource names, e.g., C<CPU>. (cf. C<man 2 prlimit>)
56  
57 =cut
58  
59 5 ▶use constant NAMES => qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
60 CPU
61 FSIZE
62 DATA
63 STACK
64 CORE
65 RSS
66 NPROC
67 NOFILE
68 MEMLOCK
69 AS
70 LOCKS
71 SIGPENDING
72 MSGQUEUE
73 NICE
74 RTPRIO
75 RTTIME
76 5 );
77  
78 =head2 NUMBER
79  
80 A reference to a hash that correlates resource name (e.g., C<FSIZE>) to number.
81  
82 =cut
83  
84 5 ▶use constant NUMBER => { map { ( (NAMES)[$_] => $_ ) } 0 .. (NAMES - 1) };
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 5 ▶use constant _TMPL => (__PACKAGE__->_PACK_u64() x 2);
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 #----------------------------------------------------------------------
89  
90 =head1 METHODS
91  
92 =head2 ($soft, $hard) = I<CLASS>->get( $PID, $RESOURCE_NUM )
93  
94 Fetches an individual resource limit. Must be called in list context.
95  
96 =cut
97  
98 8 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
99 8 my ($class, $pid, $resource) = @_;
100  
101 8 Call::Context::must_be_list();
102  
103 8 my $old = pack _TMPL();
104  
105 8 return $class->_prlimit64($pid, $resource, \undef, \$old);
106 }
107  
108 =head2 ($old_soft, $old_hard) = I<CLASS>->set( $PID, $RESOURCE_NUM, $SOFT, $HARD )
109  
110 Sets an individual resource limit. If called in list context
111 will return the old soft/hard limits. Must not be called in
112 scalar context.
113  
114 =cut
115  
116 12 ▶sub set {
Subroutine set: called CC=2 SCAR=6.9
Pod documented
117 12 my ($class, $pid, $resource, $soft, $hard) = @_;
118  
119 12 my $old;
120  
121 12 ▶ if (defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 10 2 12
122 10 Call::Context::must_be_list();
123  
124 10 $old = pack _TMPL();
125 }
126  
127 12 my $new = pack _TMPL(), $soft, $hard;
128  
129 12 return $class->_prlimit64($pid, $resource, \$new, \$old);
130 }
131  
132 20 ▶sub _prlimit64 {
Subroutine _prlimit64: called CC=3 SCAR=11.0
133 20 my ($class, $pid, $resource, $new_sr, $old_sr) = @_;
134  
135 20 $class = $class->_get_arch_module();
136  
137 # The `|| 0` avoids a warning from Perl about
138 # undefined values passed to syscall().
139 20 ▶ Linux::Perl::call( $class->NR_prlimit64(), 0 + $pid, 0 + $resource, $$new_sr, $$old_sr || 0 );
Condition100%2/2
$$old_sr || 0
l!l
182
MC/DC100%1/1
$$old_sr || 0
$$old_sr
Truth table100%2/2
A
A= $$old_sr
Aresult
11
00
140  
141 20 ▶ return wantarray ? unpack( _TMPL(), $$old_sr ) : ();
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 18 2 20
142 }
143  
144 5 1;
« Perl/signalfd.pm ↑ Summary Perl/Base.pm »