dovecot-1.1: dotlocking: If rename() fails due to ENOENT, show h...

dovecot at dovecot.org dovecot at dovecot.org
Tue Sep 9 08:48:40 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/241097889792
changeset: 7867:241097889792
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Sep 09 08:48:32 2008 +0300
description:
dotlocking: If rename() fails due to ENOENT, show how long we kept the lock.
Also for all these "replaced/deleted" notifications show how long ago the
lock was last touched (if it ever was).

diffstat:

1 file changed, 26 insertions(+), 12 deletions(-)
src/lib/file-dotlock.c |   38 ++++++++++++++++++++++++++------------

diffs (83 lines):

diff -r aac3b42f3f8a -r 241097889792 src/lib/file-dotlock.c
--- a/src/lib/file-dotlock.c	Mon Sep 08 16:56:58 2008 +0300
+++ b/src/lib/file-dotlock.c	Tue Sep 09 08:48:32 2008 +0300
@@ -646,6 +646,26 @@ int file_dotlock_create(const struct dot
 	return ret;
 }
 
+static void dotlock_replaced_warning(struct dotlock *dotlock, bool deleted)
+{
+	const char *lock_path;
+	time_t now = time(NULL);
+
+	lock_path = file_dotlock_get_lock_path(dotlock);
+	if (dotlock->mtime == dotlock->lock_time) {
+		i_warning("Our dotlock file %s was %s "
+			  "(locked %d secs ago, touched %d secs ago)",
+			  lock_path, deleted ? "deleted" : "overridden",
+			  (int)(now - dotlock->lock_time),
+			  (int)(now - dotlock->mtime));
+	} else {
+		i_warning("Our dotlock file %s was %s "
+			  "(kept it %d secs)", lock_path,
+			  deleted ? "deleted" : "overridden",
+			  (int)(now - dotlock->lock_time));
+	}
+}
+
 int file_dotlock_delete(struct dotlock **dotlock_p)
 {
 	struct dotlock *dotlock;
@@ -658,9 +678,7 @@ int file_dotlock_delete(struct dotlock *
 	lock_path = file_dotlock_get_lock_path(dotlock);
 	if (nfs_safe_lstat(lock_path, &st) < 0) {
 		if (errno == ENOENT) {
-			i_warning("Our dotlock file %s was deleted "
-				  "(kept it %d secs)", lock_path,
-				  (int)(time(NULL) - dotlock->lock_time));
+			dotlock_replaced_warning(dotlock, TRUE);
 			file_dotlock_free(&dotlock);
 			return 0;
 		}
@@ -672,9 +690,7 @@ int file_dotlock_delete(struct dotlock *
 
 	if (dotlock->ino != st.st_ino ||
 	    !CMP_DEV_T(dotlock->dev, st.st_dev)) {
-		i_warning("Our dotlock file %s was overridden "
-			  "(kept it %d secs)", lock_path,
-			  (int)(dotlock->lock_time - time(NULL)));
+		dotlock_replaced_warning(dotlock, FALSE);
 		errno = EEXIST;
 		file_dotlock_free(&dotlock);
 		return 0;
@@ -690,9 +706,7 @@ int file_dotlock_delete(struct dotlock *
 
 	if (unlink(lock_path) < 0) {
 		if (errno == ENOENT) {
-			i_warning("Our dotlock file %s was deleted "
-				  "(kept it %d secs)", lock_path,
-				  (int)(time(NULL) - dotlock->lock_time));
+			dotlock_replaced_warning(dotlock, TRUE);
 			file_dotlock_free(&dotlock);
 			return 0;
 		}
@@ -747,9 +761,7 @@ int file_dotlock_replace(struct dotlock 
 	lock_path = file_dotlock_get_lock_path(dotlock);
 	if ((flags & DOTLOCK_REPLACE_FLAG_VERIFY_OWNER) != 0 &&
 	    !file_dotlock_is_locked(dotlock)) {
-		i_warning("Our dotlock file %s was overridden "
-			  "(kept it %d secs)", lock_path,
-			  (int)(time(NULL) - dotlock->lock_time));
+		dotlock_replaced_warning(dotlock, FALSE);
 		errno = EEXIST;
 		file_dotlock_free(&dotlock);
 		return 0;
@@ -757,6 +769,8 @@ int file_dotlock_replace(struct dotlock 
 
 	if (rename(lock_path, dotlock->path) < 0) {
 		i_error("rename(%s, %s) failed: %m", lock_path, dotlock->path);
+		if (errno == ENOENT)
+			dotlock_replaced_warning(dotlock, TRUE);
 		file_dotlock_free(&dotlock);
 		return -1;
 	}


More information about the dovecot-cvs mailing list