/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
DWORD cwdLen = GetCurrentDirectoryW(0, nullptr);
std::vector<WCHAR> cwd(cwdLen);
cwdLen = GetCurrentDirectoryW(cwdLen, cwd.data()); if (cwdLen == 0 || cwdLen >= cwd.size())
{
s += L'0';
} else
{
s += L'2';
size_t n = 0; // number of trailing backslashes for (auto* p = cwd.data(); *p; ++p)
{
WCHAR c = *p; if (c == L'$')
{
s += L"\\$";
n = 0;
} elseif (c == L'\\')
{
s += L"\\\\";
n += 2;
} else
{
s += c;
n = 0;
}
} // The command line will continue with a double quote, so double any // preceding backslashes as required by Windows:
s.append(n, L'\\');
}
s += L'"'; return s;
}
// create a Windows JobObject with a memory limit
HANDLE hJobObject = nullptr; if (nMaxMemoryInMB > 0)
{
JOBOBJECT_EXTENDED_LIMIT_INFORMATION aJobLimit;
aJobLimit.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_JOB_MEMORY; if (bExcludeChildProcesses)
aJobLimit.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK;
aJobLimit.JobMemoryLimit = nMaxMemoryInMB * 1024 * 1024;
hJobObject = CreateJobObjectW(nullptr, nullptr); if (hJobObject != nullptr)
SetInformationJobObject(hJobObject, JobObjectExtendedLimitInformation, &aJobLimit, sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
}
std::vector<std::wstring> aEscapedArgs; bool bHeadlessMode = false; const size_t nPathSize = 32 * 1024; for (std::wstring_view arg : CommandArgs())
{ // Check command line arguments for "--headless" parameter. We only set the environment // variable "ATTACHED_PARENT_PROCESSID" for the headless mode as self-destruction of the // soffice.bin process can lead to certain side-effects (log-off can result in data-loss, // ".lock" is not deleted). See 138244 for more information. if (arg == L"-headless" || arg == L"--headless")
bHeadlessMode = true; // check for wildcards in arguments - Windows does not expand automatically elseif (arg.size() < nPathSize && arg.find_first_of(L"*?") != std::wstring_view::npos)
{ constwchar_t* path(arg.data()); // 1. PathCchCanonicalizeEx only works with backslashes, so preprocess to comply wchar_t buf1[nPathSize], buf2[nPathSize];
arg.copy(buf1, arg.size());
buf1[arg.size()] = '\0';
std::replace(buf1, buf1 + arg.size(), '/', '\\'); // 2. Canonicalize the path: if needed, drop the .. and . segments; if long, make sure // that path has \\?\ long path prefix present (required for FindFirstFileW) if (SUCCEEDED(
PathCchCanonicalizeEx(buf2, std::size(buf1), buf1, PATHCCH_ALLOW_LONG_PATHS)))
path = buf2; // 3. Expand the wildcards
WIN32_FIND_DATAW aFindData;
HANDLE h = FindFirstFileW(path, &aFindData); if (h != INVALID_HANDLE_VALUE)
{ wchar_t drive[3]; bool splitted = _wsplitpath_s(path, drive, std::size(drive), buf1, std::size(buf1),
nullptr, 0, nullptr, 0) == 0; if (splitted)
{ do
{ if (_wmakepath_s(buf2, drive, buf1, aFindData.cFileName, nullptr) == 0)
aEscapedArgs.push_back(EscapeArg(buf2));
} while (FindNextFileW(h, &aFindData));
}
FindClose(h); if (splitted) continue;
}
}
aEscapedArgs.push_back(EscapeArg(arg));
}
size_t n = std::accumulate(aEscapedArgs.begin(), aEscapedArgs.end(), aEscapedArgs.size(),
[](size_t a, const std::wstring& s) { return a + s.size(); });
std::wstring sCWDarg = getCWDarg();
n += sCWDarg.size() + 1;
LPWSTR lpCommandLine = new WCHAR[n];
if (bHeadlessMode)
{
WCHAR szParentProcessId[64]; // This is more than large enough for a 128 bit decimal value if (_ltow(static_cast<long>(GetCurrentProcessId()), szParentProcessId, 10))
SetEnvironmentVariableW(L"ATTACHED_PARENT_PROCESSID", szParentProcessId);
}
do
{
WCHAR* p = commandLineAppend(lpCommandLine, aEscapedArgs[0]); for (size_t i = 1; i < aEscapedArgs.size(); ++i)
{ const std::wstring& rArg = aEscapedArgs[i]; if (bFirst || EXITHELPER_NORMAL_RESTART == dwExitCode || rArg.starts_with(L"\"-env:"))
{
p = commandLineAppend(p, L" ");
p = commandLineAppend(p, rArg);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.