]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Put back some of the removed locking complexity.
authorTimo Sirainen <tss@iki.fi>
Thu, 14 Oct 2010 16:23:11 +0000 (17:23 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 14 Oct 2010 16:23:11 +0000 (17:23 +0100)
This fixes a crash when mmap_disable=no and a index was mmap()ed (which
keeps the index locked) and later its read-lock was tried to be changed to
write-lock.

src/lib-index/mail-index-lock.c

index 54d090644cba51819405d89d1fe01163cf2802e6..c964a6b3a299af12aef5af800c80bbf2610ea816 100644 (file)
@@ -42,25 +42,22 @@ static int mail_index_lock(struct mail_index *index, int lock_type,
        int ret;
 
        i_assert(lock_type == F_RDLCK || lock_type == F_WRLCK);
-       i_assert(timeout_secs == 0 || lock_type == F_RDLCK);
-
-       switch (lock_type) {
-       case F_RDLCK:
-               if (index->lock_type != F_UNLCK) {
-                       index->shared_lock_count++;
-                       *lock_id_r = index->lock_id_counter;
-                       return 1;
-               }
-               break;
-       case F_WRLCK:
-               if (index->lock_type == F_WRLCK) {
-                       index->excl_lock_count++;
-                       *lock_id_r = index->lock_id_counter + 1;
-                       return 1;
-               }
 
-               i_assert(index->lock_type == F_UNLCK);
-               break;
+       if (lock_type == F_RDLCK && index->lock_type != F_UNLCK) {
+               index->shared_lock_count++;
+               *lock_id_r = index->lock_id_counter;
+               ret = 1;
+       } else if (lock_type == F_WRLCK && index->lock_type == F_WRLCK) {
+               index->excl_lock_count++;
+               *lock_id_r = index->lock_id_counter + 1;
+               ret = 1;
+       } else {
+               ret = 0;
+       }
+
+       if (ret > 0) {
+               /* file is already locked */
+               return 1;
        }
 
        if (index->lock_method == FILE_LOCK_METHOD_DOTLOCK &&