file-lock.c revision 301b1524a822cec7b79856e8c599112c754bc4c0
/* Copyright (c) 2002-2014 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "file-lock.h"
#ifdef HAVE_FLOCK
#endif
struct file_lock {
int fd;
char *path;
int lock_type;
enum file_lock_method lock_method;
};
{
else
return FALSE;
return TRUE;
}
{
switch (method) {
case FILE_LOCK_METHOD_FCNTL:
return "fcntl";
case FILE_LOCK_METHOD_FLOCK:
return "flock";
case FILE_LOCK_METHOD_DOTLOCK:
return "dotlock";
}
i_unreached();
}
enum file_lock_method lock_method,
{
}
enum file_lock_method lock_method,
unsigned int timeout_secs)
{
int ret;
if (timeout_secs != 0)
switch (lock_method) {
case FILE_LOCK_METHOD_FCNTL: {
#ifndef HAVE_FCNTL
i_fatal("fcntl() locks not supported");
#else
const char *errstr;
if (timeout_secs != 0) alarm(0);
if (ret == 0)
break;
if (timeout_secs == 0 &&
/* locked by another process */
return 0;
}
/* most likely alarm hit, meaning we timeouted.
even if not, we probably want to be killed
so stop blocking. */
return 0;
}
"File is locked by another process (EACCES)";
i_error("fcntl(%s) locking failed for file %s: %s",
return -1;
#endif
}
case FILE_LOCK_METHOD_FLOCK: {
#ifndef HAVE_FLOCK
i_fatal("flock() locks not supported");
#else
switch (lock_type) {
case F_RDLCK:
break;
case F_WRLCK:
break;
case F_UNLCK:
break;
}
if (timeout_secs != 0) alarm(0);
if (ret == 0)
break;
/* a) locked by another process,
b) timeouted */
return 0;
}
i_error("flock(%s) locking failed for file %s: %m",
path);
return -1;
#endif
}
case FILE_LOCK_METHOD_DOTLOCK:
/* we shouldn't get here */
i_unreached();
}
return 1;
}
enum file_lock_method lock_method,
unsigned int timeout_secs,
{
int ret;
if (ret <= 0)
return ret;
return 1;
}
{
lock->lock_method, 0);
}
{
lock->lock_method, 0) == 0) {
/* this shouldn't happen */
}
}
{
}