VirtualBox

Changeset 55535 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Apr 30, 2015 2:13:56 AM (10 years ago)
Author:
vboxsync
Message:

Main,VBoxManage,VBoxShell,ValidationKit: Changed the IGuestSession:createProcess[Ex] interfaces to take argv[0] as input separate from the executable name. This is not yet implemented on the guest side.

Location:
trunk/src/VBox/Main/src-client
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestDirectoryImpl.cpp

    r53127 r55535  
    9191        GuestProcessStartupInfo procInfo;
    9292        procInfo.mName      = Utf8StrFmt(tr("Reading directory \"%s\""), openInfo.mPath.c_str());
    93         procInfo.mCommand   = Utf8Str(VBOXSERVICE_TOOL_LS);
     93        procInfo.mExecutable= Utf8Str(VBOXSERVICE_TOOL_LS);
    9494        procInfo.mTimeoutMS = 5 * 60 * 1000; /* 5 minutes timeout. */
    9595        procInfo.mFlags     = ProcessCreateFlag_WaitForStdOut;
  • trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp

    r55491 r55535  
    266266
    267267#ifdef VBOX_WITH_GUEST_CONTROL
    268     LogFlowThisFunc(("mCmd=%s, PID=%RU32\n",
    269                      mData.mProcess.mCommand.c_str(), mData.mPID));
     268    LogFlowThisFunc(("mExe=%s, PID=%RU32\n", mData.mProcess.mExecutable.c_str(), mData.mPID));
    270269
    271270    /* Terminate process if not already done yet. */
     
    334333    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    335334
    336     aExecutablePath = mData.mProcess.mCommand;
     335    aExecutablePath = mData.mProcess.mExecutable;
    337336
    338337    return S_OK;
     
    987986int GuestProcess::i_startProcess(uint32_t uTimeoutMS, int *pGuestRc)
    988987{
    989     LogFlowThisFunc(("uTimeoutMS=%RU32, procCmd=%s, procTimeoutMS=%RU32, procFlags=%x, sessionID=%RU32\n",
    990                      uTimeoutMS, mData.mProcess.mCommand.c_str(), mData.mProcess.mTimeoutMS, mData.mProcess.mFlags,
     988    LogFlowThisFunc(("uTimeoutMS=%RU32, procExe=%s, procTimeoutMS=%RU32, procFlags=%x, sessionID=%RU32\n",
     989                     uTimeoutMS, mData.mProcess.mExecutable.c_str(), mData.mProcess.mTimeoutMS, mData.mProcess.mFlags,
    991990                     mSession->i_getId()));
    992991
     
    10171016    GuestSession *pSession = mSession;
    10181017    AssertPtr(pSession);
     1018    uint32_t const uProtocol = pSession->i_getProtocolVersion();
    10191019
    10201020    const GuestCredentials &sessionCreds = pSession->i_getCredentials();
     1021
    10211022
    10221023    /* Prepare arguments. */
     
    10291030        && cArgs)
    10301031    {
    1031         char **papszArgv = (char**)RTMemAlloc((cArgs + 1) * sizeof(char*));
     1032        char const **papszArgv = (char const **)RTMemAlloc((cArgs + 1) * sizeof(papszArgv[0]));
    10321033        AssertReturn(papszArgv, VERR_NO_MEMORY);
    10331034
    1034         for (size_t i = 0; i < cArgs && RT_SUCCESS(vrc); i++)
    1035         {
    1036             const char *pszCurArg = mData.mProcess.mArguments[i].c_str();
    1037             AssertPtr(pszCurArg);
    1038             vrc = RTStrDupEx(&papszArgv[i], pszCurArg);
     1035        for (size_t i = 0; i < cArgs; i++)
     1036        {
     1037            papszArgv[i] = mData.mProcess.mArguments[i].c_str();
     1038            AssertPtr(papszArgv[i]);
    10391039        }
    10401040        papszArgv[cArgs] = NULL;
    10411041
    1042         if (RT_SUCCESS(vrc))
     1042        if (uProtocol < UINT32_C(0xdeadbeef) ) /** @todo implement a way of sending argv[0], best idea is a new command. */
     1043            vrc = RTGetOptArgvToString(&pszArgs, papszArgv + 1, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
     1044        else
    10431045            vrc = RTGetOptArgvToString(&pszArgs, papszArgv, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
    10441046
    1045         if (papszArgv)
    1046         {
    1047             size_t i = 0;
    1048             while (papszArgv[i])
    1049                 RTStrFree(papszArgv[i++]);
    1050             RTMemFree(papszArgv);
    1051         }
     1047        RTMemFree(papszArgv);
    10521048    }
    10531049
     
    10651061    if (RT_SUCCESS(vrc))
    10661062    {
    1067         AssertPtr(mSession);
    1068         uint32_t uProtocol = mSession->i_getProtocolVersion();
    1069 
    10701063        /* Prepare HGCM call. */
    10711064        VBOXHGCMSVCPARM paParms[16];
    10721065        int i = 0;
    10731066        paParms[i++].setUInt32(pEvent->ContextID());
    1074         paParms[i++].setPointer((void*)mData.mProcess.mCommand.c_str(),
    1075                                 (ULONG)mData.mProcess.mCommand.length() + 1);
     1067        paParms[i++].setPointer((void*)mData.mProcess.mExecutable.c_str(),
     1068                                (ULONG)mData.mProcess.mExecutable.length() + 1);
    10761069        paParms[i++].setUInt32(mData.mProcess.mFlags);
    10771070        paParms[i++].setUInt32((uint32_t)mData.mProcess.mArguments.size());
     
    17641757                hr = setError(VBOX_E_IPRT_ERROR,
    17651758                              tr("Reading from process \"%s\" (PID %RU32) failed: %Rrc"),
    1766                               mData.mProcess.mCommand.c_str(), mData.mPID, vrc);
     1759                              mData.mProcess.mExecutable.c_str(), mData.mPID, vrc);
    17671760                break;
    17681761        }
     
    17981791                hr = setError(VBOX_E_IPRT_ERROR,
    17991792                              tr("Terminating process \"%s\" (PID %RU32) not supported by installed Guest Additions"),
    1800                               mData.mProcess.mCommand.c_str(), mData.mPID);
     1793                              mData.mProcess.mExecutable.c_str(), mData.mPID);
    18011794                break;
    18021795
     
    18041797                hr = setError(VBOX_E_IPRT_ERROR,
    18051798                              tr("Terminating process \"%s\" (PID %RU32) failed: %Rrc"),
    1806                               mData.mProcess.mCommand.c_str(), mData.mPID, vrc);
     1799                              mData.mProcess.mExecutable.c_str(), mData.mPID, vrc);
    18071800                break;
    18081801        }
     
    18341827    HRESULT hr = S_OK;
    18351828
    1836     int guestRc; ProcessWaitResult_T waitResult;
     1829    int guestRc;
     1830    ProcessWaitResult_T waitResult;
    18371831    int vrc = i_waitFor(aWaitFor, aTimeoutMS, waitResult, &guestRc);
    18381832    if (RT_SUCCESS(vrc))
     
    18551849                hr = setError(VBOX_E_IPRT_ERROR,
    18561850                              tr("Waiting for process \"%s\" (PID %RU32) failed: %Rrc"),
    1857                               mData.mProcess.mCommand.c_str(), mData.mPID, vrc);
     1851                              mData.mProcess.mExecutable.c_str(), mData.mPID, vrc);
    18581852                break;
    18591853        }
     
    19071901                hr = setError(VBOX_E_IPRT_ERROR,
    19081902                              tr("Writing to process \"%s\" (PID %RU32) failed: %Rrc"),
    1909                               mData.mProcess.mCommand.c_str(), mData.mPID, vrc);
     1903                              mData.mProcess.mExecutable.c_str(), mData.mPID, vrc);
    19101904                break;
    19111905        }
     
    19561950                           bool fAsync, int *pGuestRc)
    19571951{
    1958     LogFlowThisFunc(("pGuestSession=%p, szCmd=%s, fAsync=%RTbool\n",
    1959                      pGuestSession, startupInfo.mCommand.c_str(), fAsync));
     1952    LogFlowThisFunc(("pGuestSession=%p, exe=%s, fAsync=%RTbool\n",
     1953                     pGuestSession, startupInfo.mExecutable.c_str(), fAsync));
    19601954
    19611955    AssertPtrReturn(pGuestSession, VERR_INVALID_POINTER);
     
    19671961    mStartupInfo.mFlags |= ProcessCreateFlag_Hidden;
    19681962
    1969     int vrc = pSession->i_processCreateExInteral(mStartupInfo, pProcess);
     1963    int vrc = pSession->i_processCreateExInternal(mStartupInfo, pProcess);
    19701964    if (RT_SUCCESS(vrc))
    19711965        vrc = fAsync
  • trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp

    r54009 r55535  
    661661
    662662    GuestProcessStartupInfo procInfo;
    663     procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKDIR);
    664     procInfo.mFlags   = ProcessCreateFlag_Hidden;
     663    procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_MKDIR);
     664    procInfo.mFlags      = ProcessCreateFlag_Hidden;
    665665
    666666    try
     
    816816
    817817    GuestProcessStartupInfo procInfo;
    818     procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKTEMP);
    819     procInfo.mFlags   = ProcessCreateFlag_WaitForStdOut;
     818    procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_MKTEMP);
     819    procInfo.mFlags      = ProcessCreateFlag_WaitForStdOut;
    820820
    821821    try
     
    12171217    GuestProcessStream      streamOut;
    12181218
    1219     procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_RM);
    1220     procInfo.mFlags   = ProcessCreateFlag_WaitForStdOut;
     1219    procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_RM);
     1220    procInfo.mFlags      = ProcessCreateFlag_WaitForStdOut;
    12211221
    12221222    try
     
    13741374    /** @todo Merge this with IGuestFile::queryInfo(). */
    13751375    GuestProcessStartupInfo procInfo;
    1376     procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_STAT);
    1377     procInfo.mFlags   = ProcessCreateFlag_WaitForStdOut;
     1376    procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_STAT);
     1377    procInfo.mFlags      = ProcessCreateFlag_WaitForStdOut;
    13781378
    13791379    try
     
    18371837
    18381838/**
    1839  * Creates but does *not* start the process yet. See GuestProcess::startProcess() or
    1840  * GuestProcess::startProcessAsync() for that.
     1839 * Creates but does *not* start the process yet.
     1840 *
     1841 * See GuestProcess::startProcess() or GuestProcess::startProcessAsync() for
     1842 * starting the process.
    18411843 *
    18421844 * @return  IPRT status code.
     
    18441846 * @param   pProcess
    18451847 */
    1846 int GuestSession::i_processCreateExInteral(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProcess)
    1847 {
    1848     LogFlowFunc(("mCmd=%s, mFlags=%x, mTimeoutMS=%RU32\n",
    1849                  procInfo.mCommand.c_str(), procInfo.mFlags, procInfo.mTimeoutMS));
     1848int GuestSession::i_processCreateExInternal(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProcess)
     1849{
     1850    LogFlowFunc(("mExe=%s, mFlags=%x, mTimeoutMS=%RU32\n",
     1851                 procInfo.mExecutable.c_str(), procInfo.mFlags, procInfo.mTimeoutMS));
    18501852#ifdef DEBUG
    18511853    if (procInfo.mArguments.size())
     
    33083310}
    33093311
    3310 HRESULT GuestSession::processCreate(const com::Utf8Str &aCommand, const std::vector<com::Utf8Str> &aArguments,
     3312HRESULT GuestSession::processCreate(const com::Utf8Str &aExecutable, const std::vector<com::Utf8Str> &aArguments,
    33113313                                    const std::vector<com::Utf8Str> &aEnvironment,
    33123314                                    const std::vector<ProcessCreateFlag_T> &aFlags,
     
    33203322    std::vector<LONG> affinityIgnored;
    33213323
    3322     return processCreateEx(aCommand, aArguments, aEnvironment, aFlags, aTimeoutMS, ProcessPriority_Default,
     3324    return processCreateEx(aExecutable, aArguments, aEnvironment, aFlags, aTimeoutMS, ProcessPriority_Default,
    33233325                           affinityIgnored, aGuestProcess);
    33243326#endif /* VBOX_WITH_GUEST_CONTROL */
    33253327}
    33263328
    3327 HRESULT GuestSession::processCreateEx(const com::Utf8Str &aCommand, const std::vector<com::Utf8Str> &aArguments,
     3329HRESULT GuestSession::processCreateEx(const com::Utf8Str &aExecutable, const std::vector<com::Utf8Str> &aArguments,
    33283330                                      const std::vector<com::Utf8Str> &aEnvironment,
    33293331                                      const std::vector<ProcessCreateFlag_T> &aFlags, ULONG aTimeoutMS,
     
    33363338    LogFlowThisFuncEnter();
    33373339
    3338     if (RT_UNLIKELY((aCommand.c_str()) == NULL || *(aCommand.c_str()) == '\0'))
    3339         return setError(E_INVALIDARG, tr("No command to execute specified"));
    3340 
     3340    /*
     3341     * Must have an executable to execute.  If none is given, we try use the
     3342     * zero'th argument.
     3343     */
     3344    const char *pszExecutable = aExecutable.c_str();
     3345    if (RT_UNLIKELY(pszExecutable == NULL || *pszExecutable == '\0'))
     3346    {
     3347        if (aArguments.size() > 0)
     3348            pszExecutable = aArguments[0].c_str();
     3349        if (pszExecutable == NULL || *pszExecutable == '\0')
     3350            return setError(E_INVALIDARG, tr("No command to execute specified"));
     3351    }
     3352
     3353    /*
     3354     * Check the session.
     3355     */
    33413356    HRESULT hr = i_isReadyExternal();
    33423357    if (FAILED(hr))
    33433358        return hr;
    33443359
     3360    /*
     3361     * Build the process startup info.
     3362     */
    33453363    GuestProcessStartupInfo procInfo;
    3346     procInfo.mCommand = aCommand;
    3347 
     3364
     3365    /* Executable and arguments. */
     3366    procInfo.mExecutable = pszExecutable;
    33483367    if (aArguments.size())
    33493368        for (size_t i = 0; i < aArguments.size(); i++)
    33503369            procInfo.mArguments.push_back(aArguments[i]);
    3351 
    3352     int rc = VINF_SUCCESS;
    33533370
    33543371    /*
     
    33603377    procInfo.mEnvironment = mData.mEnvironment; /* Apply original session environment. */
    33613378
     3379    int rc = VINF_SUCCESS;
    33623380    if (aEnvironment.size())
    33633381        for (size_t i = 0; i < aEnvironment.size() && RT_SUCCESS(rc); i++)
     3382        {
     3383            /** @todo r=bird: What ARE you trying to do here??? The documentation is crystal
     3384             *        clear on that each entry contains ONE pair, however,
     3385             *        GuestEnvironment::Set(const Utf8Str &) here will split up the input
     3386             *        into any number of pairs, from what I can tell.  Such that for e.g.
     3387             *        "VBOX_LOG_DEST=file=/tmp/foobared.log" becomes "VBOX_LOG_DEST=file"
     3388             *        and "/tmp/foobared.log" - which I obviously don't want! */
    33643389            rc = procInfo.mEnvironment.Set(aEnvironment[i]);
     3390        }
    33653391
    33663392    if (RT_SUCCESS(rc))
    33673393    {
     3394        /* Convert the flag array into a mask. */
    33683395        if (aFlags.size())
    33693396            for (size_t i = 0; i < aFlags.size(); i++)
     
    33723399        procInfo.mTimeoutMS = aTimeoutMS;
    33733400
     3401        /** @todo use RTCPUSET instead of archaic 64-bit variables! */
    33743402        if (aAffinity.size())
    33753403            for (size_t i = 0; i < aAffinity.size(); i++)
     
    33793407        procInfo.mPriority = aPriority;
    33803408
     3409        /*
     3410         * Create a guest process object.
     3411         */
    33813412        ComObjPtr<GuestProcess> pProcess;
    3382         rc = i_processCreateExInteral(procInfo, pProcess);
     3413        rc = i_processCreateExInternal(procInfo, pProcess);
    33833414        if (RT_SUCCESS(rc))
    33843415        {
    33853416            /* Return guest session to the caller. */
    33863417            HRESULT hr2 = pProcess.queryInterfaceTo(aGuestProcess.asOutParam());
    3387             if (FAILED(hr2))
     3418            if (SUCCEEDED(hr2))
     3419            {
     3420                /*
     3421                 * Start the process.
     3422                 */
     3423                rc = pProcess->i_startProcessAsync();
     3424                if (RT_FAILURE(rc))
     3425                {
     3426                    /** @todo r=bird: What happens to the interface that *aGuestProcess points to
     3427                     *        now?  Looks like a leak or an undocument hack of sorts... */
     3428                }
     3429            }
     3430            else
    33883431                rc = VERR_COM_OBJECT_NOT_FOUND;
    3389 
    3390             if (RT_SUCCESS(rc))
    3391                 rc = pProcess->i_startProcessAsync();
    3392         }
    3393     }
    3394 
     3432        }
     3433    }
     3434
     3435    /** @todo you're better off doing this is 'else if (rc == xxx') statements,
     3436     *        since there is just one place where you'll get
     3437     *        VERR_MAX_PROCS_REACHED in the above code. */
    33953438    if (RT_FAILURE(rc))
    33963439    {
  • trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp

    r53873 r55535  
    309309
    310310    GuestProcessStartupInfo procInfo;
    311     procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_CAT);
    312     procInfo.mFlags   = ProcessCreateFlag_Hidden;
     311    procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_CAT);
     312    procInfo.mFlags      = ProcessCreateFlag_Hidden;
    313313
    314314    /* Set arguments.*/
     
    318318    ComObjPtr<GuestProcess> pProcess; int guestRc;
    319319    if (RT_SUCCESS(rc))
    320         rc = pSession->i_processCreateExInteral(procInfo, pProcess);
     320        rc = pSession->i_processCreateExInternal(procInfo, pProcess);
    321321    if (RT_SUCCESS(rc))
    322322    {
     
    637637            procInfo.mName = Utf8StrFmt(GuestSession::tr("Copying file \"%s\" from guest to the host to \"%s\" (%RI64 bytes)"),
    638638                                        mSource.c_str(), mDest.c_str(), objData.mObjectSize);
    639             procInfo.mCommand  = Utf8Str(VBOXSERVICE_TOOL_CAT);
    640             procInfo.mFlags     = ProcessCreateFlag_Hidden | ProcessCreateFlag_WaitForStdOut;
     639            procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_CAT);
     640            procInfo.mFlags      = ProcessCreateFlag_Hidden | ProcessCreateFlag_WaitForStdOut;
    641641
    642642            /* Set arguments.*/
     
    645645            /* Startup process. */
    646646            ComObjPtr<GuestProcess> pProcess;
    647             rc = pSession->i_processCreateExInteral(procInfo, pProcess);
     647            rc = pSession->i_processCreateExInternal(procInfo, pProcess);
    648648            if (RT_SUCCESS(rc))
    649649                rc = pProcess->i_startProcess(30 * 1000 /* 30s timeout */,
     
    10401040                setProgressErrorMsg(VBOX_E_IPRT_ERROR,
    10411041                                    Utf8StrFmt(GuestSession::tr("Running update file \"%s\" on guest terminated with exit code %ld"),
    1042                                                procInfo.mCommand.c_str(), exitCode));
     1042                                               procInfo.mExecutable.c_str(), exitCode));
    10431043                break;
    10441044
     
    10511051                setProgressErrorMsg(VBOX_E_IPRT_ERROR,
    10521052                                    Utf8StrFmt(GuestSession::tr("Update file \"%s\" reported invalid running state"),
    1053                                                procInfo.mCommand.c_str()));
     1053                                               procInfo.mExecutable.c_str()));
    10541054                break;
    10551055
     
    10571057                setProgressErrorMsg(VBOX_E_IPRT_ERROR,
    10581058                                    Utf8StrFmt(GuestSession::tr("Error while running update file \"%s\" on guest: %Rrc"),
    1059                                                procInfo.mCommand.c_str(), vrc));
     1059                                               procInfo.mExecutable.c_str(), vrc));
    10601060                break;
    10611061        }
     
    14131413                 * calculate the specific percentage step of each copied file. */
    14141414                uint8_t uOffset = 20; /* Start at 20%. */
    1415                 uint8_t uStep = 40 / mFiles.size();
     1415                uint8_t uStep = 40 / (uint8_t)mFiles.size(); Assert(mFiles.size() <= 10);
    14161416
    14171417                LogRel(("Copying over Guest Additions update files to the guest ...\n"));
     
    14531453                 * calculate the specific percentage step of each copied file. */
    14541454                uint8_t uOffset = 60; /* Start at 60%. */
    1455                 uint8_t uStep = 35 / mFiles.size();
     1455                uint8_t uStep = 35 / (uint8_t)mFiles.size(); Assert(mFiles.size() <= 10);
    14561456
    14571457                LogRel(("Executing Guest Additions update files ...\n"));
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