VirtualBox

Ignore:
Timestamp:
Mar 22, 2023 10:13:00 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
156474
Message:

IPRT/process: Added RTPROC_FLAGS_CWD to RTProcCreateEx(), to be able to set the current working directory for created processes. bugref:8053

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/process-creation-posix.cpp

    r98103 r99109  
    216216static int rtProcPosixCreateInner(const char *pszExec, const char * const *papszArgs, RTENV hEnv, RTENV hEnvToUse,
    217217                                  uint32_t fFlags, const char *pszAsUser, uid_t uid, gid_t gid,
    218                                   unsigned cRedirFds, int *paRedirFds, PRTPROCESS phProcess);
     218                                  unsigned cRedirFds, int *paRedirFds, void *pvExtraData, PRTPROCESS phProcess);
    219219
    220220
     
    12001200                RTPROCESS hProcess = NIL_RTPROCESS;
    12011201                rc = rtProcPosixCreateInner(pszExec, apszArgs, hEnvToUse, hEnvToUse, 0 /*fFlags*/,
    1202                                             pszAsUser, uid, gid, RT_ELEMENTS(aRedirFds), aRedirFds, &hProcess);
     1202                                            pszAsUser, uid, gid, RT_ELEMENTS(aRedirFds), aRedirFds, NULL /*pvExtraData*/, &hProcess);
    12031203                if (RT_SUCCESS(rc))
    12041204                {
     
    17131713        return VERR_PROC_DETACH_NOT_SUPPORTED;
    17141714#endif
    1715     AssertReturn(pvExtraData == NULL || (fFlags & RTPROC_FLAGS_DESIRED_SESSION_ID), VERR_INVALID_PARAMETER);
     1715    AssertReturn(pvExtraData == NULL || (fFlags & (RTPROC_FLAGS_DESIRED_SESSION_ID | RTPROC_FLAGS_CWD)),
     1716                 VERR_INVALID_PARAMETER);
     1717    AssertReturn((fFlags & (RTPROC_FLAGS_DESIRED_SESSION_ID | RTPROC_FLAGS_CWD)) != (RTPROC_FLAGS_DESIRED_SESSION_ID | RTPROC_FLAGS_CWD),
     1718                 VERR_INVALID_PARAMETER);
    17161719
    17171720    /*
     
    18951898                 */
    18961899                rc = rtProcPosixCreateInner(pszNativeExec, papszArgsConverted, hEnv, hEnvToUse, fFlags, pszAsUser, uid, gid,
    1897                                             RT_ELEMENTS(aStdFds), aStdFds, phProcess);
     1900                                            RT_ELEMENTS(aStdFds), aStdFds, pvExtraData, phProcess);
    18981901
    18991902            }
     
    19401943static int rtProcPosixCreateInner(const char *pszNativeExec, const char * const *papszArgs, RTENV hEnv, RTENV hEnvToUse,
    19411944                                  uint32_t fFlags, const char *pszAsUser, uid_t uid, gid_t gid,
    1942                                   unsigned cRedirFds, int *paRedirFds, PRTPROCESS phProcess)
     1945                                  unsigned cRedirFds, int *paRedirFds, void *pvExtraData, PRTPROCESS phProcess)
    19431946{
    19441947    /*
     
    20372040    /** @todo OS/2: implement DETACHED (BACKGROUND stuff), see VbglR3Daemonize.  */
    20382041    if (   uid == ~(uid_t)0
    2039         && gid == ~(gid_t)0)
     2042        && gid == ~(gid_t)0
     2043        && !(fFlags & RTPROC_FLAGS_CWD))
    20402044    {
    20412045        /* Spawn attributes. */
     
    21872191            }
    21882192#endif
     2193            if (fFlags & RTPROC_FLAGS_CWD)
     2194            {
     2195                const char *pszCwd = (const char *)pvExtraData;
     2196                if (pszCwd && *pszCwd)
     2197                {
     2198                    rc = RTPathSetCurrent(pszCwd);
     2199                    if (RT_FAILURE(rc))
     2200                    {
     2201                        /** @todo r=bela What is the right exit code here?? */
     2202                        if (fFlags & RTPROC_FLAGS_DETACHED)
     2203                            _Exit(126);
     2204                        else
     2205                            /*exit*/_Exit(126);
     2206                    }
     2207                }
     2208            }
    21892209
    21902210            /*
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