OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / procmail / original / man1 / lockfile.1
1 .\"if n .pl +(135i-\n(.pu)
2 .de Id
3 .ds Rv \\$3
4 .ds Dt \\$4
5 ..
6 .Id $Id: lockfile.1,v 1.1 2003/06/16 17:06:40 motoki Exp $
7 .TH LOCKFILE 1 \*(Dt BuGless
8 .rn SH Sh
9 .de SH
10 .br
11 .ne 11
12 .Sh "\\$1"
13 ..
14 .rn SS Ss
15 .de SS
16 .br
17 .ne 10
18 .Ss "\\$1"
19 ..
20 .rn TP Tp
21 .de TP
22 .br
23 .ne 9
24 .Tp \\$1
25 ..
26 .rn RS Rs
27 .de RS
28 .na
29 .nf
30 .Rs
31 ..
32 .rn RE Re
33 .de RE
34 .Re
35 .fi
36 .ad
37 ..
38 .de Sx
39 .PP
40 .ne \\$1
41 .RS
42 ..
43 .de Ex
44 .RE
45 .PP
46 ..
47 .na
48 .SH NAME
49 lockfile \- conditional semaphore-file creator
50 .SH SYNOPSIS
51 .B lockfile
52 .I "\fB\-\fPsleeptime"
53 |
54 .I "\fB\-r \fPretries"
55 |
56 .if n .ti +0.5i
57 .I "\fB\-l \fPlocktimeout"
58 |
59 .I "\fB\-s \fPsuspend"
60 |
61 .B "\-!"
62 |
63 .B "\-ml"
64 |
65 .B "\-mu"
66 |
67 .I filename
68 \&.\|.\|.
69 .ad
70 .SH DESCRIPTION
71 .B lockfile
72 can be used to create one or more
73 .I semaphore
74 .IR files .
75 If lockfile can't create all the specified files (in the specified order),
76 it waits
77 .I sleeptime
78 (defaults to 8) seconds and retries the last file that didn't
79 succeed.  You can specify the number of
80 .I retries
81 to do until failure is returned.
82 If the number of
83 .I retries
84 is \-1 (default, i.e.,
85 .BR \-r\-1 )
86 lockfile will retry forever.
87 .PP
88 If the number of
89 .I retries
90 expires before all files have been created, lockfile returns failure and
91 removes all the files it created up till that point.
92 .PP
93 Using lockfile as the condition of a loop in a shell script can be done
94 easily by using the
95 .B \-!
96 flag to invert the exit status.  To prevent infinite loops, failures
97 for any reason other than the lockfile already existing are not
98 inverted to success but rather are still returned as failures.
99 .PP
100 All flags can be specified anywhere on the command line, they will be
101 processed when encountered.  The command line is simply parsed from
102 left to right.
103 .PP
104 All files created by lockfile will be read-only, and therefore
105 will have to be removed with
106 .B rm
107 .BR \-f .
108 .PP
109 If you specify a
110 .I locktimeout
111 then a lockfile will be removed by force after locktimeout seconds have
112 passed since the lockfile was last modified/created (most likely by some
113 other program that unexpectedly died a long time ago, and hence could not clean
114 up any leftover lockfiles).  Lockfile is clock skew immune.  After a lockfile
115 has been removed by force, a suspension of
116 .I suspend
117 seconds (defaults to 16) is taken into account, in order to prevent
118 the inadvertent immediate removal of any newly created lockfile by another
119 program (compare
120 .BR SUSPEND
121 in
122 .BR procmail (1)).
123 .SS "Mailbox locks"
124 If the permissions on the system mail spool directory allow it, or if lockfile
125 is suitably setgid, it will be able to lock and unlock your system mailbox by
126 using the options
127 .B "\-ml"
128 and
129 .B "\-mu"
130 respectively.
131 .SH EXAMPLES
132 Suppose you want to make sure that access to the file "important" is
133 serialised, i.e., no more than one program or shell script should be allowed
134 to access it.  For simplicity's sake, let's suppose that it is a shell
135 script.  In this case you could solve it like this:
136 .RS
137 \&.\|.\|.
138 lockfile important.lock
139 \&.\|.\|.
140 access_"important"_to_your_hearts_content
141 \&.\|.\|.
142 rm \-f important.lock
143 \&.\|.\|.
144 .RE
145 Now if all the scripts that access "important" follow this guideline, you
146 will be assured that at most one script will be executing between the
147 `lockfile' and the `rm' commands.
148 .SH ENVIRONMENT
149 .TP 2.3i
150 .B LOGNAME
151 used as a hint to determine the invoker's loginname
152 .SH FILES
153 .TP 2.3i
154 .B /etc/passwd
155 to verify and/or correct the invoker's loginname (and to find out his HOME
156 directory, if needed)
157 .TP
158 .B /var/spool/mail/$LOGNAME.lock
159 lockfile for the system mailbox, the environment variables present in here
160 will not be taken from the environment, but will be determined by looking
161 in /etc/passwd
162 .SH "SEE ALSO"
163 .na
164 .nh
165 .BR rm (1),
166 .BR mail (1),
167 .BR binmail (1),
168 .BR sendmail (8),
169 .BR procmail (1)
170 .hy
171 .ad
172 .SH DIAGNOSTICS
173 .TP 2.3i
174 Filename too long, .\|.\|.
175 Use shorter filenames.
176 .TP
177 Forced unlock denied on "x"
178 No write permission in the directory where lockfile "x" resides, or more than
179 one lockfile trying to force a lock at exactly the same time.
180 .TP
181 Forcing lock on "x"
182 Lockfile "x" is going to be removed by force because of a timeout
183 (compare
184 .BR LOCKTIMEOUT
185 in
186 .BR procmail (1)).
187 .TP
188 Out of memory, .\|.\|.
189 The system is out of swap space.
190 .TP
191 Signal received, .\|.\|.
192 Lockfile will remove anything it created till now and terminate.
193 .TP
194 Sorry, .\|.\|.
195 The
196 .I retries
197 limit has been reached.
198 .TP
199 Truncating "x" and retrying lock
200 "x" does not seem to be a valid filename.
201 .TP
202 Try praying, .\|.\|.
203 Missing subdirectories or insufficient privileges.
204 .SH BUGS
205 Definitely less than one.
206 .SH WARNINGS
207 The behavior of the
208 .B \-!
209 flag, while useful, is not necessarily intuitive or consistent.  When
210 testing lockfile's return value, shell script writers should consider
211 carefully whether they want to use the
212 .B \-!
213 flag, simply reverse the test, or do a switch on the exact exitcode.
214 In general, the
215 .B \-!
216 flag should only be used when lockfile is the conditional of a loop.
217 .SH MISCELLANEOUS
218 Lockfile is NFS-resistant and eight-bit clean.
219 .SH NOTES
220 Calling up lockfile with the \-h or \-? options will cause
221 it to display a command-line help page.  Calling it up with the \-v
222 option will cause it to display its version information.
223 .PP
224 Multiple
225 .B \-!
226 flags will toggle the return status.
227 .PP
228 Since flags can occur anywhere on the command line, any filename starting
229 with a '-' has to be preceded by './'.
230 .PP
231 The number of
232 .I retries
233 will not be reset when any following file is being created (i.e., they are
234 simply used up).  It can, however, be reset by specifying
235 .RI \-r newretries
236 after every file on the command line.
237 .PP
238 Although files with any name can be used as lockfiles, it is common practice
239 to use the extension `.lock' to lock mailfolders (it is appended to the
240 mailfolder name).  In case one does not want to have to worry about too long
241 filenames and does not have to conform to any other lockfilename convention,
242 then an excellent way to generate a lockfilename corresponding to some already
243 existing file is by taking the prefix `lock.' and appending the i-node number
244 of the file which is to be locked.
245 .Sh SOURCE
246 This program is part of the
247 .I procmail mail-processing-package
248 (v3.22) available at http://www.procmail.org/ or
249 ftp.procmail.org in
250 .BR pub/procmail/ .
251 .Sh MAILINGLIST
252 There exists a mailinglist for questions relating to any program in the
253 procmail package:
254 .RS
255 <procmail-users@procmail.org>
256 .RS
257 for submitting questions/answers.
258 .RE
259 <procmail-users-request@procmail.org>
260 .RS
261 for subscription requests.
262 .RE
263 .PP
264 .RE
265 If you would like to stay informed about new versions and official patches send
266 a subscription request to
267 .RS
268 procmail-announce-request@procmail.org
269 .RE
270 (this is a readonly list).
271 .SH AUTHORS
272 Stephen R. van den Berg
273 .RS
274 <srb@cuci.nl>
275 .RE
276 Philip A. Guenther
277 .RS
278 <guenther@sendmail.com>
279 .RE
280 .\".if n .pl -(\n(.tu-1i)
281 .rm SH
282 .rn Sh SH
283 .rm SS
284 .rn Ss SS
285 .rm TP
286 .rn Tp TP
287 .rm RS
288 .rn Rs RS
289 .rm RE
290 .rn Re RE