]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common,config: refactor method md_config_t::_get_val(const char *, char**, int) const
authorYanhu Cao <gmayyyha@gmail.com>
Wed, 14 Jun 2017 01:03:01 +0000 (09:03 +0800)
committerYanhu Cao <gmayyyha@gmail.com>
Thu, 15 Jun 2017 02:50:50 +0000 (10:50 +0800)
Signed-off-by: Yanhu Cao <gmayyyha@gmail.com>
src/common/config.cc

index 32a817deb8c9b380b5630aa02fba6a72161ddb8d..fd6ab3441da5614a1de901da2e4e6b98e7514fc5 100644 (file)
@@ -942,29 +942,21 @@ int md_config_t::_get_val(const char *key, char **buf, int len) const
   if (!key)
     return -EINVAL;
 
-  string k(ConfFile::normalize_key_name(key));
-
-  config_value_t cval = _get_val(k.c_str());
-  if (!boost::get<invalid_config_value_t>(&cval)) {
-    ostringstream oss;
-    if (bool *flagp = boost::get<bool>(&cval)) {
-      oss << (*flagp ? "true" : "false");
-    } else {
-      oss << cval;
-    }
-    string str(oss.str());
-    int l = strlen(str.c_str()) + 1;
+  string val ;
+  if (!_get_val(key, &val)) {
+    int l = val.length() + 1;
     if (len == -1) {
       *buf = (char*)malloc(l);
       if (!*buf)
         return -ENOMEM;
-      strcpy(*buf, str.c_str());
+      strncpy(*buf, val.c_str(), l);
       return 0;
     }
-    snprintf(*buf, len, "%s", str.c_str());
+    snprintf(*buf, len, "%s", val.c_str());
     return (l > len) ? -ENAMETOOLONG : 0;
   }
 
+  string k(ConfFile::normalize_key_name(key));
   // subsys?
   for (int o = 0; o < subsys.get_num(); o++) {
     std::string as_option = "debug_" + subsys.get_name(o);