]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap, pop3: Try to use the correct log prefix when service_count!=1.
authorTimo Sirainen <tss@iki.fi>
Fri, 3 Dec 2010 05:43:16 +0000 (05:43 +0000)
committerTimo Sirainen <tss@iki.fi>
Fri, 3 Dec 2010 05:43:16 +0000 (05:43 +0000)
src/imap/cmd-append.c
src/imap/cmd-idle.c
src/imap/imap-client.c
src/imap/imap-client.h
src/imap/imap-search.c
src/pop3/pop3-client.c

index 7e6b9a1ba8bd94edaa6f96a2afa4a33e183c11c8..13117bd374f612a938be05b9fe702d219cd8f384 100644 (file)
@@ -51,6 +51,7 @@ static void client_input_append(struct client_command_context *cmd)
        client->last_input = ioloop_time;
        timeout_reset(client->to_idle);
 
+       client_log_start(client);
        switch (i_stream_read(client->input)) {
        case -1:
                /* disconnected */
@@ -76,6 +77,7 @@ static void client_input_append(struct client_command_context *cmd)
                client_send_command_error(cmd, "Too long argument.");
                cmd->param_error = TRUE;
                client_command_free(&cmd);
+               client_log_stop();
                return;
        }
 
@@ -92,6 +94,7 @@ static void client_input_append(struct client_command_context *cmd)
                client_destroy(client, NULL);
        else
                client_continue_pending_input(client);
+       client_log_stop();
 }
 
 /* Returns -1 = error, 0 = need more data, 1 = successful. flags and
index 3ca259481e85761e87b8cd8ef7c263785b2b5751..a2baed422bb5964e03199f0bc26bd34654d40fe1 100644 (file)
@@ -82,6 +82,7 @@ static void idle_client_input_more(struct cmd_idle_context *ctx)
                return;
        }
 
+       client_log_start(client);
        while ((line = i_stream_next_line(client->input)) != NULL) {
                if (client->input_skip_line)
                        client->input_skip_line = FALSE;
@@ -92,6 +93,7 @@ static void idle_client_input_more(struct cmd_idle_context *ctx)
                        break;
                }
        }
+       client_log_stop();
 }
 
 static void idle_client_input(struct cmd_idle_context *ctx)
@@ -144,9 +146,11 @@ static void idle_callback(struct mailbox *box, struct cmd_idle_context *ctx)
                ctx->sync_pending = TRUE;
        else {
                ctx->manual_cork = TRUE;
+               client_log_start(client);
                idle_sync_now(box, ctx);
                if (client->disconnected)
                        client_destroy(client, NULL);
+               client_log_stop();
        }
 }
 
index 7305d295aaaccbc436bd3476fc7936b78866280c..48b31aca9ae5f84e3d123b7963c8acd4b9b1d5a0 100644 (file)
@@ -25,6 +25,8 @@ struct imap_module_register imap_module_register = { 0 };
 struct client *imap_clients = NULL;
 unsigned int imap_client_count = 0;
 
+static struct mail_user *log_prefix_user = NULL;
+
 static void client_idle_timeout(struct client *client)
 {
        if (client->output_lock == NULL)
@@ -95,6 +97,7 @@ struct client *client_create(int fd_in, int fd_out, struct mail_user *user,
        if (hook_client_created != NULL)
                hook_client_created(&client);
 
+       log_prefix_user = client->user;
        imap_refresh_proctitle();
        return client;
 }
@@ -132,6 +135,27 @@ void client_command_cancel(struct client_command_context **_cmd)
        }
 }
 
+void client_log_start(struct client *client)
+{
+       if (log_prefix_user != NULL &&
+           log_prefix_user == client->user)
+               return;
+
+       mail_user_set_log_prefix(client->user);
+       log_prefix_user = client->user;
+}
+
+void client_log_stop(void)
+{
+       if (imap_client_count == 1) {
+               mail_user_set_log_prefix(imap_clients->user);
+               log_prefix_user = imap_clients->user;
+       } else {
+               master_service_init_log(master_service, "imap: ");
+               log_prefix_user = NULL;
+       }
+}
+
 static const char *client_stats(struct client *client)
 {
        static struct var_expand_table static_tab[] = {
@@ -169,6 +193,7 @@ void client_destroy(struct client *client, const char *reason)
        i_assert(!client->destroyed);
        client->destroyed = TRUE;
 
+       client_log_start(client);
        if (!client->disconnected) {
                client->disconnected = TRUE;
                if (reason == NULL)
@@ -231,6 +256,7 @@ void client_destroy(struct client *client, const char *reason)
        mail_storage_service_user_free(&client->service_user);
        pool_unref(&client->pool);
 
+       client_log_stop();
        master_service_client_connection_destroyed(master_service);
        imap_refresh_proctitle();
 }
@@ -247,6 +273,7 @@ void client_disconnect(struct client *client, const char *reason)
        if (client->disconnected)
                return;
 
+       client_log_start(client);
        i_info("Disconnected: %s %s", reason, client_stats(client));
        client->disconnected = TRUE;
        (void)o_stream_flush(client->output);
@@ -788,6 +815,8 @@ void client_input(struct client *client)
 
        i_assert(client->io != NULL);
 
+       client_log_start(client);
+
        client->last_input = ioloop_time;
        timeout_reset(client->to_idle);
 
@@ -819,6 +848,7 @@ void client_input(struct client *client)
                client_destroy(client, NULL);
        else
                client_continue_pending_input(client);
+       client_log_stop();
 }
 
 static void client_output_cmd(struct client_command_context *cmd)
@@ -843,6 +873,7 @@ int client_output(struct client *client)
 
        i_assert(!client->destroyed);
 
+       client_log_start(client);
        client->last_output = ioloop_time;
        timeout_reset(client->to_idle);
        if (client->to_idle_output != NULL)
@@ -887,6 +918,7 @@ int client_output(struct client *client)
                client_destroy(client, NULL);
        else
                client_continue_pending_input(client);
+       client_log_stop();
        return ret;
 }
 
index 57fc7470556f92a9a3894ce199dc7b500c0c970d..af49e0a554937733429bd3851393f03fcb0a9c60 100644 (file)
@@ -209,6 +209,9 @@ void client_input(struct client *client);
 bool client_handle_input(struct client *client);
 int client_output(struct client *client);
 
+void client_log_start(struct client *client);
+void client_log_stop(void);
+
 void clients_destroy_all(void);
 
 #endif
index 6c6b842fe50288d640dd9730fa0e7a99a9996e10..9aff17b029e70e9b1756669ee6c2a2ba9912a4cc 100644 (file)
@@ -425,6 +425,7 @@ static void cmd_search_more_callback(struct client_command_context *cmd)
        struct client *client = cmd->client;
        bool finished;
 
+       client_log_start(client);
        o_stream_cork(client->output);
        finished = cmd_search_more(cmd);
        o_stream_uncork(client->output);
@@ -439,6 +440,7 @@ static void cmd_search_more_callback(struct client_command_context *cmd)
                client_destroy(client, NULL);
        else
                client_continue_pending_input(client);
+       client_log_stop();
 }
 
 int cmd_search_parse_return_if_found(struct imap_search_context *ctx,
index 693f86173f9344d7e15738b522bf770ae94cfbef..4265cd46426052a4c30abdcf2117218bfbec4348 100644 (file)
 struct client *pop3_clients;
 unsigned int pop3_client_count;
 
+static struct mail_user *log_prefix_user = NULL;
+
 static void client_input(struct client *client);
 static int client_output(struct client *client);
 
+static void client_log_start(struct client *client)
+{
+       if (log_prefix_user != NULL &&
+           log_prefix_user == client->user)
+               return;
+
+       mail_user_set_log_prefix(client->user);
+       log_prefix_user = client->user;
+}
+
+static void client_log_stop(void)
+{
+       if (pop3_client_count == 1) {
+               mail_user_set_log_prefix(pop3_clients->user);
+               log_prefix_user = pop3_clients->user;
+       } else {
+               master_service_init_log(master_service, "pop3: ");
+               log_prefix_user = NULL;
+       }
+}
+
 static void client_commit_timeout(struct client *client)
 {
        if (client->cmd != NULL) {
@@ -330,6 +353,7 @@ struct client *client_create(int fd_in, int fd_out, struct mail_user *user,
        if (hook_client_created != NULL)
                hook_client_created(&client);
 
+       log_prefix_user = client->user;
        pop3_refresh_proctitle();
        return client;
 }
@@ -428,6 +452,7 @@ void client_destroy(struct client *client, const char *reason)
        if (client->seen_change_count > 0)
                client_update_mails(client);
 
+       client_log_start(client);
        if (!client->disconnected) {
                if (reason == NULL)
                        reason = client_get_disconnect_reason(client);
@@ -480,6 +505,7 @@ void client_destroy(struct client *client, const char *reason)
        mail_storage_service_user_free(&client->service_user);
        i_free(client);
 
+       client_log_stop();
        master_service_client_connection_destroyed(master_service);
        pop3_refresh_proctitle();
 }
@@ -624,6 +650,7 @@ static void client_input(struct client *client)
        if (client->to_commit != NULL)
                timeout_reset(client->to_commit);
 
+       client_log_start(client);
        switch (i_stream_read(client->input)) {
        case -1:
                /* disconnected */
@@ -637,10 +664,12 @@ static void client_input(struct client *client)
        }
 
        (void)client_handle_input(client);
+       client_log_stop();
 }
 
 static int client_output(struct client *client)
 {
+       client_log_start(client);
        o_stream_cork(client->output);
        if (o_stream_flush(client->output) < 0) {
                client_destroy(client, NULL);
@@ -654,6 +683,7 @@ static int client_output(struct client *client)
 
        if (client->cmd != NULL)
                client->cmd(client);
+       client_log_stop();
 
        if (client->cmd == NULL) {
                if (o_stream_get_buffer_used_size(client->output) <