VirtualBox

Changeset 40571 in vbox for trunk/src/VBox/Runtime/r3


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.

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