line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- cperl -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
4
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright (C) 2002-2014 Jens Thoms Toerring |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Base class for the three modules for file locking using fcntl(2) |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package File::FcntlLock::Core; |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
86396
|
use 5.006; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
132
|
|
14
|
4
|
|
|
4
|
|
20
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
108
|
|
15
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
24
|
|
|
4
|
|
|
|
|
136
|
|
16
|
4
|
|
|
4
|
|
16
|
use POSIX; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
16
|
|
17
|
4
|
|
|
4
|
|
8572
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
300
|
|
18
|
4
|
|
|
4
|
|
24
|
use base qw( File::FcntlLock::Errors Exporter ); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
2836
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.22'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Items to export into callers namespace by default. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT = qw( F_GETLK F_SETLK F_SETLKW |
27
|
|
|
|
|
|
|
F_RDLCK F_WRLCK F_UNLCK |
28
|
|
|
|
|
|
|
SEEK_SET SEEK_CUR SEEK_END ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
########################################################### |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# Make our exports exportable by child classes |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub import |
36
|
|
|
|
|
|
|
{ |
37
|
12
|
|
|
12
|
|
5860
|
File::FcntlLock::Core->export_to_level( 1, @_ ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
########################################################### |
42
|
|
|
|
|
|
|
# Method for creating the object |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
45
|
35
|
|
|
35
|
0
|
15670
|
my $inv = shift; |
46
|
35
|
|
33
|
|
|
340
|
my $pkg = ref( $inv ) || $inv; |
47
|
|
|
|
|
|
|
|
48
|
35
|
|
|
|
|
239
|
my $self = { l_type => F_RDLCK, |
49
|
|
|
|
|
|
|
l_whence => SEEK_SET, |
50
|
|
|
|
|
|
|
l_start => 0, |
51
|
|
|
|
|
|
|
l_len => 0, |
52
|
|
|
|
|
|
|
l_pid => 0, |
53
|
|
|
|
|
|
|
errno => undef, |
54
|
|
|
|
|
|
|
error_message => undef }; |
55
|
|
|
|
|
|
|
|
56
|
35
|
50
|
|
|
|
135
|
if ( @_ % 2 ) { |
57
|
0
|
|
|
|
|
0
|
carp "Missing value in key-value initializer list " . |
58
|
|
|
|
|
|
|
"in call of new method"; |
59
|
0
|
|
|
|
|
0
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
35
|
|
|
|
|
93
|
while ( @_ ) { |
63
|
52
|
|
|
|
|
119
|
my $key = shift; |
64
|
4
|
|
|
4
|
|
16
|
no strict 'refs'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
256
|
|
65
|
52
|
50
|
|
|
|
179
|
unless ( defined &$key ) { |
66
|
0
|
|
|
|
|
0
|
carp "Flock structure has no '$key' member " . |
67
|
|
|
|
|
|
|
"in call of new method"; |
68
|
0
|
|
|
|
|
0
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
52
|
|
|
|
|
157
|
&$key( $self, shift ); |
71
|
4
|
|
|
4
|
|
16
|
use strict 'refs'; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
1264
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
35
|
|
|
|
|
153
|
bless $self, $pkg; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
########################################################### |
79
|
|
|
|
|
|
|
# Method for setting or querying the 'l_type' property |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub l_type { |
82
|
144
|
|
|
144
|
0
|
6001867
|
my $self = shift; |
83
|
|
|
|
|
|
|
|
84
|
144
|
100
|
|
|
|
431
|
if ( @_ ) { |
85
|
72
|
|
|
|
|
90
|
my $l_type = shift; |
86
|
72
|
50
|
100
|
|
|
664
|
unless ( $l_type == F_RDLCK |
|
|
|
66
|
|
|
|
|
87
|
|
|
|
|
|
|
or $l_type == F_WRLCK |
88
|
|
|
|
|
|
|
or $l_type == F_UNLCK ) { |
89
|
0
|
|
|
|
|
0
|
carp "Invalid argument in call of l_type method"; |
90
|
0
|
|
|
|
|
0
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
72
|
|
|
|
|
368
|
$self->{ l_type } = $l_type; |
93
|
|
|
|
|
|
|
} |
94
|
144
|
|
|
|
|
595
|
return $self->{ l_type }; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
########################################################### |
99
|
|
|
|
|
|
|
# Method for setting or querying the 'l_whence' property |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub l_whence { |
102
|
42
|
|
|
42
|
0
|
161
|
my $self = shift; |
103
|
|
|
|
|
|
|
|
104
|
42
|
100
|
|
|
|
115
|
if ( @_ ) { |
105
|
30
|
|
|
|
|
62
|
my $l_whence = shift; |
106
|
30
|
50
|
100
|
|
|
141
|
unless ( $l_whence == SEEK_SET |
|
|
|
66
|
|
|
|
|
107
|
|
|
|
|
|
|
or $l_whence == SEEK_CUR |
108
|
|
|
|
|
|
|
or $l_whence == SEEK_END ) { |
109
|
0
|
|
|
|
|
0
|
carp "Invalid argument in call of l_whence method"; |
110
|
0
|
|
|
|
|
0
|
return; |
111
|
|
|
|
|
|
|
} |
112
|
30
|
|
|
|
|
62
|
$self->{ l_whence } = $l_whence; |
113
|
|
|
|
|
|
|
} |
114
|
42
|
|
|
|
|
104
|
return $self->{ l_whence }; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
########################################################### |
119
|
|
|
|
|
|
|
# Method to set or query of the 'l_start' property |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub l_start { |
122
|
34
|
|
|
34
|
0
|
158
|
my $self = shift; |
123
|
|
|
|
|
|
|
|
124
|
34
|
100
|
|
|
|
102
|
$self->{ l_start } = shift if @_; |
125
|
34
|
|
|
|
|
307
|
return $self->{ l_start }; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
########################################################### |
130
|
|
|
|
|
|
|
# Method to set or query the 'l_len' property |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub l_len { |
133
|
34
|
|
|
34
|
0
|
104
|
my $self = shift; |
134
|
|
|
|
|
|
|
|
135
|
34
|
100
|
|
|
|
88
|
$self->{ l_len } = shift if @_; |
136
|
34
|
|
|
|
|
101
|
return $self->{ l_len }; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
########################################################### |
141
|
|
|
|
|
|
|
# Method to query the 'l_pid' property |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub l_pid { |
144
|
24
|
|
|
24
|
0
|
678
|
return shift->{ l_pid }; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# Local variables: |
152
|
|
|
|
|
|
|
# tab-width: 4 |
153
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
154
|
|
|
|
|
|
|
# End: |