From 5812b45fb3a7188dee8361da5092f1d7b2b0f95f Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Thu, 11 Jun 2020 15:30:36 -0400 Subject: [PATCH 1/2] lib: don't try to change/reset capabilities if process has none A couple of daemons take/use no capabilities/privs; allow cleanup of the privs/capabilities library module even if a daemon has no caps. Signed-off-by: Mark Stapp --- lib/privs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/privs.c b/lib/privs.c index 09efedf684..eb0dbe0783 100644 --- a/lib/privs.c +++ b/lib/privs.c @@ -406,9 +406,11 @@ static void zprivs_caps_init(struct zebra_privs_t *zprivs) static void zprivs_caps_terminate(void) { - /* clear all capabilities */ + /* Clear all capabilities, if we have any. */ if (zprivs_state.caps) cap_clear(zprivs_state.caps); + else + return; /* and boom, capabilities are gone forever */ if (cap_set_proc(zprivs_state.caps)) { From 70504ec45a599200650d9763028aa87d48edbcf0 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Thu, 11 Jun 2020 11:16:02 -0400 Subject: [PATCH 2/2] *: have daemons call frr_fini() at termination Fix a number of library and daemon issues so that daemons can call frr_fini() during normal termination. Without this, temporary logging files are left behind in /var/tmp/frr/. Signed-off-by: Mark Stapp --- lib/thread.c | 3 ++- ospfd/ospf_main.c | 1 + ospfd/ospfd.c | 5 +++-- pbrd/pbr_main.c | 2 ++ sharpd/sharp_main.c | 2 ++ staticd/static_main.c | 3 +++ vrrpd/vrrp_main.c | 2 ++ 7 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/thread.c b/lib/thread.c index 4d689a9f88..9b2f5661ac 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -1094,7 +1094,8 @@ static void do_thread_cancel(struct thread_master *master) } /* Delete and free all cancellation requests */ - list_delete_all_node(master->cancel_req); + if (master->cancel_req) + list_delete_all_node(master->cancel_req); /* Wake up any threads which may be blocked in thread_cancel_async() */ master->canceled = true; diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index 6a3ba9902d..0a93d5d37c 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -98,6 +98,7 @@ static void sigint(void) { zlog_notice("Terminating on signal"); ospf_terminate(); + exit(0); } /* SIGUSR1 handler. */ diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index e9f622d217..cdfcaa44d6 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -517,9 +517,9 @@ void ospf_terminate(void) SET_FLAG(om->options, OSPF_MASTER_SHUTDOWN); - /* exit immediately if OSPF not actually running */ + /* Skip some steps if OSPF not actually running */ if (listcount(om->ospf) == 0) - exit(0); + goto done; bfd_gbl_exit(); for (ALL_LIST_ELEMENTS(om->ospf, node, nnode, ospf)) @@ -543,6 +543,7 @@ void ospf_terminate(void) zclient_stop(zclient); zclient_free(zclient); +done: frr_fini(); } diff --git a/pbrd/pbr_main.c b/pbrd/pbr_main.c index b228847f06..1dbe12a039 100644 --- a/pbrd/pbr_main.c +++ b/pbrd/pbr_main.c @@ -82,6 +82,8 @@ static void sigint(void) { zlog_notice("Terminating on signal"); + frr_fini(); + exit(0); } diff --git a/sharpd/sharp_main.c b/sharpd/sharp_main.c index 120d704918..97a63e871e 100644 --- a/sharpd/sharp_main.c +++ b/sharpd/sharp_main.c @@ -81,6 +81,8 @@ static void sigint(void) { zlog_notice("Terminating on signal"); + frr_fini(); + exit(0); } diff --git a/staticd/static_main.c b/staticd/static_main.c index c77a99f280..8356876f8e 100644 --- a/staticd/static_main.c +++ b/staticd/static_main.c @@ -42,6 +42,7 @@ char backup_config_file[256]; bool mpls_enabled; + zebra_capabilities_t _caps_p[] = { }; @@ -75,6 +76,8 @@ static void sigint(void) static_vrf_terminate(); + frr_fini(); + exit(0); } diff --git a/vrrpd/vrrp_main.c b/vrrpd/vrrp_main.c index 95b3cfad8f..b214b623de 100644 --- a/vrrpd/vrrp_main.c +++ b/vrrpd/vrrp_main.c @@ -82,6 +82,8 @@ static void __attribute__((noreturn)) sigint(void) vrrp_fini(); + frr_fini(); + exit(0); }