Mercurial > dovecot > core-2.2
changeset 12192:431dff6a6ae7
lib-index: Try to keep writing to latest mailbox log.
Fixes a problem where a long running session keeps writing to a rotate log
that has already been deleted.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 28 Sep 2010 16:29:33 +0100 |
parents | e5f0231b7a40 |
children | 65855df71cf4 |
files | src/lib-index/mailbox-log.c |
diffstat | 1 files changed, 9 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mailbox-log.c Tue Sep 28 16:05:40 2010 +0100 +++ b/src/lib-index/mailbox-log.c Tue Sep 28 16:29:33 2010 +0100 @@ -1,6 +1,7 @@ /* Copyright (c) 2009-2010 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "ioloop.h" #include "eacces-error.h" #include "mailbox-log.h" @@ -14,6 +15,7 @@ struct mailbox_log { char *filepath, *filepath2; int fd; + time_t open_timestamp; mode_t mode; gid_t gid; @@ -81,6 +83,7 @@ { mode_t old_mode; + log->open_timestamp = ioloop_time; log->fd = open(log->filepath, O_RDWR | O_APPEND); if (log->fd != -1) return 0; @@ -154,11 +157,12 @@ /* we don't have to be too strict about appending to the latest log file. the records' ordering doesn't matter and iteration goes - through both logs anyway. */ - if (log->fd == -1) { - if (mailbox_log_open(log) < 0) - return -1; - } + through both logs anyway. still, if there's a long running session + it shouldn't keep writing to a rotated log forever. */ + if (log->open_timestamp != ioloop_time) + mailbox_log_close(log); + if (mailbox_log_open(log) < 0) + return -1; /* We don't bother with locking, atomic appends will protect us. If they don't (NFS), the worst that can happen is that a few