MINOR: tinfo: split the signal handler report flags into 3

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.
This commit is contained in:
Willy Tarreau 2025-02-24 13:37:52 +01:00
parent bbf824933f
commit fb7874c286
4 changed files with 14 additions and 11 deletions

View 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

View 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()

View 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) {

View File

@ -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 */