]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
config: expand metavariables for --show-config, --show-config-value
authorSage Weil <sage@newdream.net>
Thu, 5 Apr 2012 21:25:03 +0000 (14:25 -0700)
committerSage Weil <sage@newdream.net>
Thu, 5 Apr 2012 21:25:03 +0000 (14:25 -0700)
Signed-off-by: Sage Weil <sage@newdream.net>
src/common/config.cc
src/common/config.h

index 80b6e199954996cf9c7b92c8a0080ba925dce86d..fe664254a77f1200cb74e31956d3831f9dab19f0 100644 (file)
@@ -314,14 +314,23 @@ int md_config_t::parse_argv(std::vector<const char*>& args)
       _exit(0);
     }
     else if (ceph_argparse_flag(args, i, "--show_config", (char*)NULL)) {
+      expand_all_meta();
       show_config(cout);
       _exit(0);
     }
     else if (ceph_argparse_witharg(args, i, &val, "--show_config_value", (char*)NULL)) {
       char *buf = 0;
-      _get_val(val.c_str(), &buf, -1);
-      if (buf)
-       std::cout << buf << std::endl;
+      int r = _get_val(val.c_str(), &buf, -1);
+      if (r < 0) {
+       if (r == -ENOENT)
+         std::cerr << "failed to get config option '" << val << "': option not found" << std::endl;
+       else
+         std::cerr << "failed to get config option '" << val << "': " << strerror(-r) << std::endl;
+       _exit(1);
+      }
+      string s = buf;
+      expand_meta(s);
+      std::cout << s << std::endl;
       _exit(0);
     }
     else if (ceph_argparse_flag(args, i, "--foreground", "-f", (char*)NULL)) {
@@ -477,14 +486,7 @@ void md_config_t::_apply_changes(std::ostream *oss)
    * have changed. */
   typedef std::map < md_config_obs_t*, std::set <std::string> > rev_obs_map_t;
 
-  // Expand all metavariables
-  for (int i = 0; i < NUM_CONFIG_OPTIONS; i++) {
-    config_option *opt = config_optionsp + i;
-    if (opt->type == OPT_STR) {
-      std::string *str = (std::string *)opt->conf_ptr(this);
-      expand_meta(*str);
-    }
-  }
+  expand_all_meta();
 
   // create the reverse observer mapping, mapping observers to the set of
   // changed keys that they'll get.
@@ -522,14 +524,7 @@ void md_config_t::call_all_observers()
 {
   Mutex::Locker l(lock);
 
-  // Expand all metavariables
-  for (int i = 0; i < NUM_CONFIG_OPTIONS; i++) {
-    config_option *opt = config_optionsp + i;
-    if (opt->type == OPT_STR) {
-      std::string *str = (std::string *)opt->conf_ptr(this);
-      expand_meta(*str);
-    }
-  }
+  expand_all_meta();
 
   std::map<md_config_obs_t*,std::set<std::string> > obs;
   for (obs_map_t::iterator r = observers.begin(); r != observers.end(); ++r)
@@ -820,6 +815,18 @@ static const char *CONF_METAVARIABLES[] =
 static const int NUM_CONF_METAVARIABLES =
       (sizeof(CONF_METAVARIABLES) / sizeof(CONF_METAVARIABLES[0]));
 
+void md_config_t::expand_all_meta()
+{
+  // Expand all metavariables
+  for (int i = 0; i < NUM_CONFIG_OPTIONS; i++) {
+    config_option *opt = config_optionsp + i;
+    if (opt->type == OPT_STR) {
+      std::string *str = (std::string *)opt->conf_ptr(this);
+      expand_meta(*str);
+    }
+  }
+}
+
 bool md_config_t::expand_meta(std::string &val) const
 {
   assert(lock.is_locked());
index 274a4c81756561286faa4d866d5a2eba4d672e13..fec3f46c393e35c019017b850f3e6f2bedc9ea49 100644 (file)
@@ -160,6 +160,9 @@ private:
   // Returns true if any metavariables were found and expanded.
   bool expand_meta(std::string &val) const;
 
+  /// expand all metavariables in config structure.
+  void expand_all_meta();
+
   // The configuration file we read, or NULL if we haven't read one.
   ConfFile cf;