diff options
| author | Renato Westphal <renato@opensourcerouting.org> | 2020-03-30 19:34:30 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-30 19:34:30 -0300 |
| commit | 94d5e90ce3282a2abfa52de691435dfe099430d4 (patch) | |
| tree | adcb69a8979adb410763b1bbae9b9209d0d04236 /lib/northbound_grpc.cpp | |
| parent | ff82bbbb912d84a4a9bc22a7efe7f51adada02eb (diff) | |
| parent | 20b0a2ed3e8f7c7bb94e52e3fa29086d7dcad2be (diff) | |
Merge pull request #6117 from qlyoung/fix-grpc-plugin-with-daemonize
lib: defer grpc plugin initialization to post fork
Diffstat (limited to 'lib/northbound_grpc.cpp')
| -rw-r--r-- | lib/northbound_grpc.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/northbound_grpc.cpp b/lib/northbound_grpc.cpp index 089899368d..b195f1aeca 100644 --- a/lib/northbound_grpc.cpp +++ b/lib/northbound_grpc.cpp @@ -884,7 +884,14 @@ static int frr_grpc_finish(void) return 0; } -static int frr_grpc_module_late_init(struct thread_master *tm) +/* + * This is done this way because module_init and module_late_init are both + * called during daemon pre-fork initialization. Because the GRPC library + * spawns threads internally, we need to delay initializing it until after + * fork. This is done by scheduling this init function as an event task, since + * the event loop doesn't run until after fork. + */ +static int frr_grpc_module_very_late_init(struct thread *thread) { static unsigned long port = GRPC_DEFAULT_PORT; const char *args = THIS_MODULE->load_args; @@ -910,15 +917,19 @@ static int frr_grpc_module_late_init(struct thread_master *tm) if (frr_grpc_init(&port) < 0) goto error; - hook_register(frr_fini, frr_grpc_finish); - - return 0; - error: flog_err(EC_LIB_GRPC_INIT, "failed to initialize the gRPC module"); return -1; } +static int frr_grpc_module_late_init(struct thread_master *tm) +{ + thread_add_event(tm, frr_grpc_module_very_late_init, NULL, 0, NULL); + hook_register(frr_fini, frr_grpc_finish); + + return 0; +} + static int frr_grpc_module_init(void) { hook_register(frr_late_init, frr_grpc_module_late_init); |
