mirror of
https://github.com/ceph/ceph
synced 2025-03-30 07:19:14 +00:00
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 <loic@dachary.org>
This commit is contained in:
parent
38d9613bcb
commit
0b40bbd495
@ -357,6 +357,10 @@ int md_config_t::parse_argv(std::vector<const char*>& 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<const char*>& 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<const char*>& 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;
|
||||
}
|
||||
|
||||
|
@ -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]
|
||||
|
6
src/test/cli/ceph-conf/show-config.t
Normal file
6
src/test/cli/ceph-conf/show-config.t
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user