summaryrefslogtreecommitdiff
path: root/lib/sigevent.h
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2025-02-07 13:22:25 +0100
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2025-02-11 17:28:51 +0000
commit4fdb1f0496a97c3e54bfcaed121d24143862fb6d (patch)
tree8e49b72c2f59b8b9eb7b48172b4c5ca2d2c2d654 /lib/sigevent.h
parent8aca554935c374e909a44af060f84346942214ef (diff)
lib: crash handlers must be allowed on threads
Blocking all signals on non-main threads is not the way to go, at least the handlers for SIGSEGV, SIGBUS, SIGILL, SIGABRT and SIGFPE need to run so we get backtraces. Otherwise the process just exits. Signed-off-by: David Lamparter <equinox@opensourcerouting.org> (cherry picked from commit 13a6ac5b4ca8fc08b348f64de64a787982f24250)
Diffstat (limited to 'lib/sigevent.h')
-rw-r--r--lib/sigevent.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/sigevent.h b/lib/sigevent.h
index 0b07f594c1..2c51ba3767 100644
--- a/lib/sigevent.h
+++ b/lib/sigevent.h
@@ -45,6 +45,33 @@ bool frr_sigevent_check(sigset_t *setp);
/* check whether there are signals to handle, process any found */
extern int frr_sigevent_process(void);
+/* Ensure we don't handle "application-type" signals on a secondary thread by
+ * blocking these signals when creating threads
+ *
+ * NB: SIGSEGV, SIGABRT, etc. must be allowed on all threads or we get no
+ * crashlogs. Since signals vary a little bit between platforms, below is a
+ * list of known things to go to the main thread. Any unknown signals should
+ * stay thread-local.
+ */
+static inline void frr_sigset_add_mainonly(sigset_t *blocksigs)
+{
+ /* signals we actively handle */
+ sigaddset(blocksigs, SIGHUP);
+ sigaddset(blocksigs, SIGINT);
+ sigaddset(blocksigs, SIGTERM);
+ sigaddset(blocksigs, SIGUSR1);
+
+ /* signals we don't actively use but that semantically belong */
+ sigaddset(blocksigs, SIGUSR2);
+ sigaddset(blocksigs, SIGQUIT);
+ sigaddset(blocksigs, SIGCHLD);
+ sigaddset(blocksigs, SIGPIPE);
+ sigaddset(blocksigs, SIGTSTP);
+ sigaddset(blocksigs, SIGTTIN);
+ sigaddset(blocksigs, SIGTTOU);
+ sigaddset(blocksigs, SIGWINCH);
+}
+
#ifdef __cplusplus
}
#endif