VirtualBox

Changeset 99109 in vbox for trunk/src/VBox/Runtime


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

Location:
trunk/src/VBox/Runtime/r3
Files:
2 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            /*
  • trunk/src/VBox/Runtime/r3/win/process-win.cpp

    r98103 r99109  
    16131613                                  STARTUPINFOW *pStartupInfo, PROCESS_INFORMATION *pProcInfo,
    16141614                                  uint32_t fFlags, const char *pszExec, uint32_t idDesiredSession,
    1615                                   HANDLE hUserToken)
     1615                                  HANDLE hUserToken, PRTUTF16 pwszCwd)
    16161616{
    16171617    /*
     
    18041804                                                                     *        on XP and up. */
    18051805                                                                    pwszzBlock,   /* lpEnvironment */
    1806                                                                     NULL,         /* pCurrentDirectory */
     1806                                                                    pwszCwd,       /* pCurrentDirectory */
    18071807                                                                    pStartupInfo,
    18081808                                                                    pProcInfo);
     
    19421942                                  RTENV hEnv, DWORD dwCreationFlags,
    19431943                                  STARTUPINFOW *pStartupInfo, PROCESS_INFORMATION *pProcInfo,
    1944                                   uint32_t fFlags, const char *pszExec)
     1944                                  uint32_t fFlags, const char *pszExec, PRTUTF16 pwszCwd)
    19451945{
    19461946    /* The CreateProcessWithLogonW API was introduced with W2K and later.  It uses a service
     
    20422042                                                dwCreationFlags | (fCreatedSuspended ? CREATE_SUSPENDED : 0),
    20432043                                                pwszzBlock,
    2044                                                 NULL,                       /* pCurrentDirectory */
     2044                                                pwszCwd,                     /* pCurrentDirectory */
    20452045                                                pStartupInfo,
    20462046                                                pProcInfo);
     
    20932093                                 STARTUPINFOW *pStartupInfo, PROCESS_INFORMATION *pProcInfo,
    20942094                                 uint32_t fFlags, const char *pszExec, uint32_t idDesiredSession,
    2095                                  HANDLE hUserToken)
     2095                                 HANDLE hUserToken, PRTUTF16 pwszCwd)
    20962096{
    20972097    /*
     
    21052105        AssertPtr(pwszUser);
    21062106        int rc = rtProcWinCreateAsUser1(pwszUser, pwszPassword, ppwszExec, pwszCmdLine,
    2107                                         hEnv, dwCreationFlags, pStartupInfo, pProcInfo, fFlags, pszExec);
     2107                                        hEnv, dwCreationFlags, pStartupInfo, pProcInfo, fFlags, pszExec, pwszCwd);
    21082108        if (RT_SUCCESS(rc))
    21092109            return rc;
    21102110    }
    21112111    return rtProcWinCreateAsUser2(pwszUser, pwszPassword, ppwszExec, pwszCmdLine, hEnv, dwCreationFlags,
    2112                                   pStartupInfo, pProcInfo, fFlags, pszExec, idDesiredSession, hUserToken);
     2112                                  pStartupInfo, pProcInfo, fFlags, pszExec, idDesiredSession, hUserToken, pwszCwd);
    21132113}
    21142114
     
    22622262                               const char *pszPassword, void *pvExtraData, PRTPROCESS phProcess)
    22632263{
     2264    int rc;
     2265
    22642266    /*
    22652267     * Input validation
     
    22812283        ==           (RTPROC_FLAGS_DESIRED_SESSION_ID | RTPROC_FLAGS_SERVICE))
    22822284    {
     2285        AssertReturn(!(fFlags & RTPROC_FLAGS_CWD), VERR_INVALID_PARAMETER);
    22832286        AssertPtrReturn(pvExtraData, VERR_INVALID_POINTER);
    22842287        idDesiredSession = *(uint32_t *)pvExtraData;
     
    22942297     * Initialize the globals.
    22952298     */
    2296     int rc = RTOnce(&g_rtProcWinInitOnce, rtProcWinInitOnce, NULL);
     2299    rc = RTOnce(&g_rtProcWinInitOnce, rtProcWinInitOnce, NULL);
    22972300    AssertRCReturn(rc, rc);
    22982301    if (   pszAsUser
     
    24332436                                       !(fFlags & RTPROC_FLAGS_UNQUOTED_ARGS)
    24342437                                       ? RTGETOPTARGV_CNV_QUOTE_MS_CRT : RTGETOPTARGV_CNV_UNQUOTED);
     2438    PRTUTF16 pwszExec = NULL;
    24352439    if (RT_SUCCESS(rc))
    2436     {
    2437         PRTUTF16 pwszExec;
    24382440        rc = RTPathWinFromUtf8(&pwszExec, pszExec, 0 /*fFlags*/);
    2439         if (RT_SUCCESS(rc))
    2440         {
     2441    PRTUTF16 pwszCwd = NULL;
     2442    if (RT_SUCCESS(rc) && (fFlags & RTPROC_FLAGS_CWD))
     2443        rc = RTPathWinFromUtf8(&pwszCwd, (const char *)pvExtraData, 0);
     2444    if (RT_SUCCESS(rc))
     2445    {
    24412446            /*
    24422447             * Get going...
     
    24702475                                       dwCreationFlags,
    24712476                                       pwszzBlock,
    2472                                        NULL,         /* pCurrentDirectory */
     2477                                       pwszCwd,       /* pCurrentDirectory */
    24732478                                       &StartupInfo,
    24742479                                       &ProcInfo))
     
    24962501                        rc = rtProcWinCreateAsUser(pwszUser, pwszPassword, &pwszExec, pwszCmdLine, hEnv, dwCreationFlags,
    24972502                                                   &StartupInfo, &ProcInfo, fFlags, pszExec, idDesiredSession,
    2498                                                    hUserToken);
     2503                                                   hUserToken, pwszCwd);
    24992504
    25002505                        if (pwszPassword && *pwszPassword)
     
    25242529                rc = VINF_SUCCESS;
    25252530            }
    2526             RTPathWinFree(pwszExec);
    2527         }
    2528         RTUtf16Free(pwszCmdLine);
    2529     }
     2531    }
     2532    RTPathWinFree(pwszExec);
     2533    RTPathWinFree(pwszCwd);
     2534    RTUtf16Free(pwszCmdLine);
    25302535
    25312536    if (g_pfnSetHandleInformation)
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