summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'bgpd/bgp_main.c')
-rw-r--r--bgpd/bgp_main.c92
1 files changed, 42 insertions, 50 deletions
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 60b66533..38fbb7e4 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -18,15 +18,15 @@ along with GNU Zebra; see the file COPYING. If not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
-#include <zebra.h>
-#include <stdbool.h>
+#include "zebra.h"
+#include "misc.h"
#include "vector.h"
#include "vty.h"
#include "command.h"
#include "getopt.h"
#include "thread.h"
-#include <lib/version.h>
+#include "lib/version.h"
#include "memory.h"
#include "prefix.h"
#include "log.h"
@@ -118,13 +118,13 @@ static zebra_capabilities_t _caps_p [] =
struct zebra_privs_t bgpd_privs =
{
#if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
- .user = QUAGGA_USER,
- .group = QUAGGA_GROUP,
+ .user = QUAGGA_USER,
+ .group = QUAGGA_GROUP,
#endif
#ifdef VTY_GROUP
.vty_group = VTY_GROUP,
#endif
- .caps_p = _caps_p,
+ .caps_p = _caps_p,
.cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
.cap_num_i = 0,
};
@@ -184,7 +184,7 @@ void sigusr2 (void);
/* prototypes */
static void bgp_exit (int);
-static void init_second_stage(int pthreads);
+static void init_second_stage(bool pthreads);
static void bgp_in_thread_init(void);
static void routing_start(void) ;
static void routing_finish(void) ;
@@ -206,10 +206,6 @@ static struct quagga_signal_t bgp_signals[] =
.handler = &sigusr1,
},
{
- .signal = SIGUSR2,
- .handler = &sigusr2,
- },
- {
.signal = SIGINT,
.handler = &sigint,
},
@@ -240,14 +236,17 @@ sighup (void)
}
-/* SIGINT handler. */
+/* SIGINT and SIGTERM handler. */
void
sigint (void)
{
zlog_notice ("Terminating on signal");
+ vty_reset_because("Terminating");
+
/* tell the routing engine to send notifies to peers and wait
- * for all sessions to be disabled */
+ * for all sessions to be disabled, then terminate.
+ */
sigterm_enqueue();
}
@@ -258,17 +257,6 @@ sigusr1 (void)
zlog_rotate (NULL);
}
-/* SIGUSR2 handler. */
-void
-sigusr2 (void)
-{
- /* Used to signal message queues */
- if (qpthreads_enabled)
- return;
- else
- exit(1);
-}
-
/*------------------------------------------------------------------------------
* Final exit code...
*
@@ -301,6 +289,7 @@ bgp_exit (int status)
/* reverse bgp_zebra_init/if_init */
if (retain_mode)
if_add_hook (IF_DELETE_HOOK, NULL);
+
for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
{
struct listnode *c_node, *c_nnode;
@@ -351,6 +340,7 @@ bgp_exit (int status)
cmd_terminate ();
vty_terminate ();
+
if (zclient)
zclient_free (zclient);
if (zlookup)
@@ -366,10 +356,10 @@ bgp_exit (int status)
if (qpthreads_enabled)
{
- qpn_reset_free(routing_nexus);
- qpn_reset_free(bgp_nexus);
+ qpn_reset(routing_nexus, free_it);
+ qpn_reset(bgp_nexus, free_it);
} ;
- cli_nexus = qpn_reset_free(cli_nexus);
+ cli_nexus = qpn_reset(cli_nexus, free_it);
if (CONF_BGP_DEBUG (normal, NORMAL))
log_memstats_stderr ("bgpd");
@@ -388,8 +378,8 @@ bgp_exit (int status)
*
* 1. if it's there, invoke the command in the usual way
*
- * 2. if it's not there, invoke the command but with a NULL set of arguments,
- * which signals the "default" nature of the call.
+ * 2. if it's not there, invoke the command but with a *negative* count of
+ * arguments, which signals the "default" nature of the call.
*
* This mechanism is used so that the "threaded_cmd" is the time at which
* second stage initialisation is done. (But only once -- not on rereading
@@ -404,8 +394,8 @@ DEFUN_HID_CALL (threaded,
"threaded",
"Use pthreads\n")
{
- if (argv != NULL)
- config_threaded = 1 ; /* Explicit command => turn on threading */
+ if (argc == 0)
+ config_threaded = true ; /* Explicit command => turn on threading */
if (!done_2nd_stage_init)
init_second_stage(config_threaded) ;
@@ -421,7 +411,7 @@ DEFUN_HID_CALL (threaded,
* the message queues are available for the configuration data.
*/
static void
-init_second_stage(int pthreads)
+init_second_stage(bool pthreads)
{
assert(!done_2nd_stage_init) ;
@@ -431,13 +421,13 @@ init_second_stage(int pthreads)
bgp_peer_index_mutex_init();
/* Make nexus for main thread, always needed */
- cli_nexus = qpn_init_new(cli_nexus, 1); /* main thread */
+ cli_nexus = qpn_init_new(cli_nexus, true); /* main thread */
/* if using pthreads create additional nexus */
if (qpthreads_enabled)
{
- bgp_nexus = qpn_init_new(bgp_nexus, 0);
- routing_nexus = qpn_init_new(routing_nexus, 0);
+ bgp_nexus = qpn_init_new(bgp_nexus, false);
+ routing_nexus = qpn_init_new(routing_nexus, false);
}
else
{
@@ -495,9 +485,8 @@ main (int argc, char **argv)
/* Set umask before anything for security */
umask (0027);
-#ifdef QDEBUG
- fprintf(stderr, "%s\n", debug_banner);
-#endif
+ if (qdebug)
+ fprintf(stderr, "%s\n", debug_banner);
qlib_init_first_stage();
@@ -599,7 +588,11 @@ main (int argc, char **argv)
/* Initializations. */
srand (time (NULL));
signal_init (master, Q_SIGC(bgp_signals), bgp_signals);
- zprivs_init (&bgpd_privs);
+
+ cmd_getcwd() ; /* while have privilege */
+
+ zprivs_init (&bgpd_privs); /* lowers privileges */
+
cmd_init (1);
install_element (CONFIG_NODE, &threaded_cmd);
vty_init (master);
@@ -648,9 +641,9 @@ main (int argc, char **argv)
vty_start(vty_addr, vty_port, BGP_VTYSH_PATH);
/* Print banner. */
-#ifdef QDEBUG
- zlog_notice("%s", debug_banner);
-#endif
+ if (qdebug)
+ zlog_notice("%s", debug_banner);
+
zlog_notice ("BGPd %s%s starting: vty@%d, bgp@%s:%d",
QUAGGA_VERSION,
(qpthreads_enabled ? " pthreaded" : ""),
@@ -725,8 +718,6 @@ routing_background(void)
/*------------------------------------------------------------------------------
* SIGHUP: message sent to Routeing engine and the action it then takes.
- *
- * TODO: should SIGHUP be a priority message (!)
*/
static void
sighup_enqueue(void)
@@ -744,16 +735,17 @@ sighup_action(mqueue_block mqb, mqb_flag_t flag)
{
zlog_info ("bgpd restarting!");
- bgp_terminate (0, 0); /* send notifies */
+ bgp_terminate (false, false); /* send notifies */
bgp_reset ();
- /* Reload config file. */
- vty_read_config (config_file, config_default);
+ /* Reload config file -- no special first command, now */
+ vty_read_config_first_cmd_special(config_file, config_default,
+ NULL, config_ignore_warnings) ;
- /* Create VTY's socket */
+ /* Create VTY's socket */
vty_restart(vty_addr, vty_port, BGP_VTYSH_PATH);
- /* Try to return to normal operation. */
+ /* Try to return to normal operation. */
}
mqb_free(mqb);
@@ -807,7 +799,7 @@ sigterm_action(mqueue_block mqb, mqb_flag_t flag)
*/
program_terminating = true ;
- bgp_terminate(1, retain_mode);
+ bgp_terminate(true, retain_mode);
qpn_add_hook_function(&routing_nexus->foreground,
program_terminate_if_all_peers_deleted) ;