summaryrefslogtreecommitdiffstats
path: root/lib/frr_pthread.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2021-04-22 12:10:27 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2021-04-22 13:25:38 +0200
commit38554d3ae6c4ea553fd4e9ab2185c0d79f1144f7 (patch)
tree6220285e2cf240c271f63464bae64054039d02f3 /lib/frr_pthread.c
parentpathd: don't init PCEP before fork() (diff)
downloadfrr-38554d3ae6c4ea553fd4e9ab2185c0d79f1144f7.tar.xz
frr-38554d3ae6c4ea553fd4e9ab2185c0d79f1144f7.zip
lib: hard-fail creating threads before fork()
Creating any threads before we fork() into the background (if `-d` is given) is an extremely dangerous footgun; the threads are created in the parent and terminated when that exits. This is extra dangerous because while testing, you'd often run the daemon in foreground without `-d`, and everything works as expected. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/frr_pthread.c')
-rw-r--r--lib/frr_pthread.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c
index 03359f4d1..898fe98aa 100644
--- a/lib/frr_pthread.c
+++ b/lib/frr_pthread.c
@@ -28,6 +28,7 @@
#include "memory.h"
#include "linklist.h"
#include "zlog.h"
+#include "libfrr.h"
#include "libfrr_trace.h"
DEFINE_MTYPE_STATIC(LIB, FRR_PTHREAD, "FRR POSIX Thread");
@@ -162,6 +163,8 @@ int frr_pthread_run(struct frr_pthread *fpt, const pthread_attr_t *attr)
int ret;
sigset_t oldsigs, blocksigs;
+ assert(frr_is_after_fork || !"trying to start thread before fork()");
+
/* Ensure we never handle signals on a background thread by blocking
* everything here (new thread inherits signal mask)
*/