lib: postpone the sysrepo plugin initialization

From Sysrepo's documentation:
"Note: do not use fork() after creating a connection. Sysrepo
internally stores PID of every created connection and this way a
mismatch of PID and connection is created".

Introduce a new "frr_very_late_init" hook in libfrr that is only
called after the daemon is forked (when the '-d' option is used)
and after the configuration is read. This way we can initialize
the sysrepo plugin correctly even when the daemon is daemonized,
and after the Sysrepo CLI commands are processed (only "debug
northbound client sysrepo" for now).

Fixes #7062

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2020-09-11 22:39:11 -03:00
parent eac139f8f2
commit 88e635ee63
3 changed files with 12 additions and 1 deletions

View File

@ -45,6 +45,7 @@
#include "defaults.h"
DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm))
DEFINE_HOOK(frr_very_late_init, (struct thread_master * tm), (tm))
DEFINE_KOOH(frr_early_fini, (), ())
DEFINE_KOOH(frr_fini, (), ())
@ -913,6 +914,8 @@ static int frr_config_read_in(struct thread *t)
__func__, nb_err_name(ret), errmsg);
}
hook_call(frr_very_late_init, master);
return 0;
}

View File

@ -136,6 +136,7 @@ extern const char *frr_get_progname(void);
extern enum frr_cli_mode frr_get_cli_mode(void);
DECLARE_HOOK(frr_late_init, (struct thread_master * tm), (tm))
DECLARE_HOOK(frr_very_late_init, (struct thread_master * tm), (tm))
extern void frr_config_fork(void);
extern void frr_run(struct thread_master *master);

View File

@ -742,7 +742,7 @@ static int frr_sr_finish(void)
return 0;
}
static int frr_sr_module_late_init(struct thread_master *tm)
static int frr_sr_module_very_late_init(struct thread_master *tm)
{
master = tm;
@ -753,6 +753,12 @@ static int frr_sr_module_late_init(struct thread_master *tm)
}
hook_register(frr_fini, frr_sr_finish);
return 0;
}
static int frr_sr_module_late_init(struct thread_master *tm)
{
frr_sr_cli_init();
return 0;
@ -761,6 +767,7 @@ static int frr_sr_module_late_init(struct thread_master *tm)
static int frr_sr_module_init(void)
{
hook_register(frr_late_init, frr_sr_module_late_init);
hook_register(frr_very_late_init, frr_sr_module_very_late_init);
return 0;
}