INN::Utils::Shlock(3pm) | InterNetNews Documentation | INN::Utils::Shlock(3pm) |
INN::Utils::Shlock - Wrapper around the shlock program
This Perl module wraps the shlock(1) program so that it can easily be used. Calling shlock is more portable than using flock(2) and its corresponding Perl function because this function does not work as expected on all existing systems.
See the shlock(1) documentation for more information.
Using INN::Utils::Shlock is straight-forward:
use lib '<pathnews>/lib/perl'; use INN::Utils::Shlock; my $lockfile = "myprogram.LOCK"; # Acquire a lock. INN::Utils::Shlock::lock($lockfile); # Do whatever you want. The lock prevents concurrent accesses. # Unlock. INN::Utils::Shlock::unlock($lockfile);
These two functions return 1 on success, 0 on failure. For example, the success of (un)locking can be checked as:
INN::Utils::Shlock::lock($lockfile) or die "cannot create lock file";
or:
if (! INN::Utils::Shlock::lock($lockfile, 4)) { die "giving up after 4 attempts to create lock file"; }
Instead of calling "unlock(lockfile)", the "releaselocks()" function can be called. It removes any leftover locks, which is useful when several different locks are used. Another possible use is to call it in an END code block:
END { # In case we bail out, while holding a lock. INN::Utils::Shlock::releaselocks(); }
This function returns 1 on success, 0 on failure.
This function returns 1 on success, 0 on failure.
Note that "lock(lockfile)" is equivalent to "lock(lockfile, 1, 2)".
This function returns 1 on success, 0 on failure.
This function returns the number of removed lock files.
This function returns 1 on success, 0 on failure.
Documentation written by Julien Elie for InterNetNews.
2023-09-06 | INN 2.7.1 |