From c50e82c27b7f33b9024a04ec7ad7d4301bc7f7ca Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Tue, 3 Aug 2021 15:42:40 -0500 Subject: Create separate log file for clean room. --- src/burn/engine/engine.cpp | 17 +++++++++++++++++ src/burn/engine/engine.mc | 7 +++++++ src/burn/engine/logging.cpp | 19 +++++++++++++++---- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/burn/engine/engine.cpp b/src/burn/engine/engine.cpp index 99471e0d..8b4a296b 100644 --- a/src/burn/engine/engine.cpp +++ b/src/burn/engine/engine.cpp @@ -95,6 +95,7 @@ extern "C" HRESULT EngineRun( SYSTEM_INFO si = { }; RTL_OSVERSIONINFOEXW ovix = { }; LPWSTR sczExePath = NULL; + BOOL fRunUntrusted = FALSE; BOOL fRunNormal = FALSE; BOOL fRestart = FALSE; @@ -194,6 +195,8 @@ extern "C" HRESULT EngineRun( switch (engineState.internalCommand.mode) { case BURN_MODE_UNTRUSTED: + fRunUntrusted = TRUE; + hr = RunUntrusted(&engineState); ExitOnFailure(hr, "Failed to run untrusted mode."); break; @@ -296,6 +299,10 @@ LExit: LogId(REPORT_STANDARD, MSG_RESTARTING); } } + else if (fRunUntrusted) + { + LogId(REPORT_STANDARD, MSG_EXITING_CLEAN_ROOM, FAILED(hr) ? (int)hr : *pdwExitCode); + } if (fLogInitialized) { @@ -425,6 +432,10 @@ static HRESULT RunUntrusted( HANDLE hFileSelf = NULL; HANDLE hProcess = NULL; + // Initialize logging. + hr = LoggingOpen(&pEngineState->log, &pEngineState->internalCommand, &pEngineState->command, &pEngineState->variables, pEngineState->registration.sczDisplayName); + ExitOnFailure(hr, "Failed to open clean room log."); + hr = PathForCurrentProcess(&sczCurrentProcessPath, NULL); ExitOnFailure(hr, "Failed to get path for current process."); @@ -480,6 +491,12 @@ static HRESULT RunUntrusted( ExitOnFailure(hr, "Failed to wait for clean room process: %ls", wzCleanRoomBundlePath); LExit: + // If the splash screen is still around, close it. + if (::IsWindow(pEngineState->command.hwndSplashScreen)) + { + ::PostMessageW(pEngineState->command.hwndSplashScreen, WM_CLOSE, 0, 0); + } + ReleaseHandle(pi.hThread); ReleaseFileHandle(hFileSelf); ReleaseFileHandle(hFileAttached); diff --git a/src/burn/engine/engine.mc b/src/burn/engine/engine.mc index a587415d..f1ecebcd 100644 --- a/src/burn/engine/engine.mc +++ b/src/burn/engine/engine.mc @@ -142,6 +142,13 @@ Language=English Unknown burn internal command-line switch modifier encountered, switch: '%1!ls!', modifier: '%2!c!'. . +MessageId=17 +Severity=Success +SymbolicName=MSG_EXITING_CLEAN_ROOM +Language=English +Exit code: 0x%1!x! +. + MessageId=51 Severity=Error SymbolicName=MSG_FAILED_PARSE_CONDITION diff --git a/src/burn/engine/logging.cpp b/src/burn/engine/logging.cpp index 6b19cc8a..9aaf60ed 100644 --- a/src/burn/engine/logging.cpp +++ b/src/burn/engine/logging.cpp @@ -39,11 +39,12 @@ extern "C" HRESULT LoggingOpen( HRESULT hr = S_OK; LPWSTR sczLoggingBaseFolder = NULL; LPWSTR sczPrefixFormatted = NULL; + LPCWSTR wzPostfix = BURN_MODE_UNTRUSTED == pInternalCommand->mode ? L".cleanroom" : NULL; hr = InitializeLogging(pLog, pInternalCommand); ExitOnFailure(hr, "Failed to initialize logging."); - if (pLog->dwAttributes & BURN_LOGGING_ATTRIBUTE_VERBOSE || pLog->dwAttributes & BURN_LOGGING_ATTRIBUTE_EXTRADEBUG) + if ((pLog->dwAttributes & BURN_LOGGING_ATTRIBUTE_VERBOSE) || (pLog->dwAttributes & BURN_LOGGING_ATTRIBUTE_EXTRADEBUG)) { if (pLog->dwAttributes & BURN_LOGGING_ATTRIBUTE_EXTRADEBUG) { @@ -54,9 +55,17 @@ extern "C" HRESULT LoggingOpen( LogSetLevel(REPORT_VERBOSE, FALSE); } + // In these modes, make sure a log will be created even if the bundle wasn't configured to create one. if ((!pLog->sczPath || !*pLog->sczPath) && (!pLog->sczPrefix || !*pLog->sczPrefix)) { - PathCreateTimeBasedTempFile(NULL, L"Setup", NULL, L"log", &pLog->sczPath, NULL); + hr = StrAllocString(&pLog->sczPrefix, L"Setup", 0); + ExitOnFailure(hr, "Failed to copy default log prefix."); + + if (!pLog->sczExtension || !*pLog->sczExtension) + { + hr = StrAllocString(&pLog->sczExtension, L"log", 0); + ExitOnFailure(hr, "Failed to copy default log extension."); + } } } @@ -134,7 +143,7 @@ extern "C" HRESULT LoggingOpen( ExitOnFailure(hr, "Failed to get non-session specific TEMP folder."); } - hr = LogOpen(sczLoggingBaseFolder, wzPrefix, NULL, pLog->sczExtension, FALSE, FALSE, &pLog->sczPath); + hr = LogOpen(sczLoggingBaseFolder, wzPrefix, wzPostfix, pLog->sczExtension, FALSE, FALSE, &pLog->sczPath); if (FAILED(hr)) { LogDisable(); @@ -760,7 +769,9 @@ static HRESULT InitializeLogging( pLog->dwAttributes |= pInternalCommand->dwLoggingAttributes; - if (pInternalCommand->sczLogFile) + // The untrusted process needs a separate log file. + // TODO: Burn crashes if they do try to use the same log file. + if (pInternalCommand->sczLogFile && BURN_MODE_UNTRUSTED != pInternalCommand->mode) { hr = StrAllocString(&pLog->sczPath, pInternalCommand->sczLogFile, 0); ExitOnFailure(hr, "Failed to copy log file path from command line."); -- cgit v1.2.3-55-g6feb