From e263e6bca03d783ece2f2dc86345dcdfc4b9776d Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 2 Sep 2022 16:08:29 -0500 Subject: Delay closing the bundle log so that restart failures will be logged. --- src/libs/dutil/WixToolset.DUtil/inc/logutil.h | 8 ++++- src/libs/dutil/WixToolset.DUtil/logutil.cpp | 50 ++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 5 deletions(-) (limited to 'src/libs') diff --git a/src/libs/dutil/WixToolset.DUtil/inc/logutil.h b/src/libs/dutil/WixToolset.DUtil/inc/logutil.h index 0ad8510a..fba1e81e 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/logutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/logutil.h @@ -81,6 +81,12 @@ HRESULT DAPI LogRename( __in_z LPCWSTR wzNewPath ); +/******************************************************************** + LogFlush - calls ::FlushFileBuffers with the log file handle. + +********************************************************************/ +HRESULT DAPI LogFlush(); + void DAPI LogClose( __in BOOL fFooter ); @@ -344,7 +350,7 @@ HRESULT DAPI LogFooter(); LogStringWorkRaw - Write a raw, unformatted string to the log ********************************************************************/ -HRESULT LogStringWorkRaw( +HRESULT DAPI LogStringWorkRaw( __in_z LPCSTR szLogData ); diff --git a/src/libs/dutil/WixToolset.DUtil/logutil.cpp b/src/libs/dutil/WixToolset.DUtil/logutil.cpp index 606279c7..0a77a468 100644 --- a/src/libs/dutil/WixToolset.DUtil/logutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/logutil.cpp @@ -40,6 +40,9 @@ static LPCSTR LOGUTIL_DEBUG = "debug"; static LPCSTR LOGUTIL_NONE = "none"; // prototypes +static HRESULT LogStringWorkRawUnsynchronized( + __in_z LPCSTR szLogData + ); static HRESULT LogIdWork( __in REPORT_LEVEL rl, __in_opt HMODULE hModule, @@ -245,6 +248,29 @@ LExit: } +extern "C" HRESULT DAPI LogFlush() +{ + HRESULT hr = S_OK; + + ::EnterCriticalSection(&LogUtil_csLog); + + if (INVALID_HANDLE_VALUE == LogUtil_hLog) + { + ExitFunction1(hr = S_FALSE); + } + + if (!::FlushFileBuffers(LogUtil_hLog)) + { + LoguExitWithLastError(hr, "Failed to flush log file buffers."); + } + +LExit: + ::LeaveCriticalSection(&LogUtil_csLog); + + return hr; +} + + extern "C" void DAPI LogClose( __in BOOL fFooter ) @@ -630,7 +656,26 @@ extern "C" HRESULT DAPI LogFooter() return hr; } -extern "C" HRESULT LogStringWorkRaw( +extern "C" HRESULT DAPI LogStringWorkRaw( + __in_z LPCSTR szLogData + ) +{ + HRESULT hr = S_OK; + + ::EnterCriticalSection(&LogUtil_csLog); + + hr = LogStringWorkRawUnsynchronized(szLogData); + + ::LeaveCriticalSection(&LogUtil_csLog); + + return hr; +} + +// +// private worker functions +// + +static HRESULT LogStringWorkRawUnsynchronized( __in_z LPCSTR szLogData ) { @@ -671,9 +716,6 @@ LExit: return hr; } -// -// private worker functions -// static HRESULT LogIdWork( __in REPORT_LEVEL rl, __in_opt HMODULE hModule, -- cgit v1.2.3-55-g6feb