From: Stephan Bosch Date: Mon, 20 Sep 2021 00:26:46 +0000 (+0200) Subject: global: Avoid use of file_{wait,try}_lock(). X-Git-Tag: 2.3.17~67 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4dbae0e6c1de673b3b9482653c9631ce90aaf958;p=thirdparty%2Fdovecot%2Fcore.git global: Avoid use of file_{wait,try}_lock(). Use the file_{wait,try}_lock_error() variants instead. --- diff --git a/src/lib-dict/dict-file.c b/src/lib-dict/dict-file.c index 8a3942fec3..eef096e0f8 100644 --- a/src/lib-dict/dict-file.c +++ b/src/lib-dict/dict-file.c @@ -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 diff --git a/src/lib-fs/fs-posix.c b/src/lib-fs/fs-posix.c index 6ce6a88d04..9e9d3e4a8e 100644 --- a/src/lib-fs/fs-posix.c +++ b/src/lib-fs/fs-posix.c @@ -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; diff --git a/src/lib-index/mail-index-lock.c b/src/lib-index/mail-index-lock.c index bcfd3d6118..e14461b5e8 100644 --- a/src/lib-index/mail-index-lock.c +++ b/src/lib-index/mail-index-lock.c @@ -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, diff --git a/src/lib-index/mail-index-strmap.c b/src/lib-index/mail-index-strmap.c index 0210c22a99..ddfbc547a5 100644 --- a/src/lib-index/mail-index-strmap.c +++ b/src/lib-index/mail-index-strmap.c @@ -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); diff --git a/src/lib-storage/index/dbox-common/dbox-file.c b/src/lib-storage/index/dbox-common/dbox-file.c index 86b3543b71..dd4a2dbf6c 100644 --- a/src/lib-storage/index/dbox-common/dbox-file.c +++ b/src/lib-storage/index/dbox-common/dbox-file.c @@ -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, diff --git a/src/plugins/fts-squat/squat-trie.c b/src/plugins/fts-squat/squat-trie.c index 3a33c9e7b3..10c83f19c9 100644 --- a/src/plugins/fts-squat/squat-trie.c +++ b/src/plugins/fts-squat/squat-trie.c @@ -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; } diff --git a/src/plugins/fts-squat/squat-uidlist.c b/src/plugins/fts-squat/squat-uidlist.c index 5e1502efab..7364431f5a 100644 --- a/src/plugins/fts-squat/squat-uidlist.c +++ b/src/plugins/fts-squat/squat-uidlist.c @@ -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,