diff options
author | Shaun Verch <shaun.verch@10gen.com> | 2013-10-18 18:22:30 -0400 |
---|---|---|
committer | Shaun Verch <shaun.verch@10gen.com> | 2013-10-23 19:41:30 -0400 |
commit | 89218f62b7ad5114df7e956bec47b4c1f96f1fed (patch) | |
tree | 93a8e4deccf34642057a8d3e7a98b5093a8a9c73 /src | |
parent | 107978292c125ebb6674ad57548f1a4dc8f977d1 (diff) | |
download | mongo-89218f62b7ad5114df7e956bec47b4c1f96f1fed.tar.gz |
SERVER-11144 Do not call _exit directly in any options handling functions
Diffstat (limited to 'src')
30 files changed, 300 insertions, 241 deletions
diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp index b13621ba69c..d4e305622bd 100644 --- a/src/mongo/db/mongod_options.cpp +++ b/src/mongo/db/mongod_options.cpp @@ -409,24 +409,24 @@ namespace mongo { } } // namespace - Status handlePreValidationMongodOptions(const moe::Environment& params, + bool handlePreValidationMongodOptions(const moe::Environment& params, const std::vector<std::string>& args) { if (params.count("help")) { printMongodHelp(moe::startupOptions); - ::_exit(EXIT_SUCCESS); + return true; } if (params.count("version")) { cout << mongodVersion() << endl; printGitVersion(); printOpenSSLVersion(); - ::_exit(EXIT_SUCCESS); + return true; } if (params.count("sysinfo")) { sysRuntimeInfo(); - ::_exit(EXIT_SUCCESS); + return true; } - return Status::OK(); + return false; } Status storeMongodOptions(const moe::Environment& params, @@ -434,8 +434,7 @@ namespace mongo { Status ret = storeServerOptions(params, args); if (!ret.isOK()) { - std::cerr << "Error storing command line: " << ret.toString() << std::endl; - ::_exit(EXIT_BADOPTIONS); + return ret; } if (params.count("dbpath")) { @@ -486,8 +485,8 @@ namespace mongo { } if ((params.count("nodur") || params.count("nojournal")) && (params.count("dur") || params.count("journal"))) { - std::cerr << "Can't specify both --journal and --nojournal options." << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "Can't specify both --journal and --nojournal options."); } if (params.count("nodur") || params.count("nojournal")) { @@ -509,8 +508,8 @@ namespace mongo { params["journalCommitInterval"].as<unsigned>(); if (storageGlobalParams.journalCommitInterval <= 1 || storageGlobalParams.journalCommitInterval > 300) { - std::cerr << "--journalCommitInterval out of allowed range (0-300ms)" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "--journalCommitInterval out of allowed range (0-300ms)"); } } if (params.count("journalOptions")) { @@ -524,8 +523,8 @@ namespace mongo { } if (params.count("httpinterface")) { if (params.count("nohttpinterface")) { - std::cerr << "can't have both --httpinterface and --nohttpinterface" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "can't have both --httpinterface and --nohttpinterface"); } serverGlobalParams.isHttpInterfaceEnabled = true; } @@ -569,15 +568,14 @@ namespace mongo { if (params.count("diaglog")) { int x = params["diaglog"].as<int>(); if ( x < 0 || x > 7 ) { - std::cerr << "can't interpret --diaglog setting" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "can't interpret --diaglog setting"); } _diaglog.setLevel(x); } if ((params.count("dur") || params.count("journal")) && params.count("repair")) { - std::cerr << "Can't specify both --journal and --repair options." << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "Can't specify both --journal and --repair options."); } if (params.count("repair")) { @@ -608,10 +606,9 @@ namespace mongo { if (params.count("autoresync")) { replSettings.autoresync = true; if( params.count("replSet") ) { - std::cerr << "--autoresync is not used with --replSet\nsee " - << "http://dochub.mongodb.org/core/resyncingaverystalereplicasetmember" - << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "--autoresync is not used with --replSet\nsee " + "http://dochub.mongodb.org/core/resyncingaverystalereplicasetmember"); } } if (params.count("source")) { @@ -623,12 +620,10 @@ namespace mongo { } if (params.count("replSet")) { if (params.count("slavedelay")) { - std::cerr << "--slavedelay cannot be used with --replSet" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "--slavedelay cannot be used with --replSet"); } else if (params.count("only")) { - std::cerr << "--only cannot be used with --replSet" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "--only cannot be used with --replSet"); } /* seed list of hosts for the repl set */ replSettings.replSet = params["replSet"].as<string>().c_str(); @@ -645,8 +640,7 @@ namespace mongo { if( params.count("nssize") ) { int x = params["nssize"].as<int>(); if (x <= 0 || x > (0x7fffffff/1024/1024)) { - std::cerr << "bad --nssize arg" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "bad --nssize arg"); } storageGlobalParams.lenForNewNsFiles = x * 1024 * 1024; verify(storageGlobalParams.lenForNewNsFiles > 0); @@ -654,16 +648,14 @@ namespace mongo { if (params.count("oplogSize")) { long long x = params["oplogSize"].as<int>(); if (x <= 0) { - std::cerr << "bad --oplogSize arg" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "bad --oplogSize arg"); } // note a small size such as x==1 is ok for an arbiter. if( x > 1000 && sizeof(void*) == 4 ) { StringBuilder sb; - std::cerr << "--oplogSize of " << x - << "MB is too big for 32 bit version. Use 64 bit build instead." - << std::endl; - ::_exit(EXIT_BADOPTIONS); + sb << "--oplogSize of " << x + << "MB is too big for 32 bit version. Use 64 bit build instead."; + return Status(ErrorCodes::BadValue, sb.str()); } replSettings.oplogSize = x * 1024 * 1024; verify(replSettings.oplogSize > 0); @@ -671,11 +663,9 @@ namespace mongo { if (params.count("cacheSize")) { long x = params["cacheSize"].as<long>(); if (x <= 0) { - std::cerr << "bad --cacheSize arg" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "bad --cacheSize arg"); } - std::cerr << "--cacheSize option not currently supported" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "--cacheSize option not currently supported"); } if (!params.count("port")) { if( params.count("configsvr") ) { @@ -683,25 +673,23 @@ namespace mongo { } if( params.count("shardsvr") ) { if( params.count("configsvr") ) { - std::cerr << "can't do --shardsvr and --configsvr at the same time" - << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "can't do --shardsvr and --configsvr at the same time"); } serverGlobalParams.port = ServerGlobalParams::ShardServerPort; } } else { if (serverGlobalParams.port <= 0 || serverGlobalParams.port > 65535) { - std::cerr << "bad --port number" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "bad --port number"); } } if ( params.count("configsvr" ) ) { serverGlobalParams.configsvr = true; storageGlobalParams.smallfiles = true; // config server implies small files if (replSettings.usingReplSets() || replSettings.master || replSettings.slave) { - std::cerr << "replication should not be enabled on a config server" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "replication should not be enabled on a config server"); } if (!params.count("nodur") && !params.count("nojournal")) storageGlobalParams.dur = true; @@ -719,9 +707,8 @@ namespace mongo { } if (params.count("noMoveParanoia") && params.count("moveParanoia")) { - std::cerr << "The moveParanoia and noMoveParanoia flags cannot both be set; " - << "please use only one of them." << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "The moveParanoia and noMoveParanoia flags cannot both be set"); } if (params.count("noMoveParanoia")) @@ -731,28 +718,27 @@ namespace mongo { serverGlobalParams.moveParanoia = true; if (params.count("pairwith") || params.count("arbiter") || params.count("opIdMem")) { - std::cerr << "****\n" - << "Replica Pairs have been deprecated. Invalid options: --pairwith, " - << "--arbiter, and/or --opIdMem\n" - << "<http://dochub.mongodb.org/core/replicapairs>\n" - << "****" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "****\n" + "Replica Pairs have been deprecated. Invalid options: " + "--pairwith, --arbiter, and/or --opIdMem\n" + "<http://dochub.mongodb.org/core/replicapairs>\n" + "****"); } // needs to be after things like --configsvr parsing, thus here. if (params.count("repairpath")) { storageGlobalParams.repairpath = params["repairpath"].as<string>(); if (!storageGlobalParams.repairpath.size()) { - std::cerr << "repairpath is empty" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "repairpath is empty"); } if (storageGlobalParams.dur && !str::startsWith(storageGlobalParams.repairpath, storageGlobalParams.dbpath)) { - std::cerr << "You must use a --repairpath that is a subdirectory of " - << "--dbpath when using journaling" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "You must use a --repairpath that is a subdirectory of --dbpath when " + "using journaling"); } } else { @@ -779,11 +765,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongodOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongodOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongodOptions(moe::startupOptionsParsed, context->args())) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -796,7 +781,14 @@ namespace mongo { // getGlobalAuthorizationManager(). ("EndStartupOptionStorage")) (InitializerContext* context) { - return storeMongodOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongodOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } // namespace mongo diff --git a/src/mongo/db/mongod_options.h b/src/mongo/db/mongod_options.h index 5c4fef64c0c..83498414c46 100644 --- a/src/mongo/db/mongod_options.h +++ b/src/mongo/db/mongod_options.h @@ -58,7 +58,7 @@ namespace mongo { void printMongodHelp(const moe::OptionSection& options); - Status handlePreValidationMongodOptions(const moe::Environment& params, + bool handlePreValidationMongodOptions(const moe::Environment& params, const std::vector<std::string>& args); Status storeMongodOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/dbtests/framework_options.cpp b/src/mongo/dbtests/framework_options.cpp index e9f864453c3..ab32f9c0c61 100644 --- a/src/mongo/dbtests/framework_options.cpp +++ b/src/mongo/dbtests/framework_options.cpp @@ -129,11 +129,11 @@ namespace mongo { return sb.str(); } - Status handlePreValidationTestFrameworkOptions(const moe::Environment& params, + bool handlePreValidationTestFrameworkOptions(const moe::Environment& params, const std::vector<std::string>& args) { if (params.count("help")) { std::cout << getTestFrameworkHelp(args[0], moe::startupOptions) << std::endl; - ::_exit(EXIT_SUCCESS); + return true; } if (params.count("list")) { @@ -143,10 +143,10 @@ namespace mongo { std::cout << *i << std::endl; } - ::_exit(EXIT_SUCCESS); + return true; } - return Status::OK(); + return false; } Status storeTestFrameworkOptions(const moe::Environment& params, @@ -195,10 +195,10 @@ namespace mongo { try { if (boost::filesystem::exists(p)) { if (!boost::filesystem::is_directory(p)) { - std::cerr << "ERROR: path \"" << p.string() << "\" is not a directory" - << std::endl; - std::cerr << getTestFrameworkHelp(args[0], moe::startupOptions) << std::endl; - ::_exit(EXIT_BADOPTIONS); + StringBuilder sb; + sb << "ERROR: path \"" << p.string() << "\" is not a directory"; + sb << getTestFrameworkHelp(args[0], moe::startupOptions); + return Status(ErrorCodes::BadValue, sb.str()); } boost::filesystem::directory_iterator end_iter; for (boost::filesystem::directory_iterator dir_iter(p); @@ -211,8 +211,9 @@ namespace mongo { } } catch (const boost::filesystem::filesystem_error& e) { - std::cerr << "boost::filesystem threw exception: " << e.what() << std::endl; - ::_exit(EXIT_BADOPTIONS); + StringBuilder sb; + sb << "boost::filesystem threw exception: " << e.what(); + return Status(ErrorCodes::BadValue, sb.str()); } string dbpathString = p.string(); @@ -267,12 +268,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(FrameworkOptions)(InitializerContext* context) { - Status ret = handlePreValidationTestFrameworkOptions(moe::startupOptionsParsed, - context->args()); - if (!ret.isOK()) { - return ret; + if (handlePreValidationTestFrameworkOptions(moe::startupOptionsParsed, context->args())) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -280,6 +279,13 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(FrameworkOptions)(InitializerContext* context) { - return storeTestFrameworkOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeTestFrameworkOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/dbtests/framework_options.h b/src/mongo/dbtests/framework_options.h index 7ee10eb456a..1bf6acccb9f 100644 --- a/src/mongo/dbtests/framework_options.h +++ b/src/mongo/dbtests/framework_options.h @@ -45,7 +45,7 @@ namespace mongo { std::string getTestFrameworkHelp(const StringData& name, const moe::OptionSection& options); - Status preValidationTestFrameworkOptions(const moe::Environment& params, + bool handlePreValidationTestFrameworkOptions(const moe::Environment& params, const std::vector<std::string>& args); Status storeTestFrameworkOptions(const moe::Environment& params, diff --git a/src/mongo/s/mongos_options.cpp b/src/mongo/s/mongos_options.cpp index 6f29e4796e1..160e601ed8b 100644 --- a/src/mongo/s/mongos_options.cpp +++ b/src/mongo/s/mongos_options.cpp @@ -132,18 +132,24 @@ namespace mongo { std::cout << options.helpString() << std::endl; }; - Status handlePreValidationMongosOptions(const moe::Environment& params, + bool handlePreValidationMongosOptions(const moe::Environment& params, const std::vector<std::string>& args) { if (params.count("help")) { printMongosHelp(moe::startupOptions); - ::_exit(EXIT_SUCCESS); + return true; } if (params.count("version")) { printShardingVersionInfo(true); - ::_exit(EXIT_SUCCESS); + return true; + } + if ( params.count( "test" ) ) { + ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity( + ::mongo::logger::LogSeverity::Debug(5)); + StartupTest::runTests(); + return true; } - return Status::OK(); + return false; } Status storeMongosOptions(const moe::Environment& params, @@ -151,8 +157,7 @@ namespace mongo { Status ret = storeServerOptions(params, args); if (!ret.isOK()) { - std::cerr << "Error storing command line: " << ret.toString() << std::endl; - ::_exit(EXIT_BADOPTIONS); + return ret; } if ( params.count( "chunkSize" ) ) { @@ -160,21 +165,19 @@ namespace mongo { // validate chunksize before proceeding if ( csize == 0 ) { - std::cerr << "error: need a non-zero chunksize" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "error: need a non-zero chunksize"); } if ( !Chunk::setMaxChunkSizeSizeMB( csize ) ) { - std::cerr << "MaxChunkSize invalid" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "MaxChunkSize invalid"); } } if (params.count( "port" ) ) { int port = params["port"].as<int>(); if ( port <= 0 || port > 65535 ) { - out() << "error: port number must be between 1 and 65535" << endl; - ::_exit(EXIT_FAILURE); + return Status(ErrorCodes::BadValue, + "error: port number must be between 1 and 65535"); } } @@ -190,21 +193,14 @@ namespace mongo { serverGlobalParams.jsonp = true; } - if ( params.count( "test" ) ) { - ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity( - ::mongo::logger::LogSeverity::Debug(5)); - StartupTest::runTests(); - ::_exit(EXIT_SUCCESS); - } - if (params.count("noscripting")) { // This option currently has no effect for mongos } if (params.count("httpinterface")) { if (params.count("nohttpinterface")) { - std::cerr << "can't have both --httpinterface and --nohttpinterface" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "can't have both --httpinterface and --nohttpinterface"); } serverGlobalParams.isHttpInterfaceEnabled = true; } @@ -215,14 +211,12 @@ namespace mongo { } if ( ! params.count( "configdb" ) ) { - std::cerr << "error: no args for --configdb" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "error: no args for --configdb"); } splitStringDelim(params["configdb"].as<std::string>(), &mongosGlobalParams.configdbs, ','); if (mongosGlobalParams.configdbs.size() != 1 && mongosGlobalParams.configdbs.size() != 3) { - std::cerr << "need either 1 or 3 configdbs" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "need either 1 or 3 configdbs"); } if (mongosGlobalParams.configdbs.size() == 1) { @@ -240,11 +234,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongosOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongosOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongosOptions(moe::startupOptionsParsed, context->args())) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -257,7 +250,14 @@ namespace mongo { // getGlobalAuthorizationManager(). ("EndStartupOptionStorage")) (InitializerContext* context) { - return storeMongosOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongosOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } // namespace mongo diff --git a/src/mongo/s/mongos_options.h b/src/mongo/s/mongos_options.h index 9784591f8f3..f558d407509 100644 --- a/src/mongo/s/mongos_options.h +++ b/src/mongo/s/mongos_options.h @@ -42,7 +42,7 @@ namespace mongo { void printMongosHelp(const moe::OptionSection& options); - Status handlePreValidationMongosOptions(const moe::Environment& params, + bool handlePreValidationMongosOptions(const moe::Environment& params, const std::vector<std::string>& args); Status storeMongosOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/shell/shell_options.cpp b/src/mongo/shell/shell_options.cpp index e2b348e252a..63bbe842d3e 100644 --- a/src/mongo/shell/shell_options.cpp +++ b/src/mongo/shell/shell_options.cpp @@ -163,16 +163,22 @@ namespace mongo { return sb.str(); } - Status handlePreValidationMongoShellOptions(const moe::Environment& params, + bool handlePreValidationMongoShellOptions(const moe::Environment& params, const std::vector<std::string>& args) { if (params.count("help")) { std::cout << getMongoShellHelp(args[0], moe::startupOptions) << std::endl; - ::_exit(EXIT_CLEAN); + return true; } if (params.count("version")) { cout << "MongoDB shell version: " << mongo::versionString << endl; - ::_exit(EXIT_CLEAN); + return true; } + return false; + } + + Status storeMongoShellOptions(const moe::Environment& params, + const std::vector<std::string>& args) { + if (params.count("quiet")) { mongo::serverGlobalParams.quiet = true; } @@ -189,11 +195,6 @@ namespace mongo { logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(1)); } - return Status::OK(); - } - - Status storeMongoShellOptions(const moe::Environment& params, - const std::vector<std::string>& args) { if (params.count("port")) { shellGlobalParams.port = params["port"].as<string>(); } @@ -270,9 +271,10 @@ namespace mongo { } if ( shellGlobalParams.url == "*" ) { - std::cerr << "ERROR: " << "\"*\" is an invalid db address" << std::endl; - std::cerr << getMongoShellHelp(args[0], moe::startupOptions) << std::endl; - ::_exit(EXIT_BADOPTIONS); + StringBuilder sb; + sb << "ERROR: " << "\"*\" is an invalid db address"; + sb << getMongoShellHelp(args[0], moe::startupOptions); + return Status(ErrorCodes::BadValue, sb.str()); } return Status::OK(); @@ -283,11 +285,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongoShellOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoShellOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongoShellOptions(moe::startupOptionsParsed, context->args())) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -295,6 +296,13 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoShellOptions)(InitializerContext* context) { - return storeMongoShellOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongoShellOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/shell/shell_options.h b/src/mongo/shell/shell_options.h index d48b2226b9c..024af81a3d4 100644 --- a/src/mongo/shell/shell_options.h +++ b/src/mongo/shell/shell_options.h @@ -59,7 +59,7 @@ namespace mongo { std::string getMongoShellHelp(const StringData& name, const moe::OptionSection& options); - Status handlePreValidationMongoShellOptions(const moe::Environment& params, + bool handlePreValidationMongoShellOptions(const moe::Environment& params, const std::vector<std::string>& args); Status storeMongoShellOptions(const moe::Environment& params, diff --git a/src/mongo/tools/bsondump_options.cpp b/src/mongo/tools/bsondump_options.cpp index dbeadc1d524..73739f174cf 100644 --- a/src/mongo/tools/bsondump_options.cpp +++ b/src/mongo/tools/bsondump_options.cpp @@ -59,12 +59,12 @@ namespace mongo { *out << std::flush; } - Status handlePreValidationBSONDumpOptions(const moe::Environment& params) { + bool handlePreValidationBSONDumpOptions(const moe::Environment& params) { if (params.count("help")) { printBSONDumpHelp(&std::cout); - ::_exit(0); + return true; } - return Status::OK(); + return false; } Status storeBSONDumpOptions(const moe::Environment& params, @@ -101,11 +101,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(BSONDumpOptions)(InitializerContext* context) { - Status ret = handlePreValidationBSONDumpOptions(moe::startupOptionsParsed); - if (!ret.isOK()) { - return ret; + if (handlePreValidationBSONDumpOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -113,6 +112,13 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(BSONDumpOptions)(InitializerContext* context) { - return storeBSONDumpOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeBSONDumpOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/tools/bsondump_options.h b/src/mongo/tools/bsondump_options.h index 0afddd57658..367e6d90d6b 100644 --- a/src/mongo/tools/bsondump_options.h +++ b/src/mongo/tools/bsondump_options.h @@ -36,7 +36,7 @@ namespace mongo { void printBSONDumpHelp(std::ostream* out); - Status handlePreValidationBSONDumpOptions(const moe::Environment& params); + bool handlePreValidationBSONDumpOptions(const moe::Environment& params); Status storeBSONDumpOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/tools/mongobridge_options.cpp b/src/mongo/tools/mongobridge_options.cpp index 8ce860d0db5..180632b7a9c 100644 --- a/src/mongo/tools/mongobridge_options.cpp +++ b/src/mongo/tools/mongobridge_options.cpp @@ -61,27 +61,23 @@ namespace mongo { *out << std::flush; } - Status handlePreValidationMongoBridgeOptions(const moe::Environment& params) { + bool handlePreValidationMongoBridgeOptions(const moe::Environment& params) { if (params.count("help")) { printMongoBridgeHelp(&std::cout); - ::_exit(0); + return true; } - return Status::OK(); + return false; } Status storeMongoBridgeOptions(const moe::Environment& params, const std::vector<std::string>& args) { if (!params.count("port")) { - std::cerr << "Missing required option: \"--port\"" << std::endl; - printMongoBridgeHelp(&std::cerr); - ::_exit(0); + return Status(ErrorCodes::BadValue, "Missing required option: \"--port\""); } if (!params.count("dest")) { - std::cerr << "Missing required option: \"--dest\"" << std::endl; - printMongoBridgeHelp(&std::cerr); - ::_exit(0); + return Status(ErrorCodes::BadValue, "Missing required option: \"--dest\""); } mongoBridgeGlobalParams.port = params["port"].as<int>(); @@ -99,11 +95,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongoBridgeOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoBridgeOptions(moe::startupOptionsParsed); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongoBridgeOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -111,7 +106,14 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoBridgeOptions)(InitializerContext* context) { - return storeMongoBridgeOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongoBridgeOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/tools/mongobridge_options.h b/src/mongo/tools/mongobridge_options.h index 28fefd306e1..d962333f38b 100644 --- a/src/mongo/tools/mongobridge_options.h +++ b/src/mongo/tools/mongobridge_options.h @@ -45,7 +45,7 @@ namespace mongo { void printMongoBridgeHelp(std::ostream* out); - Status handlePreValidationMongoBridgeOptions(const moe::Environment& params); + bool handlePreValidationMongoBridgeOptions(const moe::Environment& params); Status storeMongoBridgeOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/tools/mongodump_options.cpp b/src/mongo/tools/mongodump_options.cpp index 28ff9dc361b..b924fcba2d5 100644 --- a/src/mongo/tools/mongodump_options.cpp +++ b/src/mongo/tools/mongodump_options.cpp @@ -84,12 +84,12 @@ namespace mongo { *out << std::flush; } - Status handlePreValidationMongoDumpOptions(const moe::Environment& params) { + bool handlePreValidationMongoDumpOptions(const moe::Environment& params) { if (params.count("help")) { printMongoDumpHelp(&std::cout); - ::_exit(0); + return true;; } - return Status::OK(); + return false; } Status storeMongoDumpOptions(const moe::Environment& params, @@ -102,21 +102,19 @@ namespace mongo { mongoDumpGlobalParams.repair = hasParam("repair"); if (mongoDumpGlobalParams.repair){ if (!hasParam("dbpath")) { - std::cerr << "repair mode only works with --dbpath" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "repair mode only works with --dbpath"); } if (!hasParam("db")) { - std::cerr << "repair mode only works on 1 db at a time right now" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "repair mode only works on 1 db at a time right now"); } } mongoDumpGlobalParams.query = getParam("query"); mongoDumpGlobalParams.useOplog = hasParam("oplog"); if (mongoDumpGlobalParams.useOplog) { if (hasParam("query") || hasParam("db") || hasParam("collection")) { - std::cerr << "oplog mode is only supported on full dumps" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "oplog mode is only supported on full dumps"); } } mongoDumpGlobalParams.outputFile = getParam("out"); @@ -144,11 +142,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongoDumpOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoDumpOptions(moe::startupOptionsParsed); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongoDumpOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -156,6 +153,13 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoDumpOptions)(InitializerContext* context) { - return storeMongoDumpOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongoDumpOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/tools/mongodump_options.h b/src/mongo/tools/mongodump_options.h index 9f051809244..e0963ad2b98 100644 --- a/src/mongo/tools/mongodump_options.h +++ b/src/mongo/tools/mongodump_options.h @@ -39,7 +39,7 @@ namespace mongo { void printMongoDumpHelp(std::ostream* out); - Status handlePreValidationMongoDumpOptions(const moe::Environment& params); + bool handlePreValidationMongoDumpOptions(const moe::Environment& params); Status storeMongoDumpOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/tools/mongoexport_options.cpp b/src/mongo/tools/mongoexport_options.cpp index b6148046d80..2b1f26e53ae 100644 --- a/src/mongo/tools/mongoexport_options.cpp +++ b/src/mongo/tools/mongoexport_options.cpp @@ -105,12 +105,12 @@ namespace mongo { *out << std::flush; } - Status handlePreValidationMongoExportOptions(const moe::Environment& params) { + bool handlePreValidationMongoExportOptions(const moe::Environment& params) { if (params.count("help")) { printMongoExportHelp(&std::cout); - ::_exit(0); + return true; } - return Status::OK(); + return false; } Status storeMongoExportOptions(const moe::Environment& params, @@ -155,11 +155,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongoExportOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoExportOptions(moe::startupOptionsParsed); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongoExportOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -167,6 +166,13 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoExportOptions)(InitializerContext* context) { - return storeMongoExportOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongoExportOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/tools/mongoexport_options.h b/src/mongo/tools/mongoexport_options.h index 86da8c3de11..d14d580a1f6 100644 --- a/src/mongo/tools/mongoexport_options.h +++ b/src/mongo/tools/mongoexport_options.h @@ -43,7 +43,7 @@ namespace mongo { void printMongoExportHelp(std::ostream* out); - Status handlePreValidationMongoExportOptions(const moe::Environment& params); + bool handlePreValidationMongoExportOptions(const moe::Environment& params); Status storeMongoExportOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/tools/mongofiles_options.cpp b/src/mongo/tools/mongofiles_options.cpp index 814106e7467..da5ffead5c4 100644 --- a/src/mongo/tools/mongofiles_options.cpp +++ b/src/mongo/tools/mongofiles_options.cpp @@ -93,12 +93,12 @@ namespace mongo { *out << std::flush; } - Status handlePreValidationMongoFilesOptions(const moe::Environment& params) { + bool handlePreValidationMongoFilesOptions(const moe::Environment& params) { if (params.count("help")) { printMongoFilesHelp(&std::cout); - ::_exit(0); + return true; } - return Status::OK(); + return false; } Status storeMongoFilesOptions(const moe::Environment& params, @@ -122,11 +122,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongoFilesOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoFilesOptions(moe::startupOptionsParsed); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongoFilesOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -134,6 +133,13 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoFilesOptions)(InitializerContext* context) { - return storeMongoFilesOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongoFilesOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/tools/mongofiles_options.h b/src/mongo/tools/mongofiles_options.h index 3dd046a40de..009645a3eea 100644 --- a/src/mongo/tools/mongofiles_options.h +++ b/src/mongo/tools/mongofiles_options.h @@ -39,7 +39,7 @@ namespace mongo { void printMongoFilesHelp(std::ostream* out); - Status handlePreValidationMongoFilesOptions(const moe::Environment& params); + bool handlePreValidationMongoFilesOptions(const moe::Environment& params); Status storeMongoFilesOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/tools/mongoimport_options.cpp b/src/mongo/tools/mongoimport_options.cpp index 0c6de3dbf1f..534f69e66e4 100644 --- a/src/mongo/tools/mongoimport_options.cpp +++ b/src/mongo/tools/mongoimport_options.cpp @@ -124,12 +124,12 @@ namespace mongo { *out << std::flush; } - Status handlePreValidationMongoImportOptions(const moe::Environment& params) { + bool handlePreValidationMongoImportOptions(const moe::Environment& params) { if (params.count("help")) { printMongoImportHelp(&std::cout); - ::_exit(0); + return true; } - return Status::OK(); + return false; } Status storeMongoImportOptions(const moe::Environment& params, @@ -177,11 +177,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongoImportOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoImportOptions(moe::startupOptionsParsed); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongoImportOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -189,6 +188,13 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoImportOptions)(InitializerContext* context) { - return storeMongoImportOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongoImportOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/tools/mongoimport_options.h b/src/mongo/tools/mongoimport_options.h index 53f378a3a31..44f7ceaf48c 100644 --- a/src/mongo/tools/mongoimport_options.h +++ b/src/mongo/tools/mongoimport_options.h @@ -44,7 +44,7 @@ namespace mongo { void printMongoImportHelp(std::ostream* out); - Status handlePreValidationMongoImportOptions(const moe::Environment& params); + bool handlePreValidationMongoImportOptions(const moe::Environment& params); Status storeMongoImportOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/tools/mongooplog_options.cpp b/src/mongo/tools/mongooplog_options.cpp index c7f600c304c..3292436e4b4 100644 --- a/src/mongo/tools/mongooplog_options.cpp +++ b/src/mongo/tools/mongooplog_options.cpp @@ -73,12 +73,12 @@ namespace mongo { *out << std::flush; } - Status handlePreValidationMongoOplogOptions(const moe::Environment& params) { + bool handlePreValidationMongoOplogOptions(const moe::Environment& params) { if (params.count("help")) { printMongoOplogHelp(&std::cout); - ::_exit(0); + return true; } - return Status::OK(); + return false; } Status storeMongoOplogOptions(const moe::Environment& params, @@ -89,8 +89,7 @@ namespace mongo { } if (!hasParam("from")) { - std::cerr << "need to specify --from" << std::endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, "need to specify --from"); } else { mongoOplogGlobalParams.from = getParam("from"); @@ -107,11 +106,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongoOplogOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoOplogOptions(moe::startupOptionsParsed); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongoOplogOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -119,6 +117,13 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoOplogOptions)(InitializerContext* context) { - return storeMongoOplogOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongoOplogOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/tools/mongooplog_options.h b/src/mongo/tools/mongooplog_options.h index e3c25ee236b..1a7095d5ed9 100644 --- a/src/mongo/tools/mongooplog_options.h +++ b/src/mongo/tools/mongooplog_options.h @@ -37,7 +37,7 @@ namespace mongo { void printMongoOplogHelp(std::ostream* out); - Status handlePreValidationMongoOplogOptions(const moe::Environment& params); + bool handlePreValidationMongoOplogOptions(const moe::Environment& params); Status storeMongoOplogOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/tools/mongorestore_options.cpp b/src/mongo/tools/mongorestore_options.cpp index c925fc4c24c..c1ad0e791f6 100644 --- a/src/mongo/tools/mongorestore_options.cpp +++ b/src/mongo/tools/mongorestore_options.cpp @@ -119,12 +119,12 @@ namespace mongo { *out << std::flush; } - Status handlePreValidationMongoRestoreOptions(const moe::Environment& params) { + bool handlePreValidationMongoRestoreOptions(const moe::Environment& params) { if (params.count("help")) { printMongoRestoreHelp(&std::cout); - ::_exit(0); + return true; } - return Status::OK(); + return false; } Status storeMongoRestoreOptions(const moe::Environment& params, @@ -161,11 +161,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongoRestoreOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoRestoreOptions(moe::startupOptionsParsed); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongoRestoreOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -173,6 +172,13 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoRestoreOptions)(InitializerContext* context) { - return storeMongoRestoreOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongoRestoreOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/tools/mongorestore_options.h b/src/mongo/tools/mongorestore_options.h index 692bdf0b343..5501fe1d22e 100644 --- a/src/mongo/tools/mongorestore_options.h +++ b/src/mongo/tools/mongorestore_options.h @@ -42,7 +42,7 @@ namespace mongo { void printMongoRestoreHelp(std::ostream* out); - Status handlePreValidationMongoRestoreOptions(const moe::Environment& params); + bool handlePreValidationMongoRestoreOptions(const moe::Environment& params); Status storeMongoRestoreOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/tools/mongostat_options.cpp b/src/mongo/tools/mongostat_options.cpp index 7f6b8084eda..b695dd6606d 100644 --- a/src/mongo/tools/mongostat_options.cpp +++ b/src/mongo/tools/mongostat_options.cpp @@ -109,12 +109,12 @@ namespace mongo { *out << std::flush; } - Status handlePreValidationMongoStatOptions(const moe::Environment& params) { + bool handlePreValidationMongoStatOptions(const moe::Environment& params) { if (params.count("help")) { printMongoStatHelp(&std::cout); - ::_exit(0); + return true; } - return Status::OK(); + return false; } Status storeMongoStatOptions(const moe::Environment& params, @@ -152,13 +152,13 @@ namespace mongo { // end of storage / start of validation if (mongoStatGlobalParams.sleep <= 0) { - cerr << "Error parsing command line: --sleep must be greater than 0" << endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "Error parsing command line: --sleep must be greater than 0"); } if (mongoStatGlobalParams.rowCount < 0) { - cerr << "Error parsing command line: --rowcount (-n) can't be negative" << endl; - ::_exit(EXIT_BADOPTIONS); + return Status(ErrorCodes::BadValue, + "Error parsing command line: --rowcount (-n) can't be negative"); } return Status::OK(); @@ -169,11 +169,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongoStatOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoStatOptions(moe::startupOptionsParsed); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongoStatOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -181,6 +180,13 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoStatOptions)(InitializerContext* context) { - return storeMongoStatOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongoStatOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/tools/mongostat_options.h b/src/mongo/tools/mongostat_options.h index 8eb3f47c925..d0a7180cfaf 100644 --- a/src/mongo/tools/mongostat_options.h +++ b/src/mongo/tools/mongostat_options.h @@ -42,7 +42,7 @@ namespace mongo { void printMongoStatHelp(std::ostream* out); - Status handlePreValidationMongoStatOptions(const moe::Environment& params); + bool handlePreValidationMongoStatOptions(const moe::Environment& params); Status storeMongoStatOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/tools/mongotop_options.cpp b/src/mongo/tools/mongotop_options.cpp index 2dde99c2565..09af7f47b10 100644 --- a/src/mongo/tools/mongotop_options.cpp +++ b/src/mongo/tools/mongotop_options.cpp @@ -58,12 +58,12 @@ namespace mongo { *out << std::flush; } - Status handlePreValidationMongoTopOptions(const moe::Environment& params) { + bool handlePreValidationMongoTopOptions(const moe::Environment& params) { if (params.count("help")) { printMongoTopHelp(&std::cout); - ::_exit(0); + return true; } - return Status::OK(); + return false; } Status storeMongoTopOptions(const moe::Environment& params, @@ -89,11 +89,10 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_VALIDATE(MongoTopOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoTopOptions(moe::startupOptionsParsed); - if (!ret.isOK()) { - return ret; + if (handlePreValidationMongoTopOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); } - ret = moe::startupOptionsParsed.validate(); + Status ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -101,6 +100,13 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoTopOptions)(InitializerContext* context) { - return storeMongoTopOptions(moe::startupOptionsParsed, context->args()); + Status ret = storeMongoTopOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); } } diff --git a/src/mongo/tools/mongotop_options.h b/src/mongo/tools/mongotop_options.h index 7a67c8f033e..e88403acd01 100644 --- a/src/mongo/tools/mongotop_options.h +++ b/src/mongo/tools/mongotop_options.h @@ -36,7 +36,7 @@ namespace mongo { void printMongoTopHelp(std::ostream* out); - Status handlePreValidationMongoTopOptions(const moe::Environment& params); + bool handlePreValidationMongoTopOptions(const moe::Environment& params); Status storeMongoTopOptions(const moe::Environment& params, const std::vector<std::string>& args); diff --git a/src/mongo/tools/tool_options.cpp b/src/mongo/tools/tool_options.cpp index 07ba3e07b73..06fac43db6e 100644 --- a/src/mongo/tools/tool_options.cpp +++ b/src/mongo/tools/tool_options.cpp @@ -228,12 +228,12 @@ namespace mongo { out << std::endl; } - Status handlePreValidationGeneralToolOptions(const moe::Environment& params) { + bool handlePreValidationGeneralToolOptions(const moe::Environment& params) { if (moe::startupOptionsParsed.count("version")) { printToolVersionString(std::cout); - ::_exit(0); + return true; } - return Status::OK(); + return false; } extern bool directoryperdb; diff --git a/src/mongo/tools/tool_options.h b/src/mongo/tools/tool_options.h index 7e30e38a7c8..346b3bd4d10 100644 --- a/src/mongo/tools/tool_options.h +++ b/src/mongo/tools/tool_options.h @@ -88,7 +88,7 @@ namespace mongo { int getParam(std::string name, int def); bool hasParam(std::string name); - Status handlePreValidationGeneralToolOptions(const moe::Environment& params); + bool handlePreValidationGeneralToolOptions(const moe::Environment& params); Status storeGeneralToolOptions(const moe::Environment& params, const std::vector<std::string>& args); |