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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML
><HEAD
><link rel='stylesheet' type='text/css' href='manpage.css'>
<!-- $Id: lockmail.sgml,v 1.4 2005/06/18 23:45:44 mrsam Exp $ -->
<!-- Copyright 2002 Double Precision, Inc. See COPYING for -->
<!-- distribution information. -->
<meta name="MSSmartTagsPreventParsing" content="TRUE">
<link rel="icon" href="icon.gif" type="image/gif" />
<TITLE
>lockmail</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"></HEAD
><BODY
CLASS="REFENTRY"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><H1
><A
NAME="LOCKMAIL"
></A
>lockmail</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN10"
></A
><H2
>Name</H2
>lockmail -- create mail lock files</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN13"
></A
><H2
>Synopsis</H2
><P
><B
CLASS="COMMAND"
>lockmail</B
> [-r] [-t <VAR
CLASS="REPLACEABLE"
>timeout</VAR
>] {<VAR
CLASS="REPLACEABLE"
>lockfile</VAR
>} {<VAR
CLASS="REPLACEABLE"
>program</VAR
>} [argument...]</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN24"
></A
><H2
>DESCRIPTION</H2
><P
><B
CLASS="COMMAND"
>lockmail</B
> 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.
<B
CLASS="COMMAND"
>lockmail</B
> uses two of the most common locking mechanisms
in use, which should work reliably on most systems.</P
><P
><VAR
CLASS="REPLACEABLE"
>lockfile</VAR
> is the pathname to an existing mailbox
file.
By default, <B
CLASS="COMMAND"
>lockmail</B
> 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, <B
CLASS="COMMAND"
>lockmail</B
> runs
<VAR
CLASS="REPLACEABLE"
>program</VAR
> as a child process, with any optional
<VAR
CLASS="REPLACEABLE"
>argument</VAR
>s.
When <VAR
CLASS="REPLACEABLE"
>program</VAR
> terminates, <B
CLASS="COMMAND"
>lockmail</B
>
removes the mailbox lock, and terminates itself.</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN37"
></A
><H2
>OPTIONS</H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>-r</DT
><DD
><P
>If a regular lock fails, try a read-only lock.
Use this option to lock mailbox files in a read-only directory.</P
></DD
><DT
>-t <VAR
CLASS="REPLACEABLE"
>timeout</VAR
></DT
><DD
><P
>If the lock attempt fails, try again for up to
<VAR
CLASS="REPLACEABLE"
>timeout</VAR
> seconds.
The actual timeout is rounded up to the next five second interval
(a lock attempt is tried every five seconds).</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN50"
></A
><H2
>DESCRIPTION</H2
><P
>This section briefly describes the locking mechanism used by
<B
CLASS="COMMAND"
>lockmail</B
>.
<B
CLASS="COMMAND"
>lockmail</B
> uses three different locking conventions in
order to maximize compatibility with other mail software:
C-Client folder locks, dot-locks, and file locks.</P
><DIV
CLASS="REFSECT2"
><A
NAME="AEN55"
></A
><H3
>C-Client folder locks</H3
><P
>Mail software based on the <TT
CLASS="LITERAL"
>C-Client</TT
> library creates
lock files named
<TT
CLASS="FILENAME"
>/tmp/.<VAR
CLASS="REPLACEABLE"
>dddddd</VAR
>.<VAR
CLASS="REPLACEABLE"
>iiiiii</VAR
></TT
>.
Here, <VAR
CLASS="REPLACEABLE"
>dddddd</VAR
> and <VAR
CLASS="REPLACEABLE"
>iiiiii</VAR
>
are the device number and the inode number of the mailbox file
(the <CODE
CLASS="STRUCTFIELD"
>st_dev</CODE
> and <CODE
CLASS="STRUCTFIELD"
>st_ino</CODE
>
fields in the inode), in hexadecimal.
If the process ID saved in the C-Client folder lock file is not valid,
<B
CLASS="COMMAND"
>lockmail</B
> concludes that it's a stale lock file, and
will remove it.</P
><DIV
CLASS="NOTE"
><P
></P
><TABLE
CLASS="NOTE"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
>NOTE:</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>A race condition exists where a <TT
CLASS="LITERAL"
>C-Client</TT
> 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 <TT
CLASS="LITERAL"
>C-Client</TT
> library does not appear to ever clear out
the lock file.</P
><P
><B
CLASS="COMMAND"
>lockmail</B
>
attempts to resolve this race condition by deleting zero-length lock files
that are at least five minutes old.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN73"
></A
><H3
>dot-locks</H3
><P
><B
CLASS="COMMAND"
>lockmail</B
>
also creates, and honors dot-lock files.
Dot-lock files are first created as temporary files, then linked to
<TT
CLASS="FILENAME"
><VAR
CLASS="REPLACEABLE"
>lockfile</VAR
>.lock</TT
>.
The link operation fails if the dot-lock file already exists.
<B
CLASS="COMMAND"
>lockmail</B
>
uses an enhanced method of dot-locking, where its process ID, and the name
of the server where <B
CLASS="COMMAND"
>lockmail</B
> 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 <B
CLASS="COMMAND"
>lockmail</B
> 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.</P
><DIV
CLASS="NOTE"
><P
></P
><TABLE
CLASS="NOTE"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
>NOTE:</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>A failure to create a dot-lock file is silently ignored if the reason for
the failure is because
<B
CLASS="COMMAND"
>lockmail</B
>
does not have the write permission in the dot-lock file's directory.
The incoming mail spool directory (usually
<TT
CLASS="FILENAME"
>/var/mail</TT
>)
typically does not have global write permissions, so the attempt to
create the dot-lock file in the spool directory will fail, and
<B
CLASS="COMMAND"
>lockmail</B
>
will be content with using file-locking only.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN87"
></A
><H3
>File locks</H3
><P
>The final locking mechanism
<B
CLASS="COMMAND"
>lockmail</B
>
uses is the operating system's file locking facility.
If
<B
CLASS="COMMAND"
>lockmail</B
>
fails to obtain all three locks,
<B
CLASS="COMMAND"
>lockmail</B
>
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
<B
CLASS="COMMAND"
>lockmail</B
>
still fails to obtain all required locks in the amount of time specified
by the <VAR
CLASS="OPTION"
>-t</VAR
> option (or its default value),
<B
CLASS="COMMAND"
>lockmail</B
> will terminate with the
<TT
CLASS="LITERAL"
>EX_TEMPFAIL</TT
> exit code.</P
><P
><B
CLASS="COMMAND"
>lockmail</B
>
runs <VAR
CLASS="REPLACEABLE"
>program</VAR
> after obtaining the last file
lock, waits until <VAR
CLASS="REPLACEABLE"
>program</VAR
> terminates, and
releases all locks.
<VAR
CLASS="REPLACEABLE"
>program</VAR
> must terminate before any of the locks
obtained by <B
CLASS="COMMAND"
>lockmail</B
> expire, and are considered stale.
<B
CLASS="COMMAND"
>lockmail</B
> will then terminate with the same exit code
as <VAR
CLASS="REPLACEABLE"
>program</VAR
>.</P
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN105"
></A
><H2
>EXIT STATUS</H2
><P
><B
CLASS="COMMAND"
>lockmail</B
> terminates with the same exit status as
<VAR
CLASS="REPLACEABLE"
>program</VAR
>
<B
CLASS="COMMAND"
>lockmail</B
> terminates with the <TT
CLASS="LITERAL"
>EX_TEMPFAIL</TT
>
exit status if it was unable to obtain a lock, or if
<VAR
CLASS="REPLACEABLE"
>program</VAR
>
was killed by a signal.</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN113"
></A
><H2
>SEE ALSO</H2
><P
><A
HREF="maildrop.html"
TARGET="_top"
><SPAN
CLASS="CITEREFENTRY"
><SPAN
CLASS="REFENTRYTITLE"
>maildrop</SPAN
>(1)</SPAN
></A
>,
<SPAN
CLASS="CITEREFENTRY"
><SPAN
CLASS="REFENTRYTITLE"
>sendmail</SPAN
>(8)</SPAN
>.</P
></DIV
></BODY
></HTML
>
|