]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: stats-file: manipulate shm-stats-file heartbeat using unsigned int
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 19 Feb 2026 13:59:52 +0000 (14:59 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 19 Feb 2026 15:13:55 +0000 (16:13 +0100)
shm-stats-file heartbeat is derived from now_ms with an extra time added
to it, thus it should be handled using the same time as now_ms is.

Until now, we used to handle heartbeat using signed integer. This was not
found to cause severe harm but it could result in improper handling due
to early wrapping because of signedness for instance, so let's better fix
that before it becomes a real issue.

It should be backported in 3.3

include/haproxy/stats-file-t.h
src/stats-file.c

index a47ddb02931e1577fc1b2e984890551d79ef3225..08731326a3da176eef65ce73de633dce6f4341db 100644 (file)
@@ -47,7 +47,7 @@ struct shm_stats_file_hdr {
         */
        struct {
                pid_t pid;
-               int heartbeat; // last activity of this process + heartbeat timeout, in ticks
+               uint heartbeat; // last activity of this process + heartbeat timeout, in ticks
        } slots[64];
        int objects; /* actual number of objects stored in the shm */
        int objects_slots; /* total available objects slots unless map is resized */
index 99d3a03e849be621820218e32991f2e3c0082b16..6942fe45f2365c2478c8c30dc12f4925b6eb696f 100644 (file)
@@ -492,7 +492,7 @@ static int shm_stats_file_check_ver(struct shm_stats_file_hdr *hdr)
        return 1;
 }
 
-static inline int shm_hb_is_stale(int hb)
+static inline int shm_hb_is_stale(uint hb)
 {
        return (hb == TICK_ETERNITY || tick_is_expired(hb, now_ms));
 }
@@ -501,7 +501,7 @@ static inline int shm_hb_is_stale(int hb)
  */
 static int shm_stats_file_slot_isfree(struct shm_stats_file_hdr *hdr, int id)
 {
-       int hb;
+       uint hb;
 
        hb = HA_ATOMIC_LOAD(&hdr->slots[id].heartbeat);
        return shm_hb_is_stale(hb);
@@ -513,7 +513,7 @@ static int shm_stats_file_slot_isfree(struct shm_stats_file_hdr *hdr, int id)
 int shm_stats_file_get_free_slot(struct shm_stats_file_hdr *hdr)
 {
        int it = 0;
-       int hb;
+       uint hb;
 
        while (it < sizeof(hdr->slots) / sizeof(hdr->slots[0])) {
                hb = HA_ATOMIC_LOAD(&hdr->slots[it].heartbeat);