[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    maillock(3X) manual page Table of Contents

Name

maillock - manage lockfile for user’s mailbox

Synopsis

cc [ flag ... ] file ... -lmail [ library ... ]

#include <maillock.h>

int maillock(const char *user, int retrycnt);

int mailunlock(void);

MT-Level

Unsafe

Description

The maillock() function attempts to create a lockfile for the user’s mailfile. If a lockfile already exists, and it has not been modified in the last 5 minutes, maillock() will remove the lockfile and set it’s own lockfile.

It is crucial that programs locking mail files refresh their locks at least every minute. Lockfiles are refreshed by calling the routine touchlock() with no arguments. It should be called before doing anything that might keep the system busy for a long time. It should be called at least every 3 minutes or the process may lose its lock on the mail file. In practice, arranging to call it once a minute works well.

The algorithm used to determine the age of the lockfile takes into account clock drift between machines using a network file system. A zero is written into the lockfile so that the lock will be respected by systems running the standard version of System V.

If the lockfile has been modified in the last 5 minutes the process will sleep until the lock is available. The sleep algorithm is to sleep for 5 seconds times the attempt number. That is, the first sleep will be for 5 seconds, the next sleep will be for 10 seconds, etc. until the number of attempts reaches retrycnt.

When the lockfile is no longer needed, it should be removed by calling mailunlock().

user is the login name of the user for whose mailbox the lockfile will be created. maillock() assumes that users’ mailfiles are in the ‘‘standard’’ place as defined in <maillock.h>.

Return Values

The following return code definitions are contained in <maillock.h>.

#defineL_SUCCESS 0/* Lockfile created or removed */
#defineL_NAMELEN 1/* Recipient name > 13 chars */
#defineL_TMPLOCK 2/* Can’t create tmp file */
#defineL_TMPWRITE 3/* Can’t write pid into lockfile */
#defineL_MAXTRYS 4/* Failed after retrycnt attempts */
#defineL_ERROR 5/* Check errno for reason */

Files

LIBDIR/llib-mail.ln
LIBDIR/mail.a
/var/mail/*
/var/mail/*.lock

Notes

mailunlock() will only remove the lockfile created from the most previous call to maillock(). Calling maillock() for different users without intervening calls to mailunlock() will cause the initially created lockfile(s) to remain, potentially blocking subsequent message delivery until the current process finally terminates.


Table of Contents