Mercurial > dovecot > core-2.2
changeset 18103:df1d0c0e7ae2
lib-index: If transaction log is unexpectedly recreated while it was locked, log a nice error.
Instead of just assert-crashing.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 20 Nov 2014 15:15:20 +0900 |
parents | c3736d065d54 |
children | 5de5be00b369 |
files | src/lib-index/mail-transaction-log-file.c src/lib-index/mail-transaction-log.c |
diffstat | 2 files changed, 16 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-transaction-log-file.c Thu Nov 20 05:40:55 2014 +0900 +++ b/src/lib-index/mail-transaction-log-file.c Thu Nov 20 15:15:20 2014 +0900 @@ -817,7 +817,7 @@ /* success */ file->fd = new_fd; mail_transaction_log_file_add_to_list(file); - return 0; + return 1; } int mail_transaction_log_file_create(struct mail_transaction_log_file *file, @@ -827,7 +827,7 @@ struct dotlock_settings new_dotlock_set; struct dotlock *dotlock; mode_t old_mask; - int fd; + int fd, ret; i_assert(!MAIL_INDEX_IS_IN_MEMORY(index)); @@ -855,12 +855,13 @@ /* either fd gets used or the dotlock gets deleted and returned fd is for the existing file */ - if (mail_transaction_log_file_create2(file, fd, reset, &dotlock) < 0) { + ret = mail_transaction_log_file_create2(file, fd, reset, &dotlock); + if (ret < 0) { if (dotlock != NULL) file_dotlock_delete(&dotlock); return -1; } - return 0; + return ret; } int mail_transaction_log_file_open(struct mail_transaction_log_file *file)
--- a/src/lib-index/mail-transaction-log.c Thu Nov 20 05:40:55 2014 +0900 +++ b/src/lib-index/mail-transaction-log.c Thu Nov 20 15:15:20 2014 +0900 @@ -233,6 +233,7 @@ struct mail_transaction_log_file *file; const char *path = log->head->filepath; struct stat st; + int ret; i_assert(log->head->locked); @@ -258,17 +259,25 @@ file->last_mtime = st.st_mtime; file->last_size = st.st_size; - if (mail_transaction_log_file_create(file, reset) < 0) { + if ((ret = mail_transaction_log_file_create(file, reset)) < 0) { mail_transaction_log_file_free(&file); return -1; } + if (ret == 0) { + mail_index_set_error(log->index, + "Transaction log %s was recreated while we had it locked - " + "locking is broken (lock_method=%s)", path, + file_lock_method_to_str(log->index->lock_method)); + mail_transaction_log_file_free(&file); + return -1; + } + i_assert(file->locked); } if (--log->head->refcount == 0) mail_transaction_logs_clean(log); else { /* the newly created log file is already locked */ - i_assert(file->locked); mail_transaction_log_file_unlock(log->head, !log->index->log_sync_locked ? "rotating" : "rotating while syncing");