[dovecot-cvs]
dovecot/src/lib file-dotlock.c,1.8,1.9 file-dotlock.h,1.4,1.5
cras at procontrol.fi
cras at procontrol.fi
Mon Oct 20 09:01:59 EEST 2003
Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv18881/lib
Modified Files:
file-dotlock.c file-dotlock.h
Log Message:
Added dotlock parameter to specify how old lock file has to be to be
immediately deleted. This fixes the problem of never deleting uidlist.lock
files.
Index: file-dotlock.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/file-dotlock.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- file-dotlock.c 20 Oct 2003 01:50:18 -0000 1.8
+++ file-dotlock.c 20 Oct 2003 05:01:57 -0000 1.9
@@ -20,6 +20,7 @@
struct lock_info {
const char *path, *lock_path, *temp_path;
unsigned int stale_timeout;
+ unsigned int immediate_stale_timeout;
int fd;
dev_t dev;
@@ -83,6 +84,22 @@
return 1;
}
+ if (lock_info->immediate_stale_timeout != 0 &&
+ now > st.st_mtime + (time_t)lock_info->immediate_stale_timeout &&
+ now > st.st_ctime + (time_t)lock_info->immediate_stale_timeout) {
+ /* old lock file */
+ if (unlink(lock_info->lock_path) < 0 && errno != ENOENT) {
+ i_error("unlink(%s) failed: %m", lock_info->lock_path);
+ return -1;
+ }
+ return 1;
+ }
+
+ if (lock_info->stale_timeout == 0) {
+ /* no change checking */
+ return 0;
+ }
+
if (lock_info->ino != st.st_ino ||
!CMP_DEV_T(lock_info->dev, st.st_dev) ||
lock_info->ctime != st.st_ctime ||
@@ -230,6 +247,7 @@
static int dotlock_create(const char *path, const char *temp_prefix,
int checkonly, int *fd,
unsigned int timeout, unsigned int stale_timeout,
+ unsigned int immediate_stale_timeout,
int (*callback)(unsigned int secs_left, int stale,
void *context),
void *context)
@@ -251,6 +269,7 @@
lock_info.path = path;
lock_info.lock_path = lock_path;
lock_info.stale_timeout = stale_timeout;
+ lock_info.immediate_stale_timeout = immediate_stale_timeout;
lock_info.last_change = now;
lock_info.fd = -1;
@@ -314,6 +333,7 @@
int file_lock_dotlock(const char *path, const char *temp_prefix, int checkonly,
unsigned int timeout, unsigned int stale_timeout,
+ unsigned int immediate_stale_timeout,
int (*callback)(unsigned int secs_left, int stale,
void *context),
void *context, struct dotlock *dotlock_r)
@@ -325,7 +345,8 @@
lock_path = t_strconcat(path, ".lock", NULL);
ret = dotlock_create(path, temp_prefix, checkonly, &fd,
- timeout, stale_timeout, callback, context);
+ timeout, stale_timeout, immediate_stale_timeout,
+ callback, context);
if (ret <= 0 || checkonly)
return ret;
@@ -407,6 +428,7 @@
int file_dotlock_open(const char *path, const char *temp_prefix,
unsigned int timeout, unsigned int stale_timeout,
+ unsigned int immediate_stale_timeout,
int (*callback)(unsigned int secs_left, int stale,
void *context),
void *context)
@@ -414,7 +436,8 @@
int ret, fd;
ret = dotlock_create(path, temp_prefix, FALSE, &fd,
- timeout, stale_timeout, callback, context);
+ timeout, stale_timeout, immediate_stale_timeout,
+ callback, context);
if (ret <= 0)
return -1;
return fd;
Index: file-dotlock.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/file-dotlock.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- file-dotlock.h 6 Aug 2003 19:46:27 -0000 1.4
+++ file-dotlock.h 20 Oct 2003 05:01:57 -0000 1.5
@@ -28,6 +28,7 @@
then, the lock will not be overridden. */
int file_lock_dotlock(const char *path, const char *temp_prefix, int checkonly,
unsigned int timeout, unsigned int stale_timeout,
+ unsigned int immediate_stale_timeout,
int (*callback)(unsigned int secs_left, int stale,
void *context),
void *context, struct dotlock *dotlock_r);
@@ -41,6 +42,7 @@
If locking timed out, returns -1 and errno = EAGAIN. */
int file_dotlock_open(const char *path, const char *temp_prefix,
unsigned int timeout, unsigned int stale_timeout,
+ unsigned int immediate_stale_timeout,
int (*callback)(unsigned int secs_left, int stale,
void *context),
void *context);
More information about the dovecot-cvs
mailing list