diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2021-04-22 12:10:27 +0200 |
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2021-04-22 13:25:38 +0200 |
| commit | 38554d3ae6c4ea553fd4e9ab2185c0d79f1144f7 (patch) | |
| tree | 6220285e2cf240c271f63464bae64054039d02f3 /lib/libfrr.c | |
| parent | 159246be247fd4332780fcafe5909874ae2c705a (diff) | |
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/libfrr.c')
| -rw-r--r-- | lib/libfrr.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/libfrr.c b/lib/libfrr.c index 38f994bdfc..970e82c064 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -70,6 +70,8 @@ static char dbfile_default[512]; #endif static char vtypath_default[512]; +/* cleared in frr_preinit(), then re-set after daemonizing */ +bool frr_is_after_fork = true; bool debug_memstats_at_exit = false; static bool nodetach_term, nodetach_daemon; static uint64_t startup_fds; @@ -308,6 +310,7 @@ void frr_init_vtydir(void) void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv) { di = daemon; + frr_is_after_fork = false; /* basename(), opencoded. */ char *p = strrchr(argv[0], '/'); @@ -990,6 +993,8 @@ void frr_config_fork(void) if (di->daemon_mode || di->terminal) frr_daemonize(); + frr_is_after_fork = true; + if (!di->pid_file) di->pid_file = pidfile_default; pid_output(di->pid_file); |
