mbox-lock.c revision 08ea8b302b62bc688f6b34f89f674e08eda7828c
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
0f9a8663b0ff6fe30389d02284a2b002c40914ebTimo Sirainen/* 0.1 .. 0.2msec */
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)rand() % 100000)
a9efdb661eb7a8a33aacfdcc3486dcc675a21543Timo Sirainen/* lock methods to use in wanted order */
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen#define DEFAULT_WRITE_LOCK_METHODS "dotlock fcntl"
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen/* lock timeout */
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen/* assume stale dotlock if mbox file hasn't changed for n seconds */
enum mbox_lock_type {
struct mbox_lock_context {
bool checked_file;
int lock_type;
bool dotlock_last_stale;
bool fcntl_locked;
struct mbox_lock_data {
const char *name;
#ifdef HAVE_FLOCK
#ifdef HAVE_LOCKF
const char *const *lock;
int i, dest;
for (i = 0; i < dest; i++) {
static void mbox_init_lock_settings(void)
const char *str;
return FALSE;
return TRUE;
int ret;
if (ret < 0) {
if (ret == 0) {
#ifdef HAVE_FLOCK
last_notify = 0;
#ifdef HAVE_LOCKF
last_notify = 0;
unsigned int next_alarm;
int wait_type;
if (max_wait_time == 0) {
alarm(0);
alarm(0);
if (next_alarm == 0)
alarm(0);
if (ret <= 0)
return ret;
bool *fcntl_locked_r)
int ret, i;
bool drop_locks;
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)
bool fcntl_locked;
int ret;
if (ret <= 0)
return ret;
MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0) {
if (fcntl_locked) {
int ret = 0;
return ret;
bool fcntl_locked;
&fcntl_locked) < 0)
for (i = 0; i < MBOX_LOCK_COUNT; i++)