diff options
author | schwerin@10gen.com <schwerin@10gen.com> | 2012-10-11 00:06:36 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2012-10-15 16:42:17 -0400 |
commit | f737a6f12cbbd8559921a91b17157e8152dd2b10 (patch) | |
tree | 147a492c57e7f29676fd9083a46d61a076946543 /src | |
parent | e11b8976f1fd776de09559f99e4c339d0da287a7 (diff) | |
download | mongo-f737a6f12cbbd8559921a91b17157e8152dd2b10.tar.gz |
SERVER-7332 Split command line processing from startup in db.cpp, part 1.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/db.cpp | 84 |
1 files changed, 37 insertions, 47 deletions
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 723e41037b0..47f6128ac4d 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -615,11 +615,6 @@ void show_help_text(po::options_description options) { cout << options << endl; }; -/* Return error string or "" if no errors. */ -string arg_error_check(int argc, char* argv[]) { - return ""; -} - static int mongoDbMain(int argc, char* argv[], char** envp); int main(int argc, char* argv[], char** envp) { @@ -777,35 +772,28 @@ static int mongoDbMain(int argc, char* argv[], char **envp) { { po::variables_map params; - string error_message = arg_error_check(argc, argv); - if (error_message != "") { - cout << error_message << endl << endl; - show_help_text(visible_options); - return 0; - } - if (!CmdLine::store(std::vector<std::string>(argv, argv + argc), visible_options, hidden_options, positional_options, params)) { - return EXIT_FAILURE; + ::_exit(EXIT_FAILURE); } - CmdLine::censor(argc, argv); - - if (!initializeServerGlobalState(params.count("shutdown"))) - return EXIT_FAILURE; - if (params.count("help")) { show_help_text(visible_options); - return 0; + ::_exit(EXIT_SUCCESS); } if (params.count("version")) { cout << mongodVersion() << endl; printGitVersion(); - return 0; + ::_exit(EXIT_SUCCESS); } + if (params.count("sysinfo")) { + sysRuntimeInfo(); + ::_exit(EXIT_SUCCESS); + } + if ( params.count( "dbpath" ) ) { dbpath = params["dbpath"].as<string>(); if ( params.count( "fork" ) && dbpath[0] != '/' ) { @@ -850,7 +838,7 @@ static int mongoDbMain(int argc, char* argv[], char **envp) { if( params.count("dur") || params.count( "journal" ) ) { if (journalExplicit) { log() << "Can't specify both --journal and --nojournal options." << endl; - return EXIT_BADOPTIONS; + ::_exit(EXIT_BADOPTIONS); } journalExplicit = true; cmdLine.dur = true; @@ -917,14 +905,10 @@ static int mongoDbMain(int argc, char* argv[], char **envp) { } _diaglog.setLevel(x); } - if (params.count("sysinfo")) { - sysRuntimeInfo(); - return 0; - } if (params.count("repair")) { if (journalExplicit && cmdLine.dur) { log() << "Can't specify both --journal and --repair options." << endl; - return EXIT_BADOPTIONS; + ::_exit(EXIT_BADOPTIONS); } Record::MemoryTrackingEnabled = false; @@ -1067,31 +1051,28 @@ static int mongoDbMain(int argc, char* argv[], char **envp) { if( repairpath.empty() ) repairpath = dbpath; - Module::configAll( params ); - dataFileSync.go(); - + // The "command" option is deprecated. For backward compatibility, still support the "run" + // and "dbppath" command. The "run" command is the same as just running mongod, so just + // falls through. if (params.count("command")) { vector<string> command = params["command"].as< vector<string> >(); - if (command[0].compare("run") == 0) { - if (command.size() > 1) { - cout << "Too many parameters to 'run' command" << endl; - cout << visible_options << endl; - return 0; - } - - initAndListen(cmdLine.port); - return 0; - } - if (command[0].compare("dbpath") == 0) { cout << dbpath << endl; - return 0; + ::_exit(EXIT_SUCCESS); } - cout << "Invalid command: " << command[0] << endl; - cout << visible_options << endl; - return 0; + if (command[0].compare("run") != 0) { + cout << "Invalid command: " << command[0] << endl; + cout << visible_options << endl; + ::_exit(EXIT_FAILURE); + } + + if (command.size() > 1) { + cout << "Too many parameters to 'run' command" << endl; + cout << visible_options << endl; + ::_exit(EXIT_FAILURE); + } } if( cmdLine.pretouch ) @@ -1123,7 +1104,7 @@ static int mongoDbMain(int argc, char* argv[], char **envp) { if (failed) { cerr << "There doesn't seem to be a server running with dbpath: " << dbpath << endl; - ::_exit(-1); + ::_exit(EXIT_FAILURE); } cout << "killing process with pid: " << pid << endl; @@ -1131,17 +1112,26 @@ static int mongoDbMain(int argc, char* argv[], char **envp) { if (ret) { int e = errno; cerr << "failed to kill process: " << errnoWithDescription(e) << endl; - ::_exit(-1); + ::_exit(EXIT_FAILURE); } while (boost::filesystem::exists(procPath)) { sleepsecs(1); } - ::_exit(0); + ::_exit(EXIT_SUCCESS); } #endif + CmdLine::censor(argc, argv); + + if (!initializeServerGlobalState()) + ::_exit(EXIT_FAILURE); + + Module::configAll( params ); + + dataFileSync.go(); + #if defined(_WIN32) vector<string> disallowedOptions; if (serviceParamsCheck( params, dbpath, defaultServiceStrings, disallowedOptions, argc, argv )) { |