Create separate log file for clean room.
Sean Hall committed
Aug 3, 2021 at 15:42 UTC
c50e82c27b7f33b9024a04ec7ad7d4301bc7f7ca
3 files changed
+39
-4
src/burn/engine/engine.cpp
+17
@@ -95,6 +95,7 @@ extern "C" HRESULT EngineRun(
95
SYSTEM_INFO si = { };
96
RTL_OSVERSIONINFOEXW ovix = { };
97
LPWSTR sczExePath = NULL;
98
+ BOOL fRunUntrusted = FALSE;
99
BOOL fRunNormal = FALSE;
100
BOOL fRestart = FALSE;
101
@@ -194,6 +195,8 @@ extern "C" HRESULT EngineRun(
195
switch (engineState.internalCommand.mode)
196
{
197
case BURN_MODE_UNTRUSTED:
198
+ fRunUntrusted = TRUE;
199
+
200
hr = RunUntrusted(&engineState);
201
ExitOnFailure(hr, "Failed to run untrusted mode.");
202
break;
@@ -296,6 +299,10 @@ LExit:
299
LogId(REPORT_STANDARD, MSG_RESTARTING);
300
}
301
}
302
+ else if (fRunUntrusted)
303
+ {
304
+ LogId(REPORT_STANDARD, MSG_EXITING_CLEAN_ROOM, FAILED(hr) ? (int)hr : *pdwExitCode);
305
+ }
306
307
if (fLogInitialized)
308
{
@@ -425,6 +432,10 @@ static HRESULT RunUntrusted(
432
HANDLE hFileSelf = NULL;
433
HANDLE hProcess = NULL;
434
435
+ // Initialize logging.
436
+ hr = LoggingOpen(&pEngineState->log, &pEngineState->internalCommand, &pEngineState->command, &pEngineState->variables, pEngineState->registration.sczDisplayName);
437
+ ExitOnFailure(hr, "Failed to open clean room log.");
438
+
439
hr = PathForCurrentProcess(&sczCurrentProcessPath, NULL);
440
ExitOnFailure(hr, "Failed to get path for current process.");
441
@@ -480,6 +491,12 @@ static HRESULT RunUntrusted(
491
ExitOnFailure(hr, "Failed to wait for clean room process: %ls", wzCleanRoomBundlePath);
492
493
LExit:
494
+ // If the splash screen is still around, close it.
495
+ if (::IsWindow(pEngineState->command.hwndSplashScreen))
496
+ {
497
+ ::PostMessageW(pEngineState->command.hwndSplashScreen, WM_CLOSE, 0, 0);
498
+ }
499
+
500
ReleaseHandle(pi.hThread);
501
ReleaseFileHandle(hFileSelf);
502
ReleaseFileHandle(hFileAttached);
src/burn/engine/engine.mc
+7
@@ -142,6 +142,13 @@ Language=English
142
Unknown burn internal command-line switch modifier encountered, switch: '%1!ls!', modifier: '%2!c!'.
143
.
144
145
+MessageId=17
146
+Severity=Success
147
+SymbolicName=MSG_EXITING_CLEAN_ROOM
148
+Language=English
149
+Exit code: 0x%1!x!
150
+.
151
+
152
MessageId=51
153
Severity=Error
154
SymbolicName=MSG_FAILED_PARSE_CONDITION
src/burn/engine/logging.cpp
+15
-4
@@ -39,11 +39,12 @@ extern "C" HRESULT LoggingOpen(
39
HRESULT hr = S_OK;
40
LPWSTR sczLoggingBaseFolder = NULL;
41
LPWSTR sczPrefixFormatted = NULL;
42
+ LPCWSTR wzPostfix = BURN_MODE_UNTRUSTED == pInternalCommand->mode ? L".cleanroom" : NULL;
43
44
hr = InitializeLogging(pLog, pInternalCommand);
45
ExitOnFailure(hr, "Failed to initialize logging.");
46
46
- if (pLog->dwAttributes & BURN_LOGGING_ATTRIBUTE_VERBOSE || pLog->dwAttributes & BURN_LOGGING_ATTRIBUTE_EXTRADEBUG)
47
+ if ((pLog->dwAttributes & BURN_LOGGING_ATTRIBUTE_VERBOSE) || (pLog->dwAttributes & BURN_LOGGING_ATTRIBUTE_EXTRADEBUG))
48
{
49
if (pLog->dwAttributes & BURN_LOGGING_ATTRIBUTE_EXTRADEBUG)
50
{
@@ -54,9 +55,17 @@ extern "C" HRESULT LoggingOpen(
55
LogSetLevel(REPORT_VERBOSE, FALSE);
56
}
57
58
+ // In these modes, make sure a log will be created even if the bundle wasn't configured to create one.
59
if ((!pLog->sczPath || !*pLog->sczPath) && (!pLog->sczPrefix || !*pLog->sczPrefix))
60
{
59
- PathCreateTimeBasedTempFile(NULL, L"Setup", NULL, L"log", &pLog->sczPath, NULL);
61
+ hr = StrAllocString(&pLog->sczPrefix, L"Setup", 0);
62
+ ExitOnFailure(hr, "Failed to copy default log prefix.");
63
+
64
+ if (!pLog->sczExtension || !*pLog->sczExtension)
65
+ {
66
+ hr = StrAllocString(&pLog->sczExtension, L"log", 0);
67
+ ExitOnFailure(hr, "Failed to copy default log extension.");
68
+ }
69
}
70
}
71
@@ -134,7 +143,7 @@ extern "C" HRESULT LoggingOpen(
143
ExitOnFailure(hr, "Failed to get non-session specific TEMP folder.");
144
}
145
137
- hr = LogOpen(sczLoggingBaseFolder, wzPrefix, NULL, pLog->sczExtension, FALSE, FALSE, &pLog->sczPath);
146
+ hr = LogOpen(sczLoggingBaseFolder, wzPrefix, wzPostfix, pLog->sczExtension, FALSE, FALSE, &pLog->sczPath);
147
if (FAILED(hr))
148
{
149
LogDisable();
@@ -760,7 +769,9 @@ static HRESULT InitializeLogging(
769
770
pLog->dwAttributes |= pInternalCommand->dwLoggingAttributes;
771
763
- if (pInternalCommand->sczLogFile)
772
+ // The untrusted process needs a separate log file.
773
+ // TODO: Burn crashes if they do try to use the same log file.
774
+ if (pInternalCommand->sczLogFile && BURN_MODE_UNTRUSTED != pInternalCommand->mode)
775
{
776
hr = StrAllocString(&pLog->sczPath, pInternalCommand->sczLogFile, 0);
777
ExitOnFailure(hr, "Failed to copy log file path from command line.");