Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6820:6dfb3969baae HEAD
FreeBSD and Solaris supports flushing attribute cache with chown(uid=-1,
gid=-1). Do it with them.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 16 Nov 2007 10:41:34 +0200 |
parents | 256725979152 |
children | eebfe0cd2add |
files | src/lib/nfs-workarounds.c |
diffstat | 1 files changed, 22 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/nfs-workarounds.c Fri Nov 16 08:10:17 2007 +0200 +++ b/src/lib/nfs-workarounds.c Fri Nov 16 10:41:34 2007 +0200 @@ -38,6 +38,10 @@ # define READ_CACHE_FLUSH_FCNTL #endif +#if defined(__FreeBSD__) || defined(__sun) +# define ATTRCACHE_FLUSH_CHOWN_UID_1 +#endif + static int nfs_safe_do(const char *path, int (*callback)(const char *path, void *context), void *context) @@ -162,6 +166,7 @@ static bool nfs_flush_fchown_uid(const char *path, int fd) { struct stat st; + uid_t uid; if (fstat(fd, &st) < 0) { if (errno == ESTALE) { @@ -171,7 +176,12 @@ i_error("nfs_flush_fchown_uid: fstat(%s) failed: %m", path); return TRUE; } - if (fchown(fd, st.st_uid, (gid_t)-1) < 0) { +#ifdef ATTRCACHE_FLUSH_CHOWN_UID_1 + uid = (uid_t)-1; +#else + uid = st.st_uid; +#endif + if (fchown(fd, uid, (gid_t)-1) < 0) { if (errno == ESTALE) { return FALSE; } @@ -188,9 +198,16 @@ #ifndef __FreeBSD__ static void nfs_flush_chown_uid(const char *path) { + uid_t uid; + +#ifdef ATTRCACHE_FLUSH_CHOWN_UID_1 + uid = (uid_t)-1; +#else struct stat st; - if (stat(path, &st) < 0) { + if (stat(path, &st) == 0) + uid = st.st_uid; + else { if (errno == ESTALE) { /* ESTALE causes the OS to flush the attr cache */ return; @@ -205,10 +222,10 @@ it probably doesn't really matter what UID is used, because as long as we're not root we don't have permission to really change it anyway */ - st.st_uid = geteuid(); + uid = geteuid(); } - - if (chown(path, st.st_uid, (gid_t)-1) < 0) { +#endif + if (chown(path, uid, (gid_t)-1) < 0) { if (errno == ESTALE || errno == EACCES || errno == EPERM || errno == ENOENT) { /* attr cache is flushed */