diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2018-09-27 04:18:48 +0200 |
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2018-12-06 16:03:55 +0100 |
| commit | 24fb501d7f72cd5de59849331115283a52b25fab (patch) | |
| tree | dc4566576c9af8c4affab2bce46b9fe693f77736 /lib/libfrr.c | |
| parent | e45f5e4b3804d587196891a1c6e5eb1c926bbc54 (diff) | |
watchfrr, lib: cleanup & delay detaching
This cleans up watchfrr to be more "normal" like the other daemons in
terms of what it does in main(), i.e. using the full frr_*() call set.
Also, this changes the startup behaviour on watchfrr to stay attached on
the daemon's parent process until startup is really complete. This
should allow removing the "watchfrr.started" hack at some point.
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/libfrr.c')
| -rw-r--r-- | lib/libfrr.c | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/lib/libfrr.c b/lib/libfrr.c index 821c57f37b..86ec8b492a 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -54,6 +54,7 @@ static char pidfile_default[512]; static char vtypath_default[256]; bool debug_memstats_at_exit = 0; +static bool nodetach_term, nodetach_daemon; static char comb_optstr[256]; static struct option comb_lo[64]; @@ -281,6 +282,8 @@ void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv) opt_extend(&os_zclient); if (!(di->flags & FRR_NO_TCPVTY)) opt_extend(&os_vty); + if (di->flags & FRR_DETACH_LATER) + nodetach_daemon = true; snprintf(config_default, sizeof(config_default), "%s/%s.conf", frr_sysconfdir, di->name); @@ -765,13 +768,16 @@ void frr_config_fork(void) { hook_call(frr_late_init, master); - /* Don't start execution if we are in dry-run mode */ - if (di->dryrun) { - frr_config_read_in(NULL); - exit(0); - } + if (!(di->flags & FRR_NO_CFG_PID_DRY)) { + /* Don't start execution if we are in dry-run mode */ + if (di->dryrun) { + frr_config_read_in(NULL); + exit(0); + } - thread_add_event(master, frr_config_read_in, NULL, 0, &di->read_in); + thread_add_event(master, frr_config_read_in, NULL, 0, + &di->read_in); + } if (di->daemon_mode || di->terminal) frr_daemonize(); @@ -781,7 +787,7 @@ void frr_config_fork(void) pid_output(di->pid_file); } -void frr_vty_serv(void) +static void frr_vty_serv(void) { /* allow explicit override of vty_path in the future * (not currently set anywhere) */ @@ -808,14 +814,22 @@ void frr_vty_serv(void) vty_serv_sock(di->vty_addr, di->vty_port, di->vty_path); } +static void frr_check_detach(void) +{ + if (nodetach_term || nodetach_daemon) + return; + + if (daemon_ctl_sock != -1) + close(daemon_ctl_sock); + daemon_ctl_sock = -1; +} + static void frr_terminal_close(int isexit) { int nullfd; - if (daemon_ctl_sock != -1) { - close(daemon_ctl_sock); - daemon_ctl_sock = -1; - } + nodetach_term = false; + frr_check_detach(); if (!di->daemon_mode || isexit) { printf("\n%s exiting\n", di->name); @@ -879,6 +893,12 @@ out: return 0; } +void frr_detach(void) +{ + nodetach_daemon = false; + frr_check_detach(); +} + void frr_run(struct thread_master *master) { char instanceinfo[64] = ""; @@ -893,6 +913,8 @@ void frr_run(struct thread_master *master) instanceinfo, di->vty_port, di->startinfo); if (di->terminal) { + nodetach_term = true; + vty_stdio(frr_terminal_close); if (daemon_ctl_sock != -1) { set_nonblocking(daemon_ctl_sock); @@ -912,9 +934,7 @@ void frr_run(struct thread_master *master) close(nullfd); } - if (daemon_ctl_sock != -1) - close(daemon_ctl_sock); - daemon_ctl_sock = -1; + frr_check_detach(); } /* end fixed stderr startup logging */ |
