]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
If fcntl() fails with EACCES, give a more understandable error message since
authorTimo Sirainen <tss@iki.fi>
Sat, 3 May 2008 23:53:55 +0000 (02:53 +0300)
committerTimo Sirainen <tss@iki.fi>
Sat, 3 May 2008 23:53:55 +0000 (02:53 +0300)
it's more similar to EAGAIN than anything to do with permissions.

--HG--
branch : HEAD

src/lib-storage/index/dbox/dbox-index.c
src/lib-storage/index/mbox/mbox-lock.c
src/lib/file-lock.c

index c280acafc82be868512bc282dd511ab2d345f7cd..cc68c29b3755d7f10d5912e422f6e59dd32772ad 100644 (file)
@@ -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;
index b4158eafc6e7cd8b460032a1e773ca752287b0f4..f74f02ee470d6dbac874172f54345cbbc95a2490 100644 (file)
@@ -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;
                }
 
index e37af29099341d696f86081397e8f20c7b3601f3..6cac0c1369af89d41abe8ce87b601f3c637e22ad 100644 (file)
@@ -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
        }