mbox-lock.c revision 474da741bfb2c405a838a8d48f77346f9d389fd0
7ef3553585e556f35d5919589cfdc1de3329e4bbTimo Sirainen/* Copyright (c) 2002-2014 Dovecot authors, see the included COPYING file */
2753f93e5d9cd5fbd773540de3772d182fcced5eStephan Bosch/* 0.1 .. 0.2msec */
2753f93e5d9cd5fbd773540de3772d182fcced5eStephan Bosch#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)rand() % 100000)
int lock_type;
bool dotlock_last_stale;
bool fcntl_locked;
bool using_privileges;
struct mbox_lock_data {
const char *name;
#ifdef HAVE_FLOCK
#ifdef HAVE_LOCKF
static int ATTR_NOWARN_UNUSED_RESULT
static int ATTR_NOWARN_UNUSED_RESULT
const char *const *lock;
int i, dest;
for (i = 0; i < dest; i++) {
return FALSE;
if (restrict_access_use_priv_gid() < 0) {
return FALSE;
return TRUE;
fname++;
if (restrict_access_use_priv_gid() < 0) {
switch (op) {
case MBOX_DOTLOCK_OP_LOCK:
if (ret > 0)
const char *errmsg =
fname);
case MBOX_DOTLOCK_OP_UNLOCK:
if (ret < 0)
case MBOX_DOTLOCK_OP_TOUCH:
if (ret < 0)
return ret;
int ret;
if (ret >= 0) {
if (ret < 0) {
if (ret == 0) {
#ifdef HAVE_FLOCK
unsigned int next_alarm;
if (max_wait_time == 0) {
alarm(0);
alarm(0);
if (next_alarm == 0)
alarm(0);
#ifdef HAVE_LOCKF
unsigned int next_alarm;
else if (max_wait_time == 0) {
max_wait_time == 0) {
alarm(0);
alarm(0);
if (next_alarm == 0)
alarm(0);
unsigned int next_alarm;
int wait_type;
if (max_wait_time == 0) {
alarm(0);
alarm(0);
if (next_alarm == 0)
alarm(0);
static int ATTR_NOWARN_UNUSED_RESULT
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;
if (fcntl_locked) {
int ret = 0;
return ret;
bool fcntl_locked;
&fcntl_locked) < 0)
for (i = 0; i < MBOX_LOCK_COUNT; i++)