VirtualBox

Ignore:
Timestamp:
Oct 27, 2016 11:38:06 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
111563
Message:

Frontends/VBoxManage: add --putenv option to the "startvm" command

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

Legend:

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

    r64315 r64434  
    950950        RTStrmPrintf(pStrm, "|headless|separate]\n");
    951951        RTStrmPrintf(pStrm,
     952                     "                            [-E|--putenv <NAME>[=<VALUE>]]\n"
    952953                     "\n");
    953954    }
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp

    r62493 r64434  
    496496    std::list<const char *> VMs;
    497497    Bstr sessionType;
     498    Utf8Str strEnv;
     499
     500#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
     501    /* make sure the VM process will by default start on the same display as VBoxManage */
     502    {
     503        const char *pszDisplay = RTEnvGet("DISPLAY");
     504        if (pszDisplay)
     505            strEnv = Utf8StrFmt("DISPLAY=%s\n", pszDisplay);
     506        const char *pszXAuth = RTEnvGet("XAUTHORITY");
     507        if (pszXAuth)
     508            strEnv.append(Utf8StrFmt("XAUTHORITY=%s\n", pszXAuth));
     509    }
     510#endif
    498511
    499512    static const RTGETOPTDEF s_aStartVMOptions[] =
     
    501514        { "--type",         't', RTGETOPT_REQ_STRING },
    502515        { "-type",          't', RTGETOPT_REQ_STRING },     // deprecated
     516        { "--putenv",       'E', RTGETOPT_REQ_STRING },
    503517    };
    504518    int c;
     
    537551                break;
    538552
     553            case 'E':   // --putenv
     554                if (!RTStrStr(ValueUnion.psz, "\n"))
     555                    strEnv.append(Utf8StrFmt("%s\n", ValueUnion.psz));
     556                else
     557                    return errorSyntax(USAGE_STARTVM, "Parameter to option --putenv must not contain any newline character");
     558                break;
     559
    539560            case VINF_GETOPT_NOT_OPTION:
    540561                VMs.push_back(ValueUnion.psz);
     
    573594        if (machine)
    574595        {
    575             Bstr env;
    576 #if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
    577             /* make sure the VM process will start on the same display as VBoxManage */
    578             Utf8Str str;
    579             const char *pszDisplay = RTEnvGet("DISPLAY");
    580             if (pszDisplay)
    581                 str = Utf8StrFmt("DISPLAY=%s\n", pszDisplay);
    582             const char *pszXAuth = RTEnvGet("XAUTHORITY");
    583             if (pszXAuth)
    584                 str.append(Utf8StrFmt("XAUTHORITY=%s\n", pszXAuth));
    585             env = str;
    586 #endif
    587596            ComPtr<IProgress> progress;
    588597            CHECK_ERROR(machine, LaunchVMProcess(a->session, sessionType.raw(),
    589                                                  env.raw(), progress.asOutParam()));
     598                                                 Bstr(strEnv).raw(), progress.asOutParam()));
    590599            if (SUCCEEDED(rc) && !progress.isNull())
    591600            {
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