mbox-lock.c revision 2c7ab05ef98c46eb70c8ba6ea85e49749aafb2a3
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (C) 2002 Timo Sirainen */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen/* 0.1 .. 0.2msec */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)rand() % 100000)
8ecbb74bc4c7f6f6145da3525941d1d0e20e67f1Timo Sirainen/* lock methods to use in wanted order */
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen#define DEFAULT_WRITE_LOCK_METHODS "dotlock fcntl"
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen/* lock timeout */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen/* assume stale dotlock if mbox file hasn't changed for n seconds */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen int (*func)(struct mbox_lock_context *ctx, int lock_type,
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainenstatic int mbox_lock_dotlock(struct mbox_lock_context *ctx, int lock_type,
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainenstatic int mbox_lock_fcntl(struct mbox_lock_context *ctx, int lock_type,
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainenstatic int mbox_lock_flock(struct mbox_lock_context *ctx, int lock_type,
6cb2c6ecddcdbeac9e6c73a292244747e12a793eTimo Sirainenstatic int mbox_lock_lockf(struct mbox_lock_context *ctx, int lock_type,
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen { MBOX_LOCK_DOTLOCK, "dotlock", mbox_lock_dotlock },
6f7617d14ae27473f55628fbdad2af2d75b909a9Timo Sirainen { MBOX_LOCK_FCNTL, "fcntl", mbox_lock_fcntl },
6f7617d14ae27473f55628fbdad2af2d75b909a9Timo Sirainen { MBOX_LOCK_FLOCK, "flock", mbox_lock_flock },
6f7617d14ae27473f55628fbdad2af2d75b909a9Timo Sirainen { MBOX_LOCK_LOCKF, "lockf", mbox_lock_lockf },
e156adefc1260d31a145df2f5e9b3c82050d4163Timo Sirainenstatic enum mbox_lock_type read_locks[MBOX_LOCK_COUNT+1];
e156adefc1260d31a145df2f5e9b3c82050d4163Timo Sirainenstatic enum mbox_lock_type write_locks[MBOX_LOCK_COUNT+1];
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainenstatic int lock_timeout, dotlock_change_timeout;
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainenstatic int mbox_lock_list(struct mbox_lock_context *ctx, int lock_type,
933a8cc7033e8a9bb7a1c7630fbc786b914f1510Timo Sirainenstatic int mbox_unlock_files(struct mbox_lock_context *ctx);
933a8cc7033e8a9bb7a1c7630fbc786b914f1510Timo Sirainenstatic void mbox_read_lock_methods(const char *str, const char *env,
d3dee2335ff3b0943085256fe341c2c13a678c4fTimo Sirainen const char *const *lock;
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen for (lock = t_strsplit(str, " "), dest = 0; *lock != NULL; lock++) {
for (i = 0; i < dest; i++) {
static void mbox_init_lock_settings(void)
const char *str;
int idx;
return FALSE;
return TRUE;
int ret;
if (ret < 0) {
if (ret == 0) {
#ifdef HAVE_FLOCK
last_notify = 0;
if (max_wait_time == 0)
#ifdef HAVE_LOCKF
last_notify = 0;
if (max_wait_time == 0)
int wait_type;
if (ret <= 0)
return ret;
for (i = 0; i < MBOX_LOCK_COUNT; i++)
if (ret <= 0) {
if (!drop_locks)
if (ret == 0) {
return ret;
if (drop_locks) {
unsigned int *lock_id_r)
int ret;
if (ret <= 0)
return ret;
int ret = 0;
return ret;
for (i = 0; i < MBOX_LOCK_COUNT; i++)