From: Stephan Bosch Date: Wed, 27 Feb 2019 02:16:57 +0000 (+0100) Subject: lib: connection - Add a unique numeric ID to the connection. X-Git-Tag: 2.3.9~738 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7c57fd29f72d19aaa34513fcd55b09cee26b903;p=thirdparty%2Fdovecot%2Fcore.git lib: connection - Add a unique numeric ID to the connection. It is incremented for each created connection. The IDs are specific to the connection list. --- diff --git a/src/lib/connection.c b/src/lib/connection.c index 693210fde9..e6b3465b52 100644 --- a/src/lib/connection.c +++ b/src/lib/connection.c @@ -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; diff --git a/src/lib/connection.h b/src/lib/connection.h index 7de43f9f6c..2c26ec2c1f 100644 --- a/src/lib/connection.h +++ b/src/lib/connection.h @@ -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; };