]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd/action: fix error getting positional argument
authorsongweibin <song.weibin@zte.com.cn>
Thu, 30 May 2019 11:58:03 +0000 (19:58 +0800)
committersongweibin <song.weibin@zte.com.cn>
Thu, 30 May 2019 23:51:32 +0000 (07:51 +0800)
Fixes: http://tracker.ceph.com/issues/40095
Signed-off-by: songweibin <song.weibin@zte.com.cn>
src/tools/rbd/action/Config.cc
src/tools/rbd/action/ImageMeta.cc
src/tools/rbd/action/Lock.cc

index ebff7aaf7d8526ad44539148db80ef64010c648c..8e8165524de52e474467141344155f589a1f40e4 100644 (file)
@@ -675,7 +675,11 @@ int execute_image_set(const po::variables_map &vm,
     return r;
   }
 
-  std::string value = utils::get_positional_argument(vm, 2);
+  std::string value = utils::get_positional_argument(vm, arg_index);
+  if (value.empty()) {
+    std::cerr << "rbd: image config value was not specified" << std::endl;
+    return -EINVAL;
+  }
 
   librados::Rados rados;
   librados::IoCtx io_ctx;
index 1ea7413d154341ad774fab4eabc01671d832af83..20c4555dab588e7144f500b94247d00be8327d96 100644 (file)
@@ -256,7 +256,7 @@ int execute_set(const po::variables_map &vm,
     return r;
   }
 
-  std::string value = utils::get_positional_argument(vm, 2);
+  std::string value = utils::get_positional_argument(vm, arg_index);
   if (value.empty()) {
     std::cerr << "rbd: metadata value was not specified" << std::endl;
     return -EINVAL;
index 4ede9245080219536a47523c21819222c30f482e..754cb384c3efc7c72904aff8adfc3ea2cee0b6ba 100644 (file)
@@ -24,11 +24,14 @@ void add_id_option(po::options_description *positional) {
     ("lock-id", "unique lock id");
 }
 
-int get_id(const po::variables_map &vm, std::string *id) {
-  *id = utils::get_positional_argument(vm, 1);
+int get_id(const po::variables_map &vm, size_t *arg_index,
+           std::string *id) {
+  *id = utils::get_positional_argument(vm, *arg_index);
   if (id->empty()) {
     std::cerr << "rbd: lock id was not specified" << std::endl;
     return -EINVAL;
+  } else {
+    ++(*arg_index);
   }
   return 0;
 }
@@ -172,7 +175,7 @@ int execute_add(const po::variables_map &vm,
   }
 
   std::string lock_cookie;
-  r = get_id(vm, &lock_cookie);
+  r = get_id(vm, &arg_index, &lock_cookie);
   if (r < 0) {
     return r;
   }
@@ -233,12 +236,12 @@ int execute_remove(const po::variables_map &vm,
   }
 
   std::string lock_cookie;
-  r = get_id(vm, &lock_cookie);
+  r = get_id(vm, &arg_index, &lock_cookie);
   if (r < 0) {
     return r;
   }
 
-  std::string lock_client = utils::get_positional_argument(vm, 2);
+  std::string lock_client = utils::get_positional_argument(vm, arg_index);
   if (lock_client.empty()) {
     std::cerr << "rbd: locker was not specified" << std::endl;
     return -EINVAL;