Perl/prlimit.pm

filter: Statementstmt 65.9% 29 / 44 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 9 / 12 Podpod 100% 2 / 2 totaltotal 59.7% 40 / 67 CC 4 SCAR 13.7
CC
4
Cov
57%
_prlimit64
12.0
set
6.0
get
2.0
CRAP 3.9
« Perl/mq.pm ↑ Summary Perl/timerfd.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 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 1 ▶use Call::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use Linux::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 use parent (
37 1 'Linux::Perl::Base',
38 'Linux::Perl::Base::BitsTest',
39 1 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
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 1 ▶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 1 use constant NAMES => qw(
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 1 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
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 1 ▶use constant NUMBER => { map { ( (NAMES)[$_] => $_ ) } 0 .. (NAMES - 1) };
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 1 ▶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 sub get {
99 0 ▶ my ($class, $pid, $resource) = @_;
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
100  
101 0 Call::Context::must_be_list();
102  
103 0 my $old = pack _TMPL();
104  
105 0 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 sub set {
117 0 ▶ my ($class, $pid, $resource, $soft, $hard) = @_;
Subroutine set: not called CC=2 SCAR=17.9
Pod documented
118  
119 0 my $old;
120  
121 0 ▶ if (defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 0 0 0
122 0 Call::Context::must_be_list();
123  
124 0 $old = pack _TMPL();
125 }
126  
127 0 my $new = pack _TMPL(), $soft, $hard;
128  
129 0 return $class->_prlimit64($pid, $resource, \$new, \$old);
130 }
131  
132 sub _prlimit64 {
133 0 ▶ my ($class, $pid, $resource, $new_sr, $old_sr) = @_;
Subroutine _prlimit64: not called CC=3 SCAR=24.8
134  
135 0 $class = $class->_get_arch_module();
136  
137 0 ▶ Linux::Perl::call( $class->NR_prlimit64(), 0 + $pid, 0 + $resource, $$new_sr, $$old_sr || () );
Condition0%0/3
$$old_sr || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$$old_sr || ()
$$old_sr ()
Truth table0%0/3
A || B
A= $$old_srB= ()
ABresult
1X1
011
000
138  
139 0 ▶ return wantarray ? unpack( _TMPL(), $$old_sr ) : ();
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
140 }
141  
142 1 1;
« Perl/mq.pm ↑ Summary Perl/timerfd.pm »