]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: If verbose_proctitle=yes, update the process state in the title.
authorTimo Sirainen <tss@iki.fi>
Tue, 5 Feb 2013 14:48:29 +0000 (16:48 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 5 Feb 2013 14:48:29 +0000 (16:48 +0200)
src/lmtp/client.c
src/lmtp/client.h
src/lmtp/commands.c

index 205a740103b4da394dfd441a74c2dce602c5e0ec..d5c1c6be3ace42d1a3bb33114ecfee2d63699355 100644 (file)
@@ -8,6 +8,7 @@
 #include "istream.h"
 #include "ostream.h"
 #include "hostpid.h"
+#include "process-title.h"
 #include "var-expand.h"
 #include "settings-parser.h"
 #include "master-service.h"
 static struct client *clients = NULL;
 unsigned int clients_count = 0;
 
+void client_state_set(struct client *client, const char *name)
+{
+       client->state.name = name;
+
+       if (!client->service_set->verbose_proctitle)
+               return;
+       if (clients_count == 0)
+               process_title_set("[idling]");
+       else if (clients_count > 1)
+               process_title_set(t_strdup_printf("[%u clients]", clients_count));
+       else
+               process_title_set(t_strdup_printf("[%s]", client->state.name));
+}
+
 static void client_idle_timeout(struct client *client)
 {
        client_destroy(client,
@@ -156,6 +171,7 @@ static void client_read_settings(struct client *client)
        lmtp_settings_dup(set_parser, client->pool, &lmtp_set, &lda_set);
        settings_var_expand(&lmtp_setting_parser_info, lmtp_set, client->pool,
                mail_storage_service_get_var_expand_table(storage_service, &input));
+       client->service_set = master_service_settings_get(master_service);
        client->lmtp_set = lmtp_set;
        client->set = lda_set;
 }
@@ -219,7 +235,6 @@ struct client *client_create(int fd_in, int fd_out,
        client_io_reset(client);
        client->state_pool = pool_alloconly_create("client state", 4096);
        client->state.mail_data_fd = -1;
-       client->state.name = "banner";
        client_read_settings(client);
        client_raw_user_create(client);
        client_generate_session_id(client);
@@ -229,6 +244,7 @@ struct client *client_create(int fd_in, int fd_out,
        DLLIST_PREPEND(&clients, client);
        clients_count++;
 
+       client_state_set(client, "banner");
        client_send_line(client, "220 %s %s", client->my_domain,
                         client->lmtp_set->login_greeting);
        i_info("Connect from %s", client_remote_id(client));
@@ -243,6 +259,8 @@ void client_destroy(struct client *client, const char *prefix,
        clients_count--;
        DLLIST_REMOVE(&clients, client);
 
+       client_state_set(client, "destroyed");
+
        if (client->raw_mail_user != NULL)
                mail_user_unref(&client->raw_mail_user);
        if (client->proxy != NULL)
@@ -326,7 +344,7 @@ void client_state_reset(struct client *client)
        client->state.mail_data_fd = -1;
 
        client_generate_session_id(client);
-       client->state.name = "reset";
+       client_state_set(client, "reset");
 }
 
 void client_send_line(struct client *client, const char *fmt, ...)
index e7b7ce779608e6cc83b0abfd5827afaa55a90cbd..70f396c7be79f5ba3a40b85df3c32972c5821ae3 100644 (file)
@@ -43,6 +43,7 @@ struct client {
        const struct setting_parser_info *user_set_info;
        const struct lda_settings *set;
        const struct lmtp_settings *lmtp_set;
+       const struct master_service_settings *service_set;
        int fd_in, fd_out;
        struct io *io;
        struct istream *input;
@@ -76,6 +77,7 @@ void client_disconnect(struct client *client, const char *prefix,
                       const char *reason);
 void client_io_reset(struct client *client);
 void client_state_reset(struct client *client);
+void client_state_set(struct client *client, const char *name);
 
 void client_input_handle(struct client *client);
 int client_input_read(struct client *client);
index d7c53c41a4d3d841db8fc1721255a358ea8838c1..307a5395617619c41f7197f03d84c7d7ee3dcc82 100644 (file)
@@ -74,7 +74,7 @@ int cmd_lhlo(struct client *client, const char *args)
 
        i_free(client->lhlo);
        client->lhlo = i_strdup(str_c(domain));
-       client->state.name = "LHLO";
+       client_state_set(client, "LHLO");
        return 0;
 }
 
@@ -143,7 +143,7 @@ int cmd_mail(struct client *client, const char *args)
        client->state.mail_from = p_strdup(client->state_pool, addr);
        p_array_init(&client->state.rcpt_to, client->state_pool, 64);
        client_send_line(client, "250 2.1.0 OK");
-       client->state.name = "MAIL FROM";
+       client_state_set(client, "MAIL FROM");
        return 0;
 }
 
@@ -488,7 +488,7 @@ int cmd_rcpt(struct client *client, const char *args)
        const char *error = NULL;
        int ret = 0;
 
-       client->state.name = "RCPT TO";
+       client_state_set(client, "RCPT TO");
 
        if (client->state.mail_from == NULL) {
                client_send_line(client, "503 5.5.1 MAIL needed first");
@@ -1014,7 +1014,7 @@ int cmd_data(struct client *client, const char *args ATTR_UNUSED)
        client_send_line(client, "354 OK");
 
        io_remove(&client->io);
-       client->state.name = "DATA";
+       client_state_set(client, "DATA");
        client->io = io_add(client->fd_in, IO_READ, client_input_data, client);
        client_input_data_handle(client);
        return -1;