Skip to content

Commit

Permalink
Fix command line argument parsing in main.
Browse files Browse the repository at this point in the history
Command line arguments are parsed twice in Scylla: once in main and once in Seastar's app_template::run.
The first parse is there to check if the "--version" flag is present --- in this case the version is printed
and the program exists.  The second parsing is correct; however, most of the arguments were improperly treated
as positional arguments during the first parsing (e.g., "--network host" would treat "host" as a positional argument).
This happened because the arguments weren't known to the command line parser.
This commit fixes the issue by moving the parsing code until after the arguments are registered.
Resolves #4141.

Signed-off-by: Kamil Braun <kbraun@scylladb.com>
(cherry picked from commit f155a2d)
  • Loading branch information
kbr-scylla authored and avikivity committed Aug 13, 2019
1 parent a198db3 commit ff8265d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions main.cc
Expand Up @@ -302,15 +302,7 @@ int main(int ac, char** av) {
auto cfg = make_lw_shared<db::config>(ext);
auto init = app.get_options_description().add_options();

// If --version is requested, print it out and exit immediately to avoid
// Seastar-specific warnings that may occur when running the app
init("version", bpo::bool_switch(), "print version number and exit");
bpo::variables_map vm;
bpo::store(bpo::command_line_parser(ac, av).options(app.get_options_description()).allow_unregistered().run(), vm);
if (vm["version"].as<bool>()) {
print("%s\n", scylla_version());
return 0;
}

bpo::options_description deprecated("Deprecated options - ignored");
deprecated.add_options()
Expand All @@ -324,6 +316,15 @@ int main(int ac, char** av) {
configurable::append_all(*cfg, init);
cfg->add_options(init);

// If --version is requested, print it out and exit immediately to avoid
// Seastar-specific warnings that may occur when running the app
bpo::variables_map vm;
bpo::store(bpo::command_line_parser(ac, av).options(app.get_options_description()).allow_unregistered().run(), vm);
if (vm["version"].as<bool>()) {
print("%s\n", scylla_version());
return 0;
}

distributed<database> db;
seastar::sharded<service::cache_hitrate_calculator> cf_cache_hitrate_calculator;
debug::db = &db;
Expand Down

0 comments on commit ff8265d

Please sign in to comment.