VirtualBox

Changeset 83554 in vbox for trunk/src


Ignore:
Timestamp:
Apr 4, 2020 1:29:02 PM (5 years ago)
Author:
vboxsync
Message:

Guest Control/VBoxService: Make sure to set a session's thread stopped state before notifying the host. bugref:9320

File:
1 edited

Legend:

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

    r83553 r83554  
    16231623    }
    16241624
    1625     VGSvcVerbose(3, "Guest session ID=%RU32 thread ended with sessionStatus=%RU32, sessionRc=%Rrc\n",
    1626                  idSession, uSessionStatus, uSessionRc);
    1627 
    1628     /*
    1629      * Report final status.
    1630      */
     1625    /* Make sure to set stopped state before we let the host know. */
     1626    ASMAtomicWriteBool(&pThread->fStopped, true);
     1627
     1628    /* Report final status, regardless if we failed to wait above, so that the host knows what's going on. */
     1629    VGSvcVerbose(3, "Reporting final status %RU32 of session ID=%RU32\n", uSessionStatus, idSession);
    16311630    Assert(uSessionStatus != GUEST_SESSION_NOTIFYTYPE_UNDEFINED);
    1632     VBGLR3GUESTCTRLCMDCTX ctx = { idClient, VBOX_GUESTCTRL_CONTEXTID_MAKE_SESSION(idSession),
    1633                                   0 /* uProtocol, unused */, 0 /* uNumParms, unused */ };
     1631
     1632    VBGLR3GUESTCTRLCMDCTX ctx = { g_idControlSvcClient, VBOX_GUESTCTRL_CONTEXTID_MAKE_SESSION(idSession)};
    16341633    rc2 = VbglR3GuestCtrlSessionNotify(&ctx, uSessionStatus, uSessionRc);
    16351634    if (RT_FAILURE(rc2))
    1636         VGSvcError("Reporting session ID=%RU32 final status failed with rc=%Rrc\n", idSession, rc2);
    1637 
    1638     VGSvcVerbose(3, "Session ID=%RU32 thread ending\n", idSession);
     1635        VGSvcError("Reporting final status of session ID=%RU32 failed with rc=%Rrc\n", idSession, rc2);
     1636
     1637    VGSvcVerbose(3, "Thread for session ID=%RU32 ended with sessionStatus=%RU32, sessionRc=%Rrc\n",
     1638                 idSession, uSessionStatus, uSessionRc);
     1639
    16391640    return VINF_SUCCESS;
    16401641}
     
    23902391    RTListForEach(pList, pSessionCur, VBOXSERVICECTRLSESSIONTHREAD, Node)
    23912392    {
    2392         AssertMsgReturn(pSessionCur->StartupInfo.uSessionID != pSessionStartupInfo->uSessionID,
    2393                         ("Guest session thread ID=%RU32 (%p) already exists when it should not\n",
    2394                          pSessionCur->StartupInfo.uSessionID, pSessionCur), VERR_ALREADY_EXISTS);
     2393        AssertMsgReturn(   pSessionCur->fStopped == true
     2394                        || pSessionCur->StartupInfo.uSessionID != pSessionStartupInfo->uSessionID,
     2395                        ("Guest session thread ID=%RU32 already exists (fStopped=%RTbool)\n",
     2396                         pSessionCur->StartupInfo.uSessionID, pSessionCur->fStopped), VERR_ALREADY_EXISTS);
    23952397    }
    23962398#endif
     
    25452547        rc = RTThreadWait(pThread->Thread, uTimeoutMS, &rcThread);
    25462548        if (RT_SUCCESS(rc))
     2549        {
     2550            AssertMsg(pThread->fStopped, ("Thread of session ID=%RU32 not in stopped state when it should\n",
     2551                      pThread->StartupInfo.uSessionID));
     2552
    25472553            VGSvcVerbose(3, "Session thread ID=%RU32 ended with rc=%Rrc\n", pThread->StartupInfo.uSessionID, rcThread);
     2554        }
    25482555        else
    25492556            VGSvcError("Waiting for session thread ID=%RU32 to close failed with rc=%Rrc\n", pThread->StartupInfo.uSessionID, rc);
    25502557    }
    2551 
     2558    else
     2559        VGSvcVerbose(3, "Thread for session ID=%RU32 not in started state, skipping wait\n", pThread->StartupInfo.uSessionID);
     2560
     2561    LogFlowFuncLeaveRC(rc);
    25522562    return rc;
    25532563}
     
    25652575    AssertPtrReturn(pThread, VERR_INVALID_POINTER);
    25662576
     2577    const uint32_t uSessionID = pThread->StartupInfo.uSessionID;
     2578
     2579    VGSvcVerbose(3, "Destroying session ID=%RU32 ...\n", uSessionID);
     2580
    25672581    int rc = VGSvcGstCtrlSessionThreadWait(pThread, 5 * 60 * 1000 /* 5 minutes timeout */, fFlags);
    2568 
    2569     /* Remove session from list and destroy object. */
    2570     RTListNodeRemove(&pThread->Node);
    2571 
    2572     RTMemFree(pThread);
    2573     pThread = NULL;
    2574 
     2582    if (RT_SUCCESS(rc))
     2583    {
     2584        /* Remove session from list and destroy object. */
     2585        RTListNodeRemove(&pThread->Node);
     2586
     2587        RTMemFree(pThread);
     2588        pThread = NULL;
     2589    }
     2590
     2591    VGSvcVerbose(3, "Destroyed session ID=%RU32 with %Rrc\n", uSessionID, rc);
    25752592    return rc;
    25762593}
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