From ebd3f0971b843527ed493a35b2303c8c15b94109 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 26 Jan 2024 13:45:01 +0100 Subject: Fall back to old bootstrap.ini [Win32] section, for backwards compatibility Change-Id: I629b2a16bc889f16595cd1718d2ee4535f31aed7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162602 Tested-by: Stephan Bergmann Reviewed-by: Stephan Bergmann (cherry picked from commit fe459b9595c851d00a861d595c8dd50b35c90be3) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163255 Tested-by: Jenkins --- desktop/win32/source/loader.cxx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'desktop') diff --git a/desktop/win32/source/loader.cxx b/desktop/win32/source/loader.cxx index 998eb189effc..bbc97a462724 100644 --- a/desktop/win32/source/loader.cxx +++ b/desktop/win32/source/loader.cxx @@ -218,6 +218,8 @@ int officeloader_impl(bool bAllowConsole) // read limit values from fundamental.override.ini unsigned int nMaxMemoryInMB = 0; bool bExcludeChildProcesses = true; + bool fallbackForMaxMemoryInMB = true; + bool fallbackForExcludeChildProcesses = true; const WCHAR* szIniFile = L"\\fundamental.override.ini"; const size_t nDirLen = wcslen(szIniDirectory); @@ -233,13 +235,44 @@ int officeloader_impl(bool bAllowConsole) std::ifstream aFile(szBootstrapIni); boost::property_tree::ini_parser::read_ini(aFile, pt); nMaxMemoryInMB = pt.get("Bootstrap.LimitMaximumMemoryInMB", nMaxMemoryInMB); + fallbackForMaxMemoryInMB = !pt.get_child_optional("Bootstrap.LimitMaximumMemoryInMB"); bExcludeChildProcesses = pt.get("Bootstrap.ExcludeChildProcessesFromLimit", bExcludeChildProcesses); + fallbackForExcludeChildProcesses + = !pt.get_child_optional("Bootstrap.ExcludeChildProcessesFromLimit"); } catch (...) { nMaxMemoryInMB = 0; } } + // For backwards compatibility, for now also try to read the values from bootstrap.ini if + // fundamental.override.ini does not provide them: + if (fallbackForMaxMemoryInMB || fallbackForExcludeChildProcesses) { + const WCHAR* szFallbackIniFile = L"\\bootstrap.ini"; + const size_t nFallbackDirLen = wcslen(szIniDirectory); + if (wcslen(szFallbackIniFile) + nFallbackDirLen < MAX_PATH) + { + WCHAR szBootstrapIni[MAX_PATH]; + wcscpy(szBootstrapIni, szIniDirectory); + wcscpy(&szBootstrapIni[nFallbackDirLen], szFallbackIniFile); + + try + { + boost::property_tree::ptree pt; + std::ifstream aFile(szBootstrapIni); + boost::property_tree::ini_parser::read_ini(aFile, pt); + if (fallbackForMaxMemoryInMB) { + nMaxMemoryInMB = pt.get("Win32.LimitMaximumMemoryInMB", nMaxMemoryInMB); + } + if (fallbackForExcludeChildProcesses) { + bExcludeChildProcesses = pt.get("Win32.ExcludeChildProcessesFromLimit", bExcludeChildProcesses); + } + } + catch (...) + { + } + } + } // create a Windows JobObject with a memory limit HANDLE hJobObject = nullptr; -- cgit