From: Timo Sirainen Date: Mon, 6 Oct 2014 23:35:41 +0000 (+0300) Subject: lib-index: Fixed cache file creation race condition. X-Git-Tag: 2.2.14~50 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e4b242684975b4d3702ca79bfd56452fe139a2bf;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Fixed cache file creation race condition. 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. --- diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index 6fb4baf26f..1cf77d8d1e 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -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; diff --git a/src/lib-index/mail-cache.h b/src/lib-index/mail-cache.h index beea1078cd..324159ffa6 100644 --- a/src/lib-index/mail-cache.h +++ b/src/lib-index/mail-cache.h @@ -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. diff --git a/src/lib-index/mail-index.c b/src/lib-index/mail-index.c index 971e133ea3..c8430d1273 100644 --- a/src/lib-index/mail-index.c +++ b/src/lib-index/mail-index.c @@ -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; }