VirtualBox

Changeset 40571 in vbox


Ignore:
Timestamp:
Mar 21, 2012 9:54:31 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
76966
Message:

ARTProcExec: dded RTPROC_FLAGS_SEARCH_PATH and implemented for posix.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/process.h

    r38618 r40571  
    186186 * be possible to wait for it, i.e. @a phProcess shall be NULL. */
    187187#define RTPROC_FLAGS_DETACHED               RT_BIT(0)
    188 /** Don't show the started process according to the specific
    189  *  OS guidelines. */
     188/** Don't show the started process.
     189 * This is a window (and maybe OS/2) concept, do not use on other platforms. */
    190190#define RTPROC_FLAGS_HIDDEN                 RT_BIT(1)
    191 /** Use special code path for starting child processes from
    192  * a service (daemon). On Windows this is required for services
    193  * because of the so called "Session 0" isolation which was
    194  * introduced with Windows Vista. */
     191/** Use special code path for starting child processes from a service (daemon).
     192 * This is a windows concept for dealing with the so called "Session 0"
     193 * isolation which was introduced with Windows Vista. Do not use on other
     194 * platforms. */
    195195#define RTPROC_FLAGS_SERVICE                RT_BIT(2)
    196196/** Suppress changing the process contract id for the child process
    197  * on Solaris. Without this flag the contract id is always changed,
    198  * as that's the more frequently used case. */
     197 * on Solaris.  Without this flag the contract id is always changed, as that's
     198 * the more frequently used case. */
    199199#define RTPROC_FLAGS_SAME_CONTRACT          RT_BIT(3)
    200 /** Do not load user profile data when executing a process. This bit
    201  * at the moment only is valid on Windows. */
     200/** Do not load user profile data when executing a process.
     201 * This bit at the moment only is valid on Windows. */
    202202#define RTPROC_FLAGS_NO_PROFILE             RT_BIT(4)
    203 /** Create process w/o a console window. This bit
    204  *  at the moment only is valid on Windows. */
     203/** Create process without a console window.
     204 * This is a Windows (and OS/2) concept, do not use on other platforms. */
    205205#define RTPROC_FLAGS_NO_WINDOW              RT_BIT(5)
     206/** Search the PATH for the executable.  */
     207#define RTPROC_FLAGS_SEARCH_PATH            RT_BIT(6)
    206208
    207209/** @}  */
  • trunk/src/VBox/Runtime/r3/posix/process-creation-posix.cpp

    r40046 r40571  
    6969#include <iprt/err.h>
    7070#include <iprt/file.h>
     71#include <iprt/path.h>
    7172#include <iprt/pipe.h>
    7273#include <iprt/socket.h>
     
    256257
    257258
     259/**
     260 * RTPathTraverseList callback used by RTProcCreateEx to locate the executable.
     261 */
     262static DECLCALLBACK(int) rtPathFindExec(char const *pchPath, size_t cchPath, void *pvUser1, void *pvUser2)
     263{
     264    const char *pszExec     = (const char *)pvUser1;
     265    char       *pszRealExec = (char *)pvUser2;
     266    int rc = RTPathJoinEx(pszRealExec, RTPATH_MAX, pchPath, cchPath, pszExec, RTSTR_MAX);
     267    if (RT_FAILURE(rc))
     268        return rc;
     269    if (!access(pszRealExec, X_OK))
     270        return VINF_SUCCESS;
     271    if (   errno == EACCES
     272        || errno == EPERM)
     273        return RTErrConvertFromErrno(errno);
     274    return VINF_TRY_AGAIN;
     275}
     276
     277
    258278RTR3DECL(int)   RTProcCreateEx(const char *pszExec, const char * const *papszArgs, RTENV hEnv, uint32_t fFlags,
    259279                               PCRTHANDLE phStdIn, PCRTHANDLE phStdOut, PCRTHANDLE phStdErr, const char *pszAsUser,
     
    267287    AssertPtrReturn(pszExec, VERR_INVALID_POINTER);
    268288    AssertReturn(*pszExec, VERR_INVALID_PARAMETER);
    269     AssertReturn(!(fFlags & ~(RTPROC_FLAGS_DETACHED | RTPROC_FLAGS_HIDDEN | RTPROC_FLAGS_SERVICE | RTPROC_FLAGS_SAME_CONTRACT | RTPROC_FLAGS_NO_PROFILE)), VERR_INVALID_PARAMETER);
     289    AssertReturn(!(fFlags & ~(RTPROC_FLAGS_DETACHED | RTPROC_FLAGS_HIDDEN | RTPROC_FLAGS_SERVICE | RTPROC_FLAGS_SAME_CONTRACT | RTPROC_FLAGS_NO_PROFILE | RTPROC_FLAGS_SEARCH_PATH)), VERR_INVALID_PARAMETER);
    270290    AssertReturn(!(fFlags & RTPROC_FLAGS_DETACHED) || !phProcess, VERR_INVALID_PARAMETER);
    271291    AssertReturn(hEnv != NIL_RTENV, VERR_INVALID_PARAMETER);
     
    340360     * Check for execute access to the file.
    341361     */
     362    char szRealExec[RTPATH_MAX];
    342363    if (access(pszExec, X_OK))
    343         return RTErrConvertFromErrno(errno);
     364    {
     365        if (   !(fFlags & RTPROC_FLAGS_SEARCH_PATH)
     366            || errno != ENOENT
     367            || RTPathHavePath(pszExec) )
     368            return RTErrConvertFromErrno(errno);
     369
     370        /* search */
     371        char *pszPath = RTEnvDupEx(hEnv, "PATH");
     372        rc = RTPathTraverseList(pszPath, ':', rtPathFindExec, (void *)pszExec, &szRealExec[0]);
     373        RTStrFree(pszPath);
     374        if (RT_FAILURE(rc))
     375            return rc == VERR_END_OF_STRING ? VERR_FILE_NOT_FOUND : rc;
     376        pszExec = szRealExec;
     377    }
    344378
    345379    pid_t pid = -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