6 ** Copyright 2002 Double Precision, Inc. See COPYING for
7 ** distribution information.
15 ** Functions for mbox mail locks
19 char *file
; /* File being locked */
21 /* c-client type lock */
32 struct ll_mail
*ll_mail_alloc(const char *filename
);
35 ** Create a c-client type lock. NOTE: c-clients will ping you with SIGUSR2,
36 ** which must be ignored for this implementation.
37 ** Returns: 0 - ok, < 0 - error.
39 ** An error return from ll_mail_lock carries some additional context in
42 ** errno == EAGAIN: potential race condition. The current lock holder MIGHT
43 ** have just terminated. The caller should sleep for AT LEAST 5 seconds, then
46 ** errno == EEXIST: another process on this server DEFINITELY has the lock.
48 ** Implementations might choose to wait and try again on EEXIST as well.
51 int ll_mail_lock(struct ll_mail
*);
54 ** Open the mail file, read/write (creating a dot-lock).
55 ** Returns: >= 0 - file descriptor, < 0 - error (if EPERM, try ll_open_ro).
57 ** errno == EEXIST: another process appears to hold a dot-lock.
59 ** errno == EAGAIN: We just blew away a stale dotlock, should try again
60 ** in at least five seconds. Should NOT get two EAGAIN's in a row.
63 int ll_mail_open(struct ll_mail
*);
66 ** Open in read-only mode.
69 int ll_mail_open_ro(struct ll_mail
*);
72 ** Release all locks, deallocate structure. NOTE: file descriptor from
73 ** ll_mail_open(_ro)? is NOT closed, it's your responsibility to do that.
76 void ll_mail_free(struct ll_mail
*);
79 ** As long as we have the logic done already, here's a generic dot-locking
82 ** dotlock - the actual filename of a dotlock file.
83 ** tmpfile - the filename of a temporary file to create first.
84 ** timeout - optional timeout.
86 ** Return code: 0: dotlock is created. Just unlink(dotlock) when you're done.
88 ** -1 error. Check errno:
90 ** EEXIST - dotlock is locked
92 ** EAGAIN - dotlock is stale (dotlock created on this machine, and the
93 ** process no longer exists, or dotlock created on another
94 ** machine, and timeout argument was > 0, and the dotlock's
95 ** timestamp was older than timeout seconds.
97 ** E????? - something's broken.
101 int ll_dotlock(const char *dotlock
, const char *tmpfile
,