dovecot-1.2: file_dotlock_create(): If nfs_flush is enabled, fda...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Oct 22 19:58:45 EEST 2009
details: http://hg.dovecot.org/dovecot-1.2/rev/c7948ebd433e
changeset: 9449:c7948ebd433e
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 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 @@ 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