1 .\" <!-- $Id: lockmail.sgml,v 1.8 2007/04/22 15:05:16 mrsam Exp $ -->
2 .\" <!-- Copyright 2002-2007 Double Precision, Inc. See COPYING for -->
3 .\" <!-- distribution information. -->
6 .\" Generator: DocBook XSL Stylesheets v1.72.0 <http://docbook.sf.net/>
8 .\" Manual: Double Precision, Inc.
9 .\" Source: Double Precision, Inc.
11 .TH "LOCKMAIL" "1" "04/22/2007" "Double Precision, Inc." "Double Precision, Inc."
12 .\" disable hyphenation
14 .\" disable justification (adjust text to left margin only)
17 lockmail \- create mail lock files
20 \fBlockmail\fR [\-r] [\-t\ \fItimeout\fR] {\fIlockfile\fR} {\fIprogram\fR} [argument...]
25 is a helper utility for working with mailbox files. Mailbox files must be locked to prevent other applications from modifying the mailbox at the same time. Different system use different locking conventions.
27 uses two of the most common locking mechanisms in use, which should work reliably on most systems.
31 is the pathname to an existing mailbox file. By default,
33 tries to lock the mailbox every five seconds (if the mailbox is already locked), and will give up after three minutes. After the mailbox is succesfully locked,
37 as a child process, with any optional
42 removes the mailbox lock, and terminates itself.
47 If a regular lock fails, try a read\-only lock. Use this option to lock mailbox files in a read\-only directory.
52 If the lock attempt fails, try again for up to
54 seconds. The actual timeout is rounded up to the next five second interval (a lock attempt is tried every five seconds).
58 This section briefly describes the locking mechanism used by
61 uses three different locking conventions in order to maximize compatibility with other mail software: C\-Client folder locks, dot\-locks, and file locks.
62 .SS "C\-Client folder locks"
64 Mail software based on the
66 library creates lock files named
67 \fI/tmp/.\fR\fI\fIdddddd\fR\fR\fI.\fR\fI\fIiiiiii\fR\fR. Here,
71 are the device number and the inode number of the mailbox file (the
75 fields in the inode), in hexadecimal. If the process ID saved in the C\-Client folder lock file is not valid,
77 concludes that it's a stale lock file, and will remove it.
80 .nr an-no-space-flag 1
85 A race condition exists where a
87 process is killed after it creates a lock file, but before saving its process ID in the lock file. The race window is very small, but it exists. The
89 library does not appear to ever clear out the lock file.
93 attempts to resolve this race condition by deleting zero\-length lock files that are at least five minutes old.
98 also creates, and honors dot\-lock files. Dot\-lock files are first created as temporary files, then linked to
99 \fI\fIlockfile\fR\fR\fI.lock\fR. The link operation fails if the dot\-lock file already exists.
101 uses an enhanced method of dot\-locking, where its process ID, and the name of the server where
103 is running is also saved in its dot\-lock file. If the operation fails due to an existing dot\-lock file that was created by another
105 process on the same server, and the process ID no longer exists, this stale dot\-lock file is removed immediately. In all other situations a dot\-lock file older than five minutes is considered stale, and removed.
108 .nr an-no-space-flag 1
113 A failure to create a dot\-lock file is silently ignored if the reason for the failure is because
115 does not have the write permission in the dot\-lock file's directory. The incoming mail spool directory (usually
116 \fI/var/mail\fR) typically does not have global write permissions, so the attempt to create the dot\-lock file in the spool directory will fail, and
118 will be content with using file\-locking only.
121 The final locking mechanism
123 uses is the operating system's file locking facility. If
125 fails to obtain all three locks,
127 will sleep for five seconds and try again. The only exception is a failure to create a dot\-lock because of no write access to the dot\-lock file's directory, which is ignored. If
129 still fails to obtain all required locks in the amount of time specified by the
131 option (or its default value),
133 will terminate with the
141 after obtaining the last file lock, waits until
143 terminates, and releases all locks.
145 must terminate before any of the locks obtained by
147 expire, and are considered stale.
149 will then terminate with the same exit code as
155 terminates with the same exit status as
160 exit status if it was unable to obtain a lock, or if
162 was killed by a signal.
166 \fI\fBmaildrop\fR(1)\fR\&[1],