VirtualBox

Changeset 58951 in vbox


Ignore:
Timestamp:
Dec 2, 2015 1:44:44 PM (9 years ago)
Author:
vboxsync
Message:

bugref:6830. Extension pack is prohibited to install if there is at least one running VM

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/ExtPackManagerImpl.h

    r52596 r58951  
    212212
    213213private:
    214 
     214    HRESULT     i_isThereAnyRunningVM() const;
    215215    // wrapped IExtPackManager properties
    216216    HRESULT getInstalledExtPacks(std::vector<ComPtr<IExtPack> > &aInstalledExtPacks);
  • trunk/src/VBox/Main/src-all/ExtPackManagerImpl.cpp

    r58132 r58951  
    20822082    if (SUCCEEDED(hrc))
    20832083    {
     2084        AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
     2085
    20842086        /*
    20852087         * Run the set-uid-to-root binary that performs the cleanup.
     
    20882090         * VBoxSVC instance.
    20892091         */
    2090         AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
    2091         hrc = i_runSetUidToRootHelper(NULL,
     2092         hrc = i_runSetUidToRootHelper(NULL,
    20922093                                      "cleanup",
    20932094                                      "--base-dir", m->strBaseDir.c_str(),
     
    25262527}
    25272528
     2529HRESULT ExtPackManager::i_isThereAnyRunningVM() const
     2530{
     2531    HRESULT res = E_FAIL;
     2532    Assert(m->pVirtualBox != NULL); /* Only called from VBoxSVC. */
     2533    /*
     2534     * Get the list of all _running_ VMs
     2535     */
     2536    com::SafeIfaceArray<IMachine> machines;
     2537    com::SafeArray<MachineState_T> states;
     2538    int rc = m->pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
     2539    if (SUCCEEDED(rc))
     2540        rc = m->pVirtualBox->GetMachineStates(ComSafeArrayAsInParam(machines), ComSafeArrayAsOutParam(states));
     2541
     2542    if (SUCCEEDED(rc))
     2543    {
     2544        /*
     2545         * Iterate through the collection
     2546         */
     2547        for (size_t i = 0; i < machines.size(); ++i)
     2548        {
     2549            if (machines[i])
     2550            {
     2551                MachineState_T machineState = states[i];
     2552                switch (machineState)
     2553                {
     2554                    case MachineState_Running:
     2555                    case MachineState_Teleporting:
     2556                    case MachineState_LiveSnapshotting:
     2557                    case MachineState_Paused:
     2558                    case MachineState_TeleportingPausedVM:
     2559                        res = S_OK;
     2560                        break;
     2561                }
     2562            }
     2563            if (res == S_OK)
     2564                break;
     2565        }
     2566    }
     2567
     2568    return res;
     2569
     2570}
     2571
    25282572/**
    25292573 * Thread wrapper around doInstall.
     
    25702614    {
    25712615        AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
    2572 
    2573         /*
    2574          * Refresh the data we have on the extension pack as it
    2575          * may be made stale by direct meddling or some other user.
    2576          */
    25772616        ExtPack *pExtPack;
    2578         hrc = i_refreshExtPack(pStrName->c_str(), false /*a_fUnusableIsError*/, &pExtPack);
     2617
     2618        hrc = i_isThereAnyRunningVM();
     2619        if(SUCCEEDED(hrc))
     2620        {
     2621            LogRel(("Install extension pack '%s' failed because at least one VM is still running.", pStrName->c_str()));
     2622            hrc = setError(E_FAIL,tr("Install extension pack '%s' failed because at least one VM is still running"),
     2623                           pStrName->c_str());
     2624        }
     2625        else
     2626        {
     2627            /*
     2628             * Refresh the data we have on the extension pack as it
     2629             * may be made stale by direct meddling or some other user.
     2630             */
     2631            hrc = i_refreshExtPack(pStrName->c_str(), false /*a_fUnusableIsError*/, &pExtPack);
     2632        }
     2633
    25792634        if (SUCCEEDED(hrc))
    25802635        {
     
    26962751    {
    26972752        AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
    2698 
    2699         /*
    2700          * Refresh the data we have on the extension pack as it may be made
    2701          * stale by direct meddling or some other user.
    2702          */
    27032753        ExtPack *pExtPack;
    2704         hrc = i_refreshExtPack(a_pstrName->c_str(), false /*a_fUnusableIsError*/, &pExtPack);
     2754
     2755        hrc = i_isThereAnyRunningVM();
     2756        if(SUCCEEDED(hrc))
     2757        {
     2758            LogRel(("Uninstall extension pack '%s' failed because at least one VM is still running.", a_pstrName->c_str()));
     2759            hrc = setError(E_FAIL,tr("Uninstall extension pack '%s' failed because at least one VM is still running"),
     2760                                               a_pstrName->c_str());
     2761        }
     2762        else
     2763        {
     2764            /*
     2765             * Refresh the data we have on the extension pack as it may be made
     2766             * stale by direct meddling or some other user.
     2767             */
     2768            hrc = i_refreshExtPack(a_pstrName->c_str(), false /*a_fUnusableIsError*/, &pExtPack);
     2769        }
     2770
    27052771        if (SUCCEEDED(hrc))
    27062772        {
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