changeset 3636:08b768956051 HEAD

Default lock_method to flock instead of fcntl. This is at least useful for not allowing Dovecot's indexes to be used accidentally with wrong settings in NFS mounted partitions.
author Timo Sirainen <tss@iki.fi>
date Tue, 04 Oct 2005 00:23:18 +0300
parents c12df370e1b2
children e30f6e541c2f
files dovecot-example.conf src/deliver/deliver.c src/imap/namespace.c src/lib-index/mail-index-lock.c src/master/master-settings.c src/pop3/main.c
diffstat 6 files changed, 24 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/dovecot-example.conf	Sat Oct 01 13:52:14 2005 +0300
+++ b/dovecot-example.conf	Tue Oct 04 00:23:18 2005 +0300
@@ -305,8 +305,8 @@
 
 # Locking method for index files. Alternatives are fcntl, flock and dotlock.
 # Dotlocking uses some tricks which may create more disk I/O than other locking
-# methods.
-#lock_method = fcntl
+# methods. NOTE: If you use NFS, remember to change also mmap_disable setting!
+#lock_method = flock
 
 # By default LIST command returns all entries in maildir beginning with dot.
 # Enabling this option makes Dovecot return only entries which are directories.
--- a/src/deliver/deliver.c	Sat Oct 01 13:52:14 2005 +0300
+++ b/src/deliver/deliver.c	Tue Oct 04 00:23:18 2005 +0300
@@ -433,11 +433,10 @@
 	    str != NULL && var_get_key(str + 1) == 'm')
 		flags |= MAIL_STORAGE_FLAG_KEEP_HEADER_MD5;
 
-	str = getenv("LOCK_METHOD");
-	if (str == NULL || strcmp(str, "fcntl") == 0)
+	if (str == NULL || strcmp(str, "flock") == 0)
+		lock_method = MAIL_STORAGE_LOCK_FLOCK;
+	if (strcmp(str, "fcntl") == 0)
 		lock_method = MAIL_STORAGE_LOCK_FCNTL;
-	else if (strcmp(str, "flock") == 0)
-		lock_method = MAIL_STORAGE_LOCK_FLOCK;
 	else if (strcmp(str, "dotlock") == 0)
 		lock_method = MAIL_STORAGE_LOCK_DOTLOCK;
 	else
--- a/src/imap/namespace.c	Sat Oct 01 13:52:14 2005 +0300
+++ b/src/imap/namespace.c	Tue Oct 04 00:23:18 2005 +0300
@@ -105,10 +105,10 @@
 		flags |= MAIL_STORAGE_FLAG_SAVE_CRLF;
 
 	str = getenv("LOCK_METHOD");
-	if (str == NULL || strcmp(str, "fcntl") == 0)
+	if (str == NULL || strcmp(str, "flock") == 0)
+		lock_method = MAIL_STORAGE_LOCK_FLOCK;
+	if (strcmp(str, "fcntl") == 0)
 		lock_method = MAIL_STORAGE_LOCK_FCNTL;
-	else if (strcmp(str, "flock") == 0)
-		lock_method = MAIL_STORAGE_LOCK_FLOCK;
 	else if (strcmp(str, "dotlock") == 0)
 		lock_method = MAIL_STORAGE_LOCK_DOTLOCK;
 	else
--- a/src/lib-index/mail-index-lock.c	Sat Oct 01 13:52:14 2005 +0300
+++ b/src/lib-index/mail-index-lock.c	Tue Oct 04 00:23:18 2005 +0300
@@ -75,8 +75,7 @@
 			errno = EAGAIN;
 			return 0;
 		}
-		mail_index_file_set_syscall_error(index, path,
-						  "mail_index_lock_fd()");
+		mail_index_file_set_syscall_error(index, path, "fcntl()");
 		return -1;
 #endif
 	}
@@ -109,8 +108,17 @@
 			   b) timeouted */
 			return 0;
 		}
-		mail_index_file_set_syscall_error(index, path,
-						  "mail_index_lock_fd()");
+		if (errno == ENOLCK) {
+			/* Give a bit more helpful error message since this
+			   is the default locking method and it doesn't work
+			   with NFS. */
+			mail_index_set_error(index,
+				"flock() failed with file %s: %m "
+				"(see lock_method setting in config file)",
+				path);
+			return -1;
+		}
+		mail_index_file_set_syscall_error(index, path, "flock()");
 		return -1;
 #endif
 	}
--- a/src/master/master-settings.c	Sat Oct 01 13:52:14 2005 +0300
+++ b/src/master/master-settings.c	Tue Oct 04 00:23:18 2005 +0300
@@ -299,7 +299,7 @@
 #else
 	MEMBER(mmap_no_write) FALSE,
 #endif
-	MEMBER(lock_method) "fcntl",
+	MEMBER(lock_method) "flock",
 	MEMBER(maildir_stat_dirs) FALSE,
 	MEMBER(maildir_copy_with_hardlinks) FALSE,
 	MEMBER(mbox_read_locks) "fcntl",
--- a/src/pop3/main.c	Sat Oct 01 13:52:14 2005 +0300
+++ b/src/pop3/main.c	Tue Oct 04 00:23:18 2005 +0300
@@ -209,10 +209,10 @@
 		flags |= MAIL_STORAGE_FLAG_KEEP_HEADER_MD5;
 
 	str = getenv("LOCK_METHOD");
-	if (str == NULL || strcmp(str, "fcntl") == 0)
+	if (str == NULL || strcmp(str, "flock") == 0)
+		lock_method = MAIL_STORAGE_LOCK_FLOCK;
+	if (strcmp(str, "fcntl") == 0)
 		lock_method = MAIL_STORAGE_LOCK_FCNTL;
-	else if (strcmp(str, "flock") == 0)
-		lock_method = MAIL_STORAGE_LOCK_FLOCK;
 	else if (strcmp(str, "dotlock") == 0)
 		lock_method = MAIL_STORAGE_LOCK_DOTLOCK;
 	else