"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/plugins/fts-squat/squat-trie.c" between
dovecot-2.3.16.tar.gz and dovecot-2.3.17.tar.gz

About: Dovecot is an IMAP and POP3 server, written with security primarily in mind.

squat-trie.c  (dovecot-2.3.16):squat-trie.c  (dovecot-2.3.17)
skipping to change at line 285 skipping to change at line 285
ret = squat_trie_is_file_stale(trie); ret = squat_trie_is_file_stale(trie);
if (ret > 0) if (ret > 0)
ret = squat_trie_open(trie); ret = squat_trie_open(trie);
return ret; return ret;
} }
static int squat_trie_lock(struct squat_trie *trie, int lock_type, static int squat_trie_lock(struct squat_trie *trie, int lock_type,
struct file_lock **file_lock_r, struct file_lock **file_lock_r,
struct dotlock **dotlock_r) struct dotlock **dotlock_r)
{ {
const char *error;
int ret; int ret;
i_assert(trie->fd != -1); i_assert(trie->fd != -1);
*file_lock_r = NULL; *file_lock_r = NULL;
*dotlock_r = NULL; *dotlock_r = NULL;
for (;;) { for (;;) {
if (trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) { if (trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
struct file_lock_settings lock_set = {
.lock_method = trie->lock_method,
};
ret = file_wait_lock(trie->fd, trie->path, lock_type, ret = file_wait_lock(trie->fd, trie->path, lock_type,
trie->lock_method, &lock_set, SQUAT_TRIE_LOCK_TIMEOUT,
SQUAT_TRIE_LOCK_TIMEOUT, file_lock_r, &error);
file_lock_r); if (ret < 0) {
i_error("squat trie %s: %s",
trie->path, error);
}
} else { } else {
ret = file_dotlock_create(&trie->dotlock_set, ret = file_dotlock_create(&trie->dotlock_set,
trie->path, 0, dotlock_r); trie->path, 0, dotlock_r);
} }
if (ret == 0) { if (ret == 0) {
i_error("squat trie %s: Locking timed out", trie->path); i_error("squat trie %s: Locking timed out", trie->path);
return 0; return 0;
} }
if (ret < 0) if (ret < 0)
return -1; return -1;
skipping to change at line 1613 skipping to change at line 1620
&ctx->file_lock, &ctx->dotlock) <= 0) &ctx->file_lock, &ctx->dotlock) <= 0)
return -1; return -1;
return 0; return 0;
} }
static int squat_trie_write(struct squat_trie_build_context *ctx) static int squat_trie_write(struct squat_trie_build_context *ctx)
{ {
struct squat_trie *trie = ctx->trie; struct squat_trie *trie = ctx->trie;
struct file_lock *file_lock = NULL; struct file_lock *file_lock = NULL;
struct ostream *output; struct ostream *output;
const char *path; const char *path, *error;
int fd = -1, ret = 0; int fd = -1, ret = 0;
if ((trie->hdr.used_file_size > sizeof(trie->hdr) && if ((trie->hdr.used_file_size > sizeof(trie->hdr) &&
trie->unmapped_child_count < trie->hdr.node_count/4) || 1) { trie->unmapped_child_count < trie->hdr.node_count/4) || 1) {
/* we might as well recreate the file */ /* we might as well recreate the file */
ctx->compress_nodes = TRUE; ctx->compress_nodes = TRUE;
path = t_strconcat(trie->path, ".tmp", NULL); path = t_strconcat(trie->path, ".tmp", NULL);
fd = squat_trie_create_fd(trie, path, O_TRUNC); fd = squat_trie_create_fd(trie, path, O_TRUNC);
if (fd == -1) if (fd == -1)
return -1; return -1;
if (trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) { if (trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
ret = file_wait_lock(fd, path, F_WRLCK, struct file_lock_settings lock_set = {
trie->lock_method, .lock_method = trie->lock_method,
};
ret = file_wait_lock(fd, path, F_WRLCK, &lock_set,
SQUAT_TRIE_LOCK_TIMEOUT, SQUAT_TRIE_LOCK_TIMEOUT,
&file_lock); &file_lock, &error);
if (ret <= 0) { if (ret <= 0) {
if (ret == 0) { i_error("file_wait_lock(%s) failed: %s",
i_error("file_wait_lock(%s) failed: %m", path, error);
path);
}
i_close_fd(&fd); i_close_fd(&fd);
return -1; return -1;
} }
} }
output = o_stream_create_fd(fd, 0); output = o_stream_create_fd(fd, 0);
o_stream_cork(output); o_stream_cork(output);
o_stream_nsend(output, &trie->hdr, sizeof(trie->hdr)); o_stream_nsend(output, &trie->hdr, sizeof(trie->hdr));
} else { } else {
/* we need to lock only while header is being written */ /* we need to lock only while header is being written */
 End of changes. 7 change blocks. 
11 lines changed or deleted 18 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)