Imported Upstream version 0.63.0
[hcoop/debian/courier-authlib.git] / liblock / lockmail.1
CommitLineData
d9898ee8 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. -->
4.\" Title: lockmail
5.\" Author:
8d138742
CE
6.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
7.\" Date: 08/23/2008
d9898ee8 8.\" Manual: Double Precision, Inc.
9.\" Source: Double Precision, Inc.
10.\"
8d138742 11.TH "LOCKMAIL" "1" "08/23/2008" "Double Precision, Inc." "Double Precision, Inc."
d9898ee8 12.\" disable hyphenation
13.nh
14.\" disable justification (adjust text to left margin only)
15.ad l
16.SH "NAME"
8d138742 17lockmail - create mail lock files
d9898ee8 18.SH "SYNOPSIS"
19.HP 9
20\fBlockmail\fR [\-r] [\-t\ \fItimeout\fR] {\fIlockfile\fR} {\fIprogram\fR} [argument...]
21.SH "DESCRIPTION"
22.PP
23
24\fBlockmail\fR
8d138742 25is 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\.
d9898ee8 26\fBlockmail\fR
8d138742 27uses two of the most common locking mechanisms in use, which should work reliably on most systems\.
d9898ee8 28.PP
29
30\fIlockfile\fR
8d138742 31is the pathname to an existing mailbox file\. By default,
d9898ee8 32\fBlockmail\fR
8d138742 33tries 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,
d9898ee8 34\fBlockmail\fR
35runs
36\fIprogram\fR
37as a child process, with any optional
8d138742 38\fIargument\fRs\. When
d9898ee8 39\fIprogram\fR
40terminates,
41\fBlockmail\fR
8d138742 42removes the mailbox lock, and terminates itself\.
d9898ee8 43.SH "OPTIONS"
44.PP
45\-r
46.RS 4
8d138742 47If a regular lock fails, try a read\-only lock\. Use this option to lock mailbox files in a read\-only directory\.
d9898ee8 48.RE
49.PP
50\-t \fItimeout\fR
51.RS 4
52If the lock attempt fails, try again for up to
53\fItimeout\fR
8d138742 54seconds\. The actual timeout is rounded up to the next five second interval (a lock attempt is tried every five seconds)\.
d9898ee8 55.RE
56.SH "DESCRIPTION"
57.PP
58This section briefly describes the locking mechanism used by
8d138742 59\fBlockmail\fR\.
d9898ee8 60\fBlockmail\fR
8d138742 61uses three different locking conventions in order to maximize compatibility with other mail software: C\-Client folder locks, dot\-locks, and file locks\.
d9898ee8 62.SS "C\-Client folder locks"
63.PP
64Mail software based on the
65C\-Client
66library creates lock files named
8d138742 67\fI/tmp/\.\fR\fI\fIdddddd\fR\fR\fI\.\fR\fI\fIiiiiii\fR\fR\. Here,
d9898ee8 68\fIdddddd\fR
69and
70\fIiiiiii\fR
71are the device number and the inode number of the mailbox file (the
72st_dev
73and
74st_ino
8d138742 75fields in the inode), in hexadecimal\. If the process ID saved in the C\-Client folder lock file is not valid,
d9898ee8 76\fBlockmail\fR
8d138742 77concludes that it\'s a stale lock file, and will remove it\.
d9898ee8 78.sp
79.it 1 an-trap
80.nr an-no-space-flag 1
81.nr an-break-flag 1
82.br
8d138742 83Note
d9898ee8 84.PP
85A race condition exists where a
86C\-Client
8d138742 87process 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
d9898ee8 88C\-Client
8d138742 89library does not appear to ever clear out the lock file\.
d9898ee8 90.PP
91
92\fBlockmail\fR
8d138742 93attempts to resolve this race condition by deleting zero\-length lock files that are at least five minutes old\.
d9898ee8 94.SS "dot\-locks"
95.PP
96
97\fBlockmail\fR
8d138742
CE
98also 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\.
d9898ee8 100\fBlockmail\fR
101uses an enhanced method of dot\-locking, where its process ID, and the name of the server where
102\fBlockmail\fR
8d138742 103is 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
d9898ee8 104\fBlockmail\fR
8d138742 105process 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\.
d9898ee8 106.sp
107.it 1 an-trap
108.nr an-no-space-flag 1
109.nr an-break-flag 1
110.br
8d138742 111Note
d9898ee8 112.PP
113A failure to create a dot\-lock file is silently ignored if the reason for the failure is because
114\fBlockmail\fR
8d138742 115does not have the write permission in the dot\-lock file\'s directory\. The incoming mail spool directory (usually
d9898ee8 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
117\fBlockmail\fR
8d138742 118will be content with using file\-locking only\.
d9898ee8 119.SS "File locks"
120.PP
121The final locking mechanism
122\fBlockmail\fR
8d138742 123uses is the operating system\'s file locking facility\. If
d9898ee8 124\fBlockmail\fR
125fails to obtain all three locks,
126\fBlockmail\fR
8d138742 127will 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
d9898ee8 128\fBlockmail\fR
129still fails to obtain all required locks in the amount of time specified by the
130\fB\-t\fR
131option (or its default value),
132\fBlockmail\fR
133will terminate with the
134EX_TEMPFAIL
8d138742 135exit code\.
d9898ee8 136.PP
137
138\fBlockmail\fR
139runs
140\fIprogram\fR
141after obtaining the last file lock, waits until
142\fIprogram\fR
8d138742 143terminates, and releases all locks\.
d9898ee8 144\fIprogram\fR
145must terminate before any of the locks obtained by
146\fBlockmail\fR
8d138742 147expire, and are considered stale\.
d9898ee8 148\fBlockmail\fR
149will then terminate with the same exit code as
8d138742 150\fIprogram\fR\.
d9898ee8 151.SH "EXIT STATUS"
152.PP
153
154\fBlockmail\fR
155terminates with the same exit status as
156\fIprogram\fR
157\fBlockmail\fR
158terminates with the
159EX_TEMPFAIL
160exit status if it was unable to obtain a lock, or if
161\fIprogram\fR
8d138742 162was killed by a signal\.
d9898ee8 163.SH "SEE ALSO"
164.PP
165
166\fI\fBmaildrop\fR(1)\fR\&[1],
8d138742
CE
167\fBsendmail\fR(8)\.
168.SH "NOTES"
d9898ee8 169.IP " 1." 4
170\fBmaildrop\fR(1)
171.RS 4
172\%maildrop.html
173.RE