diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2022-05-03 15:30:50 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-05-04 10:05:21 -0500 |
commit | 29f7e00586412163a20e298fbf84505f8a917425 (patch) | |
tree | 30257a3544f6982ded159443ebed0eb933f11a51 /src/burn | |
parent | 41d2c12d60ee84cefc26ec99abb328701883c8f5 (diff) | |
download | wix-29f7e00586412163a20e298fbf84505f8a917425.tar.gz wix-29f7e00586412163a20e298fbf84505f8a917425.tar.bz2 wix-29f7e00586412163a20e298fbf84505f8a917425.zip |
Only block shutdown during Apply.
Diffstat (limited to 'src/burn')
-rw-r--r-- | src/burn/engine/core.cpp | 4 | ||||
-rw-r--r-- | src/burn/engine/elevation.cpp | 21 | ||||
-rw-r--r-- | src/burn/engine/elevation.h | 3 | ||||
-rw-r--r-- | src/burn/engine/engine.cpp | 2 | ||||
-rw-r--r-- | src/burn/engine/plan.h | 1 | ||||
-rw-r--r-- | src/burn/engine/uithread.cpp | 20 | ||||
-rw-r--r-- | src/burn/engine/userexperience.cpp | 25 | ||||
-rw-r--r-- | src/burn/engine/userexperience.h | 5 |
8 files changed, 31 insertions, 50 deletions
diff --git a/src/burn/engine/core.cpp b/src/burn/engine/core.cpp index ec996c4c..19b739f9 100644 --- a/src/burn/engine/core.cpp +++ b/src/burn/engine/core.cpp | |||
@@ -681,6 +681,8 @@ extern "C" HRESULT CoreApply( | |||
681 | hr = ApplyLock(FALSE, &hLock); | 681 | hr = ApplyLock(FALSE, &hLock); |
682 | ExitOnFailure(hr, "Another per-user setup is already executing."); | 682 | ExitOnFailure(hr, "Another per-user setup is already executing."); |
683 | 683 | ||
684 | pEngineState->plan.fApplying = TRUE; | ||
685 | |||
684 | // Initialize only after getting a lock. | 686 | // Initialize only after getting a lock. |
685 | fApplyInitialize = TRUE; | 687 | fApplyInitialize = TRUE; |
686 | ApplyInitialize(); | 688 | ApplyInitialize(); |
@@ -814,6 +816,8 @@ LExit: | |||
814 | ApplyUninitialize(); | 816 | ApplyUninitialize(); |
815 | } | 817 | } |
816 | 818 | ||
819 | pEngineState->plan.fApplying = FALSE; | ||
820 | |||
817 | if (hLock) | 821 | if (hLock) |
818 | { | 822 | { |
819 | ::ReleaseMutex(hLock); | 823 | ::ReleaseMutex(hLock); |
diff --git a/src/burn/engine/elevation.cpp b/src/burn/engine/elevation.cpp index d2c5c8c6..75b24ec3 100644 --- a/src/burn/engine/elevation.cpp +++ b/src/burn/engine/elevation.cpp | |||
@@ -94,6 +94,7 @@ typedef struct _BURN_ELEVATION_CHILD_MESSAGE_CONTEXT | |||
94 | HANDLE hPipe; | 94 | HANDLE hPipe; |
95 | HANDLE* phLock; | 95 | HANDLE* phLock; |
96 | BOOL* pfDisabledAutomaticUpdates; | 96 | BOOL* pfDisabledAutomaticUpdates; |
97 | BOOL* pfApplying; | ||
97 | BURN_APPROVED_EXES* pApprovedExes; | 98 | BURN_APPROVED_EXES* pApprovedExes; |
98 | BURN_CACHE* pCache; | 99 | BURN_CACHE* pCache; |
99 | BURN_CONTAINERS* pContainers; | 100 | BURN_CONTAINERS* pContainers; |
@@ -176,6 +177,7 @@ static HRESULT OnApplyInitialize( | |||
176 | __in BURN_PACKAGES* pPackages, | 177 | __in BURN_PACKAGES* pPackages, |
177 | __in HANDLE* phLock, | 178 | __in HANDLE* phLock, |
178 | __in BOOL* pfDisabledWindowsUpdate, | 179 | __in BOOL* pfDisabledWindowsUpdate, |
180 | __in BOOL* pfApplying, | ||
179 | __in BYTE* pbData, | 181 | __in BYTE* pbData, |
180 | __in SIZE_T cbData | 182 | __in SIZE_T cbData |
181 | ); | 183 | ); |
@@ -185,7 +187,8 @@ static HRESULT ElevatedProcessDetect( | |||
185 | __in BURN_PACKAGES* pPackages | 187 | __in BURN_PACKAGES* pPackages |
186 | ); | 188 | ); |
187 | static HRESULT OnApplyUninitialize( | 189 | static HRESULT OnApplyUninitialize( |
188 | __in HANDLE* phLock | 190 | __in HANDLE* phLock, |
191 | __in BOOL* pfApplying | ||
189 | ); | 192 | ); |
190 | static HRESULT OnSessionBegin( | 193 | static HRESULT OnSessionBegin( |
191 | __in BURN_CACHE* pCache, | 194 | __in BURN_CACHE* pCache, |
@@ -1538,7 +1541,8 @@ extern "C" HRESULT ElevationChildPumpMessages( | |||
1538 | __out HANDLE* phLock, | 1541 | __out HANDLE* phLock, |
1539 | __out BOOL* pfDisabledAutomaticUpdates, | 1542 | __out BOOL* pfDisabledAutomaticUpdates, |
1540 | __out DWORD* pdwChildExitCode, | 1543 | __out DWORD* pdwChildExitCode, |
1541 | __out BOOL* pfRestart | 1544 | __out BOOL* pfRestart, |
1545 | __out BOOL* pfApplying | ||
1542 | ) | 1546 | ) |
1543 | { | 1547 | { |
1544 | HRESULT hr = S_OK; | 1548 | HRESULT hr = S_OK; |
@@ -1561,6 +1565,7 @@ extern "C" HRESULT ElevationChildPumpMessages( | |||
1561 | context.hPipe = hPipe; | 1565 | context.hPipe = hPipe; |
1562 | context.phLock = phLock; | 1566 | context.phLock = phLock; |
1563 | context.pfDisabledAutomaticUpdates = pfDisabledAutomaticUpdates; | 1567 | context.pfDisabledAutomaticUpdates = pfDisabledAutomaticUpdates; |
1568 | context.pfApplying = pfApplying; | ||
1564 | context.pApprovedExes = pApprovedExes; | 1569 | context.pApprovedExes = pApprovedExes; |
1565 | context.pCache = pCache; | 1570 | context.pCache = pCache; |
1566 | context.pContainers = pContainers; | 1571 | context.pContainers = pContainers; |
@@ -2114,11 +2119,11 @@ static HRESULT ProcessElevatedChildMessage( | |||
2114 | break; | 2119 | break; |
2115 | 2120 | ||
2116 | case BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE: | 2121 | case BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE: |
2117 | hrResult = OnApplyInitialize(pContext->hPipe, pContext->pVariables, pContext->pRegistration, pContext->pPackages, pContext->phLock, pContext->pfDisabledAutomaticUpdates, (BYTE*)pMsg->pvData, pMsg->cbData); | 2122 | hrResult = OnApplyInitialize(pContext->hPipe, pContext->pVariables, pContext->pRegistration, pContext->pPackages, pContext->phLock, pContext->pfDisabledAutomaticUpdates, pContext->pfApplying, (BYTE*)pMsg->pvData, pMsg->cbData); |
2118 | break; | 2123 | break; |
2119 | 2124 | ||
2120 | case BURN_ELEVATION_MESSAGE_TYPE_APPLY_UNINITIALIZE: | 2125 | case BURN_ELEVATION_MESSAGE_TYPE_APPLY_UNINITIALIZE: |
2121 | hrResult = OnApplyUninitialize(pContext->phLock); | 2126 | hrResult = OnApplyUninitialize(pContext->phLock, pContext->pfApplying); |
2122 | break; | 2127 | break; |
2123 | 2128 | ||
2124 | case BURN_ELEVATION_MESSAGE_TYPE_SESSION_BEGIN: | 2129 | case BURN_ELEVATION_MESSAGE_TYPE_SESSION_BEGIN: |
@@ -2267,6 +2272,7 @@ static HRESULT OnApplyInitialize( | |||
2267 | __in BURN_PACKAGES* pPackages, | 2272 | __in BURN_PACKAGES* pPackages, |
2268 | __in HANDLE* phLock, | 2273 | __in HANDLE* phLock, |
2269 | __in BOOL* pfDisabledWindowsUpdate, | 2274 | __in BOOL* pfDisabledWindowsUpdate, |
2275 | __in BOOL* pfApplying, | ||
2270 | __in BYTE* pbData, | 2276 | __in BYTE* pbData, |
2271 | __in SIZE_T cbData | 2277 | __in SIZE_T cbData |
2272 | ) | 2278 | ) |
@@ -2296,6 +2302,8 @@ static HRESULT OnApplyInitialize( | |||
2296 | hr = ApplyLock(TRUE, phLock); | 2302 | hr = ApplyLock(TRUE, phLock); |
2297 | ExitOnFailure(hr, "Failed to acquire lock due to setup in other session."); | 2303 | ExitOnFailure(hr, "Failed to acquire lock due to setup in other session."); |
2298 | 2304 | ||
2305 | *pfApplying = TRUE; | ||
2306 | |||
2299 | // Detect. | 2307 | // Detect. |
2300 | hr = ElevatedProcessDetect(pRegistration, pVariables, pPackages); | 2308 | hr = ElevatedProcessDetect(pRegistration, pVariables, pPackages); |
2301 | ExitOnFailure(hr, "Failed to run detection in elevated process."); | 2309 | ExitOnFailure(hr, "Failed to run detection in elevated process."); |
@@ -2419,13 +2427,16 @@ LExit: | |||
2419 | } | 2427 | } |
2420 | 2428 | ||
2421 | static HRESULT OnApplyUninitialize( | 2429 | static HRESULT OnApplyUninitialize( |
2422 | __in HANDLE* phLock | 2430 | __in HANDLE* phLock, |
2431 | __in BOOL* pfApplying | ||
2423 | ) | 2432 | ) |
2424 | { | 2433 | { |
2425 | Assert(phLock); | 2434 | Assert(phLock); |
2426 | 2435 | ||
2427 | // TODO: end system restore point. | 2436 | // TODO: end system restore point. |
2428 | 2437 | ||
2438 | *pfApplying = FALSE; | ||
2439 | |||
2429 | if (*phLock) | 2440 | if (*phLock) |
2430 | { | 2441 | { |
2431 | ::ReleaseMutex(*phLock); | 2442 | ::ReleaseMutex(*phLock); |
diff --git a/src/burn/engine/elevation.h b/src/burn/engine/elevation.h index 0dc189c5..d08d2edc 100644 --- a/src/burn/engine/elevation.h +++ b/src/burn/engine/elevation.h | |||
@@ -180,7 +180,8 @@ HRESULT ElevationChildPumpMessages( | |||
180 | __out HANDLE* phLock, | 180 | __out HANDLE* phLock, |
181 | __out BOOL* pfDisabledAutomaticUpdates, | 181 | __out BOOL* pfDisabledAutomaticUpdates, |
182 | __out DWORD* pdwChildExitCode, | 182 | __out DWORD* pdwChildExitCode, |
183 | __out BOOL* pfRestart | 183 | __out BOOL* pfRestart, |
184 | __out BOOL* pfApplying | ||
184 | ); | 185 | ); |
185 | HRESULT ElevationChildResumeAutomaticUpdates(); | 186 | HRESULT ElevationChildResumeAutomaticUpdates(); |
186 | 187 | ||
diff --git a/src/burn/engine/engine.cpp b/src/burn/engine/engine.cpp index 821626f8..ee848acf 100644 --- a/src/burn/engine/engine.cpp +++ b/src/burn/engine/engine.cpp | |||
@@ -653,7 +653,7 @@ static HRESULT RunElevated( | |||
653 | SrpInitialize(TRUE); | 653 | SrpInitialize(TRUE); |
654 | 654 | ||
655 | // Pump messages from parent process. | 655 | // Pump messages from parent process. |
656 | hr = ElevationChildPumpMessages(pEngineState->dwElevatedLoggingTlsId, pEngineState->companionConnection.hPipe, pEngineState->companionConnection.hCachePipe, &pEngineState->approvedExes, &pEngineState->cache, &pEngineState->containers, &pEngineState->packages, &pEngineState->payloads, &pEngineState->variables, &pEngineState->registration, &pEngineState->userExperience, &hLock, &fDisabledAutomaticUpdates, &pEngineState->userExperience.dwExitCode, &pEngineState->fRestart); | 656 | hr = ElevationChildPumpMessages(pEngineState->dwElevatedLoggingTlsId, pEngineState->companionConnection.hPipe, pEngineState->companionConnection.hCachePipe, &pEngineState->approvedExes, &pEngineState->cache, &pEngineState->containers, &pEngineState->packages, &pEngineState->payloads, &pEngineState->variables, &pEngineState->registration, &pEngineState->userExperience, &hLock, &fDisabledAutomaticUpdates, &pEngineState->userExperience.dwExitCode, &pEngineState->fRestart, &pEngineState->plan.fApplying); |
657 | LogRedirect(NULL, NULL); // reset logging so the next failure gets written to "log buffer" for the failure log. | 657 | LogRedirect(NULL, NULL); // reset logging so the next failure gets written to "log buffer" for the failure log. |
658 | ExitOnFailure(hr, "Failed to pump messages from parent process."); | 658 | ExitOnFailure(hr, "Failed to pump messages from parent process."); |
659 | 659 | ||
diff --git a/src/burn/engine/plan.h b/src/burn/engine/plan.h index 2b04e097..46a9a363 100644 --- a/src/burn/engine/plan.h +++ b/src/burn/engine/plan.h | |||
@@ -264,6 +264,7 @@ typedef struct _BURN_PLAN | |||
264 | LPWSTR sczLayoutDirectory; | 264 | LPWSTR sczLayoutDirectory; |
265 | BOOL fPlanPackageCacheRollback; | 265 | BOOL fPlanPackageCacheRollback; |
266 | BOOL fDowngrade; | 266 | BOOL fDowngrade; |
267 | BOOL fApplying; | ||
267 | 268 | ||
268 | DWORD64 qwCacheSizeTotal; | 269 | DWORD64 qwCacheSizeTotal; |
269 | 270 | ||
diff --git a/src/burn/engine/uithread.cpp b/src/burn/engine/uithread.cpp index bb1e5972..cdd8613c 100644 --- a/src/burn/engine/uithread.cpp +++ b/src/burn/engine/uithread.cpp | |||
@@ -17,8 +17,7 @@ struct UITHREAD_CONTEXT | |||
17 | struct UITHREAD_INFO | 17 | struct UITHREAD_INFO |
18 | { | 18 | { |
19 | BOOL fElevatedEngine; | 19 | BOOL fElevatedEngine; |
20 | BURN_USER_EXPERIENCE* pUserExperience; | 20 | BURN_ENGINE_STATE* pEngineState; |
21 | BOOL* pfCriticalShutdownInitiated; | ||
22 | }; | 21 | }; |
23 | 22 | ||
24 | 23 | ||
@@ -132,8 +131,7 @@ static DWORD WINAPI ThreadProc( | |||
132 | fRegistered = TRUE; | 131 | fRegistered = TRUE; |
133 | 132 | ||
134 | info.fElevatedEngine = fElevatedEngine; | 133 | info.fElevatedEngine = fElevatedEngine; |
135 | info.pUserExperience = &pEngineState->userExperience; | 134 | info.pEngineState = pEngineState; |
136 | info.pfCriticalShutdownInitiated = &pEngineState->fCriticalShutdownInitiated; | ||
137 | 135 | ||
138 | // Create the window to handle reboots without activating it. | 136 | // Create the window to handle reboots without activating it. |
139 | hWnd = ::CreateWindowExW(WS_EX_NOACTIVATE, wc.lpszClassName, NULL, WS_POPUP, 0, 0, 0, 0, HWND_DESKTOP, NULL, pContext->hInstance, &info); | 137 | hWnd = ::CreateWindowExW(WS_EX_NOACTIVATE, wc.lpszClassName, NULL, WS_POPUP, 0, 0, 0, 0, HWND_DESKTOP, NULL, pContext->hInstance, &info); |
@@ -196,21 +194,17 @@ static LRESULT CALLBACK WndProc( | |||
196 | { | 194 | { |
197 | DWORD dwEndSession = static_cast<DWORD>(lParam); | 195 | DWORD dwEndSession = static_cast<DWORD>(lParam); |
198 | BOOL fCritical = ENDSESSION_CRITICAL & dwEndSession; | 196 | BOOL fCritical = ENDSESSION_CRITICAL & dwEndSession; |
199 | BOOL fCancel = TRUE; | 197 | BOOL fCancel = FALSE; |
200 | BOOL fRet = FALSE; | 198 | BOOL fRet = FALSE; |
201 | 199 | ||
202 | // Always block shutdown in the elevated process, but ask the BA in the non-elevated. | 200 | // Always block shutdown during apply. |
203 | UITHREAD_INFO* pInfo = reinterpret_cast<UITHREAD_INFO*>(::GetWindowLongPtrW(hWnd, GWLP_USERDATA)); | 201 | UITHREAD_INFO* pInfo = reinterpret_cast<UITHREAD_INFO*>(::GetWindowLongPtrW(hWnd, GWLP_USERDATA)); |
204 | if (!pInfo->fElevatedEngine) | 202 | if (pInfo->pEngineState->plan.fApplying) |
205 | { | 203 | { |
206 | // TODO: instead of recommending canceling all non-critical shutdowns, maybe we should only recommend cancel | 204 | fCancel = TRUE; |
207 | // when the engine is doing work? | ||
208 | fCancel = !fCritical; | ||
209 | // TODO: There's a race condition here where the BA may not have been loaded, or already was unloaded. | ||
210 | UserExperienceOnSystemShutdown(pInfo->pUserExperience, dwEndSession, &fCancel); | ||
211 | } | 205 | } |
212 | 206 | ||
213 | *pInfo->pfCriticalShutdownInitiated |= fCritical; | 207 | pInfo->pEngineState->fCriticalShutdownInitiated |= fCritical; |
214 | 208 | ||
215 | fRet = !fCancel; | 209 | fRet = !fCancel; |
216 | LogId(REPORT_STANDARD, MSG_SYSTEM_SHUTDOWN, LoggingBoolToString(fCritical), LoggingBoolToString(pInfo->fElevatedEngine), LoggingBoolToString(fRet)); | 210 | LogId(REPORT_STANDARD, MSG_SYSTEM_SHUTDOWN, LoggingBoolToString(fCritical), LoggingBoolToString(pInfo->fElevatedEngine), LoggingBoolToString(fRet)); |
diff --git a/src/burn/engine/userexperience.cpp b/src/burn/engine/userexperience.cpp index a3cbcd4a..4325a6ee 100644 --- a/src/burn/engine/userexperience.cpp +++ b/src/burn/engine/userexperience.cpp | |||
@@ -2631,31 +2631,6 @@ LExit: | |||
2631 | return hr; | 2631 | return hr; |
2632 | } | 2632 | } |
2633 | 2633 | ||
2634 | EXTERN_C BAAPI UserExperienceOnSystemShutdown( | ||
2635 | __in BURN_USER_EXPERIENCE* pUserExperience, | ||
2636 | __in DWORD dwEndSession, | ||
2637 | __inout BOOL* pfCancel | ||
2638 | ) | ||
2639 | { | ||
2640 | HRESULT hr = S_OK; | ||
2641 | BA_ONSYSTEMSHUTDOWN_ARGS args = { }; | ||
2642 | BA_ONSYSTEMSHUTDOWN_RESULTS results = { }; | ||
2643 | |||
2644 | args.cbSize = sizeof(args); | ||
2645 | args.dwEndSession = dwEndSession; | ||
2646 | |||
2647 | results.cbSize = sizeof(results); | ||
2648 | results.fCancel = *pfCancel; | ||
2649 | |||
2650 | hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONSYSTEMSHUTDOWN, &args, &results); | ||
2651 | ExitOnFailure(hr, "BA OnSystemShutdown failed."); | ||
2652 | |||
2653 | *pfCancel = results.fCancel; | ||
2654 | |||
2655 | LExit: | ||
2656 | return hr; | ||
2657 | } | ||
2658 | |||
2659 | EXTERN_C BAAPI UserExperienceOnUnregisterBegin( | 2634 | EXTERN_C BAAPI UserExperienceOnUnregisterBegin( |
2660 | __in BURN_USER_EXPERIENCE* pUserExperience, | 2635 | __in BURN_USER_EXPERIENCE* pUserExperience, |
2661 | __inout BOOTSTRAPPER_REGISTRATION_TYPE* pRegistrationType | 2636 | __inout BOOTSTRAPPER_REGISTRATION_TYPE* pRegistrationType |
diff --git a/src/burn/engine/userexperience.h b/src/burn/engine/userexperience.h index 2059b521..e7489710 100644 --- a/src/burn/engine/userexperience.h +++ b/src/burn/engine/userexperience.h | |||
@@ -583,11 +583,6 @@ BAAPI UserExperienceOnSystemRestorePointComplete( | |||
583 | __in BURN_USER_EXPERIENCE* pUserExperience, | 583 | __in BURN_USER_EXPERIENCE* pUserExperience, |
584 | __in HRESULT hrStatus | 584 | __in HRESULT hrStatus |
585 | ); | 585 | ); |
586 | BAAPI UserExperienceOnSystemShutdown( | ||
587 | __in BURN_USER_EXPERIENCE* pUserExperience, | ||
588 | __in DWORD dwEndSession, | ||
589 | __inout BOOL* pfCancel | ||
590 | ); | ||
591 | BAAPI UserExperienceOnUnregisterBegin( | 586 | BAAPI UserExperienceOnUnregisterBegin( |
592 | __in BURN_USER_EXPERIENCE* pUserExperience, | 587 | __in BURN_USER_EXPERIENCE* pUserExperience, |
593 | __inout BOOTSTRAPPER_REGISTRATION_TYPE* pRegistrationType | 588 | __inout BOOTSTRAPPER_REGISTRATION_TYPE* pRegistrationType |