]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Fixed cache file creation race condition.
authorTimo Sirainen <tss@iki.fi>
Mon, 6 Oct 2014 23:35:41 +0000 (02:35 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 6 Oct 2014 23:35:41 +0000 (02:35 +0300)
If two processes are creating the index files at the same time, don't have
one of them delete the dovecot.index.cache that the other one just created.
This means we never should be calling mail_cache_create(), so it was removed
entirely.

src/lib-index/mail-cache.c
src/lib-index/mail-cache.h
src/lib-index/mail-index.c

index 6fb4baf26f6d2af1da50e2b6f6c86b11d6c59e08..1cf77d8d1e5953739bbede5195a0b27de51584a8 100644 (file)
@@ -546,18 +546,6 @@ struct mail_cache *mail_cache_open_or_create(struct mail_index *index)
        return cache;
 }
 
-struct mail_cache *mail_cache_create(struct mail_index *index)
-{
-       struct mail_cache *cache;
-
-       cache = mail_cache_alloc(index);
-       if (!MAIL_INDEX_IS_IN_MEMORY(index)) {
-               if (unlink(cache->filepath) < 0 && errno != ENOENT)
-                       mail_cache_set_syscall_error(cache, "unlink()");
-       }
-       return cache;
-}
-
 void mail_cache_free(struct mail_cache **_cache)
 {
        struct mail_cache *cache = *_cache;
index beea1078cd192cde2e45a9d173ff7bbf85d5e654..324159ffa6a6d4df6e83b749d575af5f16059ea5 100644 (file)
@@ -43,7 +43,6 @@ struct mail_cache_field {
 };
 
 struct mail_cache *mail_cache_open_or_create(struct mail_index *index);
-struct mail_cache *mail_cache_create(struct mail_index *index);
 void mail_cache_free(struct mail_cache **cache);
 
 /* Register fields. fields[].idx is updated to contain field index.
index 971e133ea35a1dfff27a9f38d37557746b2e1437..c8430d1273974df8bcf5e589c732fee07a76b70d 100644 (file)
@@ -474,7 +474,6 @@ static int mail_index_open_files(struct mail_index *index,
                                 enum mail_index_open_flags flags)
 {
        int ret;
-       bool created = FALSE;
 
        ret = mail_transaction_log_open(index->log);
        if (ret == 0) {
@@ -501,7 +500,6 @@ static int mail_index_open_files(struct mail_index *index,
                        index->map->hdr.indexid = index->indexid;
                }
                index->initial_create = FALSE;
-               created = TRUE;
        }
        if (ret >= 0) {
                ret = index->map != NULL ? 1 : mail_index_try_open(index);
@@ -525,10 +523,8 @@ static int mail_index_open_files(struct mail_index *index,
                        return -1;
        }
 
-       if (index->cache == NULL) {
-               index->cache = created ? mail_cache_create(index) :
-                       mail_cache_open_or_create(index);
-       }
+       if (index->cache == NULL)
+               index->cache = mail_cache_open_or_create(index);
        return 1;
 }