]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Avoid use of file_{wait,try}_lock().
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 20 Sep 2021 00:26:46 +0000 (02:26 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 23 Sep 2021 07:03:28 +0000 (07:03 +0000)
Use the file_{wait,try}_lock_error() variants instead.

src/lib-dict/dict-file.c
src/lib-fs/fs-posix.c
src/lib-index/mail-index-lock.c
src/lib-index/mail-index-strmap.c
src/lib-storage/index/dbox-common/dbox-file.c
src/plugins/fts-squat/squat-trie.c
src/plugins/fts-squat/squat-uidlist.c

index 8a3942fec30d9336ef266622a0748db600c5816c..eef096e0f810f23c52740fba97e10fa10cdbb18d 100644 (file)
@@ -522,12 +522,13 @@ file_dict_lock(struct file_dict *dict, struct file_lock **lock_r,
        *lock_r = NULL;
        do {
                file_lock_free(lock_r);
-               if (file_wait_lock(dict->fd, dict->path, F_WRLCK,
-                                  dict->lock_method,
-                                  file_dict_dotlock_settings.timeout,
-                                  lock_r) <= 0) {
+               if (file_wait_lock_error(dict->fd, dict->path, F_WRLCK,
+                                        dict->lock_method,
+                                        file_dict_dotlock_settings.timeout,
+                                        lock_r, &error) <= 0) {
                        *error_r = t_strdup_printf(
-                               "file_wait_lock(%s) failed: %m", dict->path);
+                               "file_wait_lock(%s) failed: %s",
+                               dict->path, error);
                        return -1;
                }
                /* check again if we need to reopen the file because it was
index 6ce6a88d04d015e45aa46cd35677b98d1401ea32..9e9d3e4a8e7460338cf366ad1145d648bba5be7c 100644 (file)
@@ -688,6 +688,7 @@ fs_posix_lock(struct fs_file *_file, unsigned int secs, struct fs_lock **lock_r)
        struct posix_fs *fs = container_of(_file->fs, struct posix_fs, fs);
        struct dotlock_settings dotlock_set;
        struct posix_fs_lock fs_lock, *ret_lock;
+       const char *error;
        int ret = -1;
 
        i_zero(&fs_lock);
@@ -701,17 +702,19 @@ fs_posix_lock(struct fs_file *_file, unsigned int secs, struct fs_lock **lock_r)
                             file->full_path);
 #else
                if (secs == 0) {
-                       ret = file_try_lock(file->fd, file->full_path, F_WRLCK,
-                                           FILE_LOCK_METHOD_FLOCK,
-                                           &fs_lock.file_lock);
+                       ret = file_try_lock_error(file->fd, file->full_path,
+                                                 F_WRLCK,
+                                                 FILE_LOCK_METHOD_FLOCK,
+                                                 &fs_lock.file_lock, &error);
                } else {
-                       ret = file_wait_lock(file->fd, file->full_path, F_WRLCK,
-                                            FILE_LOCK_METHOD_FLOCK, secs,
-                                            &fs_lock.file_lock);
+                       ret = file_wait_lock_error(file->fd, file->full_path,
+                                                  F_WRLCK,
+                                                  FILE_LOCK_METHOD_FLOCK, secs,
+                                                  &fs_lock.file_lock, &error);
                }
                if (ret < 0) {
-                       fs_set_error_errno(_file->event, "flock(%s) failed: %m",
-                                          file->full_path);
+                       fs_set_error_errno(_file->event, "flock(%s) failed: %s",
+                                          file->full_path, error);
                }
 #endif
                break;
index bcfd3d611847cfc40ff37d5321b9ff637c0dbec2..e14461b5e88b67fd1bd0cb93d363812d9c82f6f3 100644 (file)
@@ -27,13 +27,19 @@ int mail_index_lock_fd(struct mail_index *index, const char *path, int fd,
                       int lock_type, unsigned int timeout_secs,
                       struct file_lock **lock_r)
 {
+       const char *error;
+       int ret;
+
        if (fd == -1) {
                i_assert(MAIL_INDEX_IS_IN_MEMORY(index));
                return 1;
        }
 
-       return file_wait_lock(fd, path, lock_type, index->set.lock_method,
-                             timeout_secs, lock_r);
+       ret = file_wait_lock_error(fd, path, lock_type, index->set.lock_method,
+                                  timeout_secs, lock_r, &error);
+       if (ret < 0)
+               e_error(index->event, "%s", error);
+       return ret;
 }
 
 void mail_index_flush_read_cache(struct mail_index *index, const char *path,
index 0210c22a991229d3d1ba0be726a3c1cb1af9e9a6..ddfbc547a5ec3c8abe9791345eb9d56fae82a478 100644 (file)
@@ -1039,6 +1039,7 @@ static int mail_index_strmap_recreate(struct mail_index_strmap_view *view)
 static int mail_index_strmap_lock(struct mail_index_strmap *strmap)
 {
        unsigned int timeout_secs;
+       const char *error;
        int ret;
 
        i_assert(strmap->fd != -1);
@@ -1048,12 +1049,14 @@ static int mail_index_strmap_lock(struct mail_index_strmap *strmap)
 
                timeout_secs = I_MIN(MAIL_INDEX_STRMAP_TIMEOUT_SECS,
                                     strmap->index->set.max_lock_timeout_secs);
-               ret = file_wait_lock(strmap->fd, strmap->path, F_WRLCK,
-                                    strmap->index->set.lock_method, timeout_secs,
-                                    &strmap->file_lock);
+               ret = file_wait_lock_error(strmap->fd, strmap->path, F_WRLCK,
+                                          strmap->index->set.lock_method,
+                                          timeout_secs, &strmap->file_lock,
+                                          &error);
                if (ret <= 0) {
-                       mail_index_strmap_set_syscall_error(strmap,
-                                                           "file_wait_lock()");
+                       mail_index_set_error(strmap->index,
+                               "file_wait_lock() failed with strmap index file %s: %s",
+                               strmap->path, error);
                }
        } else {
                i_assert(strmap->dotlock == NULL);
index 86b3543b71692f981e74545f59b80809312d2dfb..dd4a2dbf6c87844b8fe2bfd7c20bbd9fb4bfbd46 100644 (file)
@@ -307,16 +307,17 @@ void dbox_file_close(struct dbox_file *file)
 
 int dbox_file_try_lock(struct dbox_file *file)
 {
+       const char *error;
        int ret;
 
        i_assert(file->fd != -1);
 
 #ifdef DBOX_FILE_LOCK_METHOD_FLOCK
-       ret = file_try_lock(file->fd, file->cur_path, F_WRLCK,
-                           FILE_LOCK_METHOD_FLOCK, &file->lock);
+       ret = file_try_lock_error(file->fd, file->cur_path, F_WRLCK,
+                                 FILE_LOCK_METHOD_FLOCK, &file->lock, &error);
        if (ret < 0) {
                mail_storage_set_critical(&file->storage->storage,
-                       "file_try_lock(%s) failed: %m", file->cur_path);
+                       "file_try_lock(%s) failed: %s", file->cur_path, error);
        }
 #else
        ret = file_dotlock_create(&dotlock_set, file->cur_path,
index 3a33c9e7b3f0d66f05be70832b7fdc84295cdfa3..10c83f19c9608f4b6979df4b74385c02a9c92789 100644 (file)
@@ -282,6 +282,7 @@ static int squat_trie_lock(struct squat_trie *trie, int lock_type,
                           struct file_lock **file_lock_r,
                           struct dotlock **dotlock_r)
 {
+       const char *error;
        int ret;
 
        i_assert(trie->fd != -1);
@@ -291,10 +292,14 @@ static int squat_trie_lock(struct squat_trie *trie, int lock_type,
 
        for (;;) {
                if (trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
-                       ret = file_wait_lock(trie->fd, trie->path, lock_type,
-                                            trie->lock_method,
-                                            SQUAT_TRIE_LOCK_TIMEOUT,
-                                            file_lock_r);
+                       ret = file_wait_lock_error(trie->fd, trie->path,
+                                                  lock_type, trie->lock_method,
+                                                  SQUAT_TRIE_LOCK_TIMEOUT,
+                                                  file_lock_r, &error);
+                       if (ret < 0) {
+                               i_error("squat trie %s: %s",
+                                       trie->path, error);
+                       }
                } else {
                        ret = file_dotlock_create(&trie->dotlock_set,
                                                  trie->path, 0, dotlock_r);
@@ -1610,7 +1615,7 @@ static int squat_trie_write(struct squat_trie_build_context *ctx)
        struct squat_trie *trie = ctx->trie;
        struct file_lock *file_lock = NULL;
        struct ostream *output;
-       const char *path;
+       const char *path, *error;
        int fd = -1, ret = 0;
 
        if ((trie->hdr.used_file_size > sizeof(trie->hdr) &&
@@ -1624,15 +1629,13 @@ static int squat_trie_write(struct squat_trie_build_context *ctx)
                        return -1;
 
                if (trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
-                       ret = file_wait_lock(fd, path, F_WRLCK,
-                                            trie->lock_method,
-                                            SQUAT_TRIE_LOCK_TIMEOUT,
-                                            &file_lock);
+                       ret = file_wait_lock_error(fd, path, F_WRLCK,
+                                                  trie->lock_method,
+                                                  SQUAT_TRIE_LOCK_TIMEOUT,
+                                                  &file_lock, &error);
                        if (ret <= 0) {
-                               if (ret == 0) {
-                                       i_error("file_wait_lock(%s) failed: %m",
-                                               path);
-                               }
+                               i_error("file_wait_lock(%s) failed: %s",
+                                       path, error);
                                i_close_fd(&fd);
                                return -1;
                        }
index 5e1502efabc9e62cc186fe6be9c56ccb6075d9bc..7364431f5a2ab25f8aefcee83f7d6817e191e22e 100644 (file)
@@ -600,6 +600,7 @@ static int squat_uidlist_is_file_stale(struct squat_uidlist *uidlist)
 
 static int squat_uidlist_lock(struct squat_uidlist *uidlist)
 {
+       const char *error;
        int ret;
 
        for (;;) {
@@ -608,11 +609,15 @@ static int squat_uidlist_lock(struct squat_uidlist *uidlist)
                i_assert(uidlist->dotlock == NULL);
 
                if (uidlist->trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
-                       ret = file_wait_lock(uidlist->fd, uidlist->path,
-                                            F_WRLCK,
-                                            uidlist->trie->lock_method,
-                                            SQUAT_TRIE_LOCK_TIMEOUT,
-                                            &uidlist->file_lock);
+                       ret = file_wait_lock_error(uidlist->fd, uidlist->path,
+                                                  F_WRLCK,
+                                                  uidlist->trie->lock_method,
+                                                  SQUAT_TRIE_LOCK_TIMEOUT,
+                                                  &uidlist->file_lock, &error);
+                       if (ret < 0) {
+                               i_error("squat uidlist %s: %s",
+                                       uidlist->path, error);
+                       }
                } else {
                        ret = file_dotlock_create(&uidlist->trie->dotlock_set,
                                                  uidlist->path, 0,