summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Reams <jbreams@mongodb.com>2016-04-15 14:51:49 -0400
committerJonathan Reams <jbreams@mongodb.com>2016-04-16 15:19:01 -0400
commit1e42c8324b94f148d35297bdd0d6c47eeec0f1fc (patch)
treeee302bd8ee6ca641085b84b2afd4b59912da52df
parent63ea3e59a735b3fb6047e994c28834f841abccaa (diff)
downloadmongo-1e42c8324b94f148d35297bdd0d6c47eeec0f1fc.tar.gz
SERVER-23757 Clear signal mask when starting unit tests
-rw-r--r--src/mongo/db/initialize_server_global_state.cpp9
-rw-r--r--src/mongo/unittest/unittest_main.cpp1
-rw-r--r--src/mongo/util/signal_handlers_synchronous.cpp9
-rw-r--r--src/mongo/util/signal_handlers_synchronous.h6
4 files changed, 20 insertions, 5 deletions
diff --git a/src/mongo/db/initialize_server_global_state.cpp b/src/mongo/db/initialize_server_global_state.cpp
index 5fa705d383b..1341f61f3ff 100644
--- a/src/mongo/db/initialize_server_global_state.cpp
+++ b/src/mongo/db/initialize_server_global_state.cpp
@@ -66,6 +66,7 @@
#include "mongo/util/net/listen.h"
#include "mongo/util/net/ssl_manager.h"
#include "mongo/util/processinfo.h"
+#include "mongo/util/signal_handlers_synchronous.h"
#include "mongo/util/quick_exit.h"
namespace fs = boost::filesystem;
@@ -108,11 +109,9 @@ static bool forkServer() {
serverGlobalParams.parentProc = ProcessId::getCurrent();
- // We need to make sure that all signals are unmasked so we can signal ourself
- // that we're fully initialized later on.
- sigset_t unblockSignalMask;
- verify(sigemptyset(&unblockSignalMask) == 0);
- verify(sigprocmask(SIG_SETMASK, &unblockSignalMask, NULL) == 0);
+ // clear signal mask so that SIGUSR2 will always be caught and we can clean up the original
+ // parent process
+ clearSignalMask();
// facilitate clean exit when child starts successfully
verify(signal(SIGUSR2, launchSignal) != SIG_ERR);
diff --git a/src/mongo/unittest/unittest_main.cpp b/src/mongo/unittest/unittest_main.cpp
index 400135aaa09..132b2cc1842 100644
--- a/src/mongo/unittest/unittest_main.cpp
+++ b/src/mongo/unittest/unittest_main.cpp
@@ -35,6 +35,7 @@
#include "mongo/util/signal_handlers_synchronous.h"
int main(int argc, char** argv, char** envp) {
+ ::mongo::clearSignalMask();
::mongo::setupSynchronousSignalHandlers();
::mongo::runGlobalInitializersOrDie(argc, argv, envp);
return ::mongo::unittest::Suite::run(std::vector<std::string>(), "", 1);
diff --git a/src/mongo/util/signal_handlers_synchronous.cpp b/src/mongo/util/signal_handlers_synchronous.cpp
index c158224448c..fa383d97800 100644
--- a/src/mongo/util/signal_handlers_synchronous.cpp
+++ b/src/mongo/util/signal_handlers_synchronous.cpp
@@ -346,4 +346,13 @@ void reportOutOfMemoryErrorAndExit() {
writeMallocFreeStreamToLog();
quickExit(EXIT_ABRUPT);
}
+
+void clearSignalMask() {
+#ifndef _WIN32
+ // We need to make sure that all signals are unmasked so signals are handled correctly
+ sigset_t unblockSignalMask;
+ invariant(sigemptyset(&unblockSignalMask) == 0);
+ invariant(sigprocmask(SIG_SETMASK, &unblockSignalMask, nullptr) == 0);
+#endif
+}
} // namespace mongo
diff --git a/src/mongo/util/signal_handlers_synchronous.h b/src/mongo/util/signal_handlers_synchronous.h
index 5ed5eec05d0..2a5abfb2ffa 100644
--- a/src/mongo/util/signal_handlers_synchronous.h
+++ b/src/mongo/util/signal_handlers_synchronous.h
@@ -50,4 +50,10 @@ void setupSynchronousSignalHandlers();
*/
void reportOutOfMemoryErrorAndExit();
+/**
+ * Clears the signal mask for the process. This is called from forkServer and to setup
+ * the unit tests. On Windows, this is a noop.
+ */
+void clearSignalMask();
+
} // namespace mongo