VirtualBox

Changeset 99120 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Mar 22, 2023 5:30:14 PM (22 months ago)
Author:
vboxsync
Message:

Guest Control: Added ability of specifying an optional current working directory to started guest processes. This needs Guest Additions which support this. bugref:8053

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r99085 r99120  
    1481414814  <interface
    1481514815    name="IGuestSession" extends="$unknown"
    14816     uuid="234f0627-866d-48c2-91a5-4c9d50f04928"
     14816    uuid="5591bead-9c1d-4cbd-9669-2d0b04fac0a8"
    1481714817    wsmap="managed"
    1481814818    reservedMethods="8" reservedAttributes="12"
     
    1594715947          If ProcessCreateFlag_WaitForStdOut and/or ProcessCreateFlag_WaitForStdErr
    1594815948          are set, the guest process will not enter the terminated state until
    15949           all data from the specified streams have been read read.
     15949          all data from the specified streams have been read.
    1595015950        </note>
    1595115951
     
    1596115961        <desc>
    1596215962          Full path to the file to execute in the guest.  The file has to
    15963           exists in the guest VM with executable right to the session user in
     15963          exist in the guest VM with executable right to the session user in
    1596415964          order to succeed.  If empty/null, the first entry in the
    1596515965          @a arguments array will be used instead (i.e. argv[0]).
     15966        </desc>
     15967      </param>
     15968      <param name="cwd" type="wstring" dir="in">
     15969        <desc>
     15970          Path to the directory in which to execute in the guest.  The
     15971          directory has to exist in the guest VM with search rights to the
     15972          session user in order to succeed.  If empty/null, the session
     15973          user's default (typically 'home') directory is used.  If not a
     15974          full path, it is interpreted relative to the default directory;
     15975          e.g. 'work' means '$HOME/work' (according to the guest's '$HOME'-
     15976          like concept).
    1596615977        </desc>
    1596715978      </param>
     
    1601716028        See <link to="IGuestSession::processCreate"/> for more information.
    1601816029      </desc>
     16030      <param name="cwd" type="wstring" dir="in">
     16031        <desc>
     16032          Path to the directory in which to execute in the guest.  The
     16033          directory has to exist in the guest VM with search rights to the
     16034          session user in order to succeed.  If empty/null, the session
     16035          user's default (typically 'home') directory is used.  If not a
     16036          full path, it is interpreted relative to the default directory;
     16037          e.g. 'work' means '$HOME/work' (according to the guest's '$HOME'-
     16038          like concept).
     16039        </desc>
     16040      </param>
    1601916041      <param name="executable" type="wstring" dir="in">
    1602016042        <desc>
    1602116043          Full path to the file to execute in the guest.  The file has to
    16022           exists in the guest VM with executable right to the session user in
     16044          exist in the guest VM with executable right to the session user in
    1602316045          order to succeed.  If empty/null, the first entry in the
    1602416046          @a arguments array will be used instead (i.e. argv[0]).
  • trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h

    r99085 r99120  
    945945    /** The executable. */
    946946    Utf8Str                     mExecutable;
     947    /** The working directory. Optional, can be empty if not used. */
     948    Utf8Str                     mCwd;
    947949    /** Arguments vector (starting with argument \#0). */
    948950    ProcessArguments            mArguments;
  • trunk/src/VBox/Main/include/GuestSessionImpl.h

    r98713 r99120  
    212212                        ULONG aMode);
    213213    HRESULT processCreate(const com::Utf8Str &aCommand,
     214                          const com::Utf8Str &aCwd,
    214215                          const std::vector<com::Utf8Str> &aArguments,
    215216                          const std::vector<com::Utf8Str> &aEnvironment,
     
    218219                          ComPtr<IGuestProcess> &aGuestProcess);
    219220    HRESULT processCreateEx(const com::Utf8Str &aCommand,
     221                            const com::Utf8Str &aCwd,
    220222                            const std::vector<com::Utf8Str> &aArguments,
    221223                            const std::vector<com::Utf8Str> &aEnvironment,
  • trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp

    r98666 r99120  
    11581158int GuestProcess::i_startProcess(uint32_t cMsTimeout, int *pvrcGuest)
    11591159{
    1160     LogFlowThisFunc(("cMsTimeout=%RU32, procExe=%s, procTimeoutMS=%RU32, procFlags=%x, sessionID=%RU32\n",
    1161                      cMsTimeout, mData.mProcess.mExecutable.c_str(), mData.mProcess.mTimeoutMS, mData.mProcess.mFlags,
    1162                      mSession->i_getId()));
     1160    LogFlowThisFunc(("cMsTimeout=%RU32, procExe=%s, cwd=%s, procTimeoutMS=%RU32, procFlags=%x, sessionID=%RU32\n",
     1161                     cMsTimeout, mData.mProcess.mExecutable.c_str(), mData.mProcess.mCwd.c_str(),
     1162                     mData.mProcess.mTimeoutMS, mData.mProcess.mFlags, mSession->i_getId()));
    11631163
    11641164    /* Wait until the caller function (if kicked off by a thread)
     
    12151215        return VERR_BUFFER_OVERFLOW;
    12161216
     1217    Guest *pGuest = mSession->i_getParent();
     1218    AssertPtr(pGuest);
     1219    const uint64_t fGuestControlFeatures0 = pGuest->i_getGuestControlFeatures0();
     1220
     1221    /* Check if the Guest Additions support setting the current working directory for the new process
     1222     * if the caller wants to set one, and bail out early if it doesn't. */
     1223    if (   !mData.mProcess.mCwd.isEmpty()
     1224        && (   uProtocol < 2
     1225            || !(fGuestControlFeatures0 & VBOX_GUESTCTRL_GF_0_PROCESS_CWD)))
     1226    {
     1227        LogRel2(("Guest Control: Installed Guest Addtions don't support setting the current working directory to '%s'!\n",
     1228                 mData.mProcess.mCwd.c_str()));
     1229        return VERR_NOT_SUPPORTED;
     1230    }
     1231
    12171232    size_t cbArgs = 0;
    12181233    char *pszArgs = NULL;
    12191234    int vrc = VINF_SUCCESS;
     1235
    12201236    if (cArgs)
    12211237    {
     
    12291245        }
    12301246        papszArgv[cArgs] = NULL;
    1231 
    1232         Guest *pGuest = mSession->i_getParent();
    1233         AssertPtr(pGuest);
    1234 
    1235         const uint64_t fGuestControlFeatures0 = pGuest->i_getGuestControlFeatures0();
    12361247
    12371248        /* If the Guest Additions don't support using argv[0] correctly (< 6.1.x), don't supply it. */
     
    12991310            /* The actual CPU affinity blocks. */
    13001311            HGCMSvcSetPv(&paParms[i++], (void *)&mData.mProcess.mAffinity, sizeof(mData.mProcess.mAffinity));
     1312            /* Supply working directory, if guest supports it. */
     1313            if (fGuestControlFeatures0 & VBOX_GUESTCTRL_GF_0_PROCESS_CWD)
     1314                HGCMSvcSetRTCStr(&paParms[i++], mData.mProcess.mCwd);
    13011315        }
    13021316
  • trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp

    r98813 r99120  
    49434943
    49444944
    4945 HRESULT GuestSession::processCreate(const com::Utf8Str &aExecutable, const std::vector<com::Utf8Str> &aArguments,
     4945HRESULT GuestSession::processCreate(const com::Utf8Str &aExecutable, const com::Utf8Str &aCwd,
     4946                                    const std::vector<com::Utf8Str> &aArguments,
    49464947                                    const std::vector<com::Utf8Str> &aEnvironment,
    49474948                                    const std::vector<ProcessCreateFlag_T> &aFlags,
     
    49514952
    49524953    std::vector<LONG> affinityIgnored;
    4953     return processCreateEx(aExecutable, aArguments, aEnvironment, aFlags, aTimeoutMS, ProcessPriority_Default,
    4954                            affinityIgnored, aGuestProcess);
    4955 }
    4956 
    4957 HRESULT GuestSession::processCreateEx(const com::Utf8Str &aExecutable, const std::vector<com::Utf8Str> &aArguments,
     4954    return processCreateEx(aExecutable, aCwd, aArguments, aEnvironment, aFlags, aTimeoutMS,
     4955                           ProcessPriority_Default, affinityIgnored, aGuestProcess);
     4956}
     4957
     4958HRESULT GuestSession::processCreateEx(const com::Utf8Str &aExecutable, const com::Utf8Str &aCwd,
     4959                                      const std::vector<com::Utf8Str> &aArguments,
    49584960                                      const std::vector<com::Utf8Str> &aEnvironment,
    49594961                                      const std::vector<ProcessCreateFlag_T> &aFlags, ULONG aTimeoutMS,
     
    49784980    }
    49794981
     4982    uint32_t const uProtocol              = i_getProtocolVersion();
     4983    uint64_t const fGuestControlFeatures0 = mParent->i_getGuestControlFeatures0();
     4984
     4985    /* If a current working directory (CWD) is set, make sure that the installed Guest Additions actually
     4986     * support this before doing anything else. */
     4987    if (   !aCwd.isEmpty()
     4988        && (   uProtocol < 2
     4989            || !(fGuestControlFeatures0 & VBOX_GUESTCTRL_GF_0_PROCESS_CWD)))
     4990        return setError(VBOX_E_NOT_SUPPORTED,
     4991                        tr("Setting the current working directory is not supported by the installed Guest Addtions!"));
     4992
    49804993    /* The rest of the input is being validated in i_processCreateEx(). */
    49814994
     
    49965009    else /* If no arguments were given, add the executable as argv[0] by default. */
    49975010        procInfo.mArguments.push_back(procInfo.mExecutable);
     5011
     5012    /* Optional working directory */
     5013    procInfo.mCwd = aCwd;
    49985014
    49995015    /* Combine the environment changes associated with the ones passed in by
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