file-lock.c revision 0d2838d564e641efeb8596252561527aba5ed728
/* Copyright (c) 2002-2003 Timo Sirainen */
#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;
};
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
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;
}
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;
}
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 */
}
}
{
}