File: lockmail.1

package info (click to toggle)
maildrop 2.0.2-11%2Betch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 15,640 kB
  • ctags: 4,350
  • sloc: ansic: 61,420; cpp: 10,038; sh: 8,515; perl: 2,637; makefile: 840
file content (150 lines) | stat: -rw-r--r-- 5,339 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
.\"  <!-- $Id: lockmail.sgml,v 1.4 2005/06/18 23:45:44 mrsam Exp $ -->
.\"  <!-- Copyright 2002 Double Precision, Inc.  See COPYING for -->
.\"  <!-- distribution information. -->
.\" This manpage has been automatically generated by docbook2man 
.\" from a DocBook document.  This tool can be found at:
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/> 
.\" Please send any bug reports, improvements, comments, patches, 
.\" etc. to Steve Cheng <steve@ggi-project.org>.
.TH "LOCKMAIL" "1" "18 June 2005" "Double Precision, Inc." ""

.SH NAME
lockmail \- create mail lock files
.SH SYNOPSIS

\fBlockmail\fR [ \fB-r\fR ] [ \fB-t \fItimeout\fB\fR ] \fB\fIlockfile\fB\fR \fB\fIprogram\fB\fR [ \fBargument\fR\fI ...\fR ]

.SH "DESCRIPTION"
.PP
\fBlockmail\fR 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.
\fBlockmail\fR uses two of the most common locking mechanisms
in use, which should work reliably on most systems.
.PP
\fIlockfile\fR is the pathname to an existing mailbox
file.
By default, \fBlockmail\fR 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, \fBlockmail\fR runs
\fIprogram\fR as a child process, with any optional
\fIargument\fRs.
When \fIprogram\fR terminates, \fBlockmail\fR
removes the mailbox lock, and terminates itself.
.SH "OPTIONS"
.TP
\fB-r\fR
If a regular lock fails, try a read-only lock.
Use this option to lock mailbox files in a read-only directory.
.TP
\fB-t \fItimeout\fB\fR
If the lock attempt fails, try again for up to
\fItimeout\fR seconds.
The actual timeout is rounded up to the next five second interval
(a lock attempt is tried every five seconds).
.SH "DESCRIPTION"
.PP
This section briefly describes the locking mechanism used by
\fBlockmail\fR\&.
\fBlockmail\fR uses three different locking conventions in
order to maximize compatibility with other mail software:
C-Client folder locks, dot-locks, and file locks.
.SS "C-CLIENT FOLDER LOCKS"
.PP
Mail software based on the C-Client library creates
lock files named
\fI/tmp/.dddddd\&.iiiiii\fR\&.
Here, \fIdddddd\fR and \fIiiiiii\fR
are the device number and the inode number of the mailbox file
(the \fBst_dev\fR and \fBst_ino\fR
fields in the inode), in hexadecimal.
If the process ID saved in the C-Client folder lock file is not valid,
\fBlockmail\fR concludes that it's a stale lock file, and
will remove it.
.sp
.RS
.B "Note:"
.PP
A race condition exists where a C-Client 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 C-Client library does not appear to ever clear out
the lock file.
.PP
\fBlockmail\fR
attempts to resolve this race condition by deleting zero-length lock files
that are at least five minutes old.
.RE
.SS "DOT-LOCKS"
.PP
\fBlockmail\fR
also creates, and honors dot-lock files.
Dot-lock files are first created as temporary files, then linked to
\fIlockfile\&.lock\fR\&.
The link operation fails if the dot-lock file already exists.
\fBlockmail\fR
uses an enhanced method of dot-locking, where its process ID, and the name
of the server where \fBlockmail\fR 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 \fBlockmail\fR 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.
.sp
.RS
.B "Note:"
A failure to create a dot-lock file is silently ignored if the reason for
the failure is because
\fBlockmail\fR
does not have the write permission in the dot-lock file's directory.
The incoming mail spool directory (usually
\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
\fBlockmail\fR
will be content with using file-locking only.
.RE
.SS "FILE LOCKS"
.PP
The final locking mechanism
\fBlockmail\fR
uses is the operating system's file locking facility.
If
\fBlockmail\fR
fails to obtain all three locks,
\fBlockmail\fR
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
\fBlockmail\fR
still fails to obtain all required locks in the amount of time specified
by the \fB-t\fR option (or its default value),
\fBlockmail\fR will terminate with the
EX_TEMPFAIL exit code.
.PP
\fBlockmail\fR
runs \fIprogram\fR after obtaining the last file
lock, waits until \fIprogram\fR terminates, and
releases all locks.
\fIprogram\fR must terminate before any of the locks
obtained by \fBlockmail\fR expire, and are considered stale.
\fBlockmail\fR will then terminate with the same exit code
as \fIprogram\fR\&.
.SH "EXIT STATUS"
.PP
\fBlockmail\fR terminates with the same exit status as
\fIprogram\fR
\fBlockmail\fR terminates with the EX_TEMPFAIL
exit status if it was unable to obtain a lock, or if
\fIprogram\fR
was killed by a signal.
.SH "SEE ALSO"
.PP
\fBmaildrop\fR(1),
\fBsendmail\fR(8)\&.