Mercurial > dovecot > original-hg > dovecot-1.2
changeset 2171:d0f9f550e71f HEAD
don't crash if we wanted to lock mbox for reading but it also needs rewriting
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 19 Jun 2004 21:21:44 +0300 |
parents | fb785d235c43 |
children | cee8c4354b20 |
files | src/lib-storage/index/mbox/mbox-sync.c |
diffstat | 1 files changed, 11 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-sync.c Sat Jun 19 20:41:30 2004 +0300 +++ b/src/lib-storage/index/mbox/mbox-sync.c Sat Jun 19 21:21:44 2004 +0300 @@ -71,7 +71,13 @@ i_assert(lock_type != F_WRLCK || !ibox->mbox_readonly); - if (sync_ctx->lock_id != 0) { + if (sync_ctx->lock_id == 0 || sync_ctx->input == NULL) { + memset(&old_st, 0, sizeof(old_st)); + if (sync_ctx->lock_id != 0) { + (void)mbox_unlock(ibox, sync_ctx->lock_id); + sync_ctx->lock_id = 0; + } + } else { if (fstat(sync_ctx->fd, &old_st) < 0) { mbox_set_syscall_error(ibox, "stat()"); return -1; @@ -82,8 +88,6 @@ (void)mbox_unlock(ibox, sync_ctx->lock_id); sync_ctx->lock_id = 0; - } else { - memset(&old_st, 0, sizeof(old_st)); } if (mbox_lock(ibox, lock_type, &sync_ctx->lock_id) <= 0) @@ -1055,6 +1059,7 @@ sync_ctx.ibox = ibox; sync_ctx.from_line = str_new(default_pool, 256); sync_ctx.header = str_new(default_pool, 4096); + sync_ctx.lock_id = lock_id; sync_ctx.index_sync_ctx = index_sync_ctx; sync_ctx.sync_view = sync_view; @@ -1072,10 +1077,10 @@ (void)mbox_unlock(ibox, lock_id); lock_id = 0; } + if (mbox_sync_lock(&sync_ctx, lock_type) < 0) - return -1; - - if (mbox_sync_do(&sync_ctx) < 0) + ret = -1; + else if (mbox_sync_do(&sync_ctx) < 0) ret = -1; if (ret < 0)