From: Timo Sirainen Date: Wed, 19 Oct 2016 18:49:30 +0000 (+0300) Subject: doveadm-server: Show incoming connection's IP and running command is process title. X-Git-Tag: 2.2.26~81 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0718145c5340bd3441fff5f9af49669a018fd249;p=thirdparty%2Fdovecot%2Fcore.git doveadm-server: Show incoming connection's IP and running command is process title. --- diff --git a/src/doveadm/client-connection-http.c b/src/doveadm/client-connection-http.c index 2e28f144d7..ea82a84247 100644 --- a/src/doveadm/client-connection-http.c +++ b/src/doveadm/client-connection-http.c @@ -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(); diff --git a/src/doveadm/client-connection-private.h b/src/doveadm/client-connection-private.h index 48a1c158dc..928158788e 100644 --- a/src/doveadm/client-connection-private.h +++ b/src/doveadm/client-connection-private.h @@ -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); diff --git a/src/doveadm/client-connection.c b/src/doveadm/client-connection.c index 49ff3623df..2719d57df6 100644 --- a/src/doveadm/client-connection.c +++ b/src/doveadm/client-connection.c @@ -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); } diff --git a/src/doveadm/client-connection.h b/src/doveadm/client-connection.h index 1daf8fd7a8..97e18711a8 100644 --- a/src/doveadm/client-connection.h +++ b/src/doveadm/client-connection.h @@ -7,6 +7,7 @@ struct client_connection { pool_t pool; int fd; + const char *name; struct io *io; struct istream *input; struct ostream *output; diff --git a/src/doveadm/doveadm.h b/src/doveadm/doveadm.h index 12e6315305..726485c2aa 100644 --- a/src/doveadm/doveadm.h +++ b/src/doveadm/doveadm.h @@ -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; diff --git a/src/doveadm/main.c b/src/doveadm/main.c index aca450dba5..a371959853 100644 --- a/src/doveadm/main.c +++ b/src/doveadm/main.c @@ -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();