diff options
author | Andy Schwerin <schwerin@10gen.com> | 2013-11-25 18:51:05 -0500 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2013-12-02 18:09:01 -0500 |
commit | 5ea897e30b45447d55289e33f636da3017b1e8db (patch) | |
tree | 43226e6f5b424237b850cda945e59fcd8cc64eff /src/mongo/db/initialize_server_global_state.cpp | |
parent | ec176dd577988fc1aa2366de8152c5e97bb95466 (diff) | |
download | mongo-5ea897e30b45447d55289e33f636da3017b1e8db.tar.gz |
SERVER-8998 Register an atexit handler to call _exit if a library calls ::exit().
This prevents static destructors from running if the program exits via ::exit()
or by returning from main(), until such time as we fix normal exit behavior.
Diffstat (limited to 'src/mongo/db/initialize_server_global_state.cpp')
-rw-r--r-- | src/mongo/db/initialize_server_global_state.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/mongo/db/initialize_server_global_state.cpp b/src/mongo/db/initialize_server_global_state.cpp index 0712c2d3052..f32250d6d4f 100644 --- a/src/mongo/db/initialize_server_global_state.cpp +++ b/src/mongo/db/initialize_server_global_state.cpp @@ -302,6 +302,24 @@ namespace mongo { return Status::OK(); } + /** + * atexit handler to terminate the process before static destructors run. + * + * Mongo server processes cannot safely call ::exit() or std::exit(), but + * some third-party libraries may call one of those functions. In that + * case, to avoid static-destructor problems in the server, this exits the + * process immediately with code EXIT_FAILURE. + * + * TODO: Remove once exit() executes safely in mongo server processes. + */ + static void shortCircuitExit() { _exit(EXIT_FAILURE); } + + MONGO_INITIALIZER(RegisterShortCircuitExitHandler)(InitializerContext*) { + if (std::atexit(&shortCircuitExit) != 0) + return Status(ErrorCodes::InternalError, "Failed setting short-circuit exit handler."); + return Status::OK(); + } + bool initializeServerGlobalState() { Listener::globalTicketHolder.resize(serverGlobalParams.maxConns); |