dovecot-2.2: lib-index: Fixed marking transaction log file corru...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jan 14 17:58:14 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/6f62a31bf0d4
changeset: 15644:6f62a31bf0d4
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jan 14 17:58:09 2013 +0200
description:
lib-index: Fixed marking transaction log file corrupted due to added O_APPEND flag.

diffstat:

 src/lib-index/mail-transaction-log-file.c |  16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diffs (31 lines):

diff -r 70b97cecdacd -r 6f62a31bf0d4 src/lib-index/mail-transaction-log-file.c
--- a/src/lib-index/mail-transaction-log-file.c	Mon Jan 14 12:56:09 2013 +0200
+++ b/src/lib-index/mail-transaction-log-file.c	Mon Jan 14 17:58:09 2013 +0200
@@ -32,12 +32,26 @@
 {
 	unsigned int offset =
 		offsetof(struct mail_transaction_log_header, indexid);
+	int flags;
 
 	if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ||
 	    file->log->index->readonly)
 		return;
 
-	/* indexid=0 marks the log file as corrupted */
+	/* indexid=0 marks the log file as corrupted. we opened the file with
+	   O_APPEND, and now we need to drop it for pwrite() to work (at least
+	   in Linux) */
+	flags = fcntl(file->fd, F_GETFL, 0);
+	if (flags < 0) {
+		mail_index_file_set_syscall_error(file->log->index,
+			file->filepath, "fcntl(F_GETFL)");
+		return;
+	}
+	if (fcntl(file->fd, F_SETFL, flags & ~O_APPEND) < 0) {
+		mail_index_file_set_syscall_error(file->log->index,
+			file->filepath, "fcntl(F_SETFL)");
+		return;
+	}
 	if (pwrite_full(file->fd, &file->hdr.indexid,
 			sizeof(file->hdr.indexid), offset) < 0) {
 		mail_index_file_set_syscall_error(file->log->index,


More information about the dovecot-cvs mailing list