]> git.proxmox.com Git - mirror_frr.git/commitdiff
*: centralize some exit cleanup into libfrr
authorDavid Lamparter <equinox@opensourcerouting.org>
Sun, 6 Aug 2017 06:28:16 +0000 (08:28 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Tue, 15 Aug 2017 11:25:44 +0000 (13:25 +0200)
Start creating a counterpart to frr_init and frr_late_init.
Unfortunately, some daemons don't do any exit handling, this doesn't
change that just yet.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
bgpd/bgp_main.c
ldpd/ldpd.c
lib/libfrr.c
lib/libfrr.h
nhrpd/nhrp_main.c
ospf6d/ospf6_main.c
zebra/main.c

index 25a562ed68f9c944a4d25e3db77dd770e83210e8..a80dff271d609e5eec5411091ca6b9873238d067 100644 (file)
@@ -172,6 +172,8 @@ static __attribute__((__noreturn__)) void bgp_exit(int status)
        /* it only makes sense for this to be called on a clean exit */
        assert(status == 0);
 
+       frr_early_fini();
+
        bfd_gbl_exit();
 
        bgp_close();
@@ -214,22 +216,16 @@ static __attribute__((__noreturn__)) void bgp_exit(int status)
        community_list_terminate(bgp_clist);
 
        bgp_vrf_terminate();
-       cmd_terminate();
-       vty_terminate();
 #if ENABLE_BGP_VNC
        vnc_zebra_destroy();
 #endif
        bgp_zebra_destroy();
 
-       /* reverse bgp_master_init */
-       if (bm->master)
-               thread_master_free(bm->master);
-
-       closezlog();
-
        list_delete(bm->bgp);
        memset(bm, 0, sizeof(*bm));
 
+       frr_fini();
+
        if (bgp_debug_count())
                log_memstats_stderr("bgpd");
        exit(status);
index 80af2b14e5da6accde082303f01eae3427835f10..0a586ec1c5b123671954ca019712d50e859bb0b3 100644 (file)
@@ -392,6 +392,8 @@ ldpd_shutdown(void)
        pid_t            pid;
        int              status;
 
+       frr_early_fini();
+
        /* close pipes */
        msgbuf_clear(&iev_ldpe->ibuf.w);
        close(iev_ldpe->ibuf.fd);
@@ -423,13 +425,9 @@ ldpd_shutdown(void)
 
        vrf_terminate();
        access_list_reset();
-       cmd_terminate();
-       vty_terminate();
        ldp_zebra_destroy();
-       zprivs_terminate(&ldpd_privs);
-       thread_master_free(master);
-       closezlog();
 
+       frr_fini();
        exit(0);
 }
 
index a5c87e6edc6d6d5f003ed2731108ca9491f542f0..255f91ec71f85564ded01ec90b29d054c7fdd783 100644 (file)
@@ -37,6 +37,8 @@
 #include "network.h"
 
 DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm))
+DEFINE_KOOH(frr_early_fini, (), ())
+DEFINE_KOOH(frr_fini, (), ())
 
 const char frr_sysconfdir[] = SYSCONFDIR;
 const char frr_vtydir[] = DAEMON_VTY_DIR;
@@ -831,3 +833,22 @@ void frr_run(struct thread_master *master)
        while (thread_fetch(master, &thread))
                thread_call(&thread);
 }
+
+void frr_early_fini(void)
+{
+       hook_call(frr_early_fini);
+}
+
+void frr_fini(void)
+{
+       hook_call(frr_fini);
+
+       /* memory_init -> nothing needed */
+       vty_terminate();
+       cmd_terminate();
+       zprivs_terminate(di->privs);
+       /* signal_init -> nothing needed */
+       thread_master_free(master);
+       closezlog();
+       /* frrmod_init -> nothing needed / hooks */
+}
index 1710fc9a846ea0a69e4fa42355f84f6a37a55ac3..8a15d168a1722290d39693b54798833036bca57d 100644 (file)
@@ -104,6 +104,14 @@ extern void frr_run(struct thread_master *master);
 extern bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,
                             const char *path);
 
+/* these two are before the protocol daemon does its own shutdown
+ * it's named this way being the counterpart to frr_late_init */
+DECLARE_KOOH(frr_early_fini, (), ())
+extern void frr_early_fini(void);
+/* and these two are after the daemon did its own cleanup */
+DECLARE_KOOH(frr_fini, (), ())
+extern void frr_fini(void);
+
 extern char config_default[256];
 extern char frr_zclientpath[256];
 extern const char frr_sysconfdir[];
index 012d5cd87c0d143a10a9615f2b9fb2a4217634f3..3a7186c1d799dfcce0d315d258d11087c8be530f 100644 (file)
@@ -81,6 +81,7 @@ static void nhrp_sigusr1(void)
 static void nhrp_request_stop(void)
 {
        debugf(NHRP_DEBUG_COMMON, "Exiting...");
+       frr_early_fini();
 
        nhrp_shortcut_terminate();
        nhrp_nhs_terminate();
@@ -89,15 +90,9 @@ static void nhrp_request_stop(void)
        evmgr_terminate();
        nhrp_vc_terminate();
        vrf_terminate();
-       /* memory_terminate(); */
-       /* vty_terminate(); */
-       cmd_terminate();
-       /* signal_terminate(); */
-       zprivs_terminate(&nhrpd_privs);
 
        debugf(NHRP_DEBUG_COMMON, "Done.");
-
-       closezlog();
+       frr_fini();
 
        exit(0);
 }
index 28bb956c403d819328bbd03b27fd2931249c6495..e582737f940e9f16c1ca2a2b702b72e7352cf5f0 100644 (file)
@@ -82,6 +82,8 @@ static void __attribute__((noreturn)) ospf6_exit(int status)
        struct listnode *node;
        struct interface *ifp;
 
+       frr_early_fini();
+
        if (ospf6)
                ospf6_delete(ospf6);
 
@@ -96,19 +98,13 @@ static void __attribute__((noreturn)) ospf6_exit(int status)
        ospf6_lsa_terminate();
 
        vrf_terminate();
-       vty_terminate();
-       cmd_terminate();
 
        if (zclient) {
                zclient_stop(zclient);
                zclient_free(zclient);
        }
 
-       if (master)
-               thread_master_free(master);
-
-       closezlog();
-
+       frr_fini();
        exit(status);
 }
 
index 538c2f0663129ed7db8e1e5463bfeeceb5d578a4..c3a7d3635fd9b3460a8148578ddae3e0092e37a3 100644 (file)
@@ -125,6 +125,7 @@ static void sigint(void)
 
        zlog_notice("Terminating on signal");
 
+       frr_early_fini();
 #ifdef HAVE_IRDP
        irdp_finish();
 #endif
@@ -147,17 +148,14 @@ static void sigint(void)
        access_list_reset();
        prefix_list_reset();
        route_map_finish();
-       cmd_terminate();
-       vty_terminate();
-       zprivs_terminate(&zserv_privs);
+
        list_delete(zebrad.client_list);
        work_queue_free(zebrad.ribq);
        if (zebrad.lsp_process_q)
                work_queue_free(zebrad.lsp_process_q);
        meta_queue_free(zebrad.mq);
-       thread_master_free(zebrad.master);
-       closezlog();
 
+       frr_fini();
        exit(0);
 }