]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-login: Add login_server_settings.update_proctitle
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 24 Mar 2023 01:26:11 +0000 (03:26 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Sun, 14 May 2023 17:52:36 +0000 (17:52 +0000)
Update the current login state in process title when enabled.

src/lib-master/master-login.c
src/lib-master/master-login.h

index b5d76ff210215341e24114131681f7890c9cdaa6..a26af403c76e120b45709e1a09610d1f0719d256 100644 (file)
@@ -8,6 +8,7 @@
 #include "str.h"
 #include "strescape.h"
 #include "time-util.h"
+#include "process-title.h"
 #include "master-service-private.h"
 #include "master-login.h"
 #include "master-login-auth.h"
@@ -55,12 +56,28 @@ struct master_login {
        char *postlogin_socket_path;
        unsigned int postlogin_timeout_secs;
 
+       bool update_proctitle:1;
        bool stopping:1;
 };
 
 static void master_login_conn_close(struct master_login_connection *conn);
 static void master_login_conn_unref(struct master_login_connection **_conn);
 
+static void login_server_proctitle_refresh(struct master_login *login)
+{
+       /* This function assumes that client_limit=1. With a higher limit
+          it just returns the first client's state, which isn't too bad
+          either. */
+       if (login->conns == NULL)
+               process_title_set("[idling]");
+       else if (login->conns->clients == NULL)
+               process_title_set("[waiting on client]");
+       else if (login->conns->clients->postlogin_client == NULL)
+               process_title_set("[auth lookup]");
+       else
+               process_title_set("[post-login script]");
+}
+
 struct master_login *
 master_login_init(struct master_service *service,
                  const struct master_login_settings *set)
@@ -78,6 +95,7 @@ master_login_init(struct master_service *service,
                                             set->request_auth_token);
        login->postlogin_socket_path = i_strdup(set->postlogin_socket_path);
        login->postlogin_timeout_secs = set->postlogin_timeout_secs;
+       login->update_proctitle = set->update_proctitle;
 
        i_assert(service->login == NULL);
        service->login = login;
@@ -356,6 +374,9 @@ static int master_login_postlogin(struct master_login_client *client,
        int fd;
        ssize_t ret;
 
+       if (login->update_proctitle)
+               process_title_set("[post-login script]");
+
        fd = net_connect_unix_with_retries(socket_path, 1000);
        if (fd == -1) {
                conn_error(client->conn, "net_connect_unix(%s) failed: %m%s",
@@ -399,6 +420,8 @@ static int master_login_postlogin(struct master_login_client *client,
 
        i_assert(client->postlogin_client == NULL);
        client->postlogin_client = pl;
+
+       login_server_proctitle_refresh(login);
        return 0;
 }
 
@@ -504,6 +527,7 @@ static void master_login_conn_input(struct master_login_connection *conn)
        memcpy(client->data, data+i, req.data_size);
        conn->refcount++;
        DLLIST_PREPEND(&conn->clients, client);
+       login_server_proctitle_refresh(login);
 
        master_login_auth_request(login->auth, &req,
                                  master_login_auth_callback, client);
@@ -523,6 +547,7 @@ void master_login_add(struct master_login *login, int fd)
        o_stream_set_no_error_handling(conn->output, TRUE);
 
        DLLIST_PREPEND(&login->conns, conn);
+       login_server_proctitle_refresh(login);
 
        /* NOTE: currently there's a separate connection for each request. */
 }
@@ -554,6 +579,7 @@ static void master_login_conn_unref(struct master_login_connection **_conn)
        o_stream_unref(&conn->output);
 
        DLLIST_REMOVE(&conn->login->conns, conn);
+       login_server_proctitle_refresh(conn->login);
 
        if (!conn->login_success)
                master_service_client_connection_destroyed(conn->login->service);
index 7029aa97f016071de5f6e381c3e446ba49e284fb..cb85d08683d2d66588cec85b390dfeb8c8ca19c0 100644 (file)
@@ -36,6 +36,7 @@ struct master_login_settings {
        master_login_callback_t *callback;
        master_login_failure_callback_t *failure_callback;
 
+       bool update_proctitle:1;
        bool request_auth_token:1;
 };