Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

inn::utils::shlock(3pm) [debian man page]

INN::Utils::Shlock(3pm) 				    InterNetNews Documentation					   INN::Utils::Shlock(3pm)

NAME
INN::Utils::Shlock - Wrapper around the shlock program DESCRIPTION
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 unsuccessful 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(); } INTERFACE
lock(lockfile) Tries to create a lock file named lockfile. This function returns 1 on success, 0 on failure. lock(lockfile, tries) Tries to create a lock file named lockfile. If it fails, locking attempts are repeated once every 2 seconds for at most tries times (including the first unsuccessful attempt). This function returns 1 on success, 0 on failure. lock(lockfile, tries, delay) Tries to create a lock file named lockfile. If it fails, locking attempts are repeated once every delay seconds for at most tries times (including the first unsuccessful attempt). Note that "lock(lockfile)" is equivalent to "lock(lockfile, 1, 2)". This function returns 1 on success, 0 on failure. releaselocks() Removes all the lock files previously created by calling the "lock(lockfile)" function. This function returns the number of removed lock files. unlock(lockfile) Removes the file named lockfile. This function returns 1 on success, 0 on failure. HISTORY
Documentation written by Julien Elie for InterNetNews. $Id: Shlock.pm.in 9409 2012-05-28 18:43:20Z iulius $ SEE ALSO
perl(1), shlock(1). INN 2.5.3 2012-06-15 INN::Utils::Shlock(3pm)

Check Out this Related Man Page

DOTLOCKFILE(1)							 Cistron Utilities						    DOTLOCKFILE(1)

NAME
dotlockfile - Utility to manage lockfiles SYNOPSIS
/usr/bin/dotlockfile [-p] [-c] [-m] [-l|-u|-t] [-r retries] [lockfile] DESCRIPTION
Dotlockfile is a command line utility to safely create, test and remove lockfiles. Lockfiles are created in an NFS-safe way. Dotlockfile can can also be used to lock and unlock mailboxes even if the mailspool directory is only writable by group mail. The name dotlockfile comes from the way mailboxes are locked for updates on a lot of UNIX systems. A lockfile is created with the same filename as the mailbox but with the string ".lock" appended. The names dotlock and lockfile were already taken - hence the name dotlockfile :). OPTIONS
-l Create a lockfile. This is the default. -u Remove a lockfile. -c Check for the existence of a valid lockfile. -t Touch an existing lockfile (update the timestamp). -p Write the process-id of the calling process into the lockfile. Also when testing for an existing lockfile, check the contents for a process-id to find out if the lockfile is still valid. -r retries The number of times dotlockfile retries to acquire the lock if it failed the first time before giving up. The initial sleep after failing to acquire the lock is 5 seconds. After each next try, a sleep of 5 seconds extra occurs up to a maximum sleep of 60 seconds between tries. The default number of retries is 5. -m Lock or unlock the current users mailbox. The path to the mailbox is the default system mailspool directory (usually /var/mail) with the username as gotten from getpwuid() appended. If the environment variable $MAIL is set, that is used instead. Then the string ".lock" is appended to get the name of the actual lockfile. lockfile The lockfile to be created/removed, unless the -m option is in effect. RETURN VALUE
Zero on success, and non-zero on failure. For the -c option, sucess means that a valid lockfile is already present. When locking (the default, or the -l option) dotlockfile returns the same values as the library function lockfile_create(3). Unlocking a non-existant lock- file is not an error. NOTES
The lockfile is created exactly as named on the command line. The extension .lock is not automatically added. This utility is a lot like the lockfile(1) utility included with procmail, and the mutt_dotlock(1) utility included with mutt. However the command-line arguments differ, and so does the return status. It is believed that dotlockfile is the most flexible implementation, since it automatically detects when it needs to use priviliges to lock a mailbox, and does it safely. The above mentioned lockfile_create(3) manpage is present in the liblockfile-dev package. BUGS
None known. SEE ALSO
lockfile_create(3), maillock(3) AUTHOR
Miquel van Smoorenburg, miquels@cistron.nl 15 May 2003 DOTLOCKFILE(1)
Man Page