5
/* lock open file for mail delivery
7
/* #include <deliver_flock.h>
9
/* int deliver_flock(fd, lock_style, why)
14
/* deliver_flock() sets one exclusive kernel lock on an open file,
15
/* for example in order to deliver mail.
16
/* It performs several non-blocking attempts to acquire an exclusive
17
/* lock before giving up.
21
/* A file descriptor that is associated with an open file.
23
/* A locking style defined in myflock(3).
25
/* A null pointer, or storage for diagnostics.
27
/* deliver_flock() returns -1 in case of problems, 0 in case
28
/* of success. The reason for failure is returned via the \fIwhy\fR
30
/* CONFIGURATION PARAMETERS
31
/* deliver_lock_attempts, number of locking attempts
32
/* deliver_lock_delay, time in seconds between attempts
33
/* sun_mailtool_compatibility, disable kernel locking
37
/* The Secure Mailer license must be distributed with this software.
40
/* IBM T.J. Watson Research
42
/* Yorktown Heights, NY 10598, USA
50
/* Utility library. */
58
#include "mail_params.h"
59
#include "deliver_flock.h"
61
/* Application-specific. */
63
#define MILLION 1000000
65
/* deliver_flock - lock open file for mail delivery */
67
int deliver_flock(int fd, int lock_style, VSTRING *why)
71
for (i = 1; /* void */ ; i++) {
72
if (myflock(fd, lock_style,
73
MYFLOCK_OP_EXCLUSIVE | MYFLOCK_OP_NOWAIT) == 0)
75
if (i >= var_flock_tries)
77
rand_sleep(var_flock_delay * MILLION, var_flock_delay * MILLION / 2);
80
vstring_sprintf(why, "unable to lock for exclusive access: %m");