From: Timo Sirainen Date: Mon, 20 Oct 2003 05:01:57 +0000 (+0300) Subject: Added dotlock parameter to specify how old lock file has to be to be X-Git-Tag: 1.1.alpha1~4284 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0de67e4b387ae597f674cf76ae7383d124d74bc6;p=thirdparty%2Fdovecot%2Fcore.git 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. --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index f7e67323a3..66e8de4798 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -35,7 +35,8 @@ #define MAIL_CACHE_GROW_PERCENTAGE 10 #define MAIL_CACHE_LOCK_TIMEOUT 120 -#define MAIL_CACHE_LOCK_STALE_TIMEOUT 60 +#define MAIL_CACHE_LOCK_CHANGE_TIMEOUT 60 +#define MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT (5*60) #define CACHE_RECORD(cache, offset) \ ((struct mail_cache_record *) ((char *) (cache)->mmap_base + offset)) @@ -452,7 +453,8 @@ static int mail_cache_open_or_create_file(struct mail_cache *cache, /* maybe a rebuild.. */ fd = file_dotlock_open(cache->filepath, NULL, MAIL_CACHE_LOCK_TIMEOUT, - MAIL_CACHE_LOCK_STALE_TIMEOUT, NULL, NULL); + MAIL_CACHE_LOCK_CHANGE_TIMEOUT, + MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT, NULL, NULL); if (fd == -1) { mail_cache_set_syscall_error(cache, "file_dotlock_open()"); return FALSE; @@ -753,7 +755,8 @@ int mail_cache_compress(struct mail_cache *cache) #endif fd = file_dotlock_open(cache->filepath, NULL, MAIL_CACHE_LOCK_TIMEOUT, - MAIL_CACHE_LOCK_STALE_TIMEOUT, NULL, NULL); + MAIL_CACHE_LOCK_CHANGE_TIMEOUT, + MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT, NULL, NULL); if (fd == -1) { mail_cache_set_syscall_error(cache, "file_dotlock_open()"); return FALSE; @@ -814,7 +817,8 @@ int mail_cache_truncate(struct mail_cache *cache) return ret > 0; fd = file_dotlock_open(cache->filepath, NULL, MAIL_CACHE_LOCK_TIMEOUT, - MAIL_CACHE_LOCK_STALE_TIMEOUT, NULL, NULL); + MAIL_CACHE_LOCK_CHANGE_TIMEOUT, + MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT, NULL, NULL); if (fd == -1) { mail_cache_set_syscall_error(cache, "file_dotlock_open()"); return FALSE; diff --git a/src/lib-index/maildir/maildir-uidlist.c b/src/lib-index/maildir/maildir-uidlist.c index 6a55c41fb5..254be9ece7 100644 --- a/src/lib-index/maildir/maildir-uidlist.c +++ b/src/lib-index/maildir/maildir-uidlist.c @@ -26,7 +26,7 @@ int maildir_uidlist_try_lock(struct mail_index *index) return 1; path = t_strconcat(index->control_dir, "/" MAILDIR_UIDLIST_NAME, NULL); - fd = file_dotlock_open(path, NULL, 0, UIDLIST_LOCK_STALE_TIMEOUT, + fd = file_dotlock_open(path, NULL, 0, 0, UIDLIST_LOCK_STALE_TIMEOUT, NULL, NULL); if (fd == -1) { if (errno == EAGAIN) diff --git a/src/lib-index/mbox/mbox-lock.c b/src/lib-index/mbox/mbox-lock.c index 7c07bb845a..2602890510 100644 --- a/src/lib-index/mbox/mbox-lock.c +++ b/src/lib-index/mbox/mbox-lock.c @@ -260,7 +260,7 @@ int mbox_lock(struct mail_index *index, enum mail_lock_type lock_type) ret = file_lock_dotlock(index->mailbox_path, NULL, lock_type == MAIL_LOCK_SHARED && !use_read_dotlock, lock_timeout, - dotlock_change_timeout, + dotlock_change_timeout, 0, dotlock_callback, &ctx, &index->mbox_dotlock); diff --git a/src/lib-storage/subscription-file/subscription-file.c b/src/lib-storage/subscription-file/subscription-file.c index b295ab1201..a69ef0afc2 100644 --- a/src/lib-storage/subscription-file/subscription-file.c +++ b/src/lib-storage/subscription-file/subscription-file.c @@ -14,7 +14,8 @@ #define MAX_MAILBOX_LENGTH PATH_MAX #define SUBSCRIPTION_FILE_LOCK_TIMEOUT 120 -#define SUBSCRIPTION_FILE_STALE_TIMEOUT 30 +#define SUBSCRIPTION_FILE_CHANGE_TIMEOUT 30 +#define SUBSCRIPTION_FILE_IMMEDIATE_TIMEOUT (5*60) struct subsfile_list_context { pool_t pool; @@ -82,7 +83,9 @@ int subsfile_set_subscribed(struct mail_storage *storage, "/" SUBSCRIPTION_FILE_NAME, NULL); /* FIXME: set lock notification callback */ fd_out = file_dotlock_open(path, NULL, SUBSCRIPTION_FILE_LOCK_TIMEOUT, - SUBSCRIPTION_FILE_STALE_TIMEOUT, NULL, NULL); + SUBSCRIPTION_FILE_CHANGE_TIMEOUT, + SUBSCRIPTION_FILE_IMMEDIATE_TIMEOUT, + NULL, NULL); if (fd_out == -1) { if (errno == EAGAIN) { mail_storage_set_error(storage, diff --git a/src/lib/file-dotlock.c b/src/lib/file-dotlock.c index 07441e3a28..8ce94d1f12 100644 --- a/src/lib/file-dotlock.c +++ b/src/lib/file-dotlock.c @@ -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 @@ static int check_lock(time_t now, struct lock_info *lock_info) 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 try_create_lock(struct lock_info *lock_info, const char *temp_prefix) 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 @@ static int dotlock_create(const char *path, const char *temp_prefix, 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 @@ static int dotlock_create(const char *path, const char *temp_prefix, 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 @@ int file_lock_dotlock(const char *path, const char *temp_prefix, int checkonly, 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_unlock_dotlock(const char *path, const struct dotlock *dotlock) 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 file_dotlock_open(const char *path, const char *temp_prefix, 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; diff --git a/src/lib/file-dotlock.h b/src/lib/file-dotlock.h index 92ff61a6dc..7c13b3ee85 100644 --- a/src/lib/file-dotlock.h +++ b/src/lib/file-dotlock.h @@ -28,6 +28,7 @@ struct dotlock { 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 @@ int file_unlock_dotlock(const char *path, const struct dotlock *dotlock); 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);