dovecot-1.2: dotlocks: When locking using hard links, make sure ...

dovecot at dovecot.org dovecot at dovecot.org
Tue Jan 25 00:10:56 EET 2011


details:   http://hg.dovecot.org/dovecot-1.2/rev/ab81fbb195e2
changeset: 9639:ab81fbb195e2
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jan 25 00:10:46 2011 +0200
description:
dotlocks: When locking using hard links, make sure the dotlock's timestamp is new enough.

diffstat:

 src/lib/file-dotlock.c |  13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diffs (41 lines):

diff -r 9a50a9dc905f -r ab81fbb195e2 src/lib/file-dotlock.c
--- a/src/lib/file-dotlock.c	Thu Jan 20 23:17:05 2011 +0200
+++ b/src/lib/file-dotlock.c	Tue Jan 25 00:10:46 2011 +0200
@@ -317,11 +317,12 @@
 }
 
 static int try_create_lock_hardlink(struct lock_info *lock_info, bool write_pid,
-				    string_t *tmp_path)
+				    string_t *tmp_path, time_t now)
 {
 	const char *temp_prefix = lock_info->set->temp_prefix;
 	const char *p;
 	mode_t old_mask;
+	struct stat st;
 
 	if (lock_info->temp_path == NULL) {
 		/* we'll need our temp file first. */
@@ -367,6 +368,14 @@
 		}
 
                 lock_info->temp_path = str_c(tmp_path);
+	} else if (fstat(lock_info->fd, &st) < 0) {
+		i_error("fstat(%s) failed: %m", lock_info->temp_path);
+		return -1;
+	} else if (st.st_ctime < now) {
+		/* we've been waiting for a while.
+		   refresh the file's timestamp. */
+		if (utime(lock_info->temp_path, NULL) < 0)
+			i_error("utime(%s) failed: %m", lock_info->temp_path);
 	}
 
 	if (nfs_safe_link(lock_info->temp_path,
@@ -522,7 +531,7 @@
 			ret = set->use_excl_lock ?
 				try_create_lock_excl(&lock_info, write_pid) :
 				try_create_lock_hardlink(&lock_info, write_pid,
-							 tmp_path);
+							 tmp_path, now);
 			if (ret != 0)
 				break;
 		}


More information about the dovecot-cvs mailing list