dovecot-1.2: dotlocking: If rename() fails due to ENOENT, show h...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Sep 9 08:48:57 EEST 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/a6ae37414011
changeset: 8178:a6ae37414011
user: Timo Sirainen <tss at iki.fi>
date: Tue Sep 09 08:48:51 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 bdc3465bb803 -r a6ae37414011 src/lib/file-dotlock.c
--- a/src/lib/file-dotlock.c Mon Sep 08 16:56:43 2008 +0300
+++ b/src/lib/file-dotlock.c Tue Sep 09 08:48:51 2008 +0300
@@ -647,6 +647,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;
@@ -659,9 +679,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;
}
@@ -673,9 +691,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;
@@ -691,9 +707,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;
}
@@ -773,9 +787,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;
@@ -783,6 +795,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