VirtualBox

Ignore:
Timestamp:
Oct 25, 2011 9:45:40 AM (13 years ago)
Author:
vboxsync
Message:

VBoxService/VMInfo: Hook CTRL_LOGOFF_EVENT to re-trigger user enumeration on Windows guests to get immediate disconnects from VRDP when a user has been logged out.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp

    r38224 r39106  
    8383
    8484
     85#ifdef RT_OS_WINDOWS
     86static BOOL WINAPI VBoxServiceVMInfoConsoleControlHandler(DWORD dwCtrlType)
     87{
     88    int rc = VINF_SUCCESS;
     89    bool fEventHandled = FALSE;
     90    switch (dwCtrlType)
     91    {
     92        case CTRL_LOGOFF_EVENT:
     93            VBoxServiceVerbose(2, "VMInfo: Received logged-off event\n");
     94            /* Trigger a re-enumeration of all logged-in users by unblocking
     95             * the multi event semaphore of the VMInfo thread. */
     96            if (g_hVMInfoEvent)
     97                rc = RTSemEventMultiSignal(g_hVMInfoEvent);
     98            fEventHandled = TRUE;
     99            break;
     100        default:
     101            break;
     102        /** @todo Add other events here. */
     103    }
     104
     105    if (RT_FAILURE(rc))
     106        VBoxServiceError("VMInfo: Event %ld handled with error rc=%Rrc\n",
     107                         dwCtrlType, rc);
     108    return fEventHandled;
     109}
     110#endif /* RT_OS_WINDOWS */
     111
     112
    85113/** @copydoc VBOXSERVICE::pfnPreInit */
    86114static DECLCALLBACK(int) VBoxServiceVMInfoPreInit(void)
     
    154182        VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/Net/Count",
    155183                                        VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE, NULL /* Delete on exit */);
     184
     185#ifdef RT_OS_WINDOWS
     186# ifndef RT_OS_NT4
     187    /* Install console control handler. */
     188    if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)VBoxServiceVMInfoConsoleControlHandler, TRUE /* Add handler */))
     189    {
     190        VBoxServiceError("VMInfo: Unable to add console control handler, error=%ld\n", GetLastError());
     191        /* Just skip this error, not critical. */
     192    }
     193# endif /* !RT_OS_NT4 */
     194#endif /* RT_OS_WINDOWS */
    156195    }
    157196    return rc;
     
    812851            break;
    813852        }
     853        else if (RT_LIKELY(RT_SUCCESS(rc2)))
     854        {
     855            /* Reset event semaphore if it got triggered. */
     856            rc2 = RTSemEventMultiReset(g_hVMInfoEvent);
     857            if (RT_FAILURE(rc2))
     858                rc2 = VBoxServiceError("VMInfo: RTSemEventMultiReset failed; rc2=%Rrc\n", rc2);
     859        }
    814860    }
    815861
     
    833879{
    834880    int rc;
     881
     882#ifdef RT_OS_WINDOWS
     883# ifndef RT_OS_NT4
     884    /* Install console control handler. */
     885    if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)NULL, FALSE /* Remove handler */))
     886    {
     887        VBoxServiceError("VMInfo: Unable to remove console control handler, error=%ld\n", GetLastError());
     888        /* Just skip this error, not critical. */
     889    }
     890# endif /* !RT_OS_NT4 */
     891#endif
    835892
    836893    if (g_hVMInfoEvent != NIL_RTSEMEVENTMULTI)
Note: See TracChangeset for help on using the changeset viewer.

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