1INN::Utils::Shlock(3pm)   InterNetNews Documentation   INN::Utils::Shlock(3pm)
2
3
4

NAME

6       INN::Utils::Shlock - Wrapper around the shlock program
7

DESCRIPTION

9       This Perl module wraps the shlock(1) program so that it can easily be
10       used.  Calling shlock is more portable than using flock(2) and its
11       corresponding Perl function because this function does not work as
12       expected on all existing systems.
13
14       See the shlock(1) documentation for more information.
15
16       Using INN::Utils::Shlock is straight-forward:
17
18           use lib '<pathnews>/lib/perl';
19           use INN::Utils::Shlock;
20
21           my $lockfile = "myprogram.LOCK";
22
23           # Acquire a lock.
24           INN::Utils::Shlock::lock($lockfile);
25
26           # Do whatever you want.  The lock prevents concurrent accesses.
27
28           # Unlock.
29           INN::Utils::Shlock::unlock($lockfile);
30
31       These two functions return 1 on success, 0 on failure.  For example,
32       the success of (un)locking can be checked as:
33
34           INN::Utils::Shlock::lock($lockfile) or die "cannot create lock file";
35
36       or:
37
38           if (! INN::Utils::Shlock::lock($lockfile, 4)) {
39               die "giving up after 4 unsuccessful attempts to create lock file";
40           }
41
42       Instead of calling "unlock(lockfile)", the "releaselocks()" function
43       can be called.  It removes any leftover locks, which is useful when
44       several different locks are used.  Another possible use is to call it
45       in an END code block:
46
47           END {
48               # In case we bail out, while holding a lock.
49               INN::Utils::Shlock::releaselocks();
50           }
51

INTERFACE

53       lock(lockfile)
54           Tries to create a lock file named lockfile.
55
56           This function returns 1 on success, 0 on failure.
57
58       lock(lockfile, tries)
59           Tries to create a lock file named lockfile.  If it fails, locking
60           attempts are repeated once every 2 seconds for at most tries times
61           (including the first unsuccessful attempt).
62
63           This function returns 1 on success, 0 on failure.
64
65       lock(lockfile, tries, delay)
66           Tries to create a lock file named lockfile.  If it fails, locking
67           attempts are repeated once every delay seconds for at most tries
68           times (including the first unsuccessful attempt).
69
70           Note that "lock(lockfile)" is equivalent to "lock(lockfile, 1, 2)".
71
72           This function returns 1 on success, 0 on failure.
73
74       releaselocks()
75           Removes all the lock files previously created by calling the
76           "lock(lockfile)" function.
77
78           This function returns the number of removed lock files.
79
80       unlock(lockfile)
81           Removes the file named lockfile.
82
83           This function returns 1 on success, 0 on failure.
84

HISTORY

86       Documentation written by Julien Elie for InterNetNews.
87

SEE ALSO

89       perl(1), shlock(1).
90
91
92
93INN 2.7.0                         2022-07-10           INN::Utils::Shlock(3pm)
Impressum