]> git.ipfire.org Git - thirdparty/bird.git/blobdiff - sysdep/unix/main.c
Unix: Remove removed option from help
[thirdparty/bird.git] / sysdep / unix / main.c
index 61b306dce60ebd747d17bd6fe1d1a1714c675a5a..921115b1a9cff12568e6ebe7a3bd0f7548fb27ff 100644 (file)
@@ -8,7 +8,9 @@
 
 #undef LOCAL_DEBUG
 
-#define _GNU_SOURCE 1
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -25,6 +27,7 @@
 #include "lib/resource.h"
 #include "lib/socket.h"
 #include "lib/event.h"
+#include "lib/timer.h"
 #include "lib/string.h"
 #include "nest/route.h"
 #include "nest/protocol.h"
  *     Debugging
  */
 
-#ifdef DEBUGGING
-static int debug_flag = 1;
-#else
-static int debug_flag = 0;
-#endif
-
 void
 async_dump(void)
 {
@@ -54,7 +51,7 @@ async_dump(void)
 
   rdump(&root_pool);
   sk_dump_all();
-  tm_dump_all();
+  // XXXX tm_dump_all();
   if_dump_all();
   neigh_dump_all();
   rta_dump_all();
@@ -69,11 +66,11 @@ async_dump(void)
  */
 
 #ifdef CONFIG_RESTRICTED_PRIVILEGES
-#include "lib/syspriv.h"
+#include CONFIG_INCLUDE_SYSPRIV_H
 #else
 
 static inline void
-drop_uid(uid_t uid)
+drop_uid(uid_t uid UNUSED)
 {
   die("Cannot change user on this platform");
 }
@@ -96,7 +93,7 @@ drop_gid(gid_t gid)
 static inline void
 add_num_const(char *name, int val)
 {
-  struct symbol *s = cf_find_symbol(name);
+  struct symbol *s = cf_get_symbol(name);
   s->class = SYM_CONSTANT | T_INT;
   s->def = cfg_allocz(sizeof(struct f_val));
   SYM_TYPE(s) = T_INT;
@@ -129,7 +126,7 @@ read_iproute_table(char *file, char *prefix, int max)
 
     if (*p == '#' || *p == '\n' || *p == 0)
       continue;
-   
+
     if (sscanf(p, "0x%x %s\n", &val, name) != 2 &&
        sscanf(p, "0x%x %s #", &val, name) != 2 &&
        sscanf(p, "%d %s\n", &val, name) != 2 &&
@@ -155,7 +152,7 @@ read_iproute_table(char *file, char *prefix, int max)
 static char *config_name = PATH_CONFIG_FILE;
 
 static int
-cf_read(byte *dest, unsigned int len, int fd)
+cf_read(byte *dest, uint len, int fd)
 {
   int l = read(fd, dest, len);
   if (l < 0)
@@ -168,6 +165,9 @@ sysdep_preconfig(struct config *c)
 {
   init_list(&c->logfiles);
 
+  c->latency_limit = UNIX_DEFAULT_LATENCY_LIMIT;
+  c->watchdog_warning = UNIX_DEFAULT_WATCHDOG_WARNING;
+
 #ifdef PATH_IPROUTE_DIR
   read_iproute_table(PATH_IPROUTE_DIR "/rt_protos", "ipp_", 256);
   read_iproute_table(PATH_IPROUTE_DIR "/rt_realms", "ipr_", 256);
@@ -179,7 +179,7 @@ sysdep_preconfig(struct config *c)
 int
 sysdep_commit(struct config *new, struct config *old UNUSED)
 {
-  log_switch(debug_flag, &new->logfiles, new->syslog_name);
+  log_switch(0, &new->logfiles, new->syslog_name);
   return 0;
 }
 
@@ -207,7 +207,7 @@ read_config(void)
   if (!unix_read_config(&conf, config_name))
     {
       if (conf->err_msg)
-       die("%s, line %d: %s", conf->err_file_name, conf->err_lino, conf->err_msg);
+       die("%s:%d:%d %s", conf->err_file_name, conf->err_lino, conf->err_chno, conf->err_msg);
       else
        die("Unable to open configuration file %s: %m", config_name);
     }
@@ -224,7 +224,7 @@ async_config(void)
   if (!unix_read_config(&conf, config_name))
     {
       if (conf->err_msg)
-       log(L_ERR "%s, line %d: %s", conf->err_file_name, conf->err_lino, conf->err_msg);
+       log(L_ERR "%s:%d:%d %s", conf->err_file_name, conf->err_lino, conf->err_chno, conf->err_msg);
       else
        log(L_ERR "Unable to open configuration file %s: %m", config_name);
       config_free(conf);
@@ -245,7 +245,7 @@ cmd_read_config(char *name)
   if (!unix_read_config(&conf, name))
     {
       if (conf->err_msg)
-       cli_msg(8002, "%s, line %d: %s", conf->err_file_name, conf->err_lino, conf->err_msg);
+       cli_msg(8002, "%s:%d:%d %s", conf->err_file_name, conf->err_lino, conf->err_chno, conf->err_msg);
       else
        cli_msg(8002, "%s: %m", name);
       config_free(conf);
@@ -297,7 +297,7 @@ cmd_reconfig_undo_notify(void)
 }
 
 void
-cmd_reconfig(char *name, int type, int timeout)
+cmd_reconfig(char *name, int type, uint timeout)
 {
   if (cli_access_restricted())
     return;
@@ -416,7 +416,7 @@ cli_get_command(cli *c)
 }
 
 static int
-cli_rx(sock *s, int size UNUSED)
+cli_rx(sock *s, uint size UNUSED)
 {
   cli_kick(s->data);
   return 0;
@@ -436,7 +436,7 @@ cli_err(sock *s, int err)
 }
 
 static int
-cli_connect(sock *s, int size UNUSED)
+cli_connect(sock *s, uint size UNUSED)
 {
   cli *c;
 
@@ -447,6 +447,7 @@ cli_connect(sock *s, int size UNUSED)
   s->err_hook = cli_err;
   s->data = c = cli_new(s);
   s->pool = c->pool;           /* We need to have all the socket buffers allocated in the cli pool */
+  s->fast_rx = 1;
   c->rx_pos = c->rx_buf;
   c->rx_aux = NULL;
   rmove(s, c->pool);
@@ -463,6 +464,7 @@ cli_init_unix(uid_t use_uid, gid_t use_gid)
   s->type = SK_UNIX_PASSIVE;
   s->rx_hook = cli_connect;
   s->rbsize = 1024;
+  s->fast_rx = 1;
 
   /* Return value intentionally ignored */
   unlink(path_control_socket);
@@ -514,7 +516,7 @@ write_pid_file(void)
   rv = ftruncate(pid_fd, 0);
   if (rv < 0)
     die("fruncate: %m");
-    
+
   rv = write(pid_fd, ps, pl);
   if(rv < 0)
     die("write: %m");
@@ -564,6 +566,10 @@ sysdep_shutdown_done(void)
  *     Signals
  */
 
+volatile int async_config_flag;
+volatile int async_dump_flag;
+volatile int async_shutdown_flag;
+
 static void
 handle_sighup(int sig UNUSED)
 {
@@ -585,6 +591,8 @@ handle_sigterm(int sig UNUSED)
   async_shutdown_flag = 1;
 }
 
+void watchdog_sigalrm(int sig UNUSED);
+
 static void
 signal_init(void)
 {
@@ -600,6 +608,9 @@ signal_init(void)
   sa.sa_handler = handle_sigterm;
   sa.sa_flags = SA_RESTART;
   sigaction(SIGTERM, &sa, NULL);
+  sa.sa_handler = watchdog_sigalrm;
+  sa.sa_flags = 0;
+  sigaction(SIGALRM, &sa, NULL);
   signal(SIGPIPE, SIG_IGN);
 }
 
@@ -607,7 +618,7 @@ signal_init(void)
  *     Parsing of command-line arguments
  */
 
-static char *opt_list = "c:dD:ps:P:u:g:fR";
+static char *opt_list = "bc:dD:ps:P:u:g:flRh";
 static int parse_and_exit;
 char *bird_name;
 static char *use_user;
@@ -615,10 +626,43 @@ static char *use_group;
 static int run_in_foreground = 0;
 
 static void
-usage(void)
+display_usage(void)
 {
-  fprintf(stderr, "Usage: %s [-c <config-file>] [-d] [-D <debug-file>] [-p] [-s <control-socket>] [-P <pid-file>] [-u <user>] [-g <group>] [-f] [-R]\n", bird_name);
-  exit(1);
+  fprintf(stderr, "Usage: %s [--version] [--help] [-c <config-file>] [OPTIONS]\n", bird_name);
+}
+
+static void
+display_help(void)
+{
+  display_usage();
+
+  fprintf(stderr,
+    "\n"
+    "Options: \n"
+    "  -c <config-file>     Use given configuration file instead of\n"
+    "                       "  PATH_CONFIG_FILE "\n"
+    "  -d                   Enable debug messages and run bird in foreground\n"
+    "  -D <debug-file>      Log debug messages to given file instead of stderr\n"
+    "  -f                   Run bird in foreground\n"
+    "  -g <group>           Use given group ID\n"
+    "  -h, --help           Display this information\n"
+    "  -l                   Look for a configuration file and a control socket\n"
+    "                       in the current working directory\n"
+    "  -p                   Test configuration file and exit without start\n"
+    "  -P <pid-file>        Create a PID file with given filename\n"
+    "  -R                   Apply graceful restart recovery after start\n"
+    "  -s <control-socket>  Use given filename for a control socket\n"
+    "  -u <user>            Drop privileges and use given user ID\n"
+    "  --version            Display version of BIRD\n");
+
+  exit(0);
+}
+
+static void
+display_version(void)
+{
+  fprintf(stderr, "BIRD version " BIRD_VERSION "\n");
+  exit(0);
 }
 
 static inline char *
@@ -667,7 +711,7 @@ get_gid(const char *s)
 
   if (!s)
     return 0;
-  
+
   errno = 0;
   rv = strtol(s, &endptr, 10);
 
@@ -684,37 +728,38 @@ get_gid(const char *s)
 static void
 parse_args(int argc, char **argv)
 {
+  int config_changed = 0;
+  int socket_changed = 0;
   int c;
 
   bird_name = get_bird_name(argv[0], "bird");
   if (argc == 2)
     {
       if (!strcmp(argv[1], "--version"))
-       {
-         fprintf(stderr, "BIRD version " BIRD_VERSION "\n");
-         exit(0);
-       }
+       display_version();
       if (!strcmp(argv[1], "--help"))
-       usage();
+       display_help();
     }
   while ((c = getopt(argc, argv, opt_list)) >= 0)
     switch (c)
       {
       case 'c':
        config_name = optarg;
+       config_changed = 1;
        break;
       case 'd':
-       debug_flag |= 1;
+       log_init_debug("");
+       run_in_foreground = 1;
        break;
       case 'D':
        log_init_debug(optarg);
-       debug_flag |= 2;
        break;
       case 'p':
        parse_and_exit = 1;
        break;
       case 's':
        path_control_socket = optarg;
+       socket_changed = 1;
        break;
       case 'P':
        pid_file = optarg;
@@ -728,14 +773,28 @@ parse_args(int argc, char **argv)
       case 'f':
        run_in_foreground = 1;
        break;
+      case 'l':
+       if (!config_changed)
+         config_name = xbasename(config_name);
+       if (!socket_changed)
+         path_control_socket = xbasename(path_control_socket);
+       break;
       case 'R':
        graceful_restart_recovery();
        break;
+      case 'h':
+       display_help();
+       break;
       default:
-       usage();
+       fputc('\n', stderr);
+       display_usage();
+       exit(1);
       }
   if (optind < argc)
-    usage();
+   {
+     display_usage();
+     exit(1);
+   }
 }
 
 /*
@@ -751,16 +810,16 @@ main(int argc, char **argv)
 #endif
 
   parse_args(argc, argv);
-  if (debug_flag == 1)
-    log_init_debug("");
-  log_switch(debug_flag, NULL, NULL);
+  log_switch(1, NULL, NULL);
 
+  net_init();
   resource_init();
+  timer_init();
   olock_init();
   io_init();
   rt_init();
   if_init();
-  roa_init();
+//  roa_init();
   config_init();
 
   uid_t use_uid = get_uid(use_user);
@@ -790,7 +849,7 @@ main(int argc, char **argv)
   if (parse_and_exit)
     exit(0);
 
-  if (!(debug_flag||run_in_foreground))
+  if (!run_in_foreground)
     {
       pid_t pid = fork();
       if (pid < 0)