Delay closing the bundle log so that restart failures will be logged.
Sean Hall committed
Sep 2, 2022 at 16:08 UTC
e263e6bca03d783ece2f2dc86345dcdfc4b9776d
4 files changed
+95
-38
src/burn/engine/engine.cpp
+35
-33
@@ -297,6 +297,41 @@ LExit:
297
hr = SUCCEEDED(hr) ? HRESULT_FROM_WIN32(ERROR_SUCCESS_REBOOT_REQUIRED) : HRESULT_FROM_WIN32(ERROR_FAIL_REBOOT_REQUIRED);
298
}
299
300
+ if (fRunNormal)
301
+ {
302
+ LogId(REPORT_STANDARD, MSG_EXITING, FAILED(hr) ? (int)hr : *pdwExitCode, LoggingBoolToString(fRestart));
303
+ }
304
+ else if (fRunUntrusted)
305
+ {
306
+ LogId(REPORT_STANDARD, MSG_EXITING_CLEAN_ROOM, FAILED(hr) ? (int)hr : *pdwExitCode);
307
+ }
308
+ else if (fRunRunOnce)
309
+ {
310
+ LogId(REPORT_STANDARD, MSG_EXITING_RUN_ONCE, FAILED(hr) ? (int)hr : *pdwExitCode);
311
+ }
312
+ else if (fRunElevated)
313
+ {
314
+ LogId(REPORT_STANDARD, MSG_EXITING_ELEVATED, FAILED(hr) ? (int)hr : *pdwExitCode);
315
+ }
316
+
317
+ if (fLogInitialized)
318
+ {
319
+ // Leave the log open before calling restart so messages can be logged from there.
320
+ // Best effort to make sure all previous messages are written to disk in case the restart causes messages to be lost in buffers.
321
+ LogFlush();
322
+ }
323
+
324
+ if (fRestart)
325
+ {
326
+ LogId(REPORT_STANDARD, MSG_RESTARTING);
327
+
328
+ HRESULT hrRestart = Restart();
329
+ if (FAILED(hrRestart))
330
+ {
331
+ LogErrorId(hrRestart, MSG_RESTART_FAILED);
332
+ }
333
+ }
334
+
335
UninitializeEngineState(&engineState);
336
337
if (fXmlInitialized)
@@ -329,42 +364,9 @@ LExit:
364
::CoUninitialize();
365
}
366
332
- if (fRunNormal)
333
- {
334
- LogId(REPORT_STANDARD, MSG_EXITING, FAILED(hr) ? (int)hr : *pdwExitCode, LoggingBoolToString(fRestart));
335
-
336
- if (fRestart)
337
- {
338
- LogId(REPORT_STANDARD, MSG_RESTARTING);
339
- }
340
- }
341
- else if (fRunUntrusted)
342
- {
343
- LogId(REPORT_STANDARD, MSG_EXITING_CLEAN_ROOM, FAILED(hr) ? (int)hr : *pdwExitCode);
344
- }
345
- else if (fRunRunOnce)
346
- {
347
- LogId(REPORT_STANDARD, MSG_EXITING_RUN_ONCE, FAILED(hr) ? (int)hr : *pdwExitCode);
348
- }
349
- else if (fRunElevated)
350
- {
351
- LogId(REPORT_STANDARD, MSG_EXITING_ELEVATED, FAILED(hr) ? (int)hr : *pdwExitCode);
352
- }
353
-
354
-
367
if (fLogInitialized)
368
{
369
DutilUninitialize();
358
- LogClose(FALSE);
359
- }
360
-
361
- if (fRestart)
362
- {
363
- Restart();
364
- }
365
-
366
- if (fLogInitialized)
367
- {
370
LogUninitialize(FALSE);
371
}
372
src/burn/engine/engine.mc
+7
@@ -184,6 +184,13 @@ Language=English
184
Elevated engine process is not running with elevated privileges. Either run the bundle as a privileged user or reconfigure Windows to allow standard users to request elevation.
185
.
186
187
+MessageId=23
188
+Severity=Error
189
+SymbolicName=MSG_RESTART_FAILED
190
+Language=English
191
+The restart request failed, error: %1!ls!. The machine will need to be manually restarted.
192
+.
193
+
194
MessageId=51
195
Severity=Error
196
SymbolicName=MSG_FAILED_PARSE_CONDITION
src/libs/dutil/WixToolset.DUtil/inc/logutil.h
+7
-1
@@ -81,6 +81,12 @@ HRESULT DAPI LogRename(
81
__in_z LPCWSTR wzNewPath
82
);
83
84
+/********************************************************************
85
+ LogFlush - calls ::FlushFileBuffers with the log file handle.
86
+
87
+********************************************************************/
88
+HRESULT DAPI LogFlush();
89
+
90
void DAPI LogClose(
91
__in BOOL fFooter
92
);
@@ -344,7 +350,7 @@ HRESULT DAPI LogFooter();
350
LogStringWorkRaw - Write a raw, unformatted string to the log
351
352
********************************************************************/
347
-HRESULT LogStringWorkRaw(
353
+HRESULT DAPI LogStringWorkRaw(
354
__in_z LPCSTR szLogData
355
);
356
src/libs/dutil/WixToolset.DUtil/logutil.cpp
+46
-4
@@ -40,6 +40,9 @@ static LPCSTR LOGUTIL_DEBUG = "debug";
40
static LPCSTR LOGUTIL_NONE = "none";
41
42
// prototypes
43
+static HRESULT LogStringWorkRawUnsynchronized(
44
+ __in_z LPCSTR szLogData
45
+ );
46
static HRESULT LogIdWork(
47
__in REPORT_LEVEL rl,
48
__in_opt HMODULE hModule,
@@ -245,6 +248,29 @@ LExit:
248
}
249
250
251
+extern "C" HRESULT DAPI LogFlush()
252
+{
253
+ HRESULT hr = S_OK;
254
+
255
+ ::EnterCriticalSection(&LogUtil_csLog);
256
+
257
+ if (INVALID_HANDLE_VALUE == LogUtil_hLog)
258
+ {
259
+ ExitFunction1(hr = S_FALSE);
260
+ }
261
+
262
+ if (!::FlushFileBuffers(LogUtil_hLog))
263
+ {
264
+ LoguExitWithLastError(hr, "Failed to flush log file buffers.");
265
+ }
266
+
267
+LExit:
268
+ ::LeaveCriticalSection(&LogUtil_csLog);
269
+
270
+ return hr;
271
+}
272
+
273
+
274
extern "C" void DAPI LogClose(
275
__in BOOL fFooter
276
)
@@ -630,7 +656,26 @@ extern "C" HRESULT DAPI LogFooter()
656
return hr;
657
}
658
633
-extern "C" HRESULT LogStringWorkRaw(
659
+extern "C" HRESULT DAPI LogStringWorkRaw(
660
+ __in_z LPCSTR szLogData
661
+ )
662
+{
663
+ HRESULT hr = S_OK;
664
+
665
+ ::EnterCriticalSection(&LogUtil_csLog);
666
+
667
+ hr = LogStringWorkRawUnsynchronized(szLogData);
668
+
669
+ ::LeaveCriticalSection(&LogUtil_csLog);
670
+
671
+ return hr;
672
+}
673
+
674
+//
675
+// private worker functions
676
+//
677
+
678
+static HRESULT LogStringWorkRawUnsynchronized(
679
__in_z LPCSTR szLogData
680
)
681
{
@@ -671,9 +716,6 @@ LExit:
716
return hr;
717
}
718
674
-//
675
-// private worker functions
676
-//
719
static HRESULT LogIdWork(
720
__in REPORT_LEVEL rl,
721
__in_opt HMODULE hModule,