VirtualBox

Ignore:
Timestamp:
Jul 26, 2011 5:02:38 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
73149
Message:

Frontends/VBoxManage: allow starting several VMs with startvm

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r38099 r38191  
    371371    {
    372372        RTStrmPrintf(pStrm,
    373                      "VBoxManage startvm          <uuid>|<name>\n");
     373                     "VBoxManage startvm          <uuid>|<name>...\n");
    374374        RTStrmPrintf(pStrm,
    375375                     "                            [--type gui");
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp

    r38099 r38191  
    5555#include "VBoxManage.h"
    5656
     57#include <list>
     58
    5759using namespace com;
    5860
     
    464466{
    465467    HRESULT rc;
    466     const char *VMName = NULL;
     468    std::list<const char *> VMs;
    467469    Bstr sessionType = "gui";
    468470
     
    508510
    509511            case VINF_GETOPT_NOT_OPTION:
    510                 if (!VMName)
    511                     VMName = ValueUnion.psz;
    512                 else
    513                     return errorSyntax(USAGE_STARTVM, "Invalid parameter '%s'", ValueUnion.psz);
     512                VMs.push_back(ValueUnion.psz);
    514513                break;
    515514
     
    532531
    533532    /* check for required options */
    534     if (!VMName)
    535         return errorSyntax(USAGE_STARTVM, "VM name required");
    536 
    537     ComPtr<IMachine> machine;
    538     CHECK_ERROR(a->virtualBox, FindMachine(Bstr(VMName).raw(),
    539                                            machine.asOutParam()));
    540     if (machine)
    541     {
    542         Bstr env;
     533    if (VMs.empty())
     534        return errorSyntax(USAGE_STARTVM, "at least one VM name or uuid required");
     535
     536    for (std::list<const char *>::const_iterator it = VMs.begin();
     537         it != VMs.end();
     538         ++it)
     539    {
     540        HRESULT rc2 = rc;
     541        const char *pszVM = *it;
     542        ComPtr<IMachine> machine;
     543        CHECK_ERROR(a->virtualBox, FindMachine(Bstr(pszVM).raw(),
     544                                               machine.asOutParam()));
     545        if (machine)
     546        {
     547            Bstr env;
    543548#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
    544         /* make sure the VM process will start on the same display as VBoxManage */
    545         Utf8Str str;
    546         const char *pszDisplay = RTEnvGet("DISPLAY");
    547         if (pszDisplay)
    548             str = Utf8StrFmt("DISPLAY=%s\n", pszDisplay);
    549         const char *pszXAuth = RTEnvGet("XAUTHORITY");
    550         if (pszXAuth)
    551             str.append(Utf8StrFmt("XAUTHORITY=%s\n", pszXAuth));
    552         env = str;
     549            /* make sure the VM process will start on the same display as VBoxManage */
     550            Utf8Str str;
     551            const char *pszDisplay = RTEnvGet("DISPLAY");
     552            if (pszDisplay)
     553                str = Utf8StrFmt("DISPLAY=%s\n", pszDisplay);
     554            const char *pszXAuth = RTEnvGet("XAUTHORITY");
     555            if (pszXAuth)
     556                str.append(Utf8StrFmt("XAUTHORITY=%s\n", pszXAuth));
     557            env = str;
    553558#endif
    554         ComPtr<IProgress> progress;
    555         CHECK_ERROR_RET(machine, LaunchVMProcess(a->session, sessionType.raw(),
    556                                                  env.raw(), progress.asOutParam()), rc);
    557         if (!progress.isNull())
    558         {
    559             RTPrintf("Waiting for the VM to power on...\n");
    560             CHECK_ERROR_RET(progress, WaitForCompletion(-1), 1);
    561 
    562             BOOL completed;
    563             CHECK_ERROR_RET(progress, COMGETTER(Completed)(&completed), rc);
    564             ASSERT(completed);
    565 
    566             LONG iRc;
    567             CHECK_ERROR_RET(progress, COMGETTER(ResultCode)(&iRc), rc);
    568             if (FAILED(iRc))
    569             {
    570                 ProgressErrorInfo info(progress);
    571                 com::GluePrintErrorInfo(info);
    572             }
    573             else
    574             {
    575                 RTPrintf("VM has been successfully started.\n");
    576             }
    577         }
    578     }
    579 
    580     /* it's important to always close sessions */
    581     a->session->UnlockMachine();
     559            ComPtr<IProgress> progress;
     560            CHECK_ERROR(machine, LaunchVMProcess(a->session, sessionType.raw(),
     561                                                 env.raw(), progress.asOutParam()));
     562            if (SUCCEEDED(rc) && !progress.isNull())
     563            {
     564                RTPrintf("Waiting for VM \"%s\" to power on...\n", pszVM);
     565                CHECK_ERROR(progress, WaitForCompletion(-1));
     566                if (SUCCEEDED(rc))
     567                {
     568                    BOOL completed = true;
     569                    CHECK_ERROR(progress, COMGETTER(Completed)(&completed));
     570                    if (SUCCEEDED(rc))
     571                    {
     572                        ASSERT(completed);
     573
     574                        LONG iRc;
     575                        CHECK_ERROR(progress, COMGETTER(ResultCode)(&iRc));
     576                        if (SUCCEEDED(rc))
     577                        {
     578                            if (FAILED(iRc))
     579                            {
     580                                ProgressErrorInfo info(progress);
     581                                com::GluePrintErrorInfo(info);
     582                            }
     583                            else
     584                            {
     585                                RTPrintf("VM \"%s\" has been successfully started.\n", pszVM);
     586                            }
     587                        }
     588                    }
     589                }
     590            }
     591        }
     592
     593        /* it's important to always close sessions */
     594        a->session->UnlockMachine();
     595
     596        /* make sure that we remember the failed state */
     597        if (FAILED(rc2))
     598            rc = rc2;
     599    }
    582600
    583601    return SUCCEEDED(rc) ? 0 : 1;
Note: See TracChangeset for help on using the changeset viewer.

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