VirtualBox

儲存庫 vbox 的更動 89202


忽略:
時間撮記:
2021-5-20 下午02:32:08 (4 年 以前)
作者:
vboxsync
訊息:

VBoxSVC: Add a bit more release logging around WM_QUERYENDSESSION.
Make the monitoring window truely hidden. Add placeholder for
SetConsoleCtrlHandler - we won't get window events in the context of
an autostart session. bugref:8161.

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Main/src-server/win/svcmain.cpp

    r88821 r89202  
    625625static LRESULT CALLBACK WinMainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    626626{
    627     LRESULT rc = 0;
     627    LRESULT lResult = 0;
     628
    628629    switch (msg)
    629630    {
    630631        case WM_QUERYENDSESSION:
    631632        {
     633            LogRel(("WM_QUERYENDSESSION:%s%s%s%s (0x%08lx)\n",
     634                    lParam == 0                  ? " shutdown" : "",
     635                    lParam & ENDSESSION_CRITICAL ? " critical" : "",
     636                    lParam & ENDSESSION_LOGOFF   ? " logoff"   : "",
     637                    lParam & ENDSESSION_CLOSEAPP ? " close"    : "",
     638                    (unsigned long)lParam));
    632639            if (g_pModule)
    633640            {
     
    635642                if (fActiveConnection)
    636643                {
     644                    lResult = FALSE;
     645                    LogRel(("VBoxSvc has active connections:"
     646                            " bActivity = %RTbool, lock count = %d\n",
     647                            g_pModule->bActivity, g_pModule->GetLockCount()));
     648
    637649                    /* place the VBoxSVC into system shutdown list */
    638650                    ShutdownBlockReasonCreateAPI(hwnd, L"Has active connections.");
    639651                    /* decrease a latency of MonitorShutdown loop */
    640652                    ASMAtomicXchgU32(&dwTimeOut, 100);
    641                     Log(("VBoxSVCWinMain: WM_QUERYENDSESSION: VBoxSvc has active connections. bActivity = %d. Loc count = %d\n",
     653                    Log(("VBoxSVCWinMain: WM_QUERYENDSESSION: VBoxSvc has active connections."
     654                         " bActivity = %d. Lock count = %d\n",
    642655                         g_pModule->bActivity, g_pModule->GetLockCount()));
    643656                }
    644                 rc = !fActiveConnection;
     657                else
     658                {
     659                    LogRel(("No active connections:"
     660                            " bActivity = %RTbool, lock count = %d\n",
     661                            g_pModule->bActivity, g_pModule->GetLockCount()));
     662                    lResult = TRUE;
     663                }
    645664            }
    646665            else
     
    650669        case WM_ENDSESSION:
    651670        {
     671            LogRel(("WM_ENDSESSION:%s%s%s%s%s (%s/0x%08lx)\n",
     672                    lParam == 0                  ? " shutdown"  : "",
     673                    lParam & ENDSESSION_CRITICAL ? " critical"  : "",
     674                    lParam & ENDSESSION_LOGOFF   ? " logoff"    : "",
     675                    lParam & ENDSESSION_CLOSEAPP ? " close"     : "",
     676                    wParam == FALSE              ? " cancelled" : "",
     677                    wParam ? "TRUE" : "FALSE",
     678                    (unsigned long)lParam));
     679
    652680            /* Restore timeout of Monitor Shutdown if user canceled system shutdown */
    653681            if (wParam == FALSE)
    654682            {
     683                Log(("VBoxSVCWinMain: user canceled system shutdown.\n"));
    655684                ASMAtomicXchgU32(&dwTimeOut, dwNormalTimeout);
    656                 Log(("VBoxSVCWinMain: user canceled system shutdown.\n"));
     685                ShutdownBlockReasonDestroyAPI(hwnd);
    657686            }
    658687            break;
    659688        }
     689
    660690        case WM_DESTROY:
    661691        {
     
    664694            break;
    665695        }
     696
    666697        default:
    667698        {
    668             rc = DefWindowProc(hwnd, msg, wParam, lParam);
    669         }
    670     }
    671     return rc;
     699            lResult = DefWindowProc(hwnd, msg, wParam, lParam);
     700            break;
     701        }
     702    }
     703    return lResult;
    672704}
    673705
     
    694726    if (atomWindowClass == 0)
    695727    {
    696         Log(("Failed to register main window class\n"));
     728        LogRel(("Failed to register window class for session monitoring\n"));
    697729        rc = VERR_NOT_SUPPORTED;
    698730    }
     
    700732    {
    701733        /* Create the window. */
    702         g_hMainWindow = CreateWindowEx(WS_EX_TOOLWINDOW |  WS_EX_TOPMOST,
    703                                        MAIN_WND_CLASS, MAIN_WND_CLASS,
    704                                        WS_POPUPWINDOW,
     734        g_hMainWindow = CreateWindowEx(0, MAIN_WND_CLASS, MAIN_WND_CLASS, 0,
    705735                                       0, 0, 1, 1, NULL, NULL, g_hInstance, NULL);
    706736        if (g_hMainWindow == NULL)
    707737        {
    708             Log(("Failed to create main window\n"));
     738            LogRel(("Failed to create window for session monitoring\n"));
    709739            rc = VERR_NOT_SUPPORTED;
    710740        }
    711         else
    712         {
    713             SetWindowPos(g_hMainWindow, HWND_TOPMOST, -200, -200, 0, 0,
    714                          SWP_NOACTIVATE | SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_NOSIZE);
    715 
    716         }
    717     }
    718     return 0;
     741    }
     742    return rc;
    719743}
    720744
     
    735759    }
    736760}
     761
     762
     763static const char * const ctrl_event_names[] = {
     764    "CTRL_C_EVENT",
     765    "CTRL_BREAK_EVENT",
     766    "CTRL_CLOSE_EVENT",
     767    /* reserved, not used */
     768    "<console control event 3>",
     769    "<console control event 4>",
     770    /* not sent to processes that load gdi32.dll or user32.dll */
     771    "CTRL_LOGOFF_EVENT",
     772    "CTRL_SHUTDOWN_EVENT",
     773};
     774
     775/** @todo r=uwe placeholder */
     776BOOL WINAPI
     777ConsoleCtrlHandler(DWORD dwCtrlType) RT_NOTHROW_DEF
     778{
     779    const char *signame;
     780    char namebuf[48];
     781    // int rc;
     782
     783    if (dwCtrlType < RT_ELEMENTS(ctrl_event_names))
     784        signame = ctrl_event_names[dwCtrlType];
     785    else
     786    {
     787        /* should not happen, but be prepared */
     788        RTStrPrintf(namebuf, sizeof(namebuf),
     789                    "<console control event %lu>", (unsigned long)dwCtrlType);
     790        signame = namebuf;
     791    }
     792    LogRel(("Got %s\n", signame));
     793
     794    if (RT_UNLIKELY(g_pModule == NULL))
     795    {
     796        LogRel(("%s: g_pModule == NULL\n", __FUNCTION__));
     797        return TRUE;
     798    }
     799
     800    /* decrease latency of the MonitorShutdown loop */
     801    ASMAtomicXchgU32(&dwTimeOut, 100);
     802
     803    bool fHasClients = g_pModule->HasActiveConnection();
     804    if (!fHasClients)
     805    {
     806        LogRel(("No clients, closing the shop.\n"));
     807        return TRUE;
     808    }
     809
     810    LogRel(("VBoxSvc has clients: bActivity = %RTbool, lock count = %d\n",
     811            g_pModule->bActivity, g_pModule->GetLockCount()));
     812
     813    /** @todo r=uwe wait for clients to disconnect */
     814    return TRUE;
     815}
     816
    737817
    738818
     
    9951075    else
    9961076    {
     1077
    9971078        g_pModule->StartMonitor();
    9981079#if _WIN32_WINNT >= 0x0400
     
    10051086        _ASSERTE(SUCCEEDED(hRes));
    10061087
     1088        /*
     1089         * Register windows console signal handler to react to Ctrl-C,
     1090         * Ctrl-Break, Close; but more importantly - to get notified
     1091         * about shutdown when we are running in the context of the
     1092         * autostart service - we won't get WM_ENDSESSION in that
     1093         * case.
     1094         */
     1095        ::SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
     1096
     1097
    10071098        if (RT_SUCCESS(CreateMainWindow()))
    10081099            Log(("SVCMain: Main window succesfully created\n"));
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette