# HG changeset patch # User Timo Sirainen # Date 1486398845 -7200 # Node ID e14d3d07c47bc00b4ef1526bb6e7483d96a8da8a # Parent 4e84b0d61d49a1ab08517720f472b99e5891254b sdbox: Fix assert-crash on mailbox create race If another process created the mailbox at the same time, the mailbox_guid wasn't set and opening the mailbox assert-crashed: Panic: file mail-storage.c: line 1744 (mailbox_get_metadata): assertion failed: ((items & MAILBOX_METADATA_GUID) == 0 || !guid_128_is_empty(metadata_r->guid)) diff -r 4e84b0d61d49 -r e14d3d07c47b src/lib-storage/index/dbox-single/sdbox-storage.c --- a/src/lib-storage/index/dbox-single/sdbox-storage.c Tue Feb 07 21:07:54 2017 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c Mon Feb 06 18:34:05 2017 +0200 @@ -373,6 +373,32 @@ } static int +sdbox_mailbox_create(struct mailbox *box, + const struct mailbox_update *update, bool directory) +{ + struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box; + struct sdbox_index_header hdr; + bool need_resize; + + if (dbox_mailbox_create(box, update, directory) < 0) + return -1; + if (directory || !guid_128_is_empty(mbox->mailbox_guid)) + return 0; + + /* another process just created the mailbox. read the mailbox_guid. */ + if (sdbox_read_header(mbox, &hdr, FALSE, &need_resize) < 0) { + mail_storage_set_critical(box->storage, + "sdbox %s: Failed to read newly created dbox header", + mailbox_get_path(&mbox->box)); + return -1; + } + memcpy(mbox->mailbox_guid, hdr.mailbox_guid, + sizeof(mbox->mailbox_guid)); + i_assert(!guid_128_is_empty(mbox->mailbox_guid)); + return 0; +} + +static int sdbox_mailbox_get_metadata(struct mailbox *box, enum mailbox_metadata_items items, struct mailbox_metadata *metadata_r) @@ -448,7 +474,7 @@ sdbox_mailbox_open, sdbox_mailbox_close, index_storage_mailbox_free, - dbox_mailbox_create, + sdbox_mailbox_create, dbox_mailbox_update, index_storage_mailbox_delete, index_storage_mailbox_rename,