]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added dotlock parameter to specify how old lock file has to be to be
authorTimo Sirainen <tss@iki.fi>
Mon, 20 Oct 2003 05:01:57 +0000 (08:01 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 20 Oct 2003 05:01:57 +0000 (08:01 +0300)
immediately deleted. This fixes the problem of never deleting uidlist.lock
files.

--HG--
branch : HEAD

src/lib-index/mail-cache.c
src/lib-index/maildir/maildir-uidlist.c
src/lib-index/mbox/mbox-lock.c
src/lib-storage/subscription-file/subscription-file.c
src/lib/file-dotlock.c
src/lib/file-dotlock.h

index f7e67323a3994b9c7bb3c6a139d7f2fa7271035f..66e8de4798f7258b1bb2a78dc0fa6da0b960afa8 100644 (file)
@@ -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;
index 6a55c41fb504ce5c3554b66830c71dd448798d30..254be9ece7ddcce0d9dc549e9836df8c7d611edb 100644 (file)
@@ -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)
index 7c07bb845a5fef1241567bc1c525ced2d13a4b19..2602890510516fbf8972f793ccbda0ee03c4019f 100644 (file)
@@ -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);
 
index b295ab12010486aa9adeadec572a9bd8a61d690c..a69ef0afc2a53c042f65f02209cdfda916180dea 100644 (file)
@@ -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,
index 07441e3a28cbe6d62c5abafc0fd396db68d9b721..8ce94d1f121dabc8e48d5d6c07ec1b64900d1abf 100644 (file)
@@ -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;
index 92ff61a6dcc291f1f071742fcf1b40223c5e42f8..7c13b3ee854ea711e787204991647d149ef3e42a 100644 (file)
@@ -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);