]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use static name with log_prefix and ID
authorAlan T. DeKok <aland@freeradius.org>
Mon, 8 Nov 2021 16:53:36 +0000 (11:53 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 8 Nov 2021 16:53:36 +0000 (11:53 -0500)
instead of re-converting them every time

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

index 710cbff79aa625865177e4b9945576e87152da9c..079a6f75bb31443471b0e1a763cc328308ac9569 100644 (file)
@@ -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));
 
index c88ca52b04e0b8faf38153f623d35f8286ed4486..0ae5055275b171856e52420fe751bc72ba0dc428 100644 (file)
@@ -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.