Mercurial > dovecot > core-2.2
changeset 2283:199eb3df762c HEAD
more checks against using old cache_offsets
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 05 Jul 2004 01:03:21 +0300 |
parents | c54f0c01da09 |
children | 1a31b3d17b1e |
files | src/lib-index/mail-transaction-log.c |
diffstat | 1 files changed, 18 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-transaction-log.c Mon Jul 05 00:56:12 2004 +0300 +++ b/src/lib-index/mail-transaction-log.c Mon Jul 05 01:03:21 2004 +0300 @@ -1076,10 +1076,11 @@ struct mail_index *index; struct mail_transaction_log *log; struct mail_transaction_log_file *file; + struct mail_index_header idx_hdr; size_t offset; uoff_t append_offset; buffer_t *hdr_buf; - unsigned int i; + unsigned int i, lock_id; int ret; index = mail_index_view_get_index(view); @@ -1101,23 +1102,21 @@ return -1; } + if (mail_index_lock_shared(log->index, TRUE, &lock_id) < 0) { + if (!log->index->log_locked) + (void)mail_transaction_log_file_lock(file, F_UNLCK); + return -1; + } + idx_hdr = *log->index->hdr; + mail_index_unlock(log->index, lock_id); + if (log->head->hdr.used_size > MAIL_TRANSACTION_LOG_ROTATE_SIZE && log->head->last_mtime < ioloop_time - MAIL_TRANSACTION_LOG_ROTATE_MIN_TIME) { /* we might want to rotate, but check first that head file sequence matches the one in index header, ie. we have everything synced in index. */ - unsigned int lock_id; - uint32_t seq; - - if (mail_index_lock_shared(log->index, TRUE, &lock_id) == 0) { - seq = index->hdr->log_file_seq; - mail_index_unlock(log->index, lock_id); - } else { - seq = 0; - } - - if (log->head->hdr.file_seq == seq) { + if (log->head->hdr.file_seq == idx_hdr.log_file_seq) { if (mail_transaction_log_rotate(log, F_WRLCK) < 0) { /* that didn't work. well, try to continue anyway */ @@ -1128,6 +1127,13 @@ file = log->head; append_offset = file->hdr.used_size; + if (t->cache_updates != NULL && + t->last_cache_file_seq < idx_hdr.cache_file_seq) { + /* cache_offsets point to old file, don't allow */ + buffer_free(t->cache_updates); + t->cache_updates = NULL; + } + if (t->appends != NULL || (t->cache_updates != NULL && t->new_cache_file_seq == 0)) { if (mail_transaction_log_scan_pending(log, t) < 0) {