]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: postpone the sysrepo plugin initialization
authorRenato Westphal <renato@opensourcerouting.org>
Sat, 12 Sep 2020 01:39:11 +0000 (22:39 -0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Tue, 6 Oct 2020 12:54:24 +0000 (15:54 +0300)
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>
lib/libfrr.c
lib/libfrr.h
lib/northbound_sysrepo.c

index 500a02aacd36ebb529dc673cca9d23bcfda90e50..800596c5639b9e8d1be1e6b41ce110c0890d1d6a 100644 (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;
 }
 
index 9d91ea9154d79b594c91b964157766bfd7ef9a43..ab72299206c959220702ff979708e712ad8e684a 100644 (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);
index 3dec685927795536fe84a2ac6247a623a96b264a..145164b90dd3d6e61f91f45a0b6686545507c7ec 100644 (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;
 }