Commit | Line | Data |
---|---|---|
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 | 17 | lockmail - 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 | 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\. |
d9898ee8 | 26 | \fBlockmail\fR |
8d138742 | 27 | uses two of the most common locking mechanisms in use, which should work reliably on most systems\. |
d9898ee8 | 28 | .PP |
29 | ||
30 | \fIlockfile\fR | |
8d138742 | 31 | is the pathname to an existing mailbox file\. By default, |
d9898ee8 | 32 | \fBlockmail\fR |
8d138742 | 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, |
d9898ee8 | 34 | \fBlockmail\fR |
35 | runs | |
36 | \fIprogram\fR | |
37 | as a child process, with any optional | |
8d138742 | 38 | \fIargument\fRs\. When |
d9898ee8 | 39 | \fIprogram\fR |
40 | terminates, | |
41 | \fBlockmail\fR | |
8d138742 | 42 | removes the mailbox lock, and terminates itself\. |
d9898ee8 | 43 | .SH "OPTIONS" |
44 | .PP | |
45 | \-r | |
46 | .RS 4 | |
8d138742 | 47 | If 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 | |
52 | If the lock attempt fails, try again for up to | |
53 | \fItimeout\fR | |
8d138742 | 54 | seconds\. 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 | |
58 | This section briefly describes the locking mechanism used by | |
8d138742 | 59 | \fBlockmail\fR\. |
d9898ee8 | 60 | \fBlockmail\fR |
8d138742 | 61 | uses 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 | |
64 | Mail software based on the | |
65 | C\-Client | |
66 | library creates lock files named | |
8d138742 | 67 | \fI/tmp/\.\fR\fI\fIdddddd\fR\fR\fI\.\fR\fI\fIiiiiii\fR\fR\. Here, |
d9898ee8 | 68 | \fIdddddd\fR |
69 | and | |
70 | \fIiiiiii\fR | |
71 | are the device number and the inode number of the mailbox file (the | |
72 | st_dev | |
73 | and | |
74 | st_ino | |
8d138742 | 75 | fields 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 | 77 | concludes 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 | 83 | Note |
d9898ee8 | 84 | .PP |
85 | A race condition exists where a | |
86 | C\-Client | |
8d138742 | 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 |
d9898ee8 | 88 | C\-Client |
8d138742 | 89 | library does not appear to ever clear out the lock file\. |
d9898ee8 | 90 | .PP |
91 | ||
92 | \fBlockmail\fR | |
8d138742 | 93 | attempts 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 |
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\. | |
d9898ee8 | 100 | \fBlockmail\fR |
101 | uses an enhanced method of dot\-locking, where its process ID, and the name of the server where | |
102 | \fBlockmail\fR | |
8d138742 | 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 |
d9898ee8 | 104 | \fBlockmail\fR |
8d138742 | 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\. |
d9898ee8 | 106 | .sp |
107 | .it 1 an-trap | |
108 | .nr an-no-space-flag 1 | |
109 | .nr an-break-flag 1 | |
110 | .br | |
8d138742 | 111 | Note |
d9898ee8 | 112 | .PP |
113 | A failure to create a dot\-lock file is silently ignored if the reason for the failure is because | |
114 | \fBlockmail\fR | |
8d138742 | 115 | does 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 | 118 | will be content with using file\-locking only\. |
d9898ee8 | 119 | .SS "File locks" |
120 | .PP | |
121 | The final locking mechanism | |
122 | \fBlockmail\fR | |
8d138742 | 123 | uses is the operating system\'s file locking facility\. If |
d9898ee8 | 124 | \fBlockmail\fR |
125 | fails to obtain all three locks, | |
126 | \fBlockmail\fR | |
8d138742 | 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 |
d9898ee8 | 128 | \fBlockmail\fR |
129 | still fails to obtain all required locks in the amount of time specified by the | |
130 | \fB\-t\fR | |
131 | option (or its default value), | |
132 | \fBlockmail\fR | |
133 | will terminate with the | |
134 | EX_TEMPFAIL | |
8d138742 | 135 | exit code\. |
d9898ee8 | 136 | .PP |
137 | ||
138 | \fBlockmail\fR | |
139 | runs | |
140 | \fIprogram\fR | |
141 | after obtaining the last file lock, waits until | |
142 | \fIprogram\fR | |
8d138742 | 143 | terminates, and releases all locks\. |
d9898ee8 | 144 | \fIprogram\fR |
145 | must terminate before any of the locks obtained by | |
146 | \fBlockmail\fR | |
8d138742 | 147 | expire, and are considered stale\. |
d9898ee8 | 148 | \fBlockmail\fR |
149 | will then terminate with the same exit code as | |
8d138742 | 150 | \fIprogram\fR\. |
d9898ee8 | 151 | .SH "EXIT STATUS" |
152 | .PP | |
153 | ||
154 | \fBlockmail\fR | |
155 | terminates with the same exit status as | |
156 | \fIprogram\fR | |
157 | \fBlockmail\fR | |
158 | terminates with the | |
159 | EX_TEMPFAIL | |
160 | exit status if it was unable to obtain a lock, or if | |
161 | \fIprogram\fR | |
8d138742 | 162 | was 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 |