Mercurial > dovecot > core-2.2
changeset 13550:fecd095394b6
file_dotlock: Don't warn about changed mtime when it's 1 second.
This is mainly to avoid bogus warnings with NFS and its caching.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 23 Sep 2011 15:01:23 +0300 |
parents | b3111bbbaf22 |
children | df74f0052707 |
files | src/lib/file-dotlock.c |
diffstat | 1 files changed, 19 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/file-dotlock.c Fri Sep 23 14:52:46 2011 +0300 +++ b/src/lib/file-dotlock.c Fri Sep 23 15:01:23 2011 +0300 @@ -33,6 +33,10 @@ /* Maximum difference between current time and create file's ctime before logging a warning. Should be less than a second in normal operation. */ #define MAX_TIME_DIFF 30 +/* NFS may return a cached mtime in stat(). A later non-cached stat() may + return a slightly different mtime. Allow the difference to be this much + and still consider it to be the same mtime. */ +#define FILE_DOTLOCK_MAX_STAT_MTIME_DIFF 1 struct dotlock { struct dotlock_settings settings; @@ -699,6 +703,19 @@ } } +static bool file_dotlock_has_mtime_changed(time_t t1, time_t t2) +{ + time_t diff; + + if (t1 == t2) + return FALSE; + + /* with NFS t1 may have been looked up from local cache. + allow it to be a little bit different. */ + diff = t1 > t2 ? t1-t2 : t2-t1; + return diff <= FILE_DOTLOCK_MAX_STAT_MTIME_DIFF; +} + int file_dotlock_delete(struct dotlock **dotlock_p) { struct dotlock *dotlock; @@ -729,7 +746,8 @@ return 0; } - if (dotlock->mtime != st.st_mtime && dotlock->fd == -1) { + if (file_dotlock_has_mtime_changed(dotlock->mtime, st.st_mtime) && + dotlock->fd == -1) { i_warning("Our dotlock file %s was modified (%s vs %s), " "assuming it wasn't overridden (kept it %d secs)", lock_path,