mbox-lock.c revision a9a1257263df42c61458bd2d9dad9fe13ef4af82
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "mbox-index.h"
#include "mbox-lock.h"
#include "mail-index-util.h"
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#ifdef HAVE_FLOCK
#endif
#ifdef HAVE_FLOCK
# define USE_FLOCK
#endif
/* 0.1 .. 0.2msec */
/* abort trying to get lock after 30 seconds */
#define MAX_LOCK_WAIT_SECONDS 30
/* remove lock after 10 mins */
#ifdef USE_FLOCK
int lock_type)
{
else
return TRUE;
}
#else
int lock_type)
{
return FALSE;
}
}
return TRUE;
}
#endif
{
int fd;
if (!set) {
return TRUE;
}
/* don't bother with the temp files as we'd just leave them lying
around. besides, postfix also relies on O_EXCL working so we
might as well. */
do {
/* lock exists, see if it's too old */
"unlink()");
break;
}
continue;
}
if (fd != -1) {
/* got it */
"close()");
}
return TRUE;
}
return FALSE;
}
} while (now < max_wait_time);
"dotlock %s", path);
return FALSE;
}
{
int lock_type;
return TRUE;
#ifdef USE_FLOCK
return FALSE;
#else
return FALSE;
#endif
if (exclusive) {
return FALSE;
}
return TRUE;
}
{
if (--index->mbox_locks > 0)
return TRUE;
#ifdef USE_FLOCK
return FALSE;
#else
return FALSE;
#endif
return FALSE;
return TRUE;
}