[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-storage.c, 1.164, 1.165

tss at dovecot.org tss at dovecot.org
Thu Feb 22 13:37:34 UTC 2007


Update of /var/lib/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv13052/mbox

Modified Files:
	mbox-storage.c 
Log Message:
When using KEEP_LOCK, the mbox/uidlist file must be locked before index file
is opened. Otherwise we can end up in a deadlock.



Index: mbox-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.c,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -d -r1.164 -r1.165
--- mbox-storage.c	19 Feb 2007 14:45:52 -0000	1.164
+++ mbox-storage.c	22 Feb 2007 13:37:30 -0000	1.165
@@ -530,11 +530,10 @@
 	mbox->ibox.storage = INDEX_STORAGE(storage);
 	mbox->ibox.mail_vfuncs = &mbox_mail_vfuncs;
 	mbox->ibox.is_recent = mbox_mail_is_recent;
-
-	index_storage_mailbox_init(&mbox->ibox, index, name, flags,
-				   want_memory_indexes(storage, path));
+	mbox->ibox.index = index;
 
 	mbox->storage = storage;
+	mbox->path = p_strdup(mbox->ibox.box.pool, path);
 	mbox->mbox_fd = -1;
 	mbox->mbox_lock_type = F_UNLCK;
 	mbox->mbox_ext_idx =
@@ -547,6 +546,18 @@
 
 	if ((STORAGE(storage)->flags & MAIL_STORAGE_FLAG_KEEP_HEADER_MD5) != 0)
 		mbox->mbox_save_md5 = TRUE;
+
+	if ((flags & MAILBOX_OPEN_KEEP_LOCKED) != 0) {
+		if (mbox_lock(mbox, F_WRLCK, &mbox->mbox_global_lock_id) <= 0) {
+			struct mailbox *box = &mbox->ibox.box;
+
+			mailbox_close(&box);
+			return NULL;
+		}
+	}
+
+	index_storage_mailbox_init(&mbox->ibox, name, flags,
+				   want_memory_indexes(storage, path));
 	return mbox;
 }
 
@@ -575,7 +586,6 @@
 
 	index = index_storage_alloc(index_dir, path, MBOX_INDEX_PREFIX);
 	mbox = mbox_alloc(storage, index, name, path, flags);
-	mbox->path = p_strdup(mbox->ibox.box.pool, path);
 
 	if (access(path, R_OK|W_OK) < 0) {
 		if (errno < EACCES)
@@ -586,15 +596,6 @@
 		}
 	}
 
-	if (mbox->ibox.keep_locked) {
-		if (mbox_lock(mbox, F_WRLCK, &mbox->mbox_global_lock_id) <= 0) {
-			struct mailbox *box = &mbox->ibox.box;
-
-			mailbox_close(&box);
-			return NULL;
-		}
-	}
-
 	return &mbox->ibox.box;
 }
 
@@ -953,13 +954,15 @@
 	const struct mail_index_header *hdr;
 	int ret = 0;
 
-	hdr = mail_index_get_header(mbox->ibox.view);
-	if ((hdr->flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0 &&
-	    !mbox->mbox_readonly) {
-		/* we've done changes to mbox which haven't been written yet.
-		   do it now. */
-		if (mbox_sync(mbox, MBOX_SYNC_REWRITE) < 0)
-			ret = -1;
+	if (mbox->ibox.view != NULL) {
+		hdr = mail_index_get_header(mbox->ibox.view);
+		if ((hdr->flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0 &&
+		    !mbox->mbox_readonly) {
+			/* we've done changes to mbox which haven't been
+			   written yet. do it now. */
+			if (mbox_sync(mbox, MBOX_SYNC_REWRITE) < 0)
+				ret = -1;
+		}
 	}
 
 	if (mbox->mbox_global_lock_id != 0)



More information about the dovecot-cvs mailing list