line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
4
|
|
|
4
|
|
141015
|
use vars '$VERSION'; |
|
4
|
|
|
|
|
26
|
|
|
4
|
|
|
|
|
244
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.02'; |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
25
|
use base 'POSIX::1003::Module'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
935
|
|
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
25
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
98
|
|
16
|
4
|
|
|
4
|
|
16
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
129
|
|
17
|
|
|
|
|
|
|
|
18
|
4
|
|
|
4
|
|
22
|
use Carp 'croak'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1152
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my (@ulimit, @rlimit, @constants, @functions); |
21
|
|
|
|
|
|
|
our %EXPORT_TAGS = |
22
|
|
|
|
|
|
|
( ulimit => \@ulimit |
23
|
|
|
|
|
|
|
, rlimit => \@rlimit |
24
|
|
|
|
|
|
|
, constants => \@constants |
25
|
|
|
|
|
|
|
, functions => \@functions |
26
|
|
|
|
|
|
|
, tables => [ qw/%ulimit %rlimit/ ] |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my ($ulimit, $rlimit); |
30
|
|
|
|
|
|
|
our (%ulimit, %rlimit); |
31
|
|
|
|
|
|
|
my ($rlim_saved_max, $rlim_saved_cur, $rlim_infinity); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
BEGIN { |
34
|
4
|
|
|
4
|
|
19
|
my @ufuncs = qw/ulimit ulimit_names/; |
35
|
4
|
|
|
|
|
29
|
my @rfuncs = qw/getrlimit setrlimit rlimit_names/; |
36
|
4
|
|
|
|
|
17
|
my @rconst = qw/RLIM_SAVED_MAX RLIM_SAVED_CUR RLIM_INFINITY/; |
37
|
|
|
|
|
|
|
|
38
|
4
|
|
|
|
|
105
|
$ulimit = ulimit_table; |
39
|
4
|
|
|
|
|
42
|
@ulimit = (keys %$ulimit, @ufuncs, '%ulimit'); |
40
|
4
|
|
|
|
|
27
|
tie %ulimit, 'POSIX::1003::ReadOnlyTable', $ulimit; |
41
|
|
|
|
|
|
|
|
42
|
4
|
|
|
|
|
61
|
$rlimit = rlimit_table; |
43
|
4
|
|
|
|
|
29
|
@rlimit = (keys %$rlimit, @rfuncs, @rconst, '%rlimit'); |
44
|
4
|
|
|
|
|
16
|
tie %rlimit, 'POSIX::1003::ReadOnlyTable', $rlimit; |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
43
|
push @constants, keys %$ulimit, keys %$rlimit; |
47
|
4
|
|
|
|
|
15
|
push @functions, @ufuncs, @rfuncs; |
48
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
44
|
$rlim_saved_max = delete $rlimit->{RLIM_SAVED_MAX}; |
50
|
4
|
|
|
|
|
11
|
$rlim_saved_cur = delete $rlimit->{RLIM_SAVED_CUR}; |
51
|
4
|
|
|
|
|
4494
|
$rlim_infinity = delete $rlimit->{RLIM_INFINITY}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
|
3
|
0
|
1090
|
sub RLIM_SAVED_MAX { $rlim_saved_max } |
55
|
2
|
|
|
2
|
0
|
10
|
sub RLIM_SAVED_CUR { $rlim_saved_cur } |
56
|
3
|
|
|
3
|
0
|
12
|
sub RLIM_INFINITY { $rlim_infinity } |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub getrlimit($); |
59
|
|
|
|
|
|
|
sub setrlimit($$;$); |
60
|
|
|
|
|
|
|
sub ulimit($;$); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub exampleValue($) |
64
|
0
|
|
|
0
|
1
|
0
|
{ my ($class, $name) = @_; |
65
|
0
|
0
|
|
|
|
0
|
if($name =~ m/^RLIMIT_/) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
{ my ($soft, $hard, $success) = getrlimit $name; |
67
|
0
|
|
|
|
|
0
|
for($soft,$hard) |
68
|
0
|
|
0
|
|
|
0
|
{ $_ //= 'undef'; |
69
|
0
|
|
|
|
|
0
|
s/18446744073709551615/2**64-1/g; |
70
|
0
|
|
|
|
|
0
|
s/9223372036854775807/2**63-1/g; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
0
|
return "$rlimit->{$name}, $soft, $hard"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif($name =~ m/^RLIM_/) |
75
|
0
|
|
0
|
|
|
0
|
{ return $rlimit->{$name} // 'undef'; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
elsif($name =~ m/^UL_GET|^GET_/) |
78
|
0
|
|
|
|
|
0
|
{ my $val = ulimit $name; |
79
|
0
|
0
|
|
|
|
0
|
return defined $val ? $val : 'undef'; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
elsif($name =~ m/^UL_SET|^SET_/) |
82
|
0
|
|
|
|
|
0
|
{ return '(setter)'; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else |
85
|
0
|
|
|
|
|
0
|
{ $class->SUPER::exampleValue($name); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub ulimit($;$) |
91
|
7
|
|
50
|
7
|
1
|
1737
|
{ my $key = shift // return; |
92
|
7
|
100
|
|
|
|
19
|
if(@_) |
93
|
1
|
50
|
|
|
|
8
|
{ $key =~ /^UL_SET|^SET_/ |
94
|
|
|
|
|
|
|
or croak "pass the constant name as string ($key)"; |
95
|
1
|
|
50
|
|
|
4
|
my $id = $ulimit->{$key} // return; |
96
|
1
|
|
|
|
|
13
|
return _ulimit($id, shift); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else |
99
|
6
|
100
|
|
|
|
327
|
{ $key =~ /^UL_GET|^GET_/ |
100
|
|
|
|
|
|
|
or croak "pass the constant name as string ($key)"; |
101
|
4
|
|
50
|
|
|
14
|
my $id = $ulimit->{$key} // return; |
102
|
4
|
|
|
|
|
36
|
_ulimit($id, 0); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _create_constant($) |
107
|
20
|
|
|
20
|
|
33
|
{ my ($class, $name) = @_; |
108
|
20
|
100
|
|
|
|
43
|
if($name =~ m/^RLIMIT_/) |
109
|
18
|
|
50
|
|
|
32
|
{ my $id = $rlimit->{$name} // return sub() {undef}; |
110
|
18
|
50
|
|
3
|
|
84
|
return sub(;$$) { @_ ? _setrlimit($id, $_[0], $_[1]) : (_getrlimit($id))[0] }; |
|
3
|
|
|
|
|
2018
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
else |
113
|
2
|
|
50
|
|
|
4
|
{ my $id = $ulimit->{$name} // return sub() {undef}; |
114
|
|
|
|
|
|
|
return $name =~ m/^UL_GET|^GET_/ |
115
|
2
|
100
|
|
0
|
|
33
|
? sub() {_ulimit($id, 0)} : sub($) {_ulimit($id, shift)}; |
|
3
|
|
|
|
|
1901
|
|
|
0
|
|
|
|
|
0
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub getrlimit($) |
121
|
21
|
|
50
|
21
|
1
|
988
|
{ my $key = shift // return; |
122
|
21
|
100
|
|
|
|
369
|
$key =~ /^RLIMIT_/ |
123
|
|
|
|
|
|
|
or croak "pass the constant name as string ($key)"; |
124
|
|
|
|
|
|
|
|
125
|
19
|
|
|
|
|
30
|
my $id = $rlimit->{$key}; |
126
|
19
|
50
|
|
|
|
159
|
defined $id ? _getrlimit($id) : (); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub setrlimit($$;$) |
131
|
1
|
|
|
1
|
1
|
279
|
{ my ($key, $cur, $max) = @_; |
132
|
1
|
50
|
|
|
|
7
|
$key =~ /^RLIMIT_/ |
133
|
|
|
|
|
|
|
or croak "pass the constant name as string ($key)"; |
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
|
|
3
|
my $id = $rlimit->{$key}; |
136
|
1
|
|
33
|
|
|
9
|
$max //= RLIM_INFINITY; |
137
|
1
|
50
|
|
|
|
17
|
defined $id ? _setrlimit($id, $cur, $max) : (); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
1
|
|
|
1
|
1
|
473
|
sub ulimit_names() { keys %$ulimit } |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
1
|
|
|
1
|
1
|
496
|
sub rlimit_names() { keys %$rlimit } |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |