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>
Thu, 20 Mar 2025 10:38:00 +0000 (11:38 +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.

(cherry picked from commit fb7874c286dbe1594837fc75b9e96783dfe160f5)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 88b97519ab35e851888761960ac64dd10614ae86)
Signed-off-by: Willy Tarreau <w@1wt.eu>

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

index 0d17f40..87a01c3 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 cf3c50a..98ad685 100644 (file)
@@ -2297,7 +2297,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
@@ -2320,7 +2320,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 035359c..c17d5a6 100644 (file)
@@ -3193,7 +3193,7 @@ void strm_dump_to_buffer(struct buffer *buf, const struct stream *strm, const ch
        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) {
@@ -3228,7 +3228,7 @@ void strm_dump_to_buffer(struct buffer *buf, const struct stream *strm, const ch
                     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) {
@@ -3257,7 +3257,7 @@ void strm_dump_to_buffer(struct buffer *buf, const struct stream *strm, const ch
        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) {
@@ -3284,7 +3284,7 @@ void strm_dump_to_buffer(struct buffer *buf, const struct stream *strm, const ch
                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 fbf0a63..5872ae2 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 */