File Coverage

blib/lib/File/FcntlLock/Errors.pm
Criterion Covered Total %
statement 46 53 86.7
branch 11 26 42.3
condition n/a
subroutine 5 9 55.5
pod 0 4 0.0
total 62 92 67.3


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             # Helper package for File::FcntLock::Core for handling error messages
10              
11             package File::FcntlLock::Errors;
12              
13              
14 4     4   112 use 5.006;
  4         12  
  4         132  
15 4     4   16 use strict;
  4         4  
  4         92  
16 4     4   16 use warnings;
  4         4  
  4         80  
17 4     4   3332 use Errno;
  4         4736  
  4         1560  
18              
19              
20             my %fcntl_error_texts;
21              
22              
23             BEGIN {
24             # Set up a hash with the error messages, but only for errno's that Errno
25             # knows about. The texts represent what is written in SUSv3 and in the
26             # man pages for Linux, TRUE64, OpenBSD3 and Solaris8.
27              
28 4     4   4 my $err;
29              
30 4 50       12 if ( $err = eval { &Errno::EACCES } ) {
  4         28  
31 4         16 $fcntl_error_texts{ $err } = "File or segment already locked " .
32             "by other process(es) or file is " .
33             "mmap()ed to virtual memory";
34             }
35              
36 4 50       4 if ( $err = eval { &Errno::EAGAIN } ) {
  4         24  
37 4         16 $fcntl_error_texts{ $err } = "File or segment already locked " .
38             "by other process(es)";
39             }
40              
41 4 50       8 if ( $err = eval { &Errno::EBADF } ) {
  4         16  
42 4         68 $fcntl_error_texts{ $err } = "Not an open file or not opened for " .
43             "writing (with F_WRLCK) or reading " .
44             "(with F_RDLCK)";
45             }
46              
47 4 50       8 if ( $err = eval { &Errno::EDEADLK } ) {
  4         16  
48 4         8 $fcntl_error_texts{ $err } = "Operation would cause a deadlock";
49             }
50              
51 4 50       8 if ( $err = eval { &Errno::EFAULT } ) {
  4         20  
52 4         12 $fcntl_error_texts{ $err } = "Lock outside accessible address space " .
53             "or to many locked regions";
54             }
55              
56 4 50       4 if ( $err = eval { &Errno::EINTR } ) {
  4         16  
57 4         12 $fcntl_error_texts{ $err } = "Operation interrupted by a signal";
58             }
59              
60 4 50       8 if ( $err = eval { &Errno::ENOLCK } ) {
  4         16  
61 4         8 $fcntl_error_texts{ $err } = "Too many segment locks open, lock " .
62             "table full or remote locking protocol " .
63             "failure (e.g. NFS)";
64             }
65              
66 4 50       4 if ( $err = eval { &Errno::EINVAL } ) {
  4         24  
67 4         12 $fcntl_error_texts{ $err } = "Illegal parameter or file does not " .
68             "support locking";
69             }
70              
71 4 50       4 if ( $err = eval { &Errno::EOVERFLOW } ) {
  4         48  
72 4         28 $fcntl_error_texts{ $err } = "One of the parameters to be returned " .
73             "can not be represented correctly";
74             }
75              
76 4 50       4 if ( $err = eval { &Errno::ENETUNREACH } ) {
  4         16  
77 4         8 $fcntl_error_texts{ $err } = "File is on remote machine that can " .
78             "not be reached anymore";
79             }
80              
81 4 50       4 if ( $err = eval { &Errno::ENOLINK } ) {
  4         12  
82 4         672 $fcntl_error_texts{ $err } = "File is on remote machine that can " .
83             "not be reached anymore";
84             }
85             }
86              
87              
88             ###########################################################
89             # Function for converting an errno to a useful, human readable
90             # message.
91              
92             sub get_error {
93 0     0 0   my ( $self, $err ) = @_;
94             return $self->{ error } =
95 0 0         defined $fcntl_error_texts{ $err } ? $fcntl_error_texts{ $err }
96             : "Unexpected error: $!";
97             }
98              
99              
100             ###########################################################
101             # Method returns the error number from the latest call of the
102             # derived classes lock() function. If the last call did not
103             # result in an error the method returns undef.
104              
105             sub lock_errno {
106 0     0 0   return shift->{ errno };
107             }
108              
109              
110             ###########################################################
111             # Method returns a short description of the error that happenend
112             # on the latest call of derived classes lock() method with the
113             # object. If there was no error the method returns undef.
114              
115             sub error {
116 0     0 0   return shift->{ error };
117             }
118              
119              
120             ###########################################################
121             # Method returns the "normal" system error message associated
122             # with errno. The method returns undef if there was no error.
123              
124             sub system_error {
125 0     0 0   local $!;
126 0           my $self = shift;
127 0 0         return $self->{ errno } ? $! = $self->{ errno } : undef;
128             }
129              
130              
131             1;
132              
133              
134             # Local variables:
135             # tab-width: 4
136             # indent-tabs-mode: nil
137             # End: