]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
We got dotlock's mtime before modifying it, which caused problems sometimes.
authorTimo Sirainen <tss@iki.fi>
Thu, 17 Apr 2003 14:20:47 +0000 (17:20 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 17 Apr 2003 14:20:47 +0000 (17:20 +0300)
--HG--
branch : HEAD

src/lib/file-dotlock.c

index 699abb1b9bf420e7c193fd48dd50aca7c540a750..b25a2fa60944f8be70128f83bb24ab03ae25d003 100644 (file)
@@ -147,17 +147,6 @@ static int try_create_lock(const char *lock_path, struct dotlock *dotlock_r)
        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 @@ static int try_create_lock(const char *lock_path, struct dotlock *dotlock_r)
                }
        }
 
+       /* 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);