From: Timo Sirainen Date: Sat, 3 May 2008 23:53:55 +0000 (+0300) Subject: If fcntl() fails with EACCES, give a more understandable error message since X-Git-Tag: 1.1.rc5~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6797b2bb35596ec47d7f140eba79d4c686f370bc;p=thirdparty%2Fdovecot%2Fcore.git If fcntl() fails with EACCES, give a more understandable error message since it's more similar to EAGAIN than anything to do with permissions. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/dbox/dbox-index.c b/src/lib-storage/index/dbox/dbox-index.c index c280acafc8..cc68c29b37 100644 --- a/src/lib-storage/index/dbox/dbox-index.c +++ b/src/lib-storage/index/dbox/dbox-index.c @@ -346,6 +346,7 @@ dbox_index_lock_range(struct dbox_index *index, int cmd, int lock_type, off_t start, off_t len) { struct flock fl; + const char *errstr; fl.l_type = lock_type; fl.l_whence = SEEK_SET; @@ -355,9 +356,12 @@ dbox_index_lock_range(struct dbox_index *index, int cmd, int lock_type, if ((errno == EACCES || errno == EAGAIN || errno == EINTR) && cmd == F_SETLK) return 0; + + errstr = errno != EACCES ? strerror(errno) : + "File is locked by another process (EACCES)"; mail_storage_set_critical(index->mbox->ibox.box.storage, - "fcntl(%s, %s) failed: %m", index->path, - lock_type == F_UNLCK ? "F_UNLCK" : "F_WRLCK"); + "fcntl(%s, %s) failed: %s", index->path, + lock_type == F_UNLCK ? "F_UNLCK" : "F_WRLCK", errstr); return -1; } return 1; diff --git a/src/lib-storage/index/mbox/mbox-lock.c b/src/lib-storage/index/mbox/mbox-lock.c index b4158eafc6..f74f02ee47 100644 --- a/src/lib-storage/index/mbox/mbox-lock.c +++ b/src/lib-storage/index/mbox/mbox-lock.c @@ -533,8 +533,15 @@ static int mbox_lock_fcntl(struct mbox_lock_context *ctx, int lock_type, /* non-blocking lock trying failed */ return 0; } - mbox_set_syscall_error(ctx->mbox, "fcntl()"); alarm(0); + if (errno != EACCES) { + mbox_set_syscall_error(ctx->mbox, "fcntl()"); + return -1; + } + mail_storage_set_critical(&ctx->mbox->storage->storage, + "fcntl() failed with mbox file %s: " + "File is locked by another process (EACCES)", + ctx->mbox->path); return -1; } diff --git a/src/lib/file-lock.c b/src/lib/file-lock.c index e37af29099..6cac0c1369 100644 --- a/src/lib/file-lock.c +++ b/src/lib/file-lock.c @@ -39,6 +39,7 @@ static int file_lock_do(int fd, const char *path, int lock_type, i_fatal("fcntl() locks not supported"); #else struct flock fl; + const char *errstr; fl.l_type = lock_type; fl.l_whence = SEEK_SET; @@ -64,10 +65,12 @@ static int file_lock_do(int fd, const char *path, int lock_type, errno = EAGAIN; return 0; } - i_error("fcntl(%s) locking failed for file %s: %m", + errstr = errno != EACCES ? strerror(errno) : + "File is locked by another process (EACCES)"; + i_error("fcntl(%s) locking failed for file %s: %s", lock_type == F_UNLCK ? "unlock" : lock_type == F_RDLCK ? "read-lock" : "write-lock", - path); + path, errstr); return -1; #endif }