New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
common: fix daemon abnormal exit at parsing invalid arguments #17664
Conversation
src/common/config.cc
Outdated
@@ -492,7 +492,7 @@ int md_config_t::parse_argv(std::vector<const char*>& args) | |||
set_val_or_die("client_mountpoint", val.c_str()); | |||
} | |||
else { | |||
parse_option(args, i, NULL); | |||
parse_option(args, i, &cerr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think it is advisable to pass cerr
here. if the caller does not expect error message on stderr, we should not. and stderr
is not always available. instead, i'd suggest return -EINVAL
here. and add a simple test in src/test/daemon_config.cc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the original logic, cerr
is finally passed in to va_ceph_argparse_witharg(,,,cerr,)
, I'm not sure is this a minimal change that conform to original intent ?..
parse_option(args, i, NULL); ->
ceph_argparse_witharg(args, i, &val,
as_option.c_str(), (char*)NULL)); ->
va_ceph_argparse_witharg(args, i, ret, cerr, ap);
src/common/config.cc
Outdated
@@ -536,9 +536,11 @@ int md_config_t::parse_option(std::vector<const char*>& args, | |||
std::string as_option("--"); | |||
as_option += "debug_"; | |||
as_option += subsys.get_name(o); | |||
if (ceph_argparse_witharg(args, i, &val, | |||
if (ceph_argparse_witharg(args, i, &val, *oss, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead i think we should update all ceph_argparse_witharg()/ceph_argparse_binary_flag()
and their caller sites, so it returns an integer instead of a boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, ceph_argparse_witharg()/ceph_argparse_binary_flag()
interface looks unfortunate. Still I am not sure it worth changing at this stage.
Although we can't use the return value to tell if parsing failed, it looks it is safe to assume it failed if something was printed to stream provides as std::ostream &oss
param.
I.e. I think the reported problem could be fixed by something like this:
ostringstream err;
if (ceph_argparse_witharg(args, i, &val, err,
as_option.c_str(), (char*)NULL)) {
if (!err.str().empty()) {
if (oss) {
*oss << err.str();
}
ret = -EINVAL;
break;
}
6118a27
to
102b76e
Compare
@tchaikov I have fixed it as you and trociny's suggestions, could you help to take a look again? thanks. |
src/common/config.cc
Outdated
as_option.c_str(), (char*)NULL)) { | ||
if (!err.str().empty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, use tellp()
instead of err.str().empty()
src/test/daemon_config.cc
Outdated
// We should complain about the missing arguments. | ||
std::string injection3("--log-graylog-port 28 --debug_ms"); | ||
ret = g_ceph_context->_conf->injectargs(injection3, &cout); | ||
ASSERT_EQ(ret, -EINVAL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ASSERT_EQ(-EINVAL, ret);
as the 1st param is the expected value, the second one is the actual value.
Signed-off-by: Yan Jun <yan.jun8@zte.com.cn>
102b76e
to
ccaba81
Compare
Signed-off-by: Yan Jun <yan.jun8@zte.com.cn>
@tchaikov thanks, have done it. and incidentally, I adjust all ASSERT_EQ in |
retest this please |
Fixes: http://tracker.ceph.com/issues/21338
Signed-off-by: Yan Jun yan.jun8@zte.com.cn