changeset 1369:945f857cb514 HEAD

We got dotlock's mtime before modifying it, which caused problems sometimes.
author Timo Sirainen <tss@iki.fi>
date Thu, 17 Apr 2003 17:20:47 +0300
parents 33cf08305781
children 5f521a721671
files src/lib/file-dotlock.c
diffstat 1 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/file-dotlock.c	Wed Apr 16 23:26:11 2003 +0300
+++ b/src/lib/file-dotlock.c	Thu Apr 17 17:20:47 2003 +0300
@@ -147,17 +147,6 @@
 	if (fd == -1)
 		return -1;
 
-	/* got it, save the inode info */
-	if (fstat(fd, &st) < 0) {
-		i_error("fstat(%s) failed: %m", lock_path);
-		(void)close(fd);
-		return -1;
-	}
-
-	dotlock_r->dev = st.st_dev;
-	dotlock_r->ino = st.st_ino;
-	dotlock_r->mtime = st.st_mtime;
-
 	/* 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) {
@@ -170,6 +159,17 @@
 		}
 	}
 
+	/* save the inode info after writing */
+	if (fstat(fd, &st) < 0) {
+		i_error("fstat(%s) failed: %m", lock_path);
+		(void)close(fd);
+		return -1;
+	}
+
+	dotlock_r->dev = st.st_dev;
+	dotlock_r->ino = st.st_ino;
+	dotlock_r->mtime = st.st_mtime;
+
 	if (close(fd) < 0) {
 		i_error("close(%s) failed: %m", lock_path);
 		(void)unlink(lock_path);