From: Timo Sirainen Date: Mon, 17 Aug 2020 12:06:42 +0000 (+0300) Subject: imap: Add imap_client_unhibernated event X-Git-Tag: 2.3.13~360 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0ea836c9b0274de2e4f5732c4dd8bc6e80cc97e3;p=thirdparty%2Fdovecot%2Fcore.git imap: Add imap_client_unhibernated event --- diff --git a/src/imap/imap-master-client.c b/src/imap/imap-master-client.c index 9fe82c5b68..57bf1be43d 100644 --- a/src/imap/imap-master-client.c +++ b/src/imap/imap-master-client.c @@ -209,7 +209,7 @@ imap_master_client_input_args(struct connection *conn, const char *const *args, struct client *imap_client; struct mail_storage_service_input input; struct imap_master_input master_input; - const char *error; + const char *error, *reason; int ret; if (imap_master_client_parse_input(args, pool, &input, &master_input, @@ -243,30 +243,35 @@ imap_master_client_input_args(struct connection *conn, const char *const *args, } client->imap_client_created = TRUE; + struct event *event = event_create(imap_client->event); + event_set_name(event, "imap_client_unhibernated"); imap_client->state_import_bad_idle_done = master_input.state_import_bad_idle_done; imap_client->state_import_idle_continue = master_input.state_import_idle_continue; if (imap_client->state_import_bad_idle_done) { - e_debug(imap_client->event, - "imap-master: Unhibernated because IDLE was stopped with BAD command"); + reason = "IDLE was stopped with BAD command"; + event_add_str(event, "reason", "idle_bad_reply"); } else if (imap_client->state_import_idle_continue) { - e_debug(imap_client->event, - "imap-master: Unhibernated to send mailbox changes"); + reason = "mailbox changes need to be sent"; + event_add_str(event, "reason", "mailbox_changes"); } else { - e_debug(imap_client->event, - "imap-master: Unhibernated because IDLE was stopped with DONE"); + reason = "IDLE was stopped with DONE"; + event_add_str(event, "reason", "idle_done"); } /* Send a success notification before we start anything that lasts potentially a long time. imap-hibernate process is waiting for us - to answer. Even if we fail later, we log the error anyway. */ + to answer. Even if we fail later, we log the error anyway. From now + on it's our responsibility to also log the imap_client_unhibernated + event. */ o_stream_nsend_str(conn->output, "+\n"); (void)o_stream_flush(conn->output); if (client_create_finish(imap_client, &error) < 0) { - e_error(imap_client->event, "imap-master(%s): %s", - input.username, error); + event_add_str(event, "error", error); + e_error(event, "imap-master: %s", error); + event_unref(&event); client_destroy(imap_client, error); return -1; } @@ -280,9 +285,12 @@ imap_master_client_input_args(struct connection *conn, const char *const *args, !i_stream_add_data(imap_client->input, master_input.client_input->data, master_input.client_input->used)) { - e_error(imap_client->event, - "imap-master: Couldn't add %zu bytes to client's input stream", + error = t_strdup_printf( + "Couldn't add %zu bytes to client's input stream", master_input.client_input->used); + event_add_str(event, "error", error); + e_error(event, "imap-master: %s", error); + event_unref(&event); client_destroy(imap_client, "Client initialization failed"); return -1; } @@ -290,8 +298,10 @@ imap_master_client_input_args(struct connection *conn, const char *const *args, ret = imap_state_import_internal(imap_client, master_input.state->data, master_input.state->used, &error); if (ret <= 0) { - e_error(imap_client->event, - "imap-master: Failed to import client state: %s", error); + error = t_strdup_printf("Failed to import client state: %s", error); + event_add_str(event, "error", error); + e_error(event, "imap-master: %s", error); + event_unref(&event); client_destroy(imap_client, "Client state initialization failed"); return -1; } @@ -299,6 +309,9 @@ imap_master_client_input_args(struct connection *conn, const char *const *args, if (master_input.tag != NULL) imap_state_import_idle_cmd_tag(imap_client, master_input.tag); + e_debug(event, "imap-master: Unhibernated because %s", reason); + event_unref(&event); + /* make sure all pending input gets handled */ if (master_input.client_input->used > 0) { e_debug(imap_client->event,