From: Timo Sirainen Date: Mon, 19 Feb 2018 10:54:53 +0000 (+0200) Subject: lib-storage: mailbox_list_index_handle_corruption() - Lock mailbox list while rebuilding X-Git-Tag: 2.3.9~2247 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ccfccd9aaeb1e85d1796b845c72c3953f4867693;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: mailbox_list_index_handle_corruption() - Lock mailbox list while rebuilding This guards against simultaneous mailbox create/delete/rename. --- diff --git a/src/lib-storage/list/mailbox-list-index.c b/src/lib-storage/list/mailbox-list-index.c index fec655418d..4326620bc3 100644 --- a/src/lib-storage/list/mailbox-list-index.c +++ b/src/lib-storage/list/mailbox-list-index.c @@ -625,7 +625,19 @@ int mailbox_list_index_handle_corruption(struct mailbox_list *list) if (ilist->handling_corruption) return 0; ilist->handling_corruption = TRUE; - ret = list_handle_corruption_locked(list, reason); + + /* Perform the rebuilding locked. Note that if we're here because + INBOX wasn't found, this may be because another process is in the + middle of creating it. Waiting for the lock here makes sure that + we don't start rebuilding before it's finished. In that case the + rebuild is a bit unnecessary, but harmless (and avoiding the rebuild + just adds extra code complexity). */ + if (mailbox_list_lock(list) < 0) + ret = -1; + else { + ret = list_handle_corruption_locked(list, reason); + mailbox_list_unlock(list); + } ilist->handling_corruption = FALSE; return ret; }