dovecot-2.0-sslstream: file_dotlock_create(): If nfs_flush is en...

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:55:23 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/9ef0821a2ce7
changeset: 10132:9ef0821a2ce7
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Oct 22 12:58:35 2009 -0400
description:
file_dotlock_create(): If nfs_flush is enabled, fdatasync after writing PID.
This makes sure that the write() doesn't fail later in close() and cause
problems.

diffstat:

1 file changed, 7 insertions(+), 4 deletions(-)
src/lib/file-dotlock.c |   11 +++++++----

diffs (40 lines):

diff -r d1384c2b08e5 -r 9ef0821a2ce7 src/lib/file-dotlock.c
--- a/src/lib/file-dotlock.c	Wed Oct 21 19:54:00 2009 -0400
+++ b/src/lib/file-dotlock.c	Thu Oct 22 12:58:35 2009 -0400
@@ -299,13 +299,14 @@ static int check_lock(time_t now, struct
 	return 0;
 }
 
-static int file_write_pid(int fd, const char *path)
+static int file_write_pid(int fd, const char *path, bool nfs_flush)
 {
 	const char *str;
 
 	/* write our pid and host, if possible */
 	str = t_strdup_printf("%s:%s", my_pid, my_hostname);
-	if (write_full(fd, str, strlen(str)) < 0) {
+	if (write_full(fd, str, strlen(str)) < 0 ||
+	    (nfs_flush && fdatasync(fd) < 0)) {
 		/* failed, leave it empty then */
 		if (ftruncate(fd, 0) < 0) {
 			i_error("ftruncate(%s) failed: %m", path);
@@ -357,7 +358,8 @@ static int try_create_lock_hardlink(stru
 
 		if (write_pid) {
 			if (file_write_pid(lock_info->fd,
-					   str_c(tmp_path)) < 0) {
+					   str_c(tmp_path),
+					   lock_info->set->nfs_flush) < 0) {
 				(void)close(lock_info->fd);
 				lock_info->fd = -1;
 				return -1;
@@ -402,7 +404,8 @@ static int try_create_lock_excl(struct l
 	}
 
 	if (write_pid) {
-		if (file_write_pid(fd, lock_info->lock_path) < 0) {
+		if (file_write_pid(fd, lock_info->lock_path,
+				   lock_info->set->nfs_flush) < 0) {
 			(void)close(fd);
 			return -1;
 		}


More information about the dovecot-cvs mailing list