diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2016-11-14 01:56:02 +0100 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2017-03-08 00:15:39 +0100 |
commit | 16077f2fc5f4d73648b4ebef877e1f021864358d (patch) | |
tree | 73d9eb31cab0943147924a5d93c938021682df36 | |
parent | *: add frr_config_fork() (diff) | |
download | frr-16077f2fc5f4d73648b4ebef877e1f021864358d.tar.xz frr-16077f2fc5f4d73648b4ebef877e1f021864358d.zip |
*: add frr_run()
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>
-rw-r--r-- | bgpd/bgp_main.c | 19 | ||||
-rw-r--r-- | isisd/isis_main.c | 12 | ||||
-rw-r--r-- | ldpd/ldpd.c | 11 | ||||
-rw-r--r-- | lib/libfrr.c | 21 | ||||
-rw-r--r-- | lib/libfrr.h | 4 | ||||
-rw-r--r-- | nhrpd/nhrp_main.c | 12 | ||||
-rw-r--r-- | ospf6d/ospf6_main.c | 15 | ||||
-rw-r--r-- | ospfd/ospf_main.c | 12 | ||||
-rw-r--r-- | pimd/pim_main.c | 13 | ||||
-rw-r--r-- | ripd/rip_main.c | 13 | ||||
-rw-r--r-- | ripngd/ripng_main.c | 13 | ||||
-rw-r--r-- | zebra/main.c | 9 |
12 files changed, 40 insertions, 114 deletions
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index 00c9576e0..ba95a5607 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -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); diff --git a/isisd/isis_main.c b/isisd/isis_main.c index 49b988b29..8c48c7e27 100644 --- a/isisd/isis_main.c +++ b/isisd/isis_main.c @@ -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); diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index f2ed70eda..205449db3 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -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); diff --git a/lib/libfrr.c b/lib/libfrr.c index ad85c6f89..570d9724d 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -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); +} diff --git a/lib/libfrr.h b/lib/libfrr.h index e7e209f60..ae4a5176a 100644 --- a/lib/libfrr.h +++ b/lib/libfrr.h @@ -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[]; diff --git a/nhrpd/nhrp_main.c b/nhrpd/nhrp_main.c index e1192205e..963399985 100644 --- a/nhrpd/nhrp_main.c +++ b/nhrpd/nhrp_main.c @@ -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; } diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index 2d5ae02fb..6c994189e 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -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); diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index ee5815832..47aa6c63e 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -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); diff --git a/pimd/pim_main.c b/pimd/pim_main.c index f446e33af..ba1c511d1 100644 --- a/pimd/pim_main.c +++ b/pimd/pim_main.c @@ -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; diff --git a/ripd/rip_main.c b/ripd/rip_main.c index 3bbd12835..a9382d942 100644 --- a/ripd/rip_main.c +++ b/ripd/rip_main.c @@ -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); diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c index e63b1ea29..c24ca28c3 100644 --- a/ripngd/ripng_main.c +++ b/ripngd/ripng_main.c @@ -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; diff --git a/zebra/main.c b/zebra/main.c index 3aa40fa92..7177fe329 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -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; |