From 5ea403a6dd414e418c1efcad70db165426f0642c Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Fri, 11 Sep 2020 22:39:11 -0300 Subject: [PATCH] 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 --- lib/libfrr.c | 3 +++ lib/libfrr.h | 1 + lib/northbound_sysrepo.c | 9 ++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/libfrr.c b/lib/libfrr.c index 500a02aacd..800596c563 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -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; } diff --git a/lib/libfrr.h b/lib/libfrr.h index 9d91ea9154..ab72299206 100644 --- a/lib/libfrr.h +++ b/lib/libfrr.h @@ -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); diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c index 3dec685927..145164b90d 100644 --- a/lib/northbound_sysrepo.c +++ b/lib/northbound_sysrepo.c @@ -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; } -- 2.39.5