]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add mailbox_set_reason()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 1 Apr 2017 18:16:37 +0000 (21:16 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 3 Apr 2017 11:00:04 +0000 (14:00 +0300)
Use it to log a debug message when mailbox is being opened.

src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c
src/lib-storage/mail-storage.h

index 940569c8beb59e742d0697081c13aa08b139c725..f2bdb70754ee1e3d1bdaf277146de08d1f841bc4 100644 (file)
@@ -346,6 +346,8 @@ struct mailbox {
        /* Filled lazily when mailbox is opened, use mailbox_get_index_path()
           to access it */
        const char *_index_path;
+       /* Reason for why mailbox is being accessed or NULL if unknown. */
+       const char *reason;
 
        /* default vfuncs for new struct mails. */
        const struct mail_vfuncs *mail_vfuncs;
index 080018c42d09d5d17dc78e9032fc3f2386c6d120..03eafb23caab250003d8605bb3892003a8ba4955 100644 (file)
@@ -819,6 +819,13 @@ struct mailbox *mailbox_alloc_guid(struct mailbox_list *list,
        return box;
 }
 
+void mailbox_set_reason(struct mailbox *box, const char *reason)
+{
+       i_assert(reason != NULL);
+
+       box->reason = p_strdup(box->pool, reason);
+}
+
 static bool mailbox_is_autocreated(struct mailbox *box)
 {
        if (box->inbox_user)
@@ -1125,6 +1132,12 @@ mailbox_open_full(struct mailbox *box, struct istream *input)
 
        if (box->opened)
                return 0;
+
+       if (box->storage->set->mail_debug && box->reason != NULL) {
+               i_debug("%s: Mailbox opened because: %s",
+                       box->vname, box->reason);
+       }
+
        switch (box->open_error) {
        case 0:
                break;
index 3dc77dd449111b1c04ec447435cc62746e549dbe..99353699975966243df7d67cbc61dd1c42f2f09f 100644 (file)
@@ -507,6 +507,9 @@ struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *vname,
 struct mailbox *mailbox_alloc_guid(struct mailbox_list *list,
                                   const guid_128_t guid,
                                   enum mailbox_flags flags);
+/* Set a human-readable reason for why this mailbox is being accessed.
+   This is used for logging purposes. */
+void mailbox_set_reason(struct mailbox *box, const char *reason);
 /* Get mailbox existence state. If auto_boxes=FALSE, return
    MAILBOX_EXISTENCE_NONE for autocreated mailboxes that haven't been
    physically created yet */