1INN::Utils::Shlock(3pm) InterNetNews Documentation INN::Utils::Shlock(3pm)
2
3
4
6 INN::Utils::Shlock - Wrapper around the shlock program
7
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)
35 or die "cannot create lock file";
36
37 or:
38
39 if (! INN::Utils::Shlock::lock($lockfile, 4)) {
40 die "giving up after 4 attempts to create lock file";
41 }
42
43 Instead of calling "unlock(lockfile)", the "releaselocks()" function
44 can be called. It removes any leftover locks, which is useful when
45 several different locks are used. Another possible use is to call it
46 in an END code block:
47
48 END {
49 # In case we bail out, while holding a lock.
50 INN::Utils::Shlock::releaselocks();
51 }
52
54 lock(lockfile)
55 Tries to create a lock file named lockfile.
56
57 This function returns 1 on success, 0 on failure.
58
59 lock(lockfile, tries)
60 Tries to create a lock file named lockfile. If it fails, locking
61 attempts are repeated once every 2 seconds for at most tries times
62 (including the first unsuccessful attempt).
63
64 This function returns 1 on success, 0 on failure.
65
66 lock(lockfile, tries, delay)
67 Tries to create a lock file named lockfile. If it fails, locking
68 attempts are repeated once every delay seconds for at most tries
69 times (including the first unsuccessful attempt).
70
71 Note that "lock(lockfile)" is equivalent to "lock(lockfile, 1, 2)".
72
73 This function returns 1 on success, 0 on failure.
74
75 releaselocks()
76 Removes all the lock files previously created by calling the
77 "lock(lockfile)" function.
78
79 This function returns the number of removed lock files.
80
81 unlock(lockfile)
82 Removes the file named lockfile.
83
84 This function returns 1 on success, 0 on failure.
85
87 Documentation written by Julien Elie for InterNetNews.
88
90 perl(1), shlock(1).
91
92
93
94INN 2.7.1 2023-04-16 INN::Utils::Shlock(3pm)