]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: force the name at creation time to be a const.
authorWilly Tarreau <w@1wt.eu>
Tue, 5 Aug 2025 17:07:47 +0000 (19:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 6 Aug 2025 17:20:28 +0000 (19:20 +0200)
This is already the case as all names are constant so that's fine. If
it would ever change, it's not very hard to just replace it in-situ
via an strdup() and set a flag to mention that it's dynamically
allocated. We just don't need this right now.

One immediately visible effect is in "show pools detailed" where the
names are no longer truncated.

include/haproxy/pool-t.h
include/haproxy/pool.h
src/pool.c

index 524c871b82cced8f9f673a442076d68ded7d441a..4a8752ad6d72ceb6b59e0c4c46cdea40ef6fab8f 100644 (file)
@@ -70,7 +70,7 @@ struct pool_cache_head {
  */
 struct pool_registration {
        struct list list;    /* link element */
-       char name[12];       /* name of the pool */
+       const char *name;    /* name of the pool */
        unsigned int size;   /* expected object size */
        unsigned int flags;  /* MEM_F_* */
        unsigned int align;  /* expected alignment; 0=unspecified */
index 963e5b6aee2c0a477520d7d1ca0b757916d5026c..3c9651e402ca9b584667b8ef005216085df5a93e 100644 (file)
@@ -123,8 +123,8 @@ unsigned long long pool_total_allocated(void);
 unsigned long long pool_total_used(void);
 void pool_flush(struct pool_head *pool);
 void pool_gc(struct pool_head *pool_ctx);
-struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags);
-struct pool_head *create_pool_from_reg(char *name, struct pool_registration *reg);
+struct pool_head *create_pool(const char *name, unsigned int size, unsigned int flags);
+struct pool_head *create_pool_from_reg(const char *name, struct pool_registration *reg);
 void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size);
 void *pool_destroy(struct pool_head *pool);
 void pool_destroy_all(void);
index 43359403fbd8c6ff60d07fae833d42cd9ae6c1ea..507a52032aa48b280ca5de37372318100bdfed58 100644 (file)
@@ -290,8 +290,9 @@ static int mem_should_fail(const struct pool_head *pool)
  * is available for a new creation. Two flags are supported :
  *   - MEM_F_SHARED to indicate that the pool may be shared with other users
  *   - MEM_F_EXACT to indicate that the size must not be rounded up
+ * The name must be a stable pointer during all the program's life time.
  */
-struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags)
+struct pool_head *create_pool(const char *name, unsigned int size, unsigned int flags)
 {
        struct pool_registration *reg;
        struct pool_head *pool;
@@ -300,7 +301,7 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags)
        if (!reg)
                return NULL;
 
-       strlcpy2(reg->name, name, sizeof(reg->name));
+       reg->name = name;
        reg->size = size;
        reg->flags = flags;
        reg->align = 0;
@@ -314,7 +315,7 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags)
 /* create a pool from a pool registration. All configuration is taken from
  * there.
  */
-struct pool_head *create_pool_from_reg(char *name, struct pool_registration *reg)
+struct pool_head *create_pool_from_reg(const char *name, struct pool_registration *reg)
 {
        unsigned int extra_mark, extra_caller, extra;
        unsigned int flags = reg->flags;