Use the file_{wait,try}_lock_error() variants instead.
*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
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);
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;
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,
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);
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);
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,
struct file_lock **file_lock_r,
struct dotlock **dotlock_r)
{
+ const char *error;
int ret;
i_assert(trie->fd != -1);
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);
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) &&
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;
}
static int squat_uidlist_lock(struct squat_uidlist *uidlist)
{
+ const char *error;
int ret;
for (;;) {
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,