From: Alan T. DeKok Date: Mon, 8 Nov 2021 16:53:36 +0000 (-0500) Subject: use static name with log_prefix and ID X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9aef76937061996c166f6a334eba757445f97a7;p=thirdparty%2Ffreeradius-server.git use static name with log_prefix and ID instead of re-converting them every time --- diff --git a/src/lib/server/connection.c b/src/lib/server/connection.c index 710cbff79aa..079a6f75bb3 100644 --- a/src/lib/server/connection.c +++ b/src/lib/server/connection.c @@ -22,8 +22,8 @@ * * @copyright 2017-2019 Arran Cudbard-Bell (a.cudbardb@freeradius.org) */ -#define LOG_PREFIX "%s - [%" PRIu64 "] " -#define LOG_PREFIX_ARGS conn->pub.log_prefix, conn->pub.id +#define LOG_PREFIX "%s " +#define LOG_PREFIX_ARGS conn->pub.name typedef struct fr_connection_s fr_connection_t; #define _CONNECTION_PRIVATE 1 @@ -1503,15 +1503,19 @@ fr_connection_t *fr_connection_alloc(TALLOC_CTX *ctx, fr_event_list_t *el, { size_t i; fr_connection_t *conn; + uint64_t id; fr_assert(el); conn = talloc(ctx, fr_connection_t); if (!conn) return NULL; talloc_set_destructor(conn, _connection_free); + + id = atomic_fetch_add_explicit(&connection_counter, 1, memory_order_relaxed); + *conn = (fr_connection_t){ .pub = { - .id = atomic_fetch_add_explicit(&connection_counter, 1, memory_order_relaxed), + .id = id, .state = FR_CONNECTION_STATE_HALTED, .el = el }, @@ -1523,7 +1527,7 @@ fr_connection_t *fr_connection_alloc(TALLOC_CTX *ctx, fr_event_list_t *el, .failed = funcs->failed, .shutdown = funcs->shutdown, .is_closed = true, /* Starts closed */ - .pub.log_prefix = talloc_typed_strdup(conn, log_prefix) + .pub.name = talloc_asprintf(conn, "%s - [%" PRIu64 "]", log_prefix, id) }; memcpy(&conn->uctx, &uctx, sizeof(conn->uctx)); diff --git a/src/lib/server/connection.h b/src/lib/server/connection.h index c88ca52b04e..0ae5055275b 100644 --- a/src/lib/server/connection.h +++ b/src/lib/server/connection.h @@ -65,12 +65,13 @@ typedef enum { * the connection API. */ struct fr_connection_pub_s { + char const * _CONST name; //!< Prefix to add to log messages. + fr_connection_state_t _CONST state; //!< Current connection state. fr_connection_state_t _CONST prev; //!< The previous state the connection was in. uint64_t _CONST id; //!< Unique identifier for the connection. void * _CONST h; //!< Connection handle fr_event_list_t * _CONST el; //!< Event list for timers and I/O events. - char const * _CONST log_prefix; //!< Prefix to add to log messages. uint64_t _CONST reconnected; //!< How many times we've attempted to establish or ///< re-establish this connection.