From: songweibin Date: Thu, 30 May 2019 11:58:03 +0000 (+0800) Subject: rbd/action: fix error getting positional argument X-Git-Tag: v14.2.3~100^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ff2629bf889e303e0b31d0726f409c1262d659d5;p=ceph.git rbd/action: fix error getting positional argument Fixes: http://tracker.ceph.com/issues/40095 Signed-off-by: songweibin (cherry picked from commit 32a044b0911aef248aec4f6dda6171693b7c9280) --- diff --git a/src/tools/rbd/action/Config.cc b/src/tools/rbd/action/Config.cc index 40093172ff84..2868c7ad1d74 100644 --- a/src/tools/rbd/action/Config.cc +++ b/src/tools/rbd/action/Config.cc @@ -676,7 +676,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; diff --git a/src/tools/rbd/action/ImageMeta.cc b/src/tools/rbd/action/ImageMeta.cc index 1ea7413d1543..20c4555dab58 100644 --- a/src/tools/rbd/action/ImageMeta.cc +++ b/src/tools/rbd/action/ImageMeta.cc @@ -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; diff --git a/src/tools/rbd/action/Lock.cc b/src/tools/rbd/action/Lock.cc index 4ede92450802..754cb384c3ef 100644 --- a/src/tools/rbd/action/Lock.cc +++ b/src/tools/rbd/action/Lock.cc @@ -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;