]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mbox: Add mbox_[io]stream_set_syscall_error()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 3 Feb 2021 15:18:09 +0000 (17:18 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 17 Feb 2021 10:20:18 +0000 (10:20 +0000)
This allows logging the iostream-specific error rather than the more generic
errno.

src/lib-storage/index/mbox/mbox-storage.c
src/lib-storage/index/mbox/mbox-storage.h

index 6721020a30a87e1e4e571105ca2198f62726e6b2..2e8eae4b70d9121990a006a9cd9df7cdcd879ceb 100644 (file)
@@ -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)
index a64bb0f9fbb2c0ce23bc9e228395be613592d9fd..e35a7956e4872633e52b6fbbc61de6565572a286 100644 (file)
@@ -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);