]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tinfo: split the signal handler report flags into 3
authorWilly Tarreau <w@1wt.eu>
Mon, 24 Feb 2025 12:37:52 +0000 (13:37 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 24 Feb 2025 12:37:52 +0000 (13:37 +0100)
While signals are not recursive, one signal (e.g. wdt) may interrupt
another one (e.g. debug). The problem this causes is that when leaving
the inner handler, it removes the outer's flag, hence the protection
that comes with it. Let's just have 3 distinct flags for regular signals,
debug signal and watchdog signal. We add a 4th definition which is an
aggregate of the 3 to ease testing.

include/haproxy/tinfo-t.h
src/debug.c
src/stream.c
src/wdt.c

index a8a3e0d8bf9df4e682cf812e1f4b83cc643077eb..95604b0f563fa66038f7c93ccad1dddda13efa2e 100644 (file)
@@ -65,7 +65,10 @@ enum {
 #define TH_FL_STARTED           0x00000010  /* set once the thread starts */
 #define TH_FL_IN_LOOP           0x00000020  /* set only inside the polling loop */
 #define TH_FL_DUMPING_OTHERS    0x00000040  /* thread currently dumping other threads */
-#define TH_FL_IN_SIG_HANDLER    0x00000080  /* thread currently in signal handler */
+#define TH_FL_IN_SIG_HANDLER    0x00000080  /* thread currently in the generic signal handler */
+#define TH_FL_IN_DBG_HANDLER    0x00000100  /* thread currently in the debug signal handler */
+#define TH_FL_IN_WDT_HANDLER    0x00000200  /* thread currently in the wdt signal handler */
+#define TH_FL_IN_ANY_HANDLER    0x00000380  /* mask to test if the thread is in any signal handler */
 
 /* we have 4 buffer-wait queues, in highest to lowest emergency order */
 #define DYNBUF_NBQ              4
index 2e5c06a9e324a881164d89ec4d55ce4931b24e68..147e73ea146a5345cdf440cc1fe43a85a13fedfc 100644 (file)
@@ -2379,7 +2379,7 @@ void debug_handler(int sig, siginfo_t *si, void *arg)
                return;
 
        /* inform callees to be careful, we're in a signal handler! */
-       _HA_ATOMIC_OR(&th_ctx->flags, TH_FL_IN_SIG_HANDLER);
+       _HA_ATOMIC_OR(&th_ctx->flags, TH_FL_IN_DBG_HANDLER);
 
        /* Special value 0x2 is used during panics and requires that the thread
         * allocates its own dump buffer among its own trash buffers. The goal
@@ -2402,7 +2402,7 @@ void debug_handler(int sig, siginfo_t *si, void *arg)
        while (no_return)
                wait(NULL);
 
-       _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_IN_SIG_HANDLER);
+       _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_IN_DBG_HANDLER);
 }
 
 static int init_debug_per_thread()
index 43e9e7d43fc98f8a7d06db00167afeef4d02d0b4..5acb01ed907ba7c4bcc859af9d94ebfce8fb50b7 100644 (file)
@@ -3284,7 +3284,7 @@ static void __strm_dump_to_buffer(struct buffer *buf, const struct show_sess_ctx
        conn = objt_conn(strm_orig(strm));
 
        /* be careful not to allocate RAM from a signal handler! */
-       if (conn && !conn->src && !(th_ctx->flags & TH_FL_IN_SIG_HANDLER))
+       if (conn && !conn->src && !(th_ctx->flags & TH_FL_IN_ANY_HANDLER))
                conn_get_src(conn);
 
        switch (conn && conn->src ? addr_to_str(conn->src, pn, sizeof(pn)) : AF_UNSPEC) {
@@ -3324,7 +3324,7 @@ static void __strm_dump_to_buffer(struct buffer *buf, const struct show_sess_ctx
                     strm_li(strm) ? strm_li(strm)->luid : 0);
 
        /* be careful not to allocate RAM from a signal handler! */
-       if (conn && !conn->dst && !(th_ctx->flags & TH_FL_IN_SIG_HANDLER))
+       if (conn && !conn->dst && !(th_ctx->flags & TH_FL_IN_ANY_HANDLER))
                conn_get_dst(conn);
 
        switch (conn && conn->dst ? addr_to_str(conn->dst, pn, sizeof(pn)) : AF_UNSPEC) {
@@ -3355,7 +3355,7 @@ static void __strm_dump_to_buffer(struct buffer *buf, const struct show_sess_ctx
        conn = sc_conn(strm->scb);
 
        /* be careful not to allocate RAM from a signal handler! */
-       if (conn && !conn->src && !(th_ctx->flags & TH_FL_IN_SIG_HANDLER))
+       if (conn && !conn->src && !(th_ctx->flags & TH_FL_IN_ANY_HANDLER))
                conn_get_src(conn);
 
        switch (conn && conn->src ? addr_to_str(conn->src, pn, sizeof(pn)) : AF_UNSPEC) {
@@ -3384,7 +3384,7 @@ static void __strm_dump_to_buffer(struct buffer *buf, const struct show_sess_ctx
                chunk_appendf(buf, "%s  server=<NONE> (id=-1)", pfx);
 
        /* be careful not to allocate RAM from a signal handler! */
-       if (conn && !conn->dst && !(th_ctx->flags & TH_FL_IN_SIG_HANDLER))
+       if (conn && !conn->dst && !(th_ctx->flags & TH_FL_IN_ANY_HANDLER))
                conn_get_dst(conn);
 
        switch (conn && conn->dst ? addr_to_str(conn->dst, pn, sizeof(pn)) : AF_UNSPEC) {
index b5edece447311fa91b657294b614092b9b327a4b..be1b65c31e0d9c28f3f7eb73e5be0574464effb6 100644 (file)
--- a/src/wdt.c
+++ b/src/wdt.c
@@ -69,7 +69,7 @@ void wdt_handler(int sig, siginfo_t *si, void *arg)
        int thr, tgrp;
 
        /* inform callees to be careful, we're in a signal handler! */
-       _HA_ATOMIC_OR(&th_ctx->flags, TH_FL_IN_SIG_HANDLER);
+       _HA_ATOMIC_OR(&th_ctx->flags, TH_FL_IN_WDT_HANDLER);
 
        switch (si->si_code) {
        case SI_TIMER:
@@ -166,7 +166,7 @@ void wdt_handler(int sig, siginfo_t *si, void *arg)
 #endif
        default:
                /* unhandled other conditions */
-               _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_IN_SIG_HANDLER);
+               _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_IN_WDT_HANDLER);
                return;
        }
 
@@ -182,13 +182,13 @@ void wdt_handler(int sig, siginfo_t *si, void *arg)
 #endif
                ha_panic();
 
-       _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_IN_SIG_HANDLER);
+       _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_IN_WDT_HANDLER);
        return;
 
  update_and_leave:
        wdt_ping(thr);
 
-       _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_IN_SIG_HANDLER);
+       _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_IN_WDT_HANDLER);
 }
 
 /* parse the "warn-blocked-traffic-after" parameter */