dovecot-2.0: lib-index: Put back some of the removed locking com...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Oct 14 19:23:36 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/ff1ac6f22ba1
changeset: 12267:ff1ac6f22ba1
user: Timo Sirainen <tss at iki.fi>
date: Thu Oct 14 17:23:11 2010 +0100
description:
lib-index: Put back some of the removed locking complexity.
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.
diffstat:
src/lib-index/mail-index-lock.c | 31 ++++++++++++++-----------------
1 files changed, 14 insertions(+), 17 deletions(-)
diffs (43 lines):
diff -r c38f630dae09 -r ff1ac6f22ba1 src/lib-index/mail-index-lock.c
--- a/src/lib-index/mail-index-lock.c Thu Oct 14 17:02:20 2010 +0100
+++ b/src/lib-index/mail-index-lock.c Thu Oct 14 17:23:11 2010 +0100
@@ -42,25 +42,22 @@
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;
- }
+ 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;
+ }
- i_assert(index->lock_type == F_UNLCK);
- break;
+ if (ret > 0) {
+ /* file is already locked */
+ return 1;
}
if (index->lock_method == FILE_LOCK_METHOD_DOTLOCK &&
More information about the dovecot-cvs
mailing list