Mercurial > dovecot > original-hg > dovecot-1.2
changeset 3982:15c48c43cc75 HEAD
Added file_dotlock_touch() for updating lock file's timestamp.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 05 Feb 2006 14:58:05 +0200 |
parents | 0d64f8888dcd |
children | 565e3040a9f5 |
files | src/lib/file-dotlock.c src/lib/file-dotlock.h |
diffstat | 2 files changed, 31 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/file-dotlock.c Sun Feb 05 14:46:07 2006 +0200 +++ b/src/lib/file-dotlock.c Sun Feb 05 14:58:05 2006 +0200 @@ -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);
--- a/src/lib/file-dotlock.h Sun Feb 05 14:46:07 2006 +0200 +++ b/src/lib/file-dotlock.h Sun Feb 05 14:58:05 2006 +0200 @@ -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);