]> git.proxmox.com Git - mirror_frr.git/commitdiff
*: add frr_run()
authorDavid Lamparter <equinox@opensourcerouting.org>
Mon, 14 Nov 2016 00:56:02 +0000 (09:56 +0900)
committerDavid Lamparter <equinox@opensourcerouting.org>
Tue, 7 Mar 2017 23:15:39 +0000 (00:15 +0100)
Contains the fetch-and-run-thread logic, and vty startup (which is the
last thing happening before entering the main loop).

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
12 files changed:
bgpd/bgp_main.c
isisd/isis_main.c
ldpd/ldpd.c
lib/libfrr.c
lib/libfrr.h
nhrpd/nhrp_main.c
ospf6d/ospf6_main.c
ospfd/ospf_main.c
pimd/pim_main.c
ripd/rip_main.c
ripngd/ripng_main.c
zebra/main.c

index 00c9576e0c94a63f9765da138ac89c52e381684a..ba95a56074debdd20f9ddc6fc79b4ca355bbf5d3 100644 (file)
@@ -360,7 +360,6 @@ int
 main (int argc, char **argv)
 {
   int opt;
-  struct thread thread;
   int tmp_port;
 
   int bgp_port = BGP_PORT_DEFAULT;
@@ -427,20 +426,12 @@ main (int argc, char **argv)
   /* BGP related initialization.  */
   bgp_init ();
 
-  frr_config_fork ();
-
-  /* Make bgp vty socket. */
-  frr_vty_serv ();
+  snprintf (bgpd_di.startinfo, sizeof (bgpd_di.startinfo), ", bgp@%s:%d",
+            (bm->address ? bm->address : "<all>"),
+            bm->port);
 
-  /* Print banner. */
-  zlog_notice ("BGPd %s starting: vty@%d, bgp@%s:%d", FRR_VERSION,
-              bgpd_di.vty_port,
-              (bm->address ? bm->address : "<all>"),
-              bm->port);
-
-  /* Start finite state machine, here we go! */
-  while (thread_fetch (bm->master, &thread))
-    thread_call (&thread);
+  frr_config_fork ();
+  frr_run (bm->master);
 
   /* Not reached. */
   return (0);
index 49b988b29f36243ee2ea8b42df62348fde8f0be5..8c48c7e27c5550a867f36bee8bf83a5114e59a6c 100644 (file)
@@ -198,7 +198,6 @@ int
 main (int argc, char **argv, char **envp)
 {
   int opt;
-  struct thread thread;
 
   /* for reload */
   _argc = argc;
@@ -259,16 +258,7 @@ main (int argc, char **argv, char **envp)
   isis_zebra_init(master);
 
   frr_config_fork ();
-
-  /* Make isis vty socket. */
-  frr_vty_serv ();
-
-  /* Print banner. */
-  zlog_notice ("Quagga-ISISd %s starting: vty@%d", FRR_VERSION, isisd_di.vty_port);
-
-  /* Start finite state machine. */
-  while (thread_fetch (master, &thread))
-    thread_call (&thread);
+  frr_run (master);
 
   /* Not reached. */
   exit (0);
index f2ed70eda2ef44570fb5d701e54bfc7146dee767..205449db3e4a86bdbf11008aa22cf9cc5ebd42aa 100644 (file)
@@ -186,7 +186,6 @@ main(int argc, char *argv[])
        char                    *ctl_sock_name;
        const char              *user = NULL;
        const char              *group = NULL;
-       struct thread            thread;
 
        ldpd_process = PROC_MAIN;
 
@@ -364,15 +363,7 @@ main(int argc, char *argv[])
        if (ldpd_conf->ipv6.flags & F_LDPD_AF_ENABLED)
                main_imsg_send_net_sockets(AF_INET6);
 
-       /* Create VTY socket */
-       frr_vty_serv();
-
-       /* Print banner. */
-       log_notice("LDPd %s starting: vty@%d", FRR_VERSION, ldpd_di.vty_port);
-
-       /* Fetch next active thread. */
-       while (thread_fetch(master, &thread))
-               thread_call(&thread);
+       frr_run(master);
 
        /* NOTREACHED */
        return (0);
index ad85c6f89ac2f1427b6471bf38dd251353350e46..570d9724d7e413e1da8a4d2a0a7419b4f43f9f05 100644 (file)
@@ -369,3 +369,24 @@ void frr_vty_serv(void)
        vty_serv_sock(di->vty_addr, di->vty_port, di->vty_path);
 }
 
+void frr_run(struct thread_master *master)
+{
+       char instanceinfo[64] = "";
+
+       frr_vty_serv();
+
+       if (di->instance)
+               snprintf(instanceinfo, sizeof(instanceinfo), "instance %u ",
+                               di->instance);
+
+       zlog_notice("%s %s starting: %svty@%d%s",
+                       di->name,
+                       FRR_VERSION,
+                       instanceinfo,
+                       di->vty_port,
+                       di->startinfo);
+
+       struct thread thread;
+       while (thread_fetch(master, &thread))
+               thread_call(&thread);
+}
index e7e209f6069bdf5171b38ac38a493a0102d2e938..ae4a5176a3acf65a01fb5cca435e6d31ed712cad 100644 (file)
@@ -53,6 +53,7 @@ struct frr_daemon_info {
        const char *proghelp;
        void (*printhelp)(FILE *target);
        const char *copyright;
+       char startinfo[128];
 
        struct quagga_signal_t *signals;
        size_t n_signals;
@@ -89,6 +90,9 @@ extern void frr_config_fork(void);
 
 extern void frr_vty_serv(void);
 
+/* note: contains call to frr_vty_serv() */
+extern void frr_run(struct thread_master *master);
+
 extern char config_default[256];
 extern const char frr_sysconfdir[];
 extern const char frr_vtydir[];
index e1192205e65a37749f39e44f318b37812054b479..96339998555d0f3b21966e520cd2fbdd80637342 100644 (file)
@@ -123,8 +123,6 @@ FRR_DAEMON_INFO(nhrpd, NHRP,
 
 int main(int argc, char **argv)
 {
-       struct thread thread;
-
        frr_preinit(&nhrpd_di, argc, argv);
        frr_opt_add("", longopts, "");
 
@@ -151,14 +149,6 @@ int main(int argc, char **argv)
        nhrp_config_init();
 
        frr_config_fork();
-
-       /* Create VTY socket */
-       frr_vty_serv();
-       zlog_notice("nhrpd starting: vty@%d", nhrpd_di.vty_port);
-
-       /* Main loop */
-       while (thread_fetch(master, &thread))
-               thread_call(&thread);
-
+       frr_run(master);
        return 0;
 }
index 2d5ae02fbc5719e202a7e78adcc066cbf0001041..6c994189ee7dc63a184e0ffb1b68abc8a6c2d9d9 100644 (file)
@@ -191,7 +191,6 @@ int
 main (int argc, char *argv[], char *envp[])
 {
   int opt;
-  struct thread thread;
 
   frr_preinit (&ospf6d_di, argc, argv);
   frr_opt_add ("", longopts, "");
@@ -232,19 +231,7 @@ main (int argc, char *argv[], char *envp[])
   ospf6_init ();
 
   frr_config_fork ();
-
-  frr_vty_serv ();
-
-  /* Print start message */
-  zlog_notice ("OSPF6d (Quagga-%s ospf6d-%s) starts: vty@%d",
-               FRR_VERSION, OSPF6_DAEMON_VERSION, ospf6d_di.vty_port);
-
-  /* Start finite state machine, here we go! */
-  while (thread_fetch (master, &thread))
-    thread_call (&thread);
-
-  /* Log in case thread failed */
-  zlog_warn ("Thread failed");
+  frr_run (master);
 
   /* Not reached. */
   ospf6_exit (0);
index ee5815832acb516f44d3fc8763918e1c8fc6aaa2..47aa6c63eead53a181d83a60761414e6ebfd9b1b 100644 (file)
@@ -166,7 +166,6 @@ int
 main (int argc, char **argv)
 {
   u_short instance = 0;
-  struct thread thread;
 
 #ifdef SUPPORT_OSPF_API
   /* OSPF apiserver is disabled by default. */
@@ -255,15 +254,8 @@ main (int argc, char **argv)
       exit (1);
     }
 
-  frr_vty_serv ();
-
-  /* Print banner. */
-  zlog_notice ("OSPFd %s starting: vty@%d, %s", FRR_VERSION,
-               ospfd_di.vty_port, ospfd_di.vty_path);
-
-  /* Fetch next active thread. */
-  while (thread_fetch (master, &thread))
-    thread_call (&thread);
+  frr_config_fork();
+  frr_run (master);
 
   /* Not reached. */
   return (0);
index f446e33af4d898229fe66b4413d494230a017c3f..ba1c511d164ea9c391f690c4a9956eb3aefc79fc 100644 (file)
@@ -90,8 +90,6 @@ FRR_DAEMON_INFO(pimd, PIM,
 )
 
 int main(int argc, char** argv, char** envp) {
-  struct thread thread;
-
   frr_preinit(&pimd_di, argc, argv);
   frr_opt_add("", longopts, "");
 
@@ -138,11 +136,6 @@ int main(int argc, char** argv, char** envp) {
 
   frr_config_fork();
 
-  frr_vty_serv();
-
-  zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting, VTY interface at port TCP %d",
-              FRR_VERSION, PIMD_VERSION, pimd_di.vty_port);
-
 #ifdef PIM_DEBUG_BYDEFAULT
   zlog_notice("PIM_DEBUG_BYDEFAULT: Enabling all debug commands");
   PIM_DO_DEBUG_PIM_EVENTS;
@@ -165,11 +158,7 @@ int main(int argc, char** argv, char** envp) {
   zlog_notice("PIM_UNEXPECTED_KERNEL_UPCALL: report unexpected kernel upcall");
 #endif
 
-  while (thread_fetch(master, &thread))
-    thread_call(&thread);
-
-  zlog_err("%s %s: thread_fetch() returned NULL, exiting",
-          __FILE__, __PRETTY_FUNCTION__);
+  frr_run(master);
 
   /* never reached */
   return 0;
index 3bbd12835d841be38e099299ee55c1059f411ccf..a9382d942f289f61ac82f835c97358a0e961cfe6 100644 (file)
@@ -146,8 +146,6 @@ FRR_DAEMON_INFO(ripd, RIP,
 int
 main (int argc, char **argv)
 {
-  struct thread thread;
-
   frr_preinit (&ripd_di, argc, argv);
   frr_opt_add ("r", longopts,
        "  -r, --retain       When program terminates, retain added route by ripd.\n");
@@ -189,16 +187,7 @@ main (int argc, char **argv)
   rip_peer_init ();
 
   frr_config_fork ();
-
-  /* Create VTY's socket */
-  frr_vty_serv ();
-
-  /* Print banner. */
-  zlog_notice ("RIPd %s starting: vty@%d", FRR_VERSION, ripd_di.vty_port);
-
-  /* Execute each thread. */
-  while (thread_fetch (master, &thread))
-    thread_call (&thread);
+  frr_run (master);
 
   /* Not reached. */
   return (0);
index e63b1ea294d758e4294c0c6b8d9bad9fbdb3757a..c24ca28c364ead04c6b40b28942a6193ed3133bd 100644 (file)
@@ -149,8 +149,6 @@ FRR_DAEMON_INFO(ripngd, RIPNG,
 int
 main (int argc, char **argv)
 {
-  struct thread thread;
-
   frr_preinit (&ripngd_di, argc, argv);
   frr_opt_add ("r", longopts,
        "  -r, --retain       When program terminates, retain added route by ripd.\n");
@@ -188,16 +186,7 @@ main (int argc, char **argv)
   ripng_peer_init ();
 
   frr_config_fork ();
-
-  /* Create VTY socket */
-  frr_vty_serv ();
-
-  /* Print banner. */
-  zlog_notice ("RIPNGd %s starting: vty@%d", FRR_VERSION, ripngd_di.vty_port);
-
-  /* Fetch next active thread. */
-  while (thread_fetch (master, &thread))
-    thread_call (&thread);
+  frr_run (master);
 
   /* Not reached. */
   return 0;
index 3aa40fa92c7a997c087ced3c97ea78db41c0ba90..7177fe329ff423d53b121e4460304a5d26e1524a 100644 (file)
@@ -219,7 +219,6 @@ int
 main (int argc, char **argv)
 {
   // int batch_mode = 0;
-  struct thread thread;
   char *zserv_path = NULL;
   char *fpm_format = NULL;
 
@@ -360,13 +359,7 @@ main (int argc, char **argv)
   /* This must be done only after locking pidfile (bug #403). */
   zebra_zserv_socket_init (zserv_path);
 
-  frr_vty_serv ();
-
-  /* Print banner. */
-  zlog_notice ("Zebra %s starting: vty@%d", FRR_VERSION, zebra_di.vty_port);
-
-  while (thread_fetch (zebrad.master, &thread))
-    thread_call (&thread);
+  frr_run (zebrad.master);
 
   /* Not reached... */
   return 0;