From b00e7d56600ef977a231f805309be4729d4429a9 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 3 Feb 2021 17:18:09 +0200 Subject: [PATCH] mbox: Add mbox_[io]stream_set_syscall_error() This allows logging the iostream-specific error rather than the more generic errno. --- src/lib-storage/index/mbox/mbox-storage.c | 30 ++++++++++++++++++++--- src/lib-storage/index/mbox/mbox-storage.h | 6 +++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index 6721020a30..2e8eae4b70 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -3,6 +3,7 @@ #include "lib.h" #include "ioloop.h" #include "istream.h" +#include "ostream.h" #include "restrict-access.h" #include "master-service.h" #include "mailbox-list-private.h" @@ -73,7 +74,9 @@ static struct event_category event_category_mbox = { static MODULE_CONTEXT_DEFINE_INIT(mbox_mailbox_list_module, &mailbox_list_module_register); -void mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function) +static void +mbox_set_syscall_error_str(struct mbox_mailbox *mbox, const char *function, + const char *error) { i_assert(function != NULL); @@ -83,11 +86,32 @@ void mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function) } else { const char *toobig_error = errno != EFBIG ? "" : " (process was started with ulimit -f limit)"; - mailbox_set_critical(&mbox->box, - "%s failed with mbox: %m%s", function, toobig_error); + mailbox_set_critical(&mbox->box, "%s failed with mbox: %s%s", + function, error, toobig_error); } } +void mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function) +{ + mbox_set_syscall_error_str(mbox, function, strerror(errno)); +} + +void mbox_istream_set_syscall_error(struct mbox_mailbox *mbox, + struct istream *input, + const char *function) +{ + errno = input->stream_errno; + mbox_set_syscall_error_str(mbox, function, i_stream_get_error(input)); +} + +void mbox_ostream_set_syscall_error(struct mbox_mailbox *mbox, + struct ostream *output, + const char *function) +{ + errno = output->stream_errno; + mbox_set_syscall_error_str(mbox, function, o_stream_get_error(output)); +} + static int mbox_list_get_path(struct mailbox_list *list, const char *name, enum mailbox_list_path_type type, const char **path_r) diff --git a/src/lib-storage/index/mbox/mbox-storage.h b/src/lib-storage/index/mbox/mbox-storage.h index a64bb0f9fb..e35a7956e4 100644 --- a/src/lib-storage/index/mbox/mbox-storage.h +++ b/src/lib-storage/index/mbox/mbox-storage.h @@ -88,6 +88,12 @@ extern const char *mbox_hide_headers[], *mbox_save_drop_headers[]; extern unsigned int mbox_hide_headers_count, mbox_save_drop_headers_count; void mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function); +void mbox_istream_set_syscall_error(struct mbox_mailbox *mbox, + struct istream *input, + const char *function); +void mbox_ostream_set_syscall_error(struct mbox_mailbox *mbox, + struct ostream *output, + const char *function); struct mailbox_sync_context * mbox_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags); -- 2.47.3