]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm-server: Show incoming connection's IP and running command is process title.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 19 Oct 2016 18:49:30 +0000 (21:49 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 20 Oct 2016 20:04:40 +0000 (23:04 +0300)
src/doveadm/client-connection-http.c
src/doveadm/client-connection-private.h
src/doveadm/client-connection.c
src/doveadm/client-connection.h
src/doveadm/doveadm.h
src/doveadm/main.c

index 2e28f144d791fe68079431f1ad49756b5d79d235..ea82a84247adde1eb10aeecadd2ff70c395121ed 100644 (file)
@@ -354,7 +354,9 @@ doveadm_http_server_command_execute(struct client_connection_http *conn)
                i_info("Executing command '%s' as '%s'", cctx.cmd->name, user);
        else
                i_info("Executing command '%s'", cctx.cmd->name);
+       client_connection_set_proctitle(&conn->client, cctx.cmd->name);
        cctx.cmd->cmd(&cctx);
+       client_connection_set_proctitle(&conn->client, "");
 
        io_loop_set_current(prev_ioloop);
        lib_signals_reset_ioloop();
index 48a1c158dc716e72fdff35e76be49714f8574c9b..928158788e348ea7287a6dd8ac6c8d094a42a21b 100644 (file)
@@ -8,6 +8,9 @@ bool doveadm_client_is_allowed_command(const struct doveadm_settings *set,
 
 int client_connection_init(struct client_connection *conn, int fd);
 
+void client_connection_set_proctitle(struct client_connection *conn,
+                                    const char *text);
+
 void doveadm_http_server_init(void);
 void doveadm_http_server_deinit(void);
 
index 49ff3623df09d098509fb06e8ad7f6e8080c22bb..2719d57df6d34650c84253d9ed87aab575c6e15f 100644 (file)
@@ -7,6 +7,7 @@
 #include "istream.h"
 #include "ostream.h"
 #include "strescape.h"
+#include "process-title.h"
 #include "settings-parser.h"
 #include "iostream-ssl.h"
 #include "master-service.h"
@@ -327,10 +328,12 @@ static bool client_handle_command(struct client_connection *conn, char **args)
                return FALSE;
        }
 
+       client_connection_set_proctitle(conn, cmd_name);
        o_stream_cork(conn->output);
        if (doveadm_cmd_handle(conn, cmd_name, argc-2, (const char**)(args+2), &cctx) < 0)
                o_stream_nsend(conn->output, "\n-\n", 3);
        o_stream_uncork(conn->output);
+       client_connection_set_proctitle(conn, "");
 
        /* flush the output and possibly run next command */
        net_set_nonblock(conn->fd, FALSE);
@@ -548,11 +551,12 @@ client_connection_create(int fd, int listen_fd, bool ssl)
                return NULL;
         doveadm_print_init(DOVEADM_PRINT_TYPE_SERVER);
 
+       conn->name = p_strdup(pool, net_ip2addr(&conn->remote_ip));
        conn->io = io_add(fd, IO_READ, client_connection_input, conn);
        conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE);
        conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
-       i_stream_set_name(conn->input, net_ip2addr(&conn->remote_ip));
-       o_stream_set_name(conn->output, net_ip2addr(&conn->remote_ip));
+       i_stream_set_name(conn->input, conn->name);
+       o_stream_set_name(conn->output, conn->name);
        o_stream_set_no_error_handling(conn->output, TRUE);
 
        if (ssl) {
@@ -562,6 +566,7 @@ client_connection_create(int fd, int listen_fd, bool ssl)
                }
        }
        client_connection_send_auth_handshake(conn, listen_fd);
+       client_connection_set_proctitle(conn, "");
 
        doveadm_print_ostream = conn->output;
        return conn;
@@ -594,4 +599,22 @@ void client_connection_destroy(struct client_connection **_conn)
        doveadm_print_ostream = NULL;
        doveadm_client = NULL;
        master_service_client_connection_destroyed(master_service);
+
+       if (doveadm_verbose_proctitle)
+               process_title_set("[idling]");
+}
+
+void client_connection_set_proctitle(struct client_connection *conn,
+                                    const char *text)
+{
+       const char *str;
+
+       if (!doveadm_verbose_proctitle)
+               return;
+
+       if (text[0] == '\0')
+               str = t_strdup_printf("[%s]", conn->name);
+       else
+               str = t_strdup_printf("[%s %s]", conn->name, text);
+       process_title_set(str);
 }
index 1daf8fd7a86a8bad583b6824b3fce9299047daca..97e18711a812975a384e6ead60a74fcecd2da7f5 100644 (file)
@@ -7,6 +7,7 @@ struct client_connection {
        pool_t pool;
 
        int fd;
+       const char *name;
        struct io *io;
        struct istream *input;
        struct ostream *output;
index 12e6315305909e0eabeccd47cb6179676e907d79..726485c2aaa764ab5b575fec57003282f0c1653c 100644 (file)
@@ -11,6 +11,7 @@
 #define DOVEADM_EX_NOTFOUND EX_NOHOST
 #define DOVEADM_EX_NOTPOSSIBLE EX_DATAERR
 
+extern bool doveadm_verbose_proctitle;
 extern int doveadm_exit_code;
 
 void usage(void) ATTR_NORETURN;
index aca450dba561b98825af478f08a4171c70fe7573..a3719598532a080f8bf1ca0d008be8085b5db5f8 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "restrict-access.h"
+#include "process-title.h"
 #include "master-service.h"
 #include "master-service-settings.h"
 #include "settings-parser.h"
@@ -22,6 +23,7 @@ const struct doveadm_print_vfuncs *doveadm_print_vfuncs_all[] = {
 };
 
 struct client_connection *doveadm_client;
+bool doveadm_verbose_proctitle;
 int doveadm_exit_code = 0;
 
 static void doveadm_die(void)
@@ -70,6 +72,10 @@ static void main_init(void)
        doveadm_settings = settings_dup(&doveadm_setting_parser_info,
                                        doveadm_settings,
                                        pool_datastack_create());
+       doveadm_verbose_proctitle =
+               master_service_settings_get(master_service)->verbose_proctitle;
+       if (doveadm_verbose_proctitle)
+               process_title_set("[idling]");
 
        doveadm_http_server_init();
        doveadm_cmds_init();