]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Fix double dash handling
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 14 Sep 2011 16:53:47 +0000 (09:53 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 14 Sep 2011 16:56:39 +0000 (09:56 -0700)
Several functions examine argv in order to set options. Only the last
argument parsing pass should remove the '--' from the argument vector.
If it is removed earlier than that, entries may be parsed as options,
when that was not the user's intent.

This changes fixes the common argument parsing loops so that they do not
remove the double dash. It also rearranges some programs so that the
user's argument parsing loop comes last, rather than coming before the
common argument parsing loops.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/ceph_argparse.cc
src/common/config.cc
src/librados-config.cc
src/tools/ceph.cc
src/tools/gceph.cc

index 641586de11c5c4669fed9a22fea3fc689ae441a9..027479b316e6c6efaf335a45565fc6d6e721a929 100644 (file)
@@ -344,7 +344,10 @@ CephInitParameters ceph_argparse_early_args
   CephInitParameters iparams(module_type);
   std::string val;
   for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
-    if (ceph_argparse_double_dash(args, i)) {
+    if (strcmp(*i, "--") == 0) {
+      /* Normally we would use ceph_argparse_double_dash. However, in this
+       * function we *don't* want to remove the double dash, because later
+       * argument parses will still need to see it. */
       break;
     }
     else if (ceph_argparse_flag(args, i, "--version", "-v", (char*)NULL)) {
index 22dc4e17697a6ff2249e7f947690e60e69a72e87..7aeb5e2b2a9af9c42a9ed6aac3b68b759288b533 100644 (file)
@@ -609,7 +609,10 @@ parse_argv(std::vector<const char*>& args)
   // observer notifications later.
   std::string val;
   for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
-    if (ceph_argparse_double_dash(args, i)) {
+    if (strcmp(*i, "--") == 0) {
+      /* Normally we would use ceph_argparse_double_dash. However, in this
+       * function we *don't* want to remove the double dash, because later
+       * argument parses will still need to see it. */
       break;
     }
     else if (ceph_argparse_flag(args, i, "--show_conf", (char*)NULL)) {
index ca84724d07f813f39a224de650931d6b00dd6028..9fbef57a0c3b3fafc9f7a8dfae348b6457c51115 100644 (file)
@@ -42,9 +42,15 @@ int main(int argc, const char **argv)
   bool opt_version = false;
   bool opt_vernum = false;
 
+  global_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+  common_init_finish(g_ceph_context);
+
   for (std::vector<const char*>::iterator i = args.begin();
        i != args.end(); ) {
-    if (strcmp(*i, "--version") == 0) {
+    if (strcmp(*i, "--") == 0) {
+      break;
+    }
+    else if (strcmp(*i, "--version") == 0) {
       opt_version = true;
       i = args.erase(i);
     }
@@ -56,9 +62,6 @@ int main(int argc, const char **argv)
       ++i;
   }
 
-  global_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
-  common_init_finish(g_ceph_context);
-
   if (!opt_version && !opt_vernum)
     usage_exit();
 
index 5102d693afd636f436a3740bd86ebbce36a586c7..d602639024150b857692a20d9bcccfe03e4a67af 100644 (file)
@@ -117,14 +117,14 @@ int main(int argc, const char **argv)
   argv_to_vec(argc, argv, args);
   env_to_vec(args);
 
-  // parse user input
-  bool concise = false;
-  parse_cmd_args(args, &in_file, &out_file, &mode, &concise);
-
   // initialize globals
   global_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
   common_init_finish(g_ceph_context);
 
+  // parse user input
+  bool concise = false;
+  parse_cmd_args(args, &in_file, &out_file, &mode, &concise);
+
   // input
   bufferlist indata;
   if (!in_file.empty()) {
index 5557b77529402029d696e356a8184bb92a6bfe57..5270813dd90cc4dbe6d176804baaf36426f78b9c 100644 (file)
@@ -79,10 +79,9 @@ int main(int argc, const char **argv)
   argv_to_vec(argc, argv, args);
   env_to_vec(args);
 
-  parse_gceph_args(args);
   global_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
   common_init_finish(g_ceph_context);
-  vec_to_argv(args, argc, argv);
+  parse_gceph_args(args);
 
   ctx = ceph_tool_common_init(CEPH_TOOL_MODE_GUI, false);
   if (!ctx) {
@@ -92,6 +91,7 @@ int main(int argc, const char **argv)
 
   atexit(ceph_tool_common_shutdown_wrapper);
 
+  vec_to_argv(args, argc, argv);
   if (cephtool_run_gui(ctx, argc, argv))
     ret = 1;