Merge branch 'debian'
[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:
6.\" Generator: DocBook XSL Stylesheets v1.72.0 <http://docbook.sf.net/>
7.\" Date: 04/22/2007
8.\" Manual: Double Precision, Inc.
9.\" Source: Double Precision, Inc.
10.\"
11.TH "LOCKMAIL" "1" "04/22/2007" "Double Precision, Inc." "Double Precision, Inc."
12.\" disable hyphenation
13.nh
14.\" disable justification (adjust text to left margin only)
15.ad l
16.SH "NAME"
17lockmail \- create mail lock files
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
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.
26\fBlockmail\fR
27uses two of the most common locking mechanisms in use, which should work reliably on most systems.
28.PP
29
30\fIlockfile\fR
31is the pathname to an existing mailbox file. By default,
32\fBlockmail\fR
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,
34\fBlockmail\fR
35runs
36\fIprogram\fR
37as a child process, with any optional
38\fIargument\fRs. When
39\fIprogram\fR
40terminates,
41\fBlockmail\fR
42removes the mailbox lock, and terminates itself.
43.SH "OPTIONS"
44.PP
45\-r
46.RS 4
47If a regular lock fails, try a read\-only lock. Use this option to lock mailbox files in a read\-only directory.
48.RE
49.PP
50\-t \fItimeout\fR
51.RS 4
52If the lock attempt fails, try again for up to
53\fItimeout\fR
54seconds. The actual timeout is rounded up to the next five second interval (a lock attempt is tried every five seconds).
55.RE
56.SH "DESCRIPTION"
57.PP
58This section briefly describes the locking mechanism used by
59\fBlockmail\fR.
60\fBlockmail\fR
61uses 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"
63.PP
64Mail software based on the
65C\-Client
66library creates lock files named
67\fI/tmp/.\fR\fI\fIdddddd\fR\fR\fI.\fR\fI\fIiiiiii\fR\fR. Here,
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
75fields in the inode), in hexadecimal. If the process ID saved in the C\-Client folder lock file is not valid,
76\fBlockmail\fR
77concludes that it's a stale lock file, and will remove it.
78.sp
79.it 1 an-trap
80.nr an-no-space-flag 1
81.nr an-break-flag 1
82.br
83\fBNote\fR
84.PP
85A race condition exists where a
86C\-Client
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
88C\-Client
89library does not appear to ever clear out the lock file.
90.PP
91
92\fBlockmail\fR
93attempts to resolve this race condition by deleting zero\-length lock files that are at least five minutes old.
94.SS "dot\-locks"
95.PP
96
97\fBlockmail\fR
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.
100\fBlockmail\fR
101uses an enhanced method of dot\-locking, where its process ID, and the name of the server where
102\fBlockmail\fR
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
104\fBlockmail\fR
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.
106.sp
107.it 1 an-trap
108.nr an-no-space-flag 1
109.nr an-break-flag 1
110.br
111\fBNote\fR
112.PP
113A failure to create a dot\-lock file is silently ignored if the reason for the failure is because
114\fBlockmail\fR
115does 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
117\fBlockmail\fR
118will be content with using file\-locking only.
119.SS "File locks"
120.PP
121The final locking mechanism
122\fBlockmail\fR
123uses is the operating system's file locking facility. If
124\fBlockmail\fR
125fails to obtain all three locks,
126\fBlockmail\fR
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
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
135exit code.
136.PP
137
138\fBlockmail\fR
139runs
140\fIprogram\fR
141after obtaining the last file lock, waits until
142\fIprogram\fR
143terminates, and releases all locks.
144\fIprogram\fR
145must terminate before any of the locks obtained by
146\fBlockmail\fR
147expire, and are considered stale.
148\fBlockmail\fR
149will then terminate with the same exit code as
150\fIprogram\fR.
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
162was killed by a signal.
163.SH "SEE ALSO"
164.PP
165
166\fI\fBmaildrop\fR(1)\fR\&[1],
167\fBsendmail\fR(8).
168.SH "REFERENCES"
169.IP " 1." 4
170\fBmaildrop\fR(1)
171.RS 4
172\%maildrop.html
173.RE