changeset 15644:6f62a31bf0d4

lib-index: Fixed marking transaction log file corrupted due to added O_APPEND flag.
author Timo Sirainen <tss@iki.fi>
date Mon, 14 Jan 2013 17:58:09 +0200
parents 70b97cecdacd
children 970dc6b0760b
files src/lib-index/mail-transaction-log-file.c
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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,