]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cconf: remove second argument to cconf --lookup
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 22 Feb 2011 17:00:21 +0000 (09:00 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 23 Feb 2011 18:17:30 +0000 (10:17 -0800)
Everyone uses get_conf to get configuration values. So the logic for
defaulting to some value if we can't find the requested key should live
there. Also fix a case in cconf where we could encounter a usage error
and keep on going.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/cconf.cc
src/ceph_common.sh

index 24935de5dbad394c995bc8ef25142f97f5e6a1fe..cb25aadb67134440c48e8f65c4b7b035f52c72f9 100644 (file)
@@ -37,11 +37,9 @@ cconf <flags> <action>\n\
 \n\
 ACTIONS\n\
   -l|--list-sections <prefix>     List sections in prefix\n\
-  --lookup <key> [defval]         Print a configuration setting to stdout.\n\
-                                 If the setting is not defined, and the\n\
-                                 optional argument defval is provide, it will\n\
-                                 be printed instead. variables in defval are\n\
-                                 interpolated.\n\
+  --lookup <key>                  Print a configuration setting to stdout.\n\
+                                  Returns 0 (success) if the configuration setting is\n\
+                                 found; 1 otherwise.\n\
   -r|--resolve-search             search for the first file that exists and\n\
                                   can be opened in the resulted comma\n\
                                   delimited search list.\n\
@@ -62,11 +60,6 @@ List sections beginning with 'mon'.\n\
 RETURN CODE\n\
 Return code will be 0 on success; error code otherwise.\n\
 ";
-}
-
-void error_exit()
-{
-  usage();
   exit(1);
 }
 
@@ -96,9 +89,8 @@ static void print_val(const char *val, bool resolve_search)
   }
 }
 
-static int lookup_impl(const deque<const char *> &sections,
-                   const char *key, const char *defval,
-                    bool resolve_search)
+static int lookup(const deque<const char *> &sections,
+                 const char *key, bool resolve_search)
 {
   char *val = NULL;
   if (!g_conf.cf)
@@ -119,49 +111,6 @@ static int lookup_impl(const deque<const char *> &sections,
     }
   }
 
-  if (defval) {
-    val = conf_post_process_val(defval);
-    if (val) {
-      print_val(val, resolve_search);
-      free(val);
-      return 0;
-    }
-  }
-
-  {
-    // TODO: document exactly what we are doing here?
-    std::vector<const char *> empty_args;
-    bool force_fg_logging = false;
-    parse_startup_config_options(empty_args, type,
-                        STARTUP_FLAG_FORCE_FG_LOGGING, &force_fg_logging);
-    char buf[1024];
-    memset(buf, 0, sizeof(buf));
-    if (ceph_def_conf_by_name(key, buf, sizeof(buf))) {
-      print_val(buf, resolve_search);
-      return 0;
-    }
-  }
-
-  return 1;
-}
-
-static int lookup(const deque<const char *> &sections,
-                 const vector<const char*> &nargs,
-                 vector<const char*>::const_iterator n,
-                  bool resolve_search)
-{
-  const char *key = *n;
-  ++n;
-  if (n == nargs.end())
-    return lookup_impl(sections, key, NULL, resolve_search);
-  const char *defval = *n;
-  ++n;
-  if (n == nargs.end())
-    return lookup_impl(sections, key, defval, resolve_search);
-
-  cerr << "lookup: Too many arguments. Expected only 1 or 2."
-       << std::endl;
-  error_exit();
   return 1;
 }
 
@@ -213,18 +162,22 @@ int main(int argc, const char **argv)
 
   if (do_list) {
     if (nargs.size() != 1)
-      error_exit();
+      usage();
     return list_sections(nargs[0]);
   } else if (do_lookup) {
-    if (nargs.size() < 1 || nargs.size() > 2)
-      error_exit();
-    vector<const char*>::const_iterator n = nargs.begin();
-    return lookup(sections, nargs, n, resolve_search);
+    if (nargs.size() != 1) {
+      cerr << "lookup: expected exactly one argument" << std::endl;
+      usage();
+    }
+    return lookup(sections, nargs[0], resolve_search);
   } else if ((nargs.size() >= 1) && (nargs[0][0] == '-')) {
     cerr << "Parse error at argument: " << nargs[0] << std::endl;
-    error_exit();
+    usage();
   } else {
-    vector<const char*>::const_iterator n = nargs.begin();
-    return lookup(sections, nargs, n, resolve_search);
+    if (nargs.size() != 1) {
+      cerr << "lookup: expected exactly one argument" << std::endl;
+      usage();
+    }
+    return lookup(sections, nargs[0], resolve_search);
   }
 }
index f8567f8b269ce53874b665fbb47e85407a74d849..99c6e8f54560d52075cfecd42fa414cb2ccfef59 100644 (file)
@@ -146,8 +146,8 @@ get_conf() {
        key=$3
        shift; shift; shift
 
-       [ $verbose -eq 1 ] && echo "$CCONF -c $conf -i $id -t $type $tmp \"$key\" \"$def\""
-       eval "$var=\"`$CCONF -c $conf -i $id -t $type $tmp \"$key\" \"$def\"`\""
+       [ "$verbose" -eq 1 ] && echo "$CCONF -c $conf -i $id -t $type \"$key\""
+       eval "$var=\"`$CCONF -c $conf -i $id -t $type \"$key\" || eval echo -n \"$def\"`\""
 }
 
 get_conf_bool() {