]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: connection - Add a unique numeric ID to the connection.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Wed, 27 Feb 2019 02:16:57 +0000 (03:16 +0100)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Fri, 1 Mar 2019 23:55:37 +0000 (00:55 +0100)
It is incremented for each created connection. The IDs are specific to the
connection list.

src/lib/connection.c
src/lib/connection.h

index 693210fde9449c398682d2b74788b9029b6dbdb2..e6b3465b525e45a46ed18e06b3bc7c096aa93724 100644 (file)
@@ -284,6 +284,11 @@ connection_update_label(struct connection *conn)
        }
        if (unix_socket && str_len(label) > 0)
                str_insert(label, 0, "unix:");
+       if (conn->list->set.log_connection_id) {
+               if (str_len(label) > 0)
+                       str_append_c(label, ' ');
+               str_printfa(label, "[%u]", conn->id);
+       }
 
        i_free(conn->label);
        conn->label = i_strdup(str_c(label));
@@ -414,6 +419,12 @@ static void
 connection_init_full(struct connection_list *list, struct connection *conn,
                     const char *name, int fd_in, int fd_out)
 {
+       if (conn->id == 0) {
+               if (list->id_counter == 0)
+                       list->id_counter++;
+               conn->id = list->id_counter++;
+       }
+
        conn->ioloop = current_ioloop;
        conn->fd_in = fd_in;
        conn->fd_out = fd_out;
index 7de43f9f6c683379947eebaafa454f9f661fea44..2c26ec2c1f4de8f49d932fc723a9c6823559b1d1 100644 (file)
@@ -97,6 +97,8 @@ struct connection_settings {
           to make the functionality identical with inet sockets, which may
           simplify the calling code. */
        bool delayed_unix_client_connected_callback;
+       /* Put the connection id in the log prefix */
+       bool log_connection_id;
        /* If connect() to UNIX socket fails with EAGAIN, retry for this many
           milliseconds before giving up (0 = try once) */
        unsigned int unix_client_connect_msecs;
@@ -111,6 +113,7 @@ struct connection {
        char *name;
        char *label;
        char *property_label;
+       unsigned int id;
 
        int fd_in, fd_out;
        struct ioloop *ioloop;
@@ -154,6 +157,8 @@ struct connection_list {
        struct connection *connections;
        unsigned int connections_count;
 
+       unsigned int id_counter;
+
        struct connection_settings set;
        struct connection_vfuncs v;
 };