| 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
|
|
|
|
|
|
|
# Package for file locking with fcntl(2) in which the binary layout of |
|
10
|
|
|
|
|
|
|
# the C flock struct has been determined via a C program on installation |
|
11
|
|
|
|
|
|
|
# and appropriate Perl code been appended to the package. |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package File::FcntlLock::Pure; |
|
14
|
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
2192
|
use 5.006; |
|
|
4
|
|
|
|
|
12
|
|
|
|
4
|
|
|
|
|
136
|
|
|
16
|
4
|
|
|
4
|
|
24
|
use strict; |
|
|
4
|
|
|
|
|
4
|
|
|
|
4
|
|
|
|
|
112
|
|
|
17
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
112
|
|
|
18
|
4
|
|
|
4
|
|
20
|
use base qw( File::FcntlLock::Core ); |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
1252
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = File::FcntlLock::Core->VERSION; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @EXPORT = @File::FcntlLock::Core::EXPORT; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
########################################################### |
|
27
|
|
|
|
|
|
|
# Function for doing the actual fcntl() call: assembles the binary |
|
28
|
|
|
|
|
|
|
# structure that must be passed to fcntl() from the File::FcntlLock |
|
29
|
|
|
|
|
|
|
# object we get passed, calls it and then modifies the File::FcntlLock |
|
30
|
|
|
|
|
|
|
# with the data from the flock structure |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub lock { |
|
33
|
28
|
|
|
28
|
1
|
4012713
|
my ( $self, $fh, $action ) = @_; |
|
34
|
28
|
|
|
|
|
146
|
my $buf = $self->pack_flock( ); |
|
35
|
28
|
|
|
|
|
326
|
my $ret = fcntl( $fh, $action, $buf ); |
|
36
|
|
|
|
|
|
|
|
|
37
|
28
|
50
|
|
|
|
105
|
if ( $ret ) { |
|
38
|
28
|
|
|
|
|
108
|
$self->unpack_flock( $buf ); |
|
39
|
28
|
|
|
|
|
163
|
$self->{ errno } = $self->{ error } = undef; |
|
40
|
|
|
|
|
|
|
} else { |
|
41
|
0
|
|
|
|
|
0
|
$self->get_error( $self->{ errno } = $! + 0 ); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
28
|
|
|
|
|
132
|
return $ret; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
########################################################### |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Method created automatically while running 'perl Makefile.PL' |
|
51
|
|
|
|
|
|
|
# (based on the the C 'struct flock' in ) for packing |
|
52
|
|
|
|
|
|
|
# the data from the 'flock_struct' into a binary blob to be |
|
53
|
|
|
|
|
|
|
# passed to fcntl(). |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub pack_flock { |
|
56
|
28
|
|
|
28
|
0
|
72
|
my $self = shift; |
|
57
|
|
|
|
|
|
|
return pack( 'ssx4qqlx4', |
|
58
|
|
|
|
|
|
|
$self->{ l_type }, |
|
59
|
|
|
|
|
|
|
$self->{ l_whence }, |
|
60
|
|
|
|
|
|
|
$self->{ l_start }, |
|
61
|
|
|
|
|
|
|
$self->{ l_len }, |
|
62
|
28
|
|
|
|
|
569
|
$self->{ l_pid } ); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
########################################################### |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Method created automatically while running 'perl Makefile.PL' |
|
69
|
|
|
|
|
|
|
# (based on the the C 'struct flock' in ) for unpacking |
|
70
|
|
|
|
|
|
|
# the binary blob received from a call of fcntl() into the |
|
71
|
|
|
|
|
|
|
# 'flock_struct'. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub unpack_flock { |
|
74
|
28
|
|
|
28
|
0
|
62
|
my ( $self, $data ) = @_; |
|
75
|
|
|
|
|
|
|
( $self->{ l_type }, |
|
76
|
|
|
|
|
|
|
$self->{ l_whence }, |
|
77
|
|
|
|
|
|
|
$self->{ l_start }, |
|
78
|
|
|
|
|
|
|
$self->{ l_len }, |
|
79
|
28
|
|
|
|
|
237
|
$self->{ l_pid } ) = unpack( 'ssx4qqlx4', $data ); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |