]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
conf: cconf return default values from config.cc if not found
authorYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 5 Oct 2010 22:02:01 +0000 (15:02 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 5 Oct 2010 22:02:01 +0000 (15:02 -0700)
src/cconf.cc
src/config.cc
src/config.h

index 5cf1503c24d36485a64c2de4c557cd7c0c7082dd..f483c2ce6817806e13e96c222fa34ff796834b5b 100644 (file)
@@ -32,6 +32,8 @@ int main(int argc, const char **argv)
   vector<const char*> args, nargs;
   deque<const char *> sections;
   unsigned i;
+  std::vector<const char *> empty_args;
+  char buf[1024];
   DEFINE_CONF_VARS(usage);
 
   argv_to_vec(argc, argv, args);
@@ -110,6 +112,10 @@ int main(int argc, const char **argv)
     goto done_ok;
   }
 
+  parse_startup_config_options(empty_args, type);
+  if (ceph_def_conf_by_name(key, buf, sizeof(buf)))
+    cout << buf << std::endl;
+
   exit(1);
 
 done_ok:
index 2270ca0038af81e7997fdbaac2898403085221d4..a2bf9341d5c6c124af34c872e1868a8b9d972d13 100644 (file)
@@ -741,6 +741,58 @@ static bool init_g_conf()
   return true;
 }
 
+static int def_conf_to_str(config_option *opt, char *buf, int len)
+{
+  int ret = 0;
+
+  switch (opt->type) {
+  case OPT_INT:
+  case OPT_BOOL:
+    ret = snprintf(buf, len, "%d", (int)opt->def_longlong);
+    break;
+  case OPT_LONGLONG:
+    ret = snprintf(buf, len, "%lld", opt->def_longlong);
+    break;
+  case OPT_STR:
+  case OPT_ADDR:
+    ret = snprintf(buf, len, "%s", opt->def_str);
+    break;
+  case OPT_FLOAT:
+  case OPT_DOUBLE:
+    ret = snprintf(buf, len, "%f", opt->def_double);
+    break;
+  default:
+    break;
+  }
+  return ret;
+}
+
+int ceph_def_conf_by_name(const char *name, char *buf, int buflen)
+{
+  char *newname = strdup(name);
+  int len = strlen(name);
+  config_option *opt;
+  int ret = 0;
+  int i;
+
+  for (i = 0; i < len; i++) {
+    if (newname[i] == ' ')
+      newname[i] = '_';
+  }
+
+  len = sizeof(config_optionsp)/sizeof(config_option);
+
+  for (i = 0; i < len; i++) {
+    opt = &config_optionsp[i];
+    if (strcmp(opt->name, newname) == 0) {
+      ret = def_conf_to_str(opt, buf, buflen);
+      break;
+    }
+  }
+  free(newname);
+  return ret;
+}
+
 static void fini_g_conf()
 {
   int len = sizeof(config_optionsp)/sizeof(config_option);
index 013301a9e65948e15e1c4519fc186c36287d46bd..d04f6be7937d65edbd2bd39640f354938dde84b7 100644 (file)
@@ -482,6 +482,7 @@ char *conf_post_process_val(const char *val);
 int conf_read_key(const char *alt_section, const char *key, opt_type_t type, void *out, void *def, bool free_old_val = false);
 bool conf_set_conf_val(void *field, opt_type_t type, const char *val);
 bool conf_cmd_equals(const char *cmd, const char *opt, char char_opt, unsigned int *val_pos);
+int ceph_def_conf_by_name(const char *name, char *buf, int len);
 
 class ExportControl;
 ExportControl *conf_get_export_control();