| 1 | # Copyrights 2011-2020 by [Mark Overmeer]. | ||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||||||
| 5 | # This code is part of distribution POSIX-1003. Meta-POD processed with | ||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | package POSIX::1003::Limit; | ||||||||||||||||||||||
| 10 | 6 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 6 | $VERSION = '1.02'; | |||||||||||||||||||||
| 12 | |||||||||||||||||||||||
| 13 | 6 | ▶ | use base 'POSIX::1003::Module'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | 6 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | 6 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | 6 | ▶ | use Carp 'croak'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | 6 | my (@ulimit, @rlimit, @constants, @functions); | |||||||||||||||||||||
| 21 | 6 | our %EXPORT_TAGS = | |||||||||||||||||||||
| 22 | ( ulimit => \@ulimit | ||||||||||||||||||||||
| 23 | , rlimit => \@rlimit | ||||||||||||||||||||||
| 24 | , constants => \@constants | ||||||||||||||||||||||
| 25 | , functions => \@functions | ||||||||||||||||||||||
| 26 | , tables => [ qw/%ulimit %rlimit/ ] | ||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | 6 | my ($ulimit, $rlimit); | |||||||||||||||||||||
| 30 | 6 | our (%ulimit, %rlimit); | |||||||||||||||||||||
| 31 | 6 | my ($rlim_saved_max, $rlim_saved_cur, $rlim_infinity); | |||||||||||||||||||||
| 32 | |||||||||||||||||||||||
| 33 | 6 | ▶ | BEGIN { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 34 | 6 | my @ufuncs = qw/ulimit ulimit_names/; | |||||||||||||||||||||
| 35 | 6 | my @rfuncs = qw/getrlimit setrlimit rlimit_names/; | |||||||||||||||||||||
| 36 | 6 | my @rconst = qw/RLIM_SAVED_MAX RLIM_SAVED_CUR RLIM_INFINITY/; | |||||||||||||||||||||
| 37 | |||||||||||||||||||||||
| 38 | 6 | $ulimit = ulimit_table; | |||||||||||||||||||||
| 39 | 6 | @ulimit = (keys %$ulimit, @ufuncs, '%ulimit'); | |||||||||||||||||||||
| 40 | 6 | tie %ulimit, 'POSIX::1003::ReadOnlyTable', $ulimit; | |||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | 6 | $rlimit = rlimit_table; | |||||||||||||||||||||
| 43 | 6 | @rlimit = (keys %$rlimit, @rfuncs, @rconst, '%rlimit'); | |||||||||||||||||||||
| 44 | 6 | tie %rlimit, 'POSIX::1003::ReadOnlyTable', $rlimit; | |||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | 6 | push @constants, keys %$ulimit, keys %$rlimit; | |||||||||||||||||||||
| 47 | 6 | push @functions, @ufuncs, @rfuncs; | |||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | 6 | $rlim_saved_max = delete $rlimit->{RLIM_SAVED_MAX}; | |||||||||||||||||||||
| 50 | 6 | $rlim_saved_cur = delete $rlimit->{RLIM_SAVED_CUR}; | |||||||||||||||||||||
| 51 | 6 | $rlim_infinity = delete $rlimit->{RLIM_INFINITY}; | |||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | 3 | ▶ | sub RLIM_SAVED_MAX { $rlim_saved_max } | ||||||||||||||||||||
|
Subroutine
RLIM_SAVED_MAX: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 55 | 2 | ▶ | sub RLIM_SAVED_CUR { $rlim_saved_cur } | ||||||||||||||||||||
|
Subroutine
RLIM_SAVED_CUR: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 56 | 3 | ▶ | sub RLIM_INFINITY { $rlim_infinity } | ||||||||||||||||||||
|
Subroutine
RLIM_INFINITY: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | sub getrlimit($); | ||||||||||||||||||||||
| 59 | sub setrlimit($$;$); | ||||||||||||||||||||||
| 60 | sub ulimit($;$); | ||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | |||||||||||||||||||||||
| 63 | sub exampleValue($) | ||||||||||||||||||||||
| 64 | 0 | ▶ | { my ($class, $name) = @_; | ||||||||||||||||||||
|
Subroutine
exampleValue: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||
| 65 | 0 | ▶ | if($name =~ m/^RLIMIT_/) | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 66 | 0 | { my ($soft, $hard, $success) = getrlimit $name; | |||||||||||||||||||||
| 67 | 0 | for($soft,$hard) | |||||||||||||||||||||
| 68 | 0 | ▶ | { $_ //= 'undef'; | ||||||||||||||||||||
|
Condition0%0/2
$_ //= "undef"
MC/DC0%0/1
$_ //= "undef"
$_
Truth table0%0/2
A
A= $_
| |||||||||||||||||||||||
| 69 | 0 | s/18446744073709551615/2**64-1/g; | |||||||||||||||||||||
| 70 | 0 | s/9223372036854775807/2**63-1/g; | |||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||
| 72 | 0 | return "$rlimit->{$name}, $soft, $hard"; | |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||
| 74 | elsif($name =~ m/^RLIM_/) | ||||||||||||||||||||||
| 75 | 0 | ▶ | { return $rlimit->{$name} // 'undef'; | ||||||||||||||||||||
|
Condition0%0/2
$rlimit->{$name} // "undef"
MC/DC0%0/1
$rlimit->{$name} // "undef"
$rlimit->{$name}
Truth table0%0/2
A
A= $rlimit->{$name}
| |||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||
| 77 | elsif($name =~ m/^UL_GET|^GET_/) | ||||||||||||||||||||||
| 78 | 0 | { my $val = ulimit $name; | |||||||||||||||||||||
| 79 | 0 | ▶ | return defined $val ? $val : 'undef'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||
| 81 | elsif($name =~ m/^UL_SET|^SET_/) | ||||||||||||||||||||||
| 82 | 0 | { return '(setter)'; | |||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||
| 84 | else | ||||||||||||||||||||||
| 85 | 0 | { $class->SUPER::exampleValue($name); | |||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||
| 88 | |||||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | sub ulimit($;$) | ||||||||||||||||||||||
| 91 | 7 | ▶ | { my $key = shift // return; | ||||||||||||||||||||
|
Subroutine
ulimit: called CC=7 SCAR=20.0
Pod
documented
Condition50%1/2
shift() // (return)
MC/DC0%0/1
shift() // (return)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||
| 92 | 7 | ▶ | if(@_) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 93 | 1 | ▶ | { $key =~ /^UL_SET|^SET_/ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 94 | or croak "pass the constant name as string ($key)"; | ||||||||||||||||||||||
| 95 | 1 | ▶ | my $id = $ulimit->{$key} // return; | ||||||||||||||||||||
|
Condition50%1/2
$ulimit->{$key} // (return)
MC/DC0%0/1
$ulimit->{$key} // (return)
$ulimit->{$key}
Truth table50%1/2
A
A= $ulimit->{$key}
| |||||||||||||||||||||||
| 96 | 1 | return _ulimit($id, shift); | |||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||
| 98 | else | ||||||||||||||||||||||
| 99 | 6 | ▶ | { $key =~ /^UL_GET|^GET_/ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 100 | or croak "pass the constant name as string ($key)"; | ||||||||||||||||||||||
| 101 | 4 | ▶ | my $id = $ulimit->{$key} // return; | ||||||||||||||||||||
|
Condition50%1/2
$ulimit->{$key} // (return)
MC/DC0%0/1
$ulimit->{$key} // (return)
$ulimit->{$key}
Truth table50%1/2
A
A= $ulimit->{$key}
| |||||||||||||||||||||||
| 102 | 4 | _ulimit($id, 0); | |||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | sub _create_constant($) | ||||||||||||||||||||||
| 107 | 20 | ▶ | { my ($class, $name) = @_; | ||||||||||||||||||||
|
Subroutine
_create_constant: called CC=5 SCAR=16.6
| |||||||||||||||||||||||
| 108 | 20 | ▶ | if($name =~ m/^RLIMIT_/) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 109 | 18 | ▶ | { my $id = $rlimit->{$name} // return sub() {undef}; | ||||||||||||||||||||
|
Condition50%1/2
$rlimit->{$name} // (return sub () { undef }
)
MC/DC0%0/1
$rlimit->{$name} // (return sub () { undef }
)
$rlimit->{$name}
Truth table50%1/2
A
A= $rlimit->{$name}
| |||||||||||||||||||||||
| 110 | 18 | ▶ | return sub(;$$) { @_ ? _setrlimit($id, $_[0], $_[1]) : (_getrlimit($id))[0] }; | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||
| 112 | else | ||||||||||||||||||||||
| 113 | 2 | ▶ | { my $id = $ulimit->{$name} // return sub() {undef}; | ||||||||||||||||||||
|
Condition50%1/2
$ulimit->{$name} // (return sub () { undef }
)
MC/DC0%0/1
$ulimit->{$name} // (return sub () { undef }
)
$ulimit->{$name}
Truth table50%1/2
A
A= $ulimit->{$name}
| |||||||||||||||||||||||
| 114 | return $name =~ m/^UL_GET|^GET_/ | ||||||||||||||||||||||
| 115 | 0 | ▶ | ? sub() {_ulimit($id, 0)} : sub($) {_ulimit($id, shift)}; | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Subroutine
__ANON__: not called CC=1 SCAR=0.1
Branch: 1 branch
| |||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | |||||||||||||||||||||||
| 120 | sub getrlimit($) | ||||||||||||||||||||||
| 121 | 21 | ▶ | { my $key = shift // return; | ||||||||||||||||||||
|
Subroutine
getrlimit: called CC=4 SCAR=14.2
Pod
documented
Condition50%1/2
shift() // (return)
MC/DC0%0/1
shift() // (return)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||
| 122 | 21 | ▶ | $key =~ /^RLIMIT_/ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 123 | or croak "pass the constant name as string ($key)"; | ||||||||||||||||||||||
| 124 | |||||||||||||||||||||||
| 125 | 19 | my $id = $rlimit->{$key}; | |||||||||||||||||||||
| 126 | 19 | ▶ | defined $id ? _getrlimit($id) : (); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | |||||||||||||||||||||||
| 130 | sub setrlimit($$;$) | ||||||||||||||||||||||
| 131 | 1 | ▶ | { my ($key, $cur, $max) = @_; | ||||||||||||||||||||
|
Subroutine
setrlimit: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||
| 132 | 1 | ▶ | $key =~ /^RLIMIT_/ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 133 | or croak "pass the constant name as string ($key)"; | ||||||||||||||||||||||
| 134 | |||||||||||||||||||||||
| 135 | 1 | my $id = $rlimit->{$key}; | |||||||||||||||||||||
| 136 | 1 | ▶ | $max //= RLIM_INFINITY; | ||||||||||||||||||||
|
Condition33%1/3
$max //= RLIM_INFINITY()
MC/DC0%0/2
$max //= RLIM_INFINITY()
$max
RLIM_INFINITY()
Truth table33%1/3
A //= B
A= $maxB= RLIM_INFINITY()
| |||||||||||||||||||||||
| 137 | 1 | ▶ | defined $id ? _setrlimit($id, $cur, $max) : (); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||
| 139 | |||||||||||||||||||||||
| 140 | |||||||||||||||||||||||
| 141 | 1 | ▶ | sub ulimit_names() { keys %$ulimit } | ||||||||||||||||||||
|
Subroutine
ulimit_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 142 | |||||||||||||||||||||||
| 143 | |||||||||||||||||||||||
| 144 | 1 | ▶ | sub rlimit_names() { keys %$rlimit } | ||||||||||||||||||||
|
Subroutine
rlimit_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 145 | |||||||||||||||||||||||
| 146 | |||||||||||||||||||||||
| 147 | |||||||||||||||||||||||
| 148 | 6 | 1; | |||||||||||||||||||||