From: Timo Sirainen Date: Sun, 4 Apr 2010 20:01:23 +0000 (+0300) Subject: sdbox: Avoid logging multiple adjacent "Invalid dbox header size" errors. X-Git-Tag: 2.0.beta5~250 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4b2a4c8c762e3eaddf7fd2abfe7d4cca6e5e3fd8;p=thirdparty%2Fdovecot%2Fcore.git sdbox: Avoid logging multiple adjacent "Invalid dbox header size" errors. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.c b/src/lib-storage/index/dbox-single/sdbox-storage.c index d0cfeb1964..f315e63180 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.c +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c @@ -64,7 +64,7 @@ sdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list, } int sdbox_read_header(struct sdbox_mailbox *mbox, - struct sdbox_index_header *hdr) + struct sdbox_index_header *hdr, bool log_error) { const void *data; size_t data_size; @@ -73,9 +73,12 @@ int sdbox_read_header(struct sdbox_mailbox *mbox, &data, &data_size); if (data_size < SDBOX_INDEX_HEADER_MIN_SIZE && (!mbox->creating || data_size != 0)) { - mail_storage_set_critical(&mbox->storage->storage.storage, - "dbox %s: Invalid dbox header size", - mbox->box.path); + if (log_error) { + mail_storage_set_critical( + &mbox->storage->storage.storage, + "dbox %s: Invalid dbox header size", + mbox->box.path); + } return -1; } memset(hdr, 0, sizeof(*hdr)); @@ -89,7 +92,7 @@ void sdbox_update_header(struct sdbox_mailbox *mbox, { struct sdbox_index_header hdr, new_hdr; - if (sdbox_read_header(mbox, &hdr) < 0) + if (sdbox_read_header(mbox, &hdr, TRUE) < 0) memset(&hdr, 0, sizeof(hdr)); new_hdr = hdr; @@ -176,13 +179,13 @@ sdbox_mailbox_get_guid(struct mailbox *box, uint8_t guid[MAIL_GUID_128_SIZE]) struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box; struct sdbox_index_header hdr; - if (sdbox_read_header(mbox, &hdr) < 0) + if (sdbox_read_header(mbox, &hdr, TRUE) < 0) memset(&hdr, 0, sizeof(hdr)); if (mail_guid_128_is_empty(hdr.mailbox_guid)) { /* regenerate it */ if (sdbox_write_index_header(box, NULL) < 0 || - sdbox_read_header(mbox, &hdr) < 0) + sdbox_read_header(mbox, &hdr, TRUE) < 0) return -1; } memcpy(guid, hdr.mailbox_guid, MAIL_GUID_128_SIZE); diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.h b/src/lib-storage/index/dbox-single/sdbox-storage.h index 1728a31751..df1052d5d8 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.h +++ b/src/lib-storage/index/dbox-single/sdbox-storage.h @@ -40,7 +40,7 @@ int sdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r, uint32_t dbox_get_uidvalidity_next(struct mailbox_list *list); int sdbox_read_header(struct sdbox_mailbox *mbox, - struct sdbox_index_header *hdr); + struct sdbox_index_header *hdr, bool log_error); void sdbox_update_header(struct sdbox_mailbox *mbox, struct mail_index_transaction *trans, const struct mailbox_update *update); diff --git a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c index 3014fca957..416df21441 100644 --- a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c +++ b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c @@ -130,7 +130,7 @@ static void sdbox_sync_update_header(struct dbox_sync_rebuild_context *ctx) struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->box; struct sdbox_index_header hdr; - if (sdbox_read_header(mbox, &hdr) < 0) + if (sdbox_read_header(mbox, &hdr, FALSE) < 0) memset(&hdr, 0, sizeof(hdr)); if (!mail_guid_128_is_empty(hdr.mailbox_guid)) mail_generate_guid_128(hdr.mailbox_guid); diff --git a/src/lib-storage/index/dbox-single/sdbox-sync.c b/src/lib-storage/index/dbox-single/sdbox-sync.c index 3886debd7c..1e698517bb 100644 --- a/src/lib-storage/index/dbox-single/sdbox-sync.c +++ b/src/lib-storage/index/dbox-single/sdbox-sync.c @@ -142,21 +142,22 @@ static int sdbox_sync_index(struct sdbox_sync_context *ctx) return ret; } -static int sdbox_refresh_header(struct sdbox_mailbox *mbox, bool retry) +static int +sdbox_refresh_header(struct sdbox_mailbox *mbox, bool retry, bool log_error) { struct mail_index_view *view; struct sdbox_index_header hdr; int ret; view = mail_index_view_open(mbox->box.index); - ret = sdbox_read_header(mbox, &hdr); + ret = sdbox_read_header(mbox, &hdr, log_error); mail_index_view_close(&view); if (ret == 0) { ret = mbox->sync_rebuild ? -1 : 0; } else if (retry) { (void)mail_index_refresh(mbox->box.index); - return sdbox_refresh_header(mbox, FALSE); + return sdbox_refresh_header(mbox, FALSE, log_error); } return ret; } @@ -171,7 +172,7 @@ int sdbox_sync_begin(struct sdbox_mailbox *mbox, enum sdbox_sync_flags flags, int ret; bool rebuild; - rebuild = sdbox_refresh_header(mbox, TRUE) < 0 || + rebuild = sdbox_refresh_header(mbox, TRUE, FALSE) < 0 || (flags & SDBOX_SYNC_FLAG_FORCE_REBUILD) != 0; ctx = i_new(struct sdbox_sync_context, 1); @@ -199,8 +200,8 @@ int sdbox_sync_begin(struct sdbox_mailbox *mbox, enum sdbox_sync_flags flags, return ret; } - /* now that we're locked, check again if we want to rebuild */ - if (sdbox_refresh_header(mbox, FALSE) < 0) + /* now that we're locked, check again if we want to rebuild. */ + if (sdbox_refresh_header(mbox, FALSE, TRUE) < 0) ret = 0; else { if ((ret = sdbox_sync_index(ctx)) > 0)