diff options
author | Matt Kneiser <matt.kneiser@mongodb.com> | 2022-07-05 17:09:20 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-07 18:26:31 +0000 |
commit | c44db4ac9d0c4c368835dac9f2fbd5869d885f17 (patch) | |
tree | c07de8fbd279573725d877619f263a684ec420f4 /src/mongo/db/initialize_server_global_state.cpp | |
parent | 2f2dc04da0c7fd853a2ff68c245c5f6e28f50fa1 (diff) | |
download | mongo-c44db4ac9d0c4c368835dac9f2fbd5869d885f17.tar.gz |
SERVER-9434 Audit and Normalize Process Exit Codes
- Put all references to ExitCode enumerators under an enum class to namespace
all the enumerators and avoid polluting the mongo namespace with possible
naming collisions.
- Added magic-number exit codes to exit_code.h like 50 & 51
(LauncherMiddleError & LauncherError respectively).
- Reserved a range of exit codes to account for FreeBSD's usage of 64-78.
- Renamed all enums with removal of EXIT_ which could conflict or get confused
with built-in macros.
- camelCased all ExitCode enum values.
- Added the generic - ExitCode::fail - for returning 1 as failure.
- Added explicit dependency on the exit_code.h header for all files using
ExitCode's.
- Removed all references to implementation-defined exit codes like EXIT_FAILURE
and EXIT_SUCCESS.
- Narrowed return values of the shell's undocumented quit() argument to portable
values within 0-255, 0/ExitCode::clean otherwise.
- Deprecated 8 unused ExitCode's
- java
- oomMalloc
- oomRealloc
- fs
- clockSkew
- windowsServiceStop
- possibleCorruption
- test
- Wrapped the 2 Windows-only ExitCode's in #ifdef's
- ntServiceError
- windowsServiceStop
Diffstat (limited to 'src/mongo/db/initialize_server_global_state.cpp')
-rw-r--r-- | src/mongo/db/initialize_server_global_state.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/mongo/db/initialize_server_global_state.cpp b/src/mongo/db/initialize_server_global_state.cpp index 18c2cf45555..240c2830fcb 100644 --- a/src/mongo/db/initialize_server_global_state.cpp +++ b/src/mongo/db/initialize_server_global_state.cpp @@ -69,7 +69,7 @@ namespace mongo::initialize_server_global_state { #ifndef _WIN32 static void croak(StringData prefix, int savedErr = errno) { std::cout << prefix << ": " << errorMessage(posixError(savedErr)) << std::endl; - quickExit(EXIT_ABRUPT); + quickExit(ExitCode::abrupt); } void signalForkSuccess() { @@ -92,7 +92,7 @@ void signalForkSuccess() { "Write to child pipe failed", "errno"_attr = ec.value(), "errnoDesc"_attr = errorMessage(ec)); - quickExit(1); + quickExit(ExitCode::fail); } } else if (nw == 0) { continue; @@ -190,22 +190,22 @@ static bool forkServer() { std::cout << "about to fork child process, waiting until server is ready for connections." << std::endl; - auto waitAndPropagate = [&](pid_t pid, int signalCode, bool verbose) { + auto waitAndPropagate = [&](pid_t pid, ExitCode signalCode, bool verbose) { int pstat; if (waitpid(pid, &pstat, 0) == -1) croak("waitpid"); if (!WIFEXITED(pstat)) - quickExit(signalCode); // child died from a signal + quickExit(signalCode); if (int ec = WEXITSTATUS(pstat)) { if (verbose) std::cout << "ERROR: child process failed, exited with " << ec << std::endl << "To see additional information in this output, start without " << "the \"--fork\" option." << std::endl; - quickExit(ec); + quickExit(ExitCode::fail); } if (verbose) std::cout << "child process started successfully, parent exiting" << std::endl; - quickExit(0); + quickExit(ExitCode::clean); }; // Start in the <launcher> process. @@ -215,7 +215,7 @@ static bool forkServer() { break; default: // In the <launcher> process - waitAndPropagate(middle, 50, true); + waitAndPropagate(middle, ExitCode::launcherMiddleError, true); break; case 0: break; @@ -250,8 +250,8 @@ static bool forkServer() { if (nr == 0) // pipe reached eof without the daemon signalling readiness. // Wait for <daemon> to exit, and exit with its exit code. - waitAndPropagate(daemon, 51, false); - quickExit(0); + waitAndPropagate(daemon, ExitCode::launcherError, false); + quickExit(ExitCode::clean); } break; case 0: break; @@ -287,7 +287,7 @@ static bool forkServer() { void forkServerOrDie() { if (!forkServer()) - quickExit(EXIT_FAILURE); + quickExit(ExitCode::fail); } namespace { @@ -398,12 +398,12 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection, * 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. + * process immediately with code ExitCode::fail. * * TODO: Remove once exit() executes safely in mongo server processes. */ static void shortCircuitExit() { - quickExit(EXIT_FAILURE); + quickExit(ExitCode::fail); } MONGO_INITIALIZER(RegisterShortCircuitExitHandler)(InitializerContext*) { |