line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2011-2015 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.01. |
5
|
4
|
|
|
4
|
|
1017
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
104
|
|
6
|
4
|
|
|
4
|
|
11
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
99
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package POSIX::1003::Fcntl; |
9
|
4
|
|
|
4
|
|
13
|
use vars '$VERSION'; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
143
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.99_07'; |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
10
|
use base 'POSIX::1003::Module'; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
252
|
|
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
|
451
|
use POSIX::1003::FdIO qw/SEEK_SET O_CLOEXEC/; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
24
|
|
15
|
4
|
|
|
4
|
|
664
|
use POSIX::1003::Errno qw/ENOSYS/; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
27
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my @constants; |
18
|
|
|
|
|
|
|
my @functions = qw/fcntl |
19
|
|
|
|
|
|
|
fcntl_dup |
20
|
|
|
|
|
|
|
getfd_control |
21
|
|
|
|
|
|
|
setfd_control |
22
|
|
|
|
|
|
|
getfd_flags |
23
|
|
|
|
|
|
|
setfd_flags |
24
|
|
|
|
|
|
|
setfd_lock |
25
|
|
|
|
|
|
|
getfd_islocked |
26
|
|
|
|
|
|
|
getfd_owner |
27
|
|
|
|
|
|
|
setfd_owner |
28
|
|
|
|
|
|
|
setfd_signal |
29
|
|
|
|
|
|
|
getfd_signal |
30
|
|
|
|
|
|
|
setfd_lease |
31
|
|
|
|
|
|
|
getfd_lease |
32
|
|
|
|
|
|
|
setfd_notify |
33
|
|
|
|
|
|
|
setfd_pipe_size |
34
|
|
|
|
|
|
|
getfd_pipe_size |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
flock |
37
|
|
|
|
|
|
|
flockfd |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
lockf |
40
|
|
|
|
|
|
|
/; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
our %EXPORT_TAGS = |
43
|
|
|
|
|
|
|
( constants => \@constants |
44
|
|
|
|
|
|
|
, functions => \@functions |
45
|
|
|
|
|
|
|
, flock => [ qw/flock flockfd LOCK_SH LOCK_EX LOCK_UN LOCK_NB/ ] |
46
|
|
|
|
|
|
|
, lockf => [ qw/lockf F_LOCK F_TLOCK F_ULOCK F_TEST/ ] |
47
|
|
|
|
|
|
|
, tables => [ qw/%fcntl/ ] |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
our @IN_CORE = qw/fcntl flock/; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $fcntl; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# We need to address all of our own constants via this HASH, because |
55
|
|
|
|
|
|
|
# they will not be available at compile-time of this file. |
56
|
|
|
|
|
|
|
our %fcntl; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
BEGIN { |
59
|
4
|
|
|
4
|
|
72
|
$fcntl = fcntl_table; |
60
|
4
|
|
|
|
|
38
|
push @constants, keys %$fcntl; |
61
|
4
|
|
|
|
|
19
|
tie %fcntl, 'POSIX::1003::ReadOnlyTable', $fcntl; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# required parameter which does not get used by the OS. |
65
|
4
|
|
|
4
|
|
18
|
use constant UNUSED => 0; |
|
4
|
|
|
|
|
2
|
|
|
4
|
|
|
|
|
4011
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub flockfd($$) |
69
|
0
|
|
|
0
|
1
|
0
|
{ my ($file, $flags) = @_; |
70
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
71
|
0
|
|
|
|
|
0
|
_flock($fd, $flags); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub lockf($$;$) |
76
|
0
|
|
|
0
|
1
|
0
|
{ my ($file, $flags, $len) = @_; |
77
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
78
|
0
|
|
0
|
|
|
0
|
_lockf($fd, $flags, $len//0); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub fcntl_dup($%) |
83
|
2
|
|
|
2
|
1
|
480
|
{ my ($file, %args) = @_; |
84
|
2
|
50
|
|
|
|
8
|
my $fd = ref $file ? fileno($file) : $file; |
85
|
2
|
50
|
|
|
|
16
|
my $func = $args{close_on_exec} ? $fcntl->{F_DUPFD_CLOEXEC} : $fcntl->{F_DUPFD}; |
86
|
|
|
|
|
|
|
|
87
|
2
|
50
|
|
|
|
28
|
return _fcntl $fd, $fcntl->{F_DUPFD}, UNUSED |
88
|
|
|
|
|
|
|
if !$args{close_on_exec}; |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
0
|
return _fcntl $fd, $fcntl->{F_DUPFD_CLOEXEC}, UNUSED |
91
|
|
|
|
|
|
|
if defined $fcntl->{F_DUPFD_CLOEXEC}; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
0
|
_fcntl $fd, $fcntl->{F_DUPFD}, UNUSED; |
94
|
0
|
|
|
|
|
0
|
setfd_control $fd, O_CLOEXEC; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub getfd_control($) |
99
|
0
|
|
|
0
|
1
|
0
|
{ my ($file) = @_; |
100
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
101
|
0
|
|
|
|
|
0
|
_fcntl $fd, $fcntl->{F_GETFD}, UNUSED; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub setfd_control($$) |
106
|
0
|
|
|
0
|
1
|
0
|
{ my ($file, $flags) = @_; |
107
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
108
|
0
|
|
|
|
|
0
|
_fcntl $fd, $fcntl->{F_SETFD}, $flags; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub getfd_flags($) |
113
|
2
|
|
|
2
|
1
|
6
|
{ my ($file) = @_; |
114
|
2
|
50
|
|
|
|
8
|
my $fd = ref $file ? fileno($file) : $file; |
115
|
2
|
|
|
|
|
14
|
_fcntl $fd, $fcntl->{F_GETFL}, UNUSED; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub setfd_flags($$) |
120
|
0
|
|
|
0
|
1
|
0
|
{ my ($file, $flags) = @_; |
121
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
122
|
0
|
|
|
|
|
0
|
_fcntl $fd, $fcntl->{F_SETFL}, $flags; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub setfd_lock($%) |
127
|
2
|
|
|
2
|
1
|
2001291
|
{ my ($file, %args) = @_; |
128
|
2
|
50
|
|
|
|
50
|
my $fd = ref $file ? fileno($file) : $file; |
129
|
|
|
|
|
|
|
|
130
|
2
|
|
|
|
|
11
|
my $func; |
131
|
2
|
0
|
|
|
|
39
|
$func = $args{wait} ? $fcntl->{F_SETLKP} : $fcntl->{F_SETLKWP} |
|
|
50
|
|
|
|
|
|
132
|
|
|
|
|
|
|
if $args{private}; |
133
|
|
|
|
|
|
|
|
134
|
2
|
50
|
33
|
|
|
263
|
$func //= $args{wait} ? $fcntl->{F_SETLK} : $fcntl->{F_SETLKW}; |
135
|
|
|
|
|
|
|
|
136
|
2
|
|
33
|
|
|
15
|
$args{type} //= $fcntl->{F_RDLCK}; |
137
|
2
|
|
50
|
|
|
29
|
$args{whence} //= SEEK_SET; |
138
|
2
|
|
50
|
|
|
7
|
$args{start} //= 0; |
139
|
2
|
|
50
|
|
|
6
|
$args{len} //= 0; |
140
|
2
|
|
|
|
|
92
|
_lock $fd, $func, \%args; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub getfd_islocked($%) |
145
|
2
|
|
|
2
|
1
|
3001725
|
{ my ($file, %args) = @_; |
146
|
2
|
50
|
|
|
|
26
|
my $fd = ref $file ? fileno($file) : $file; |
147
|
2
|
|
33
|
|
|
18
|
$args{type} //= $fcntl->{F_RDLCK}; |
148
|
2
|
|
50
|
|
|
26
|
$args{whence} //= SEEK_SET; |
149
|
2
|
|
50
|
|
|
80
|
$args{start} //= 0; |
150
|
2
|
|
50
|
|
|
11
|
$args{len} //= 0; |
151
|
|
|
|
|
|
|
|
152
|
2
|
50
|
0
|
|
|
15
|
my $func = $args{private} ? ($fcntl->{F_GETLKW}//$fcntl->{F_GETLK}) : $fcntl->{F_GETLK}; |
153
|
2
|
50
|
|
|
|
50
|
my $lock = _lock $fd, $func, \%args |
154
|
|
|
|
|
|
|
or return undef; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
#XXX MO: how to represent "ENOSYS"? |
157
|
2
|
100
|
|
|
|
29
|
$lock->{type}==$fcntl->{F_UNLCK} ? undef : $lock; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub getfd_owner($%) |
162
|
0
|
|
|
0
|
1
|
0
|
{ my ($file, %args) = @_; |
163
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
0
|
my ($type, $pid) = _own_ex $fd, $fcntl->{F_GETOWN_EX}, UNUSED, UNUSED; |
166
|
0
|
0
|
0
|
|
|
0
|
unless(defined $type && $!==ENOSYS) |
167
|
0
|
|
|
|
|
0
|
{ $pid = _fcntl $fd, $fcntl->{F_GETOWN}, UNUSED; |
168
|
0
|
0
|
|
|
|
0
|
if($pid < 0) |
169
|
0
|
|
|
|
|
0
|
{ $pid = -$pid; |
170
|
0
|
|
0
|
|
|
0
|
$type = $fcntl->{F_OWNER_PGRP} // 2; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
else |
173
|
0
|
|
0
|
|
|
0
|
{ $type = $fcntl->{F_OWNER_PID} // 1; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
0
|
0
|
|
|
|
0
|
wantarray ? ($type, $pid) : $pid; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub setfd_owner($$%) |
182
|
0
|
|
|
0
|
1
|
0
|
{ my ($file, $pid, %args) = @_; |
183
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
0
|
|
|
0
|
my $type = $args{type} |
186
|
|
|
|
|
|
|
|| ($pid < 0 ? ($fcntl->{F_OWNER_PGRP}//2) : ($fcntl->{F_OWNER_PID}//1)); |
187
|
|
|
|
|
|
|
|
188
|
0
|
0
|
|
|
|
0
|
$pid = -$pid if $pid < 0; |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
0
|
my ($t, $p) = _own_ex $fd, $fcntl->{F_SETOWN_EX}, $pid, $type; |
191
|
0
|
0
|
0
|
|
|
0
|
unless($t && $!==ENOSYS) |
192
|
0
|
0
|
0
|
|
|
0
|
{ my $sig_pid = $type==($fcntl->{F_OWNER_PGRP}//2) ? -$pid : $pid; |
193
|
0
|
|
|
|
|
0
|
($t, $p) = _fcntl $fd, $fcntl->{F_SETOWN}, $pid; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
0
|
defined $t; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub setfd_signal($$) |
201
|
0
|
|
|
0
|
1
|
0
|
{ my ($file, $signal) = @_; |
202
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
203
|
0
|
|
|
|
|
0
|
_fcntl $fd, $fcntl->{F_SETSIG}, $signal; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub getfd_signal($) |
208
|
0
|
|
|
0
|
1
|
0
|
{ my $file = shift; |
209
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
210
|
0
|
|
|
|
|
0
|
_fcntl $fd, $fcntl->{F_SETSIG}, UNUSED; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub setfd_lease($$) |
215
|
0
|
|
|
0
|
1
|
0
|
{ my ($file, $flags) = @_; |
216
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
217
|
0
|
|
|
|
|
0
|
_fcntl $fd, $fcntl->{F_SETLEASE}, $flags; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub getfd_lease($) |
222
|
0
|
|
|
0
|
1
|
0
|
{ my $file = shift; |
223
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
224
|
0
|
|
|
|
|
0
|
_fcntl $fd, $fcntl->{F_GETLEASE}, UNUSED; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub setfd_notify($$) |
230
|
0
|
|
|
0
|
1
|
0
|
{ my ($dir, $flags) = @_; |
231
|
0
|
0
|
|
|
|
0
|
my $fd = ref $dir ? fileno($dir) : $dir; |
232
|
0
|
|
|
|
|
0
|
_fcntl $fd, $fcntl->{F_NOTIFY}, $flags; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub setfd_pipe_size($$) |
237
|
0
|
|
|
0
|
1
|
0
|
{ my ($file, $size) = @_; |
238
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
239
|
0
|
|
|
|
|
0
|
_fcntl $fd, $fcntl->{F_SETPIPE_SZ}, $size; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub getfd_pipe_size($) |
244
|
0
|
|
|
0
|
1
|
0
|
{ my $file = shift; |
245
|
0
|
0
|
|
|
|
0
|
my $fd = ref $file ? fileno($file) : $file; |
246
|
0
|
|
|
|
|
0
|
_fcntl $fd, $fcntl->{F_GETPIPE_SZ}, UNUSED; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub _create_constant($) |
251
|
84
|
|
|
84
|
|
76
|
{ my ($class, $name) = @_; |
252
|
84
|
|
|
|
|
54
|
my $val = $fcntl->{$name}; |
253
|
84
|
|
|
0
|
|
326
|
sub() {$val}; |
|
0
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
1; |