summaryrefslogtreecommitdiff
path: root/src/mongo/db/initialize_server_global_state.cpp
diff options
context:
space:
mode:
authorJonathan Reams <jbreams@mongodb.com>2018-10-19 14:26:52 -0400
committerJonathan Reams <jbreams@mongodb.com>2018-10-26 10:32:54 -0400
commita15cf62de1d5de973160ec1a23609aaf6f0f500f (patch)
tree8a14b13fb2a70ce54e0335e314da361a342911ce /src/mongo/db/initialize_server_global_state.cpp
parent8fe142c376ae279e99ddae7547a8f7cd4e0ce5e3 (diff)
downloadmongo-a15cf62de1d5de973160ec1a23609aaf6f0f500f.tar.gz
SERVER-36977 Set process umask before creating log file
Diffstat (limited to 'src/mongo/db/initialize_server_global_state.cpp')
-rw-r--r--src/mongo/db/initialize_server_global_state.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/mongo/db/initialize_server_global_state.cpp b/src/mongo/db/initialize_server_global_state.cpp
index afc86a94aef..0c7a70b67b9 100644
--- a/src/mongo/db/initialize_server_global_state.cpp
+++ b/src/mongo/db/initialize_server_global_state.cpp
@@ -213,9 +213,12 @@ void forkServerOrDie() {
}
MONGO_EXPORT_SERVER_PARAMETER(maxLogSizeKB, int, logger::LogContext::kDefaultMaxLogSizeKB);
-MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
- ("GlobalLogManager", "EndStartupOptionHandling", "ForkServer"),
- ("default"))
+// On POSIX platforms we need to set our umask before opening any log files, so this
+// should depend on MungeUmask above, but not on Windows.
+MONGO_INITIALIZER_GENERAL(
+ ServerLogRedirection,
+ ("GlobalLogManager", "EndStartupOptionHandling", "ForkServer", "MungeUmask"),
+ ("default"))
(InitializerContext*) {
using logger::LogManager;
using logger::MessageEventEphemeral;
@@ -353,17 +356,22 @@ MONGO_INITIALIZER(RegisterShortCircuitExitHandler)(InitializerContext*) {
// restrictions we want to apply and set it back. The overall effect
// is to set the bits for 'other' and 'group', but leave umask bits
// bits for 'user' unaltered.
-#ifndef _WIN32
namespace {
+#ifndef _WIN32
MONGO_EXPORT_STARTUP_SERVER_PARAMETER(honorSystemUmask, bool, false);
-MONGO_INITIALIZER(MungeUmask)(InitializerContext*) {
+#endif
+
+MONGO_INITIALIZER_WITH_PREREQUISITES(MungeUmask, ("EndStartupOptionHandling"))
+(InitializerContext*) {
+#ifndef _WIN32
if (!honorSystemUmask) {
umask(umask(S_IRWXU | S_IRWXG | S_IRWXO) | S_IRWXG | S_IRWXO);
}
+#endif
+
return Status::OK();
}
} // namespace
-#endif
bool initializeServerGlobalState(ServiceContext* service) {
#ifndef _WIN32