From: Timo Sirainen Date: Tue, 28 Sep 2010 15:29:33 +0000 (+0100) Subject: lib-index: Try to keep writing to latest mailbox log. X-Git-Tag: 2.0.5~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a68b403f982d0f1b2d628ea826ea5385771a787;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/lib-index/mailbox-log.c b/src/lib-index/mailbox-log.c index 16befda47a..7dfb3c1b95 100644 --- a/src/lib-index/mailbox-log.c +++ b/src/lib-index/mailbox-log.c @@ -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 @@ static int mailbox_log_open(struct mailbox_log *log) { 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 @@ int mailbox_log_append(struct mailbox_log *log, /* 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