[Xorp-cvs] SF.net SVN: xorp:[11678] trunk/xorp/rtrmgr

bms_fbsd at users.sourceforge.net bms_fbsd at users.sourceforge.net
Fri Dec 4 08:19:59 PST 2009


Revision: 11678
          http://xorp.svn.sourceforge.net/xorp/?rev=11678&view=rev
Author:   bms_fbsd
Date:     2009-12-04 16:19:58 +0000 (Fri, 04 Dec 2009)

Log Message:
-----------
Allow the Router Manager's paths to the modules and operational
mode commands to be re-targeted, to enable operation when the
FHS compliant directory layout is used.

 * Add util.cc helper functions xorp_module_dir() and xorp_command_dir()
   to facilitate this.
 * Pass module path down to ModuleManager.
 * Add xorp_rtrmgr command line options:
  * -c is the new name for -b, to allow the path to the configuration
    file to be overridden, and to bring it into line with the usual
    expected options for most UNIX daemons.
    * -b is still accepted as an alias for this option, for now.
  * -m allows the path to the modules directory to be overridden.
  * -C allows the path to the operational commands to be overridden.
 * Sort xorp_rtrmgr -h options text alphabetically.
 * Sort getopt() parameters.
 * Add clint FALLTHROUGH to switch cases.
 * s/boot_file/config_file/ 

Modified Paths:
--------------
    trunk/xorp/rtrmgr/main_rtrmgr.cc
    trunk/xorp/rtrmgr/main_rtrmgr.hh
    trunk/xorp/rtrmgr/module_manager.cc
    trunk/xorp/rtrmgr/module_manager.hh
    trunk/xorp/rtrmgr/util.cc
    trunk/xorp/rtrmgr/util.hh

Modified: trunk/xorp/rtrmgr/main_rtrmgr.cc
===================================================================
--- trunk/xorp/rtrmgr/main_rtrmgr.cc	2009-12-04 15:27:20 UTC (rev 11677)
+++ trunk/xorp/rtrmgr/main_rtrmgr.cc	2009-12-04 16:19:58 UTC (rev 11678)
@@ -77,22 +77,29 @@
 // Local state
 //
 static volatile bool	running = false;
+
+static string	module_dir;
+static string	command_dir;
 static string	template_dir;
-static string	boot_file;
+static string	config_file;
+static string	xrl_targets_dir;	// for DEBUG_XRLDB
+
 static bool     do_logfile = false;
 static bool     do_pidfile = false;
 static bool     do_syslog = false;
 static bool	do_exec = default_do_exec;
 static bool	do_restart = default_do_restart;
 static bool	verbose = default_verbose;
+
 list<IPv4>	bind_addrs;
 uint16_t	bind_port = FinderConstants::FINDER_DEFAULT_PORT();
+
 static string	syslogspec;
 static string	logfilename;
 static string	pidfilename;
+
 int32_t		quit_time = -1;
 static bool	daemon_mode = false;
-static string	xrl_targets_dir;	// for DEBUG_XRLDB
 
 static void cleanup_and_exit(int errcode);
 
@@ -108,20 +115,25 @@
     fprintf(stderr, "Usage: %s [options]\n", xorp_basename(argv0));
     fprintf(stderr, "Options:\n");
     fprintf(stderr, "  -a <allowed host> Host allowed by the finder\n");
+    fprintf(stderr, "  -b|-c <file> Specify configuration file\n");
+    fprintf(stderr, "  -C <dir>  Specify operational commands directory\n");
     fprintf(stderr, "  -d        Run in daemon mode in background\n");
+    fprintf(stderr, "  -h        Display this information\n");
+    fprintf(stderr, "  -i <addr> Set or add an interface run Finder on\n");
+    fprintf(stderr, "  -L <facility.priority> Log to syslog facility\n");
     fprintf(stderr, "  -l <file> Log to file <file>\n");
-    fprintf(stderr, "  -L <facility.priority> Log to syslog facility\n");
+    fprintf(stderr, "  -m <dir>  Specify protocol modules directory\n");
+    // This option is only for testing
+    fprintf(stderr, "  -N        Do not execute XRLs and do not start processes\n");
     fprintf(stderr, "  -n <allowed net>  Subnet allowed by the finder\n");
     fprintf(stderr, "  -P <pid>  Write process ID to file <pid>\n");
-    fprintf(stderr, "  -h        Display this information\n");
-    fprintf(stderr, "  -v        Print verbose information\n");
-    fprintf(stderr, "  -b <file> Specify boot file\n");
-    fprintf(stderr, "  -N        Do not execute XRLs and do not start processes\n");
-    fprintf(stderr, "  -r        Restart failed processes (not implemented yet)\n");
-    fprintf(stderr, "  -i <addr> Set or add an interface run Finder on\n");
     fprintf(stderr, "  -p <port> Set port to run Finder on\n");
+    // This option is only for testing
     fprintf(stderr, "  -q <secs> Set forced quit period\n");
+    fprintf(stderr, "  -r        Restart failed processes (not implemented yet)\n");
     fprintf(stderr, "  -t <dir>  Specify templates directory\n");
+    fprintf(stderr, "  -v        Print verbose information\n");
+    // This option is only for testing
 #ifdef DEBUG_XRLDB
     fprintf(stderr,
 	    "  -x <dir>  Specify Xrl targets directory (debug_xrldb)\n");
@@ -132,8 +144,12 @@
 display_defaults()
 {
     fprintf(stderr, "Defaults:\n");
-    fprintf(stderr, "  Boot file                  := %s\n",
-	    xorp_boot_file().c_str());
+    fprintf(stderr, "  Configuration file         := %s\n",
+	    xorp_config_file().c_str());
+    fprintf(stderr, "  Module directory           := %s\n",
+	    xorp_module_dir().c_str());
+    fprintf(stderr, "  Command directory          := %s\n",
+	    xorp_command_dir().c_str());
     fprintf(stderr, "  Templates directory        := %s\n",
 	    xorp_template_dir().c_str());
 #ifdef DEBUG_XRLDB
@@ -165,10 +181,11 @@
     ((MasterTemplateTree*)tt)->add_cmd_action(cmd, action);
 }
 
-
-Rtrmgr::Rtrmgr(const string& template_dir, 
+Rtrmgr::Rtrmgr(const string& module_dir, 
+               const string& command_dir, 
+               const string& template_dir, 
 	       const string& xrl_targets_dir,
-	       const string& boot_file,
+	       const string& config_file,
 	       const list<IPv4>& bind_addrs,
 	       uint16_t bind_port,
 	       bool	do_exec,
@@ -176,9 +193,11 @@
 	       bool	verbose,
 	       int32_t quit_time,
 	       bool daemon_mode)
-    : _template_dir(template_dir),
+    : _module_dir(module_dir),
+      _command_dir(command_dir),
+      _template_dir(template_dir),
       _xrl_targets_dir(xrl_targets_dir),
-      _boot_file(boot_file),
+      _config_file(config_file),
       _bind_addrs(bind_addrs),
       _bind_port(bind_port),
       _do_exec(do_exec),
@@ -229,8 +248,12 @@
     //
     // Print various information
     //
-    XLOG_TRACE(_verbose, "Boot file                  := %s\n",
-	       boot_file.c_str());
+    XLOG_TRACE(_verbose, "Configuration fil          := %s\n",
+	       config_file.c_str());
+    XLOG_TRACE(_verbose, "Module directory           := %s\n",
+	       module_dir.c_str());
+    XLOG_TRACE(_verbose, "Command directory          := %s\n",
+	       command_dir.c_str());
     XLOG_TRACE(_verbose, "Templates directory        := %s\n",
 	       template_dir.c_str());
     XLOG_TRACE(_verbose, "Execute Xrls               := %s\n",
@@ -307,7 +330,7 @@
     // Start the module manager
     //
     ModuleManager mmgr(eventloop, *this, _do_restart, _verbose,
-		       xorp_binary_root_dir());
+		       xorp_binary_root_dir(), module_dir);
 
     try {
 	//
@@ -328,7 +351,7 @@
 	mmgr.set_xrl_interface(_xrt);
 #endif
 
-	_mct = new MasterConfigTree(boot_file, tt, mmgr, xclient, _do_exec,
+	_mct = new MasterConfigTree(config_file, tt, mmgr, xclient, _do_exec,
 				    _verbose);
 	if (_daemon_mode) {
 	    _mct->set_task_completed(callback(this, &Rtrmgr::daemonize));
@@ -530,8 +553,10 @@
     // Expand the default variables to include the XORP root path
     //
     xorp_path_init(argv[0]);
+    module_dir		= xorp_module_dir();
+    command_dir		= xorp_command_dir();
     template_dir	= xorp_template_dir();
-    boot_file		= xorp_boot_file();
+    config_file		= xorp_config_file();
     xrl_targets_dir	= xorp_xrl_targets_dir();
 
 #ifdef DEBUG_XRLDB
@@ -541,12 +566,12 @@
 #endif
 
     static const char* optstring =
-	"da:l:L:n:t:b:" RTRMGR_X_OPT "i:P:p:q:Nrvh";
+	"a:b:c:C:dhi:L:l:m:P:p:q:Nn:rt:v" RTRMGR_X_OPT;
     int c;
     while ((c = getopt(argc, argv, optstring)) != EOF) {
 	switch(c) {
 	case 'd':
-	    daemon_mode = true;
+	    daemon_mode = true;    // XXX must come before other options?
 	    break;
 	case 'a':
 	    //
@@ -561,6 +586,9 @@
 		cleanup_and_exit(1);
 	    }
 	    break;
+	case 'C':
+	    command_dir = optarg;
+	    break;
 	case 'l':
 	    do_logfile = true;
 	    logfilename = optarg;
@@ -569,6 +597,9 @@
 	    do_syslog = true;
 	    syslogspec = optarg;
 	    break;
+	case 'm':
+	    module_dir = optarg;
+	    break;
 	case 'n':
 	    //
 	    // User is specifying a network address to accept finder
@@ -586,7 +617,9 @@
 	    template_dir = optarg;
 	    break;
 	case 'b':
-	    boot_file = optarg;
+	    /* FALLTHROUGH */
+	case 'c':
+	    config_file = optarg;
 	    break;
 #ifdef DEBUG_XRLDB
 	case 'x':
@@ -645,7 +678,9 @@
 	    }
 	    break;
 	case 'h':
+	    /* FALLTHROUGH */
 	case '?':
+	    /* FALLTHROUGH */
 	default:
 	    usage(argv[0]);
 	    display_defaults();
@@ -671,7 +706,8 @@
     //
     // The main procedure
     //
-    Rtrmgr rtrmgr(template_dir, xrl_targets_dir, boot_file, bind_addrs,
+    Rtrmgr rtrmgr(module_dir, command_dir, template_dir, xrl_targets_dir,
+		  config_file, bind_addrs,
 		  bind_port, do_exec, do_restart, verbose, quit_time,
 		  daemon_mode);
     errcode = rtrmgr.run();

Modified: trunk/xorp/rtrmgr/main_rtrmgr.hh
===================================================================
--- trunk/xorp/rtrmgr/main_rtrmgr.hh	2009-12-04 15:27:20 UTC (rev 11677)
+++ trunk/xorp/rtrmgr/main_rtrmgr.hh	2009-12-04 16:19:58 UTC (rev 11678)
@@ -34,9 +34,11 @@
 
 class Rtrmgr {
 public:
-    Rtrmgr(const string& template_dir,
+    Rtrmgr(const string& module_dir,
+	   const string& command_dir,
+	   const string& template_dir,
 	   const string& xrl_targets_dir,
-	   const string& boot_file,
+	   const string& config_file,
 	   const list<IPv4>& bind_addrs,
 	   uint16_t bind_port,
 	   bool	do_exec,
@@ -54,9 +56,11 @@
     bool verbose() const { return _verbose; }
 
 private:
+    string	_module_dir;
+    string	_command_dir;
     string	_template_dir;
-    string	_xrl_targets_dir;
-    string	_boot_file;
+    string	_xrl_targets_dir;        // Only used by DEBUG_XRLDB.
+    string	_config_file;
     list<IPv4>	_bind_addrs;
     uint16_t	_bind_port;
 

Modified: trunk/xorp/rtrmgr/module_manager.cc
===================================================================
--- trunk/xorp/rtrmgr/module_manager.cc	2009-12-04 15:27:20 UTC (rev 11677)
+++ trunk/xorp/rtrmgr/module_manager.cc	2009-12-04 16:19:58 UTC (rev 11678)
@@ -329,13 +329,15 @@
 
 ModuleManager::ModuleManager(EventLoop& eventloop, Rtrmgr& rtrmgr,
 			     bool do_restart, bool verbose,
-			     const string& xorp_root_dir)
+			     const string& xorp_root_dir,
+			     const string& xorp_module_dir)
     : GenericModuleManager(eventloop, verbose),
       _rtrmgr(rtrmgr),
       _master_config_tree(NULL),
       _do_restart(do_restart),
       _verbose(verbose),
-      _xorp_root_dir(xorp_root_dir)
+      _xorp_root_dir(xorp_root_dir),
+      _xorp_module_dir(xorp_module_dir)
 {
 }
 
@@ -359,8 +361,8 @@
 	// The path to the module doesn't starts from the user home directory
 	// and is not an absolute path (in UNIX, DOS or NT UNC form).
 	//
-	// Add the XORP root path to the front
-	expath = xorp_root_dir() + PATH_DELIMITER_STRING + path;
+	// Add the XORP module path to the front
+	expath = xorp_module_dir() + PATH_DELIMITER_STRING + path;
     }
 
     if (! is_absolute_path(expath, false)) {

Modified: trunk/xorp/rtrmgr/module_manager.hh
===================================================================
--- trunk/xorp/rtrmgr/module_manager.hh	2009-12-04 15:27:20 UTC (rev 11677)
+++ trunk/xorp/rtrmgr/module_manager.hh	2009-12-04 16:19:58 UTC (rev 11678)
@@ -166,10 +166,12 @@
      * @param do_restart if true, then restart a module if it failed.
      * @param verbose if true, then output trace messages.
      * @param xorp_root_dir the XORP root directory.
+     * @param xorp_module_dir the XORP module directory.
      */
     ModuleManager(EventLoop& eventloop, Rtrmgr& rtrmgr,
 		  bool do_restart, bool verbose,
-		  const string& xorp_root_dir);
+		  const string& xorp_root_dir,
+		  const string& xorp_module_dir);
 
     /**
      * The default destructor.
@@ -316,6 +318,13 @@
     const string& xorp_root_dir() const { return _xorp_root_dir; }
 
     /**
+     * Get the XORP module directory.
+     *
+     * @return the XORP module directory.
+     */
+    const string& xorp_module_dir() const { return _xorp_module_dir; }
+
+    /**
      * Get the master configuration tree.
      *
      * @return the master configuration tree.
@@ -392,6 +401,7 @@
     bool		_do_restart;	// Set to true to enable module restart
     bool		_verbose;	// Set to true if output is verbose
     string		_xorp_root_dir;	// The root of the XORP tree
+    string		_xorp_module_dir; // Module directory
 };
 
 #endif // __RTRMGR_MODULE_MANAGER_HH__

Modified: trunk/xorp/rtrmgr/util.cc
===================================================================
--- trunk/xorp/rtrmgr/util.cc	2009-12-04 15:27:20 UTC (rev 11677)
+++ trunk/xorp/rtrmgr/util.cc	2009-12-04 16:19:58 UTC (rev 11678)
@@ -33,7 +33,7 @@
 
 static string s_cfg_root;
 static string s_bin_root;
-static string s_boot_file;
+static string s_config_file;
 
 /**
  * Find the directory of executable program.
@@ -117,7 +117,7 @@
     if (xr != NULL) {
 	s_bin_root = xr;
 	s_cfg_root = xr;
-	s_boot_file = s_cfg_root + "/etc/xorp.conf";
+	s_config_file = s_cfg_root + "/etc/xorp.conf";
 	return;
     }
 
@@ -133,11 +133,11 @@
     if (current_root == build_root) {
 	s_bin_root = build_root;
 	s_cfg_root = xorp_real_path(XORP_SRC_ROOT);
-	s_boot_file = s_cfg_root + "/rtrmgr/xorp.conf";
+	s_config_file = s_cfg_root + "/rtrmgr/xorp.conf";
 
 	debug_msg("s_bin_root:   %s\n", s_bin_root.c_str());
 	debug_msg("s_cfg_root:   %s\n", s_cfg_root.c_str());
-	debug_msg("s_boot_file:  %s\n", s_boot_file.c_str());
+	debug_msg("s_config_file:  %s\n", s_config_file.c_str());
 
 	return;
     }
@@ -145,11 +145,11 @@
     string install_root = xorp_real_path(XORP_INSTALL_ROOT);
     s_bin_root = install_root;
     s_cfg_root = install_root;
-    s_boot_file = s_cfg_root + "/etc/xorp.conf";
+    s_config_file = s_cfg_root + "/etc/xorp.conf";
 
     debug_msg("s_bin_root:   %s\n", s_bin_root.c_str());
     debug_msg("s_cfg_root:   %s\n", s_cfg_root.c_str());
-    debug_msg("s_boot_file:  %s\n", s_boot_file.c_str());
+    debug_msg("s_config_file:  %s\n", s_config_file.c_str());
 }
 
 const string&
@@ -165,6 +165,18 @@
 }
 
 string
+xorp_module_dir()
+{
+    return s_cfg_root + string("/lib/xorp/sbin");
+}
+
+string
+xorp_command_dir()
+{
+    return s_cfg_root + string("/lib/xorp/bin");
+}
+
+string
 xorp_template_dir()
 {
     return s_cfg_root + string("/share/xorp/templates");
@@ -177,9 +189,9 @@
 }
 
 string
-xorp_boot_file()
+xorp_config_file()
 {
-    return s_boot_file;
+    return s_config_file;
 }
 
 string&

Modified: trunk/xorp/rtrmgr/util.hh
===================================================================
--- trunk/xorp/rtrmgr/util.hh	2009-12-04 15:27:20 UTC (rev 11677)
+++ trunk/xorp/rtrmgr/util.hh	2009-12-04 16:19:58 UTC (rev 11678)
@@ -34,9 +34,11 @@
  *
  *   @li @ref xorp_binary_root_dir()
  *   @li @ref xorp_config_root_dir()
+ *   @li @ref xorp_module_dir()
+ *   @li @ref xorp_command_dir()
  *   @li @ref xorp_template_dir()
  *   @li @ref xorp_xrl_targets_dir()
- *   @li @ref xorp_boot_file()
+ *   @li @ref xorp_config_file()
  *
  * @param argv0 the argv[0] supplied to main().
  */
@@ -59,6 +61,24 @@
 const string& xorp_config_root_dir();
 
 /**
+ * Return the path of the xorp module directory given the xorp_root
+ * path.
+ *
+ * @ref xorp_path_init() must be called before this method will return a sane
+ * value.
+ */
+string xorp_module_dir();
+
+/**
+ * Return the path of the xorp command directory given the xorp_root
+ * path.
+ *
+ * @ref xorp_path_init() must be called before this method will return a sane
+ * value.
+ */
+string xorp_command_dir();
+
+/**
  * Return the path of the xorp templates directory given the xorp_root
  * path.
  *
@@ -82,7 +102,7 @@
  * @ref xorp_path_init() must be called before this method will return a sane
  * value.
  */
-string xorp_boot_file();
+string xorp_config_file();
 
 /**
  * Remove enclosing quotes from string.


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Xorp-cvs mailing list