Skip to content
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

Merged
merged 2 commits into from Sep 15, 2017

Conversation

Yan-waller
Copy link
Contributor

@Yan-waller Yan-waller commented Sep 12, 2017

@@ -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);
Copy link
Contributor

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.

Copy link
Contributor Author

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);

@@ -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,
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trociny and @jdurgin what do you think?

Copy link
Contributor

@trociny trociny Sep 12, 2017

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;
      }

@Yan-waller Yan-waller force-pushed the wip-walle-0912moninjectargs branch 3 times, most recently from 6118a27 to 102b76e Compare September 13, 2017 06:21
@Yan-waller
Copy link
Contributor Author

@tchaikov I have fixed it as you and trociny's suggestions, could you help to take a look again? thanks.

as_option.c_str(), (char*)NULL)) {
if (!err.str().empty()) {
Copy link
Contributor

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()

// 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);
Copy link
Contributor

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>
Signed-off-by: Yan Jun <yan.jun8@zte.com.cn>
@Yan-waller
Copy link
Contributor Author

@tchaikov thanks, have done it. and incidentally, I adjust all ASSERT_EQ in daemon_config.cc file as another commit.

@Yan-waller
Copy link
Contributor Author

retest this please

@tchaikov tchaikov merged commit 3643063 into ceph:master Sep 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants