Mercurial > dovecot > core-2.2
changeset 231:bbd248788571 HEAD
we shouldn't crash anymore when modify log gets full
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 15 Sep 2002 11:36:14 +0300 |
parents | fc1859e67253 |
children | 9277e893304e |
files | src/lib-index/mail-modifylog.c |
diffstat | 1 files changed, 22 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-modifylog.c Sun Sep 15 10:20:35 2002 +0300 +++ b/src/lib-index/mail-modifylog.c Sun Sep 15 11:36:14 2002 +0300 @@ -37,7 +37,7 @@ static const unsigned int no_expunges[] = { 0 }; static int modifylog_set_syscall_error(MailModifyLog *log, - const char *function) + const char *function) { i_assert(function != NULL); @@ -188,8 +188,17 @@ return TRUE; } -static int mail_modifylog_open_and_init_file(MailModifyLog *log, - const char *path) +static int modifylog_mark_full(MailModifyLog *log) +{ + log->header->sync_id = SYNC_ID_FULL; + + if (msync(log->mmap_base, sizeof(ModifyLogHeader), MS_SYNC) < 0) + return modifylog_set_syscall_error(log, "msync()"); + + return TRUE; +} + +static int modifylog_open_and_init_file(MailModifyLog *log, const char *path) { int fd, ret; @@ -209,11 +218,13 @@ } if (ret == 1 && mail_modifylog_init_fd(log, fd, path)) { - mail_modifylog_close(log); + if (log->fd == -1 || modifylog_mark_full(log)) { + mail_modifylog_close(log); - log->fd = fd; - log->filepath = i_strdup(path); - return TRUE; + log->fd = fd; + log->filepath = i_strdup(path); + return TRUE; + } } (void)close(fd); @@ -230,7 +241,7 @@ log = mail_modifylog_new(index); path = t_strconcat(log->index->filepath, ".log", NULL); - if (!mail_modifylog_open_and_init_file(log, path) || + if (!modifylog_open_and_init_file(log, path) || !mail_modifylog_wait_lock(log) || !mmap_update(log)) { /* fatal failure */ @@ -309,10 +320,10 @@ } /* try creating/reusing them */ - if (mail_modifylog_open_and_init_file(log, path1)) + if (modifylog_open_and_init_file(log, path1)) return TRUE; - if (mail_modifylog_open_and_init_file(log, path2)) + if (modifylog_open_and_init_file(log, path2)) return TRUE; /* maybe the file was just switched, check the logs again */ @@ -464,12 +475,7 @@ path = t_strconcat(log->index->filepath, log->second_log ? ".log" : ".log.2", NULL); - if (mail_modifylog_open_and_init_file(log, path)) { - /* FIXME: we want to update the _old_ file's header. - and this changes the new one. and it's already closed the - old one and mmap() is invalid, and we crash here.. */ - log->header->sync_id = SYNC_ID_FULL; - } + (void)modifylog_open_and_init_file(log, path); } int mail_modifylog_mark_synced(MailModifyLog *log)