From 0b40bbd49507b1c3a5b75badd5eff6696d59cf6b Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Mon, 30 Dec 2013 10:30:51 +0100 Subject: [PATCH] common: evaluate --show-config* after CEPH_ARGS The content of CEPH_ARGS is appended to the list of arguments. When --show-config or --show-config-value is also set, it should be evaluated after all arguments are parsed to accurately reflect the value that would be visible to the program. It failed to do so because the action for --show-config* was carried out immediately. It is postponed until all options are parsed instead. Signed-off-by: Loic Dachary --- src/common/config.cc | 48 ++++++++++++++-------- src/test/cli/ceph-conf/show-config-value.t | 5 +++ src/test/cli/ceph-conf/show-config.t | 6 +++ 3 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 src/test/cli/ceph-conf/show-config.t diff --git a/src/common/config.cc b/src/common/config.cc index 5c64f4ec151..50923956cc1 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -357,6 +357,10 @@ int md_config_t::parse_argv(std::vector& args) return -ENOSYS; } + bool show_config = false; + bool show_config_value = false; + string show_config_value_arg; + // In this function, don't change any parts of the configuration directly. // Instead, use set_val to set them. This will allow us to send the proper // observer notifications later. @@ -373,24 +377,11 @@ int md_config_t::parse_argv(std::vector& args) _exit(0); } else if (ceph_argparse_flag(args, i, "--show_config", (char*)NULL)) { - expand_all_meta(); - _show_config(&cout, NULL); - _exit(0); + show_config = true; } else if (ceph_argparse_witharg(args, i, &val, "--show_config_value", (char*)NULL)) { - char *buf = 0; - int r = _get_val(val.c_str(), &buf, -1); - if (r < 0) { - if (r == -ENOENT) - std::cerr << "failed to get config option '" << val << "': option not found" << std::endl; - else - std::cerr << "failed to get config option '" << val << "': " << strerror(-r) << std::endl; - _exit(1); - } - string s = buf; - expand_meta(s); - std::cout << s << std::endl; - _exit(0); + show_config_value = true; + show_config_value_arg = val; } else if (ceph_argparse_flag(args, i, "--foreground", "-f", (char*)NULL)) { set_val_or_die("daemonize", "false"); @@ -429,6 +420,31 @@ int md_config_t::parse_argv(std::vector& args) parse_option(args, i, NULL); } } + + if (show_config) { + expand_all_meta(); + _show_config(&cout, NULL); + _exit(0); + } + + if (show_config_value) { + char *buf = 0; + int r = _get_val(show_config_value_arg.c_str(), &buf, -1); + if (r < 0) { + if (r == -ENOENT) + std::cerr << "failed to get config option '" << + show_config_value_arg << "': option not found" << std::endl; + else + std::cerr << "failed to get config option '" << + show_config_value_arg << "': " << strerror(-r) << std::endl; + _exit(1); + } + string s = buf; + expand_meta(s); + std::cout << s << std::endl; + _exit(0); + } + return 0; } diff --git a/src/test/cli/ceph-conf/show-config-value.t b/src/test/cli/ceph-conf/show-config-value.t index 03d7ed8e086..3d7d319416c 100644 --- a/src/test/cli/ceph-conf/show-config-value.t +++ b/src/test/cli/ceph-conf/show-config-value.t @@ -3,3 +3,8 @@ $ ceph-conf -n osd.0 --show-config-value log_file -c /dev/null /var/log/ceph/ceph-osd.0.log + $ CEPH_ARGS="--fsid 96a3abe6-7552-4635-a79b-f3c096ff8b95" ceph-conf -n osd.0 --show-config-value fsid -c /dev/null + 96a3abe6-7552-4635-a79b-f3c096ff8b95 + $ ceph-conf -n osd.0 --show-config-value INVALID -c /dev/null + failed to get config option 'INVALID': option not found + [1] diff --git a/src/test/cli/ceph-conf/show-config.t b/src/test/cli/ceph-conf/show-config.t new file mode 100644 index 00000000000..cfd723997c8 --- /dev/null +++ b/src/test/cli/ceph-conf/show-config.t @@ -0,0 +1,6 @@ + $ ceph-conf -n osd.0 --show-config -c /dev/null | grep ceph-osd + admin_socket = /var/run/ceph/ceph-osd.0.asok + log_file = /var/log/ceph/ceph-osd.0.log + mon_debug_dump_location = /var/log/ceph/ceph-osd.0.tdump + $ CEPH_ARGS="--fsid 96a3abe6-7552-4635-a79b-f3c096ff8b95" ceph-conf -n osd.0 --show-config -c /dev/null | grep fsid + fsid = 96a3abe6-7552-4635-a79b-f3c096ff8b95 -- 2.47.3