changeset 3576:827c7137fd78 HEAD

If dotlock is overwritten/deleted, say in the error message how long we kept the lock.
author Timo Sirainen <tss@iki.fi>
date Fri, 16 Sep 2005 15:30:08 +0300
parents e1888f3d3423
children 51d30414b8bd
files src/lib/file-dotlock.c
diffstat 1 files changed, 20 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/file-dotlock.c	Sun Sep 11 23:28:34 2005 +0300
+++ b/src/lib/file-dotlock.c	Fri Sep 16 15:30:08 2005 +0300
@@ -28,6 +28,8 @@
 
 	char *path;
 	int fd;
+
+	time_t lock_time;
 };
 
 struct lock_info {
@@ -423,11 +425,13 @@
 			i_error("fstat(%s) failed: %m", lock_path);
 			ret = -1;
 		} else {
+			/* successful dotlock creation */
 			dotlock->dev = st.st_dev;
 			dotlock->ino = st.st_ino;
 
 			dotlock->path = i_strdup(path);
 			dotlock->fd = lock_info.fd;
+                        dotlock->lock_time = now;
 			lock_info.fd = -1;
 		}
 	}
@@ -524,7 +528,9 @@
 
 	if (lstat(lock_path, &st) < 0) {
 		if (errno == ENOENT) {
-			i_warning("Our dotlock file %s was deleted", lock_path);
+			i_warning("Our dotlock file %s was deleted "
+				  "(kept it %d secs)", lock_path,
+				  (int)(dotlock->lock_time - time(NULL)));
 			file_dotlock_free(dotlock);
 			return 0;
 		}
@@ -536,7 +542,9 @@
 
 	if (dotlock->ino != st.st_ino ||
 	    !CMP_DEV_T(dotlock->dev, st.st_dev)) {
-		i_warning("Our dotlock file %s was overridden", lock_path);
+		i_warning("Our dotlock file %s was overridden "
+			  "(kept it %d secs)", lock_path,
+			  (int)(dotlock->lock_time - time(NULL)));
 		errno = EEXIST;
 		file_dotlock_free(dotlock);
 		return 0;
@@ -544,13 +552,17 @@
 
 	if (dotlock->mtime != st.st_mtime && dotlock->fd == -1) {
 		i_warning("Our dotlock file %s was modified (%s vs %s), "
-			  "assuming it wasn't overridden", lock_path,
-			  dec2str(dotlock->mtime), dec2str(st.st_mtime));
+			  "assuming it wasn't overridden (kept it %d secs)",
+			  lock_path,
+			  dec2str(dotlock->mtime), dec2str(st.st_mtime),
+			  (int)(dotlock->lock_time - time(NULL)));
 	}
 
 	if (unlink(lock_path) < 0) {
 		if (errno == ENOENT) {
-			i_warning("Our dotlock file %s was deleted", lock_path);
+			i_warning("Our dotlock file %s was deleted "
+				  "(kept it %d secs)", lock_path,
+				  (int)(dotlock->lock_time - time(NULL)));
 			file_dotlock_free(dotlock);
 			return 0;
 		}
@@ -616,8 +628,9 @@
 
 		if (st.st_ino != st2.st_ino ||
 		    !CMP_DEV_T(st.st_dev, st2.st_dev)) {
-			i_warning("Our dotlock file %s was overridden",
-				  lock_path);
+			i_warning("Our dotlock file %s was overridden "
+				  "(kept it %u secs)", lock_path,
+				  dotlock->lock_time - time(NULL));
 			errno = EEXIST;
 			file_dotlock_free(dotlock);
 			return 0;