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