Mercurial > dovecot > original-hg > dovecot-1.2
changeset 366:0da2b09461aa HEAD
more locking fixes.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 06 Oct 2002 09:08:26 +0300 |
parents | cb405d2f5fd5 |
children | 9b36fc3c1385 |
files | src/lib-index/mail-index.h src/lib-index/mbox/mbox-lock.c |
diffstat | 2 files changed, 19 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index.h Sun Oct 06 08:52:43 2002 +0300 +++ b/src/lib-index/mail-index.h Sun Oct 06 09:08:26 2002 +0300 @@ -321,6 +321,7 @@ uoff_t mbox_size; /* last synced size of mbox file */ int mbox_fd; int mbox_locks; + int mbox_lock_type; int fd; /* opened index file */ char *error; /* last error message */ @@ -355,7 +356,8 @@ #define MAIL_INDEX_PRIVATE_FILL \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ + 0 /* defaults - same as above but prefixed with mail_index_. */ int mail_index_open(MailIndex *index, int update_recent, int fast);
--- a/src/lib-index/mbox/mbox-lock.c Sun Oct 06 08:52:43 2002 +0300 +++ b/src/lib-index/mbox/mbox-lock.c Sun Oct 06 09:08:26 2002 +0300 @@ -125,8 +125,6 @@ static int mbox_lock(MailIndex *index, int exclusive) { - int lock_type; - i_assert(index->mbox_fd != -1); if (++index->mbox_locks > 1) @@ -137,13 +135,17 @@ return FALSE; } - lock_type = exclusive ? F_WRLCK : F_RDLCK; + index->mbox_lock_type = exclusive ? F_WRLCK : F_RDLCK; #ifdef USE_FLOCK - if (!mbox_lock_flock(index, lock_type)) + if (!mbox_lock_flock(index, index->mbox_lock_type)) { + (void)mbox_lock_dotlock(index, index->mbox_path, FALSE); return FALSE; + } #else - if (!mbox_lock_fcntl(index, lock_type)) + if (!mbox_lock_fcntl(index, index->mbox_lock_type)) { + (void)mbox_lock_dotlock(index, index->mbox_path, FALSE); return FALSE; + } #endif return TRUE; @@ -156,26 +158,31 @@ int mbox_lock_write(MailIndex *index) { + i_assert(index->mbox_lock_type != F_RDLCK); return mbox_lock(index, TRUE); } int mbox_unlock(MailIndex *index) { + int failed; + i_assert(index->mbox_fd != -1); i_assert(index->mbox_locks > 0); if (--index->mbox_locks > 0) return TRUE; + index->mbox_lock_type = F_UNLCK; + failed = FALSE; #ifdef USE_FLOCK if (!mbox_lock_flock(index, F_UNLCK)) - return FALSE; + failed = TRUE; #else if (!mbox_lock_fcntl(index, F_UNLCK)) - return FALSE; + failed = TRUE; #endif if (!mbox_lock_dotlock(index, index->mbox_path, FALSE)) - return FALSE; + failed = TRUE; - return TRUE; + return !failed; }