/usr/share/perl5/LockDev.pm is in liblockdev1-perl 1.0.3-1.5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | package LockDev;
use strict;
use Carp;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
require Exporter;
require DynaLoader;
@ISA = qw(Exporter DynaLoader);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
@EXPORT_OK = qw(
&dev_testlock
&dev_lock
&dev_relock
&dev_unlock
);
$VERSION = '1.0';
sub AUTOLOAD {
# This AUTOLOAD is used to 'autoload' constants from the constant()
# XS function. If a constant is not found then control is passed
# to the AUTOLOAD in AutoLoader.
my $constname;
($constname = $AUTOLOAD) =~ s/.*:://;
my $val = constant($constname, @_ ? $_[0] : 0);
if ($! != 0) {
if ($! =~ /Invalid/) {
$AutoLoader::AUTOLOAD = $AUTOLOAD;
goto &AutoLoader::AUTOLOAD;
}
else {
croak "Your vendor has not defined LockDev macro $constname";
}
}
eval "sub $AUTOLOAD { $val }";
goto &$AUTOLOAD;
}
bootstrap LockDev $VERSION;
# Preloaded methods go here.
# Autoload methods go after =cut, and are processed by the autosplit program.
1;
__END__
# Below is the stub of documentation for your module. You better edit it!
=head1 NAME
LockDev - Perl extension to manage device lockfiles
=head1 SYNOPSIS
use LockDev;
$pid = LockDev::dev_testlock( $device);
$pid = LockDev::dev_lock( $device);
$pid = LockDev::dev_relock( $device, $oldpid);
$pid = LockDev::dev_unlock( $device, $oldpid);
=head1 DESCRIPTION
The LockDev methods act on device locks normally located in /var/lock .
The lock is acquired creating a pair of files hardlinked between them
and named after the device name (as mandated by FSSTND) and the device's
major and minor numbers (as in SVr4 locks). This permits to circumvent
a problem using only the FSSTND lock method when the same device exists
under different names (for convenience or when a device must be accessable
by more than one group of users).
The lock file names are typically in the form LCK..ttyS1 and LCK.004.065 ,
and their content is the pid of the process who owns the lock.
=head1 METHODS
$pid = LockDev::dev_testlock( $device);
This method simply checks if the device is in some way locked and if
the owner of the lock is still active (otherways it removes the lock).
It recognise a valid lock even if only one of the two lock files exists
(and is owned by an existing process), thus permitting a safe use of
this library toghether with programs using only FSSTND or SVr4 lock style.
$pid = LockDev::dev_lock( $device);
This method first checks if the device is already locked and then tryes
to acquire the lock building the two lock files. First it creates the
file which name contains the major and minor numbers (in SVr4 style),
then it creates the file with the device name in its name. This order
reduces the clashes with other processes trying to lock the same device
(even with a different name) and using this library. It has no problem
with processes that uses only the FSSTND algorithm.
$pid = LockDev::dev_relock( $device, $oldpid);
This method changes the owner of an existing lock; if the pid of the
old owner is provided, then it checks if the lock was correctly assigned
(otherways there is the possibility of a process acquiring a lock which
was owned by another unrelated process). If the device was not locked,
locks it.
$pid = LockDev::dev_unlock( $device, $oldpid);
This method removes the existing locks on the device. If the pid of the
owner of the lock is provided, then it check if the locks are assigned
to that process, avoiding to remove locks assigned to other existing
processes.
=head1 RETURN VALUES
All the methods in LockDev library return ZERO on successfull completion
of the function (LockDev::dev_testlock returns zero if there is no
lock on the device), otherways, if the device is currently locked by
an existing process, they return the pid of the process owner of the
lock. They return a negative number when some kind of error happens.
Actually they all return only (-1).
=head1 AUTHOR
(c) 1997 by Fabrizio Polacco <fpolacco@icenet.fi>. The LockDev extension
library and the liblockdev 'C' library are licensed under the FSF's LGPL.
=head1 SEE ALSO
perl(1), lockdev(3).
=cut
|