# HG changeset patch # User Timo Sirainen # Date 1256230715 14400 # Node ID c7948ebd433e1d368de1b693c183043c383bc0e1 # Parent ab32d7e2c0d6ea1c25297fb4ce7546ded8e6a471 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. diff -r ab32d7e2c0d6 -r c7948ebd433e src/lib/file-dotlock.c --- a/src/lib/file-dotlock.c Tue Oct 20 15:49:01 2009 -0400 +++ b/src/lib/file-dotlock.c Thu Oct 22 12:58:35 2009 -0400 @@ -299,13 +299,14 @@ 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 @@ 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 @@ } 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; }