2 .\"<!-- Copyright 2002-2007 Double Precision, Inc. See COPYING for -->
3 .\"<!-- distribution information. -->
5 .\" Author: Sam Varshavchik
6 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
8 .\" Manual: Double Precision, Inc.
9 .\" Source: Courier Mail Server
12 .TH "LOCKMAIL" "1" "09/08/2017" "Courier Mail Server" "Double Precision, Inc\&."
13 .\" -----------------------------------------------------------------
14 .\" * Define some portability stuff
15 .\" -----------------------------------------------------------------
16 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17 .\" http://bugs.debian.org/507673
18 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
19 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 .\" -----------------------------------------------------------------
23 .\" * set default formatting
24 .\" -----------------------------------------------------------------
25 .\" disable hyphenation
27 .\" disable justification (adjust text to left margin only)
29 .\" -----------------------------------------------------------------
30 .\" * MAIN CONTENT STARTS HERE *
31 .\" -----------------------------------------------------------------
33 lockmail \- create mail lock files
35 .HP \w'\fBlockmail\fR\ 'u
36 \fBlockmail\fR [\-r] [\-t\ \fItimeout\fR] {\fIlockfile\fR} {\fIprogram\fR} [argument...]
40 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\&.
42 uses two of the most common locking mechanisms in use, which should work reliably on most systems\&.
45 is the pathname to an existing mailbox file\&. By default,
47 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 successfully locked,
51 as a child process, with any optional
52 \fIargument\fRs\&. When
56 removes the mailbox lock, and terminates itself\&.
61 If a regular lock fails, try a read\-only lock\&. Use this option to lock mailbox files in a read\-only directory\&.
66 If the lock attempt fails, try again for up to
68 seconds\&. The actual timeout is rounded up to the next five second interval (a lock attempt is tried every five seconds)\&.
72 This section briefly describes the locking mechanism used by
75 uses three different locking conventions in order to maximize compatibility with other mail software: C\-Client folder locks, dot\-locks, and file locks\&.
76 .SS "C\-Client folder locks"
78 Mail software based on the
80 library creates lock files named
81 /tmp/\&.\fIdddddd\fR\&.\fIiiiiii\fR\&. Here,
85 are the device number and the inode number of the mailbox file (the
89 fields in the inode), in hexadecimal\&. If the process ID saved in the C\-Client folder lock file is not valid,
91 concludes that it\*(Aqs a stale lock file, and will remove it\&.
97 .nr an-no-space-flag 1
105 A race condition exists where a
107 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
109 library does not appear to ever clear out the lock file\&.
112 attempts to resolve this race condition by deleting zero\-length lock files that are at least five minutes old\&.
118 also creates, and honors dot\-lock files\&. Dot\-lock files are first created as temporary files, then linked to
119 \fIlockfile\fR\&.lock\&. The link operation fails if the dot\-lock file already exists\&.
121 uses an enhanced method of dot\-locking, where its process ID, and the name of the server where
123 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
125 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\&.
131 .nr an-no-space-flag 1
139 A failure to create a dot\-lock file is silently ignored if the reason for the failure is because
141 does not have the write permission in the dot\-lock file\*(Aqs directory\&. The incoming mail spool directory (usually
142 /var/mail) typically does not have global write permissions, so the attempt to create the dot\-lock file in the spool directory will fail, and
144 will be content with using file\-locking only\&.
149 The final locking mechanism
151 uses is the operating system\*(Aqs file locking facility\&. If
153 fails to obtain all three locks,
155 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\*(Aqs directory, which is ignored\&. If
157 still fails to obtain all required locks in the amount of time specified by the
159 option (or its default value),
161 will terminate with the
168 after obtaining the last file lock, waits until
170 terminates, and releases all locks\&.
172 must terminate before any of the locks obtained by
174 expire, and are considered stale\&.
176 will then terminate with the same exit code as
181 terminates with the same exit status as
186 exit status if it was unable to obtain a lock, or if
188 was killed by a signal\&.
191 \m[blue]\fB\fBmaildrop\fR(1)\fR\m[]\&\s-2\u[1]\d\s+2,
195 \fBSam Varshavchik\fR
203 \%http://www.courier-mta.org/maildrop.html