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>
#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
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
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()
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) {
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) {
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) {
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) {
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:
#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;
}
#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 */