VirtualBox

Changeset 24074 in vbox for trunk/src


Ignore:
Timestamp:
Oct 26, 2009 1:02:06 PM (15 years ago)
Author:
vboxsync
Message:

Main/Machine: fix race when spawning session, caused VBoxSVC crash due to temporary setting the session state to "Spawning", without having a progress object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/MachineImpl.cpp

    r24024 r24074  
    25662566                        tr("Setting passthrough rejected as the device attached to device slot %d on port %d of controller '%ls' is not a DVD"),
    25672567                        aDevice, aControllerPort, aControllerName);
    2568     pAttach->updatePassthrough(aPassthrough);
     2568    pAttach->updatePassthrough(!!aPassthrough);
    25692569
    25702570    return S_OK;
     
    37713771
    37723772    /* may not be busy */
    3773     AssertReturn(!Global::IsOnlineOrTransient (mData->mMachineState), E_FAIL);
     3773    AssertReturn(!Global::IsOnlineOrTransient(mData->mMachineState), E_FAIL);
    37743774
    37753775    /* get the session PID */
    37763776    RTPROCESS pid = NIL_RTPROCESS;
    3777     AssertCompile (sizeof (ULONG) == sizeof (RTPROCESS));
    3778     aControl->GetPID ((ULONG *) &pid);
    3779     Assert (pid != NIL_RTPROCESS);
     3777    AssertCompile(sizeof(ULONG) == sizeof(RTPROCESS));
     3778    aControl->GetPID((ULONG *) &pid);
     3779    Assert(pid != NIL_RTPROCESS);
    37803780
    37813781    if (mData->mSession.mState == SessionState_Spawning)
     
    38003800    ComObjPtr<SessionMachine> sessionMachine;
    38013801    sessionMachine.createObject();
    3802     HRESULT rc = sessionMachine->init (this);
    3803     AssertComRC (rc);
     3802    HRESULT rc = sessionMachine->init(this);
     3803    AssertComRC(rc);
    38043804
    38053805    /* NOTE: doing return from this function after this point but
     
    38123812    {
    38133813#ifdef VBOX_WITH_RESOURCE_USAGE_API
    3814         registerMetrics (mParent->performanceCollector(), this, pid);
     3814        registerMetrics(mParent->performanceCollector(), this, pid);
    38153815#endif /* VBOX_WITH_RESOURCE_USAGE_API */
    38163816
     
    38363836
    38373837        LogFlowThisFunc(("Calling AssignMachine()...\n"));
    3838         rc = aControl->AssignMachine (sessionMachine);
     3838        rc = aControl->AssignMachine(sessionMachine);
    38393839        LogFlowThisFunc(("AssignMachine() returned %08X\n", rc));
    38403840
    38413841        /* The failure may occur w/o any error info (from RPC), so provide one */
    3842         if (FAILED (rc))
    3843             setError (VBOX_E_VM_ERROR,
    3844                 tr ("Failed to assign the machine to the session (%Rrc)"), rc);
     3842        if (FAILED(rc))
     3843            setError(VBOX_E_VM_ERROR,
     3844                tr("Failed to assign the machine to the session (%Rrc)"), rc);
    38453845
    38463846        if (SUCCEEDED(rc) && origState == SessionState_Spawning)
     
    38503850            /* get the console from the direct session */
    38513851            ComPtr<IConsole> console;
    3852             rc = aControl->GetRemoteConsole (console.asOutParam());
    3853             ComAssertComRC (rc);
     3852            rc = aControl->GetRemoteConsole(console.asOutParam());
     3853            ComAssertComRC(rc);
    38543854
    38553855            if (SUCCEEDED(rc) && !console)
    38563856            {
    3857                 ComAssert (!!console);
     3857                ComAssert(!!console);
    38583858                rc = E_FAIL;
    38593859            }
     
    38683868                LogFlowThisFunc(("Calling AssignRemoteMachine()...\n"));
    38693869                rc = mData->mSession.mRemoteControls.front()->
    3870                     AssignRemoteMachine (sessionMachine, console);
     3870                    AssignRemoteMachine(sessionMachine, console);
    38713871                LogFlowThisFunc(("AssignRemoteMachine() returned %08X\n", rc));
    38723872
     
    39323932         * at least on XPCOM) */
    39333933        ComPtr<IUnknown> unk = mData->mSession.mDirectControl;
    3934         NOREF (unk);
     3934        NOREF(unk);
    39353935    }
    39363936
     
    39383938    {
    39393939        /* finalize the progress after setting the state, for consistency */
    3940         mData->mSession.mProgress->notifyComplete (rc);
     3940        mData->mSession.mProgress->notifyComplete(rc);
    39413941        mData->mSession.mProgress.setNull();
    39423942    }
     
    44074407
    44084408    /* VirtualBox::addProcessToReap() needs a write lock */
    4409     AutoMultiWriteLock2 alock (mParent, this);
     4409    AutoMultiWriteLock2 alock(mParent, this);
    44104410
    44114411    if (mData->mSession.mState != SessionState_Spawning)
     
    44184418    HRESULT rc = S_OK;
    44194419
    4420 #if defined (RT_OS_WINDOWS) || defined (RT_OS_OS2)
     4420#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
    44214421
    44224422    /* the process was already unexpectedly terminated, we just need to set an
     
    44274427#else
    44284428
     4429    /* PID not yet initialized, skip check. */
     4430    if (mData->mSession.mPid == NIL_RTPROCESS)
     4431        return false;
     4432
    44294433    RTPROCSTATUS status;
    4430     int vrc = ::RTProcWait (mData->mSession.mPid, RTPROCWAIT_FLAGS_NOBLOCK,
    4431                             &status);
     4434    int vrc = ::RTProcWait(mData->mSession.mPid, RTPROCWAIT_FLAGS_NOBLOCK,
     4435                           &status);
    44324436
    44334437    if (vrc != VERR_PROCESS_RUNNING)
     
    44434447         * the relevant part in checkForSpawnFailure()). */
    44444448
    4445         Assert (mData->mSession.mRemoteControls.size() == 1);
     4449        Assert(mData->mSession.mRemoteControls.size() == 1);
    44464450        if (mData->mSession.mRemoteControls.size() == 1)
    44474451        {
     
    44544458
    44554459        /* finalize the progress after setting the state, for consistency */
    4456         mData->mSession.mProgress->notifyComplete (rc);
    4457         mData->mSession.mProgress.setNull();
    4458 
    4459         mParent->addProcessToReap (mData->mSession.mPid);
     4460        if (!mData->mSession.mProgress.isNull())
     4461        {
     4462            mData->mSession.mProgress->notifyComplete(rc);
     4463            mData->mSession.mProgress.setNull();
     4464        }
     4465
     4466        mParent->addProcessToReap(mData->mSession.mPid);
    44604467        mData->mSession.mPid = NIL_RTPROCESS;
    44614468
    4462         mParent->onSessionStateChange (mData->mUuid, SessionState_Closed);
     4469        mParent->onSessionStateChange(mData->mUuid, SessionState_Closed);
    44634470        return true;
    44644471    }
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