VirtualBox

Changeset 99627 in vbox for trunk


Ignore:
Timestamp:
May 5, 2023 10:07:31 AM (17 months ago)
Author:
vboxsync
Message:

Guest / Host: Make sure to close the display server connections when done in VBGHDisplayServerTypeDetect(). bugref:10427

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/DisplayServerType.cpp

    r99620 r99627  
    8282
    8383    /* Try to connect to the wayland display, assuming it succeeds only when a wayland compositor is active: */
    84     void *pWaylandDisplay = NULL;
     84    bool     fHasWayland    = false;
    8585    RTLDRMOD hWaylandClient = NIL_RTLDRMOD;
    8686    int rc = RTLdrLoadSystem("libwayland-client.so", /* fNoUnload = */ true, &hWaylandClient);
     
    8888    {
    8989        void * (*pWaylandDisplayConnect)(const char *);
     90        void (*pWaylandDisplayDisconnect)(void *);
    9091        rc = RTLdrGetSymbol(hWaylandClient, "wl_display_connect", (void **)&pWaylandDisplayConnect);
    91         if (   RT_SUCCESS(rc)
    92             && pWaylandDisplayConnect)
    93             pWaylandDisplay = pWaylandDisplayConnect(NULL);
     92        if (RT_SUCCESS(rc))
     93            rc = RTLdrGetSymbol(hWaylandClient, "wl_display_disconnect", (void **)&pWaylandDisplayDisconnect);
     94        if (RT_SUCCESS(rc))
     95        {
     96            AssertPtrReturn(pWaylandDisplayConnect, VBGHDISPLAYSERVERTYPE_NONE);
     97            AssertPtrReturn(pWaylandDisplayDisconnect, VBGHDISPLAYSERVERTYPE_NONE);
     98            void *pDisplay = pWaylandDisplayConnect(NULL);
     99            if (pDisplay)
     100            {
     101                fHasWayland = true;
     102                pWaylandDisplayDisconnect(pDisplay);
     103            }
     104        }
    94105        RTLdrClose(hWaylandClient);
    95106    }
    96107
    97108    /* Also try to connect to the default X11 display to determine if Xserver is running: */
    98     void *pXDisplay = NULL;
    99     RTLDRMOD hX11 = NIL_RTLDRMOD;
     109    bool     fHasX = false;
     110    RTLDRMOD hX11  = NIL_RTLDRMOD;
    100111    rc = RTLdrLoadSystem("libX11.so", /* fNoUnload = */ true, &hX11);
    101112    if (RT_SUCCESS(rc))
    102113    {
    103114        void * (*pfnOpenDisplay)(const char *);
     115        int (*pfnCloseDisplay)(void *);
    104116        rc = RTLdrGetSymbol(hX11, "XOpenDisplay", (void **)&pfnOpenDisplay);
    105         if (   RT_SUCCESS(rc)
    106             && pfnOpenDisplay)
    107             pXDisplay = pfnOpenDisplay(NULL);
     117        if (RT_SUCCESS(rc))
     118            rc = RTLdrGetSymbol(hX11, "XCloseDisplay", (void **)&pfnCloseDisplay);
     119
     120        if (RT_SUCCESS(rc))
     121        {
     122            AssertPtrReturn(pfnOpenDisplay, VBGHDISPLAYSERVERTYPE_NONE);
     123            AssertPtrReturn(pfnCloseDisplay, VBGHDISPLAYSERVERTYPE_NONE);
     124            void *pDisplay = pfnOpenDisplay(NULL);
     125            if (pDisplay)
     126            {
     127                fHasX = true;
     128                pfnCloseDisplay(pDisplay);
     129            }
     130        }
     131
    108132        RTLdrClose(hX11);
    109133    }
     
    111135    /* If both wayland and X11 display can be connected then we should have XWayland: */
    112136    VBGHDISPLAYSERVERTYPE retSessionType = VBGHDISPLAYSERVERTYPE_NONE;
    113     if (pWaylandDisplay && pXDisplay)
     137    if (fHasWayland && fHasX)
    114138        retSessionType = VBGHDISPLAYSERVERTYPE_XWAYLAND;
    115     else if (pWaylandDisplay && !pXDisplay)
     139    else if (fHasWayland)
    116140        retSessionType = VBGHDISPLAYSERVERTYPE_WAYLAND;
    117     else if (!pWaylandDisplay && pXDisplay)
     141    else if (fHasX)
    118142        retSessionType = VBGHDISPLAYSERVERTYPE_X11;
    119143
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