]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Synchronize signals to the main select/event/timer loop.
authorMartin Mares <mj@ucw.cz>
Sat, 13 Feb 1999 19:43:21 +0000 (19:43 +0000)
committerMartin Mares <mj@ucw.cz>
Sat, 13 Feb 1999 19:43:21 +0000 (19:43 +0000)
Parse command line options.

sysdep/unix/io.c
sysdep/unix/main.c
sysdep/unix/unix.h

index bb8f8afa4420c25eecc1774495ae81a55e0b2504..d8713f4c4990f1050f4dc2f8a842201c8567e530 100644 (file)
@@ -677,6 +677,9 @@ sk_dump_all(void)
  *     Main I/O Loop
  */
 
+volatile int async_config_flag;                /* Asynchronous reconfiguration/dump scheduled */
+volatile int async_dump_flag;
+
 void
 io_init(void)
 {
@@ -735,6 +738,24 @@ io_loop(void)
            }
        }
 
+      /*
+       * Yes, this is racy. But even if the signal comes before this test
+       * and entering select(), it gets caught on the next timer tick.
+       */
+
+      if (async_config_flag)
+       {
+         async_config();
+         async_config_flag = 0;
+       }
+      if (async_dump_flag)
+       {
+         async_dump();
+         async_dump_flag = 0;
+       }
+
+      /* And finally enter select() to find active sockets */
+
       hi = select(hi+1, &rd, &wr, NULL, &timo);
       if (hi < 0)
        {
index d49b6f00f2ee3baf529b29e26ee97a3be9a206c8..7b306539cf4bd17f6e931a9a9085af6e44dad033 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/signal.h>
  *     Debugging
  */
 
-static void
-handle_sigusr(int sig)
+void
+async_dump(void)
 {
-  debug("SIGUSR1: Debugging dump...\n\n");
+  debug("INTERNAL STATE DUMP\n\n");
 
   sk_dump_all();
   tm_dump_all();
@@ -45,23 +46,12 @@ handle_sigusr(int sig)
   debug("\n");
 }
 
-static void
-signal_init(void)
-{
-  static struct sigaction sa;
-
-  sa.sa_handler = handle_sigusr;
-  sa.sa_flags = SA_RESTART;
-  if (sigaction(SIGUSR1, &sa, NULL) < 0)
-    die("sigaction: %m");
-  signal(SIGPIPE, SIG_IGN);
-}
-
 /*
  *     Reading the Configuration
  */
 
 static int conf_fd;
+static char *config_name = PATH_CONFIG;
 
 static int
 cf_read(byte *dest, unsigned int len)
@@ -75,27 +65,101 @@ cf_read(byte *dest, unsigned int len)
 static void
 read_config(void)
 {
-  struct config *conf = config_alloc(PATH_CONFIG);
+  struct config *conf = config_alloc(config_name);
 
-  conf_fd = open(PATH_CONFIG, O_RDONLY);
+  conf_fd = open(config_name, O_RDONLY);
   if (conf_fd < 0)
-    die("Unable to open configuration file " PATH_CONFIG ": %m");
+    die("Unable to open configuration file %s: %m", config_name);
   cf_read_hook = cf_read;
   if (!config_parse(conf))
-    die(PATH_CONFIG ", line %d: %s", conf->err_lino, conf->err_msg);
+    die("%s, line %d: %s", config_name, conf->err_lino, conf->err_msg);
   config_commit(conf);
 }
 
+void
+async_config(void)
+{
+  debug("Asynchronous reconfigurations are not supported in demo version\n");
+}
+
+/*
+ *     Signals
+ */
+
+static void
+handle_sighup(int sig)
+{
+  debug("Caught SIGHUP...\n");
+  async_config_flag = 1;
+}
+
+static void
+handle_sigusr(int sig)
+{
+  debug("Caught SIGUSR...\n");
+  async_dump_flag = 1;
+}
+
+static void
+signal_init(void)
+{
+  struct sigaction sa;
+
+  bzero(&sa, sizeof(sa));
+  sa.sa_handler = handle_sigusr;
+  sa.sa_flags = SA_RESTART;
+  sigaction(SIGUSR1, &sa, NULL);
+  sa.sa_handler = handle_sighup;
+  sa.sa_flags = SA_RESTART;
+  sigaction(SIGHUP, &sa, NULL);
+  signal(SIGPIPE, SIG_IGN);
+}
+
+/*
+ *     Parsing of command-line arguments
+ */
+
+static char *opt_list = "c:d:";
+
+static void
+usage(void)
+{
+  fprintf(stderr, "Usage: bird [-c <config-file>] [-d <debug-file>]\n");
+  exit(1);
+}
+
+static void
+parse_args(int argc, char **argv)
+{
+  int c;
+
+  while ((c = getopt(argc, argv, opt_list)) >= 0)
+    switch (c)
+      {
+      case 'c':
+       config_name = optarg;
+       break;
+      case 'd':
+       log_init_debug(optarg);
+       break;
+      default:
+       usage();
+      }
+  if (optind < argc)
+    usage();
+}
+
 /*
  *     Hic Est main()
  */
 
 int
-main(void)
+main(int argc, char **argv)
 {
-  log(L_INFO "Launching BIRD 0.0.0...");
-
   log_init_debug(NULL);
+  parse_args(argc, argv);
+
+  log(L_INFO "Launching BIRD 0.0.0...");
 
   debug("Initializing.\n");
   resource_init();
@@ -115,7 +179,7 @@ main(void)
   protos_start();
 
   ev_run_list(&global_event_list);
-  handle_sigusr(0);
+  async_dump();
 
   debug("Entering I/O loop.\n");
 
index c25f3edbb754a3910af9e1b57a5a93f3a9b8f3a2..a79db2ed0000e49eed4ad068e4edb0515950634e 100644 (file)
@@ -9,8 +9,16 @@
 #ifndef _BIRD_UNIX_H_
 #define _BIRD_UNIX_H_
 
+/* main.c */
+
+void async_config(void);
+void async_dump(void);
+
 /* io.c */
 
+volatile int async_config_flag;
+volatile int async_dump_flag;
+
 void io_init(void);
 void io_loop(void);
 void fill_in_sockaddr(struct sockaddr_in *sa, ip_addr a, unsigned port);