SERVER-106469 Handle null device for logpath on Windows (#41284) (#41346)

GitOrigin-RevId: b63f5d77b45487f5920850565b4967b8f1e0b4b0
This commit is contained in:
Didier Nadeau 2025-09-18 13:00:41 -04:00 committed by MongoDB Bot
parent 2191f30bf4
commit 9a81256d9c

View File

@ -374,11 +374,18 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
#endif // defined(_WIN32)
} else if (!serverGlobalParams.logpath.empty()) {
fassert(16448, !serverGlobalParams.logWithSyslog);
std::string absoluteLogpath =
boost::filesystem::absolute(serverGlobalParams.logpath, serverGlobalParams.cwd)
.string();
bool exists = checkAndMoveLogFile(absoluteLogpath);
auto [absoluteLogpath, exists] = [&] {
#ifdef _WIN32
constexpr auto kWindowsNUL = "NUL"_sd;
if (serverGlobalParams.logpath == kWindowsNUL) {
return std::make_tuple(std::string(kWindowsNUL), true);
}
#endif // defined(_WIN32)
std::string absolutePath =
boost::filesystem::absolute(serverGlobalParams.logpath, serverGlobalParams.cwd)
.string();
return std::make_tuple(absolutePath, checkAndMoveLogFile(absolutePath));
}();
lv2Config.consoleEnabled = false;
lv2Config.fileEnabled = true;