Changeset 76092 in vbox for trunk/src/VBox/Main/src-server/win
- Timestamp:
- Dec 9, 2018 11:19:16 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 127333
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/win/svcmain.cpp
r76091 r76092 28 28 #include "VBox/com/com.h" 29 29 #include "VBox/com/VirtualBox.h" 30 #include "VBox/com/array.h"31 30 32 31 #include "VirtualBoxImpl.h" … … 43 42 #include <iprt/message.h> 44 43 #include <iprt/asm.h> 45 46 //#ifdef VBOX_WITH_SDS47 //# include <TlHelp32.h>48 //#endif49 44 50 45 … … 98 93 volatile uint32_t dwTimeOut = dwNormalTimeout; /* time for EXE to be idle before shutting down. Can be decreased at system shutdown phase. */ 99 94 100 101 #if 0 //def VBOX_WITH_SDS102 103 BOOL CALLBACK CloseWindowProc(_In_ HWND hWnd, _In_ LPARAM /* lParam */)104 {105 _ASSERTE(hWnd);106 DWORD_PTR dwResult;107 // Close topmost windows in the thread108 LRESULT lResult = SendMessageTimeout(hWnd, WM_CLOSE, NULL, NULL,109 SMTO_ABORTIFHUNG | SMTO_BLOCK, 0, &dwResult);110 if (lResult != 0)111 {112 LogRel(("EnumThreadWndProc: Close message sent to window %x successfully \n", hWnd));113 }114 else115 {116 LogRel(("EnumThreadWndProc: Cannot send event to window %x. result: %d, last error: %x\n",117 hWnd, dwResult, GetLastError()));118 }119 return TRUE;120 }121 122 void SendCloseToAllThreads(DWORD dwTargetPid)123 {124 HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);125 if (hSnapshot == NULL)126 {127 LogRel(("SendCloseToAllThreads: cannot get threads snapshot. error: 0x%x \n",128 GetLastError()));129 return;130 }131 132 THREADENTRY32 threadEntry;133 ZeroMemory(&threadEntry, sizeof(threadEntry));134 threadEntry.dwSize = sizeof(threadEntry);135 136 if (Thread32First(hSnapshot, &threadEntry))137 {138 do139 {140 LogRel(("SendCloseToAllThreads: process: %d thread: %x \n",141 threadEntry.th32OwnerProcessID, threadEntry.th32ThreadID));142 if (threadEntry.th32OwnerProcessID == dwTargetPid)143 {144 BOOL bRes = EnumThreadWindows(threadEntry.th32ThreadID, CloseWindowProc, NULL);145 if (!bRes)146 {147 LogRel(("SendCloseToAllThreads: EnumThreadWindows() failed to enumerate threads. error: %x \n",148 GetLastError()));149 }150 else151 {152 LogRel(("SendCloseToAllThreads: about to close window in thread %x of process d\n",153 threadEntry.th32ThreadID, dwTargetPid));154 }155 }156 } while (Thread32Next(hSnapshot, &threadEntry));157 }158 CloseHandle(hSnapshot);159 }160 161 static int CloseActiveClients()162 {163 ComPtr<IVirtualBoxClientList> ptrClientList;164 /**165 * Connect to VBoxSDS.166 * here we close all API client processes: our own and customers167 */168 LogRelFunc(("Forcibly close API clients during system shutdown on Windows 7:\n"));169 HRESULT hrc = CoCreateInstance(CLSID_VirtualBoxClientList, NULL, CLSCTX_LOCAL_SERVER, IID_IVirtualBoxClientList,170 (void **)ptrClientList.asOutParam());171 if (SUCCEEDED(hrc))172 {173 com::SafeArray<LONG> aCllients;174 hrc = ptrClientList->get_Clients(aCllients.__asOutParam());175 RTCList<LONG> clientsList = aCllients.toList();176 LogRel(("==========Client list begin ========\n"));177 for (size_t i = 0; i < clientsList.size(); i++)178 {179 LogRel(("About to close client pid: %d\n", clientsList[i]));180 SendCloseToAllThreads(clientsList[i]);181 }182 LogRel(("==========Client list end ========\n"));183 }184 else185 {186 LogFunc(("Error to connect to VBoxSDS: hr=%Rhrf\n", hrc));187 }188 return 0;189 }190 191 // These are copies of functions defined in VersionHelpers.h192 bool IsWindowsVersionOrGreaterWrap(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)193 {194 OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0,{ 0 }, 0, 0 };195 DWORDLONG const dwlConditionMask = VerSetConditionMask(196 VerSetConditionMask(197 VerSetConditionMask(198 0, VER_MAJORVERSION, VER_GREATER_EQUAL),199 VER_MINORVERSION, VER_GREATER_EQUAL),200 VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);201 202 osvi.dwMajorVersion = wMajorVersion;203 osvi.dwMinorVersion = wMinorVersion;204 osvi.wServicePackMajor = wServicePackMajor;205 206 return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;207 }208 209 #if !defined _WIN32_WINNT_WIN8210 211 #define _WIN32_WINNT_WIN8 0x0602212 213 #endif // #if !defined _WIN32_WINNT_WIN8214 215 bool IsWindows8OrGreaterWrap()216 {217 return IsWindowsVersionOrGreaterWrap(HIBYTE(_WIN32_WINNT_WIN8), LOBYTE(_WIN32_WINNT_WIN8), 0);218 }219 220 #endif // !VBOX_WITH_SDS221 95 222 96 … … 367 241 HRESULT VirtualBoxClassFactory::i_registerWithSds(IUnknown **ppOtherVirtualBox); 368 242 void VirtualBoxClassFactory::i_deregisterWithSds(void); 369 void VirtualBoxClassFactory::i_finishVBoxSvc();370 243 371 244 friend VBoxSVCRegistration; … … 438 311 return m_pFactory->i_getVirtualBox(ppResult); 439 312 return E_FAIL; 440 }441 442 // IVBoxSVCRegistration: called from443 STDMETHOD(NotifyClientsFinished)()444 {445 LogRelFunc(("All clients gone - shutdown sequence initiated\n"));446 if (m_pFactory)447 m_pFactory->i_finishVBoxSvc();448 449 // This is not enough to finish VBoxSvc such as reference to crashed client still is in action450 // So I forcebly shutdown VBoxSvc451 LONG cLocks = g_pModule->Unlock();452 LogRelFunc(("Unlock -> %d\n", cLocks));453 while (cLocks > 0)454 cLocks = g_pModule->Unlock();455 456 LogRelFunc(("returns\n"));457 return S_OK;458 313 } 459 314 }; … … 507 362 NOREF(hrc); 508 363 } 509 } 510 i_finishVBoxSvc(); 364 m_ptrVirtualBoxSDS.setNull(); 365 g_fRegisteredWithVBoxSDS = false; 366 } 367 if (m_pVBoxSVC) 368 { 369 m_pVBoxSVC->m_pFactory = NULL; 370 m_pVBoxSVC->Release(); 371 m_pVBoxSVC = NULL; 372 } 511 373 } 512 374 … … 534 396 Log(("VirtualBoxClassFactory::GetVirtualBox: E_FAIL\n")); 535 397 return E_FAIL; 536 }537 538 539 void VirtualBoxClassFactory::i_finishVBoxSvc()540 {541 LogRelFunc(("Finish work of VBoxSVC and VBoxSDS\n"));542 if (m_ptrVirtualBoxSDS.isNotNull())543 {544 m_ptrVirtualBoxSDS.setNull();545 g_fRegisteredWithVBoxSDS = false;546 }547 if (m_pVBoxSVC)548 {549 m_pVBoxSVC->m_pFactory = NULL;550 m_pVBoxSVC->Release();551 m_pVBoxSVC = NULL;552 }553 398 } 554 399 … … 794 639 Log(("VBoxSVCWinMain: WM_QUERYENDSESSION: VBoxSvc has active connections. bActivity = %d. Loc count = %d\n", 795 640 g_pModule->bActivity, g_pModule->GetLockCount())); 796 797 #if 0 //def VBOX_WITH_SDS798 // On Windows 7 our clients doesn't receive right sequence of Session End events799 // So we send them all WM_QUIT to forcible close them.800 // Windows 10 sends end session events correctly801 // Note: the IsWindows8Point1() and IsWindows10OrGreater() doesnt work in802 // application without manifest so I use old compatible functions for detection of Win 7803 if(!IsWindows8OrGreaterWrap())804 CloseActiveClients();805 #endif806 641 } 807 642 rc = !fActiveConnection;
Note:
See TracChangeset
for help on using the changeset viewer.