diff options
author | Andrew Morrow <acm@mongodb.com> | 2016-03-11 14:34:47 -0500 |
---|---|---|
committer | Andrew Morrow <acm@mongodb.com> | 2016-03-21 22:55:32 -0400 |
commit | 4d6dd3b4359dc3cc8145beb10e54f84353689351 (patch) | |
tree | d2ca8c518ef2064854d5e9c1584fd89eab31d9e6 /src/mongo/shell | |
parent | 20ca6518797b67206d1f23d097c61c78a3ad8810 (diff) | |
download | mongo-4d6dd3b4359dc3cc8145beb10e54f84353689351.tar.gz |
SERVER-23103 Unify exit handling
Diffstat (limited to 'src/mongo/shell')
-rw-r--r-- | src/mongo/shell/clientAndShell.cpp | 23 | ||||
-rw-r--r-- | src/mongo/shell/dbshell.cpp | 29 | ||||
-rw-r--r-- | src/mongo/shell/shell_utils_launcher.cpp | 12 | ||||
-rw-r--r-- | src/mongo/shell/shell_utils_launcher.h | 1 |
4 files changed, 13 insertions, 52 deletions
diff --git a/src/mongo/shell/clientAndShell.cpp b/src/mongo/shell/clientAndShell.cpp index abbb03be656..f1ecde12eeb 100644 --- a/src/mongo/shell/clientAndShell.cpp +++ b/src/mongo/shell/clientAndShell.cpp @@ -47,29 +47,6 @@ class Client; class DBClientBase; class OperationContext; - -bool dbexitCalled = false; - -void dbexit(ExitCode returnCode, const char* whyMsg) { - { - stdx::lock_guard<stdx::mutex> lk(shell_utils::mongoProgramOutputMutex); - dbexitCalled = true; - } - - log() << "dbexit called" << endl; - - if (whyMsg) { - log() << " b/c " << whyMsg << endl; - } - - log() << "exiting" << endl; - quickExit(returnCode); -} - -bool inShutdown() { - return dbexitCalled; -} - bool haveLocalShardingInfo(OperationContext* txn, const string& ns) { return false; } diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp index c064c292e83..1c45cb71f6e 100644 --- a/src/mongo/shell/dbshell.cpp +++ b/src/mongo/shell/dbshell.cpp @@ -54,7 +54,7 @@ #include "mongo/shell/shell_options.h" #include "mongo/shell/shell_utils.h" #include "mongo/shell/shell_utils_launcher.h" -#include "mongo/util/exit_code.h" +#include "mongo/util/exit.h" #include "mongo/util/file.h" #include "mongo/util/log.h" #include "mongo/util/net/ssl_options.h" @@ -88,8 +88,6 @@ static volatile bool atPrompt = false; // can eval before getting to prompt namespace mongo { Scope* shellMainScope; - -extern bool dbexitCalled; } void generateCompletions(const string& prefix, vector<string>& all) { @@ -179,21 +177,10 @@ void killOps() { // Stubs for signal_handlers.cpp namespace mongo { void logProcessDetailsForLogRotate() {} - -void exitCleanly(ExitCode code) { - { - stdx::lock_guard<stdx::mutex> lk(mongo::shell_utils::mongoProgramOutputMutex); - mongo::dbexitCalled = true; - } - - ::killOps(); - ::shellHistoryDone(); - quickExit(0); -} } void quitNicely(int sig) { - exitCleanly(EXIT_CLEAN); + shutdown(EXIT_CLEAN); } // the returned string is allocated with strdup() or malloc() and must be freed by calling free() @@ -585,6 +572,14 @@ static void edit(const string& whatToEdit) { } int _main(int argc, char* argv[], char** envp) { + registerShutdownTask([] { + // NOTE: This function may be called at any time. It must not + // depend on the prior execution of mongo initializers or the + // existence of threads. + ::killOps(); + ::shellHistoryDone(); + }); + setupSignalHandlers(); setupSignals(); @@ -905,10 +900,6 @@ int _main(int argc, char* argv[], char** envp) { shellHistoryDone(); } - { - stdx::lock_guard<stdx::mutex> lk(mongo::shell_utils::mongoProgramOutputMutex); - mongo::dbexitCalled = true; - } return (lastLineSuccessful ? 0 : 1); } diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp index beb80eff4a2..3fb2ec1489d 100644 --- a/src/mongo/shell/shell_utils_launcher.cpp +++ b/src/mongo/shell/shell_utils_launcher.cpp @@ -54,6 +54,7 @@ #include "mongo/scripting/engine.h" #include "mongo/shell/shell_utils.h" #include "mongo/stdx/thread.h" +#include "mongo/util/exit.h" #include "mongo/util/log.h" #include "mongo/util/net/hostandport.h" #include "mongo/util/quick_exit.h" @@ -72,8 +73,6 @@ using std::string; using std::stringstream; using std::vector; -extern bool dbexitCalled; - #ifdef _WIN32 inline int close(int fd) { return _close(fd); @@ -192,14 +191,9 @@ void ProgramRegistry::insertHandleForPid(ProcessId pid, HANDLE handle) { ProgramRegistry& registry = *(new ProgramRegistry()); -void goingAwaySoon() { - stdx::lock_guard<stdx::mutex> lk(mongoProgramOutputMutex); - mongo::dbexitCalled = true; -} - void ProgramOutputMultiplexer::appendLine(int port, ProcessId pid, const char* line) { stdx::lock_guard<stdx::mutex> lk(mongoProgramOutputMutex); - uassert(28695, "program is terminating", !mongo::dbexitCalled); + uassert(28695, "program is terminating", !mongo::inShutdown()); stringstream buf; string name = registry.programName(pid); if (port > 0) @@ -342,7 +336,7 @@ void ProgramRunner::operator()() { } verify(lenToRead > 0); int ret = read(_pipe, (void*)start, lenToRead); - if (mongo::dbexitCalled) + if (mongo::inShutdown()) break; verify(ret != -1); start[ret] = '\0'; diff --git a/src/mongo/shell/shell_utils_launcher.h b/src/mongo/shell/shell_utils_launcher.h index fd58c1bd614..8c4449aee41 100644 --- a/src/mongo/shell/shell_utils_launcher.h +++ b/src/mongo/shell/shell_utils_launcher.h @@ -54,7 +54,6 @@ struct MongoProgramScope { }; void KillMongoProgramInstances(); -void goingAwaySoon(); void installShellUtilsLauncher(Scope& scope); /** Record log lines from concurrent programs. All public members are thread safe. */ |