[dovecot-cvs] dovecot/src/lib file-dotlock.c, 1.31, 1.32 file-dotlock.h, 1.12, 1.13

cras at dovecot.org cras at dovecot.org
Sun Feb 5 14:58:08 EET 2006


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv2620/lib

Modified Files:
	file-dotlock.c file-dotlock.h 
Log Message:
Added file_dotlock_touch() for updating lock file's timestamp.



Index: file-dotlock.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/file-dotlock.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- file-dotlock.c	5 Feb 2006 12:46:07 -0000	1.31
+++ file-dotlock.c	5 Feb 2006 12:58:05 -0000	1.32
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <signal.h>
 #include <time.h>
+#include <utime.h>
 #include <sys/stat.h>
 
 #define DEFAULT_LOCK_SUFFIX ".lock"
@@ -29,7 +30,7 @@
 	char *path;
 	int fd;
 
-	time_t lock_time;
+	time_t lock_time, lock_update_mtime;
 };
 
 struct file_change_info {
@@ -434,6 +435,7 @@
 			dotlock->path = i_strdup(path);
 			dotlock->fd = lock_info.fd;
                         dotlock->lock_time = now;
+                        dotlock->lock_update_mtime = now;
 			lock_info.fd = -1;
 		}
 	}
@@ -645,6 +647,29 @@
 	return 1;
 }
 
+int file_dotlock_touch(struct dotlock *dotlock)
+{
+	time_t now = time(NULL);
+	struct utimbuf buf;
+	const char *lock_path;
+	int ret = 0;
+
+	if (dotlock->lock_update_mtime == now)
+		return 0;
+
+	dotlock->lock_update_mtime = now;
+	buf.actime = buf.modtime = now;
+
+	t_push();
+	lock_path = file_dotlock_get_lock_path(dotlock);
+	if (utime(lock_path, &buf) < 0) {
+		i_error("utime(%s) failed: %m", lock_path);
+		ret = -1;
+	}
+	t_pop();
+	return ret;
+}
+
 const char *file_dotlock_get_lock_path(struct dotlock *dotlock)
 {
 	return t_strconcat(dotlock->path, dotlock->settings.lock_suffix, NULL);

Index: file-dotlock.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/file-dotlock.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- file-dotlock.h	5 Feb 2006 12:46:07 -0000	1.12
+++ file-dotlock.h	5 Feb 2006 12:58:05 -0000	1.13
@@ -41,7 +41,7 @@
 };
 
 enum dotlock_replace_flags {
-	/* Check that lock file hasn't been overwritten before renaming. */
+	/* Check that lock file hasn't been overridden before renaming. */
 	DOTLOCK_REPLACE_FLAG_VERIFY_OWNER	= 0x01,
 	/* Don't close the file descriptor. */
 	DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD	= 0x02
@@ -66,6 +66,10 @@
 /* Replaces the file dotlock protects with the dotlock file itself. */
 int file_dotlock_replace(struct dotlock **dotlock,
 			 enum dotlock_replace_flags flags);
+/* Update dotlock's mtime. If you're keeping the dotlock for a long time,
+   it's a good idea to update it once in a while so others won't override it.
+   If the timestamp is less than a second old, it's not updated. */
+int file_dotlock_touch(struct dotlock *dotlock);
 
 /* Returns the lock file path. */
 const char *file_dotlock_get_lock_path(struct dotlock *dotlock);



More information about the dovecot-cvs mailing list