VirtualBox

Changeset 26804 in vbox for trunk


Ignore:
Timestamp:
Feb 25, 2010 4:26:10 PM (15 years ago)
Author:
vboxsync
Message:

process-posix.cpp: Drop the old RTProcCreate code.

File:
1 edited

Legend:

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

    r26802 r26804  
    6868RTR3DECL(int)   RTProcCreate(const char *pszExec, const char * const *papszArgs, RTENV Env, unsigned fFlags, PRTPROCESS pProcess)
    6969{
    70 #if 0
    71     int rc;
    72 
    73     /*
    74      * Validate input.
    75      */
    76     AssertPtrReturn(pszExec, VERR_INVALID_POINTER);
    77     AssertReturn(*pszExec, VERR_INVALID_PARAMETER);
    78     AssertReturn(!(fFlags & ~RTPROC_FLAGS_DAEMONIZE), VERR_INVALID_PARAMETER);
    79     AssertReturn(Env != NIL_RTENV, VERR_INVALID_PARAMETER);
    80     const char * const *papszEnv = RTEnvGetExecEnvP(Env);
    81     AssertPtrReturn(papszEnv, VERR_INVALID_HANDLE);
    82     AssertPtrReturn(papszArgs, VERR_INVALID_PARAMETER);
    83     /* later: path searching. */
    84 
    85 
    86     /*
    87      * Check for execute access to the file.
    88      */
    89     if (access(pszExec, X_OK))
    90     {
    91         rc = RTErrConvertFromErrno(errno);
    92         AssertMsgFailed(("'%s' %Rrc!\n", pszExec, rc));
    93         return rc;
    94     }
    95 
    96 #if 0
    97     /*
    98      * Squeeze gdb --args in front of what's being spawned.
    99      */
    100     unsigned cArgs = 0;
    101     while (papszArgs[cArgs])
    102         cArgs++;
    103     cArgs += 3;
    104     const char **papszArgsTmp = (const char **)alloca(cArgs * sizeof(char *));
    105     papszArgsTmp[0] = "/usr/bin/gdb";
    106     papszArgsTmp[1] = "--args";
    107     papszArgsTmp[2] = pszExec;
    108     for (unsigned i = 1; papszArgs[i]; i++)
    109         papszArgsTmp[i + 2] = papszArgs[i];
    110     papszArgsTmp[cArgs - 1] = NULL;
    111     pszExec = papszArgsTmp[0];
    112     papszArgs = papszArgsTmp;
    113 #endif
    114 
    115     /*
    116      * Spawn the child.
    117      *
    118      * HACK ALERT! Put the process into a new process group with pgid = pid
    119      * to make sure it differs from that of the parent process to ensure that
    120      * the IPRT waipit call doesn't race anyone (read XPCOM) doing group wide
    121      * waits.
    122      */
    123     pid_t pid;
    124 #ifdef HAVE_POSIX_SPAWN
    125     if (!(fFlags & RTPROC_FLAGS_DAEMONIZE))
    126     {
    127         posix_spawnattr_t Attr;
    128 
    129         rc = posix_spawnattr_init(&Attr);
    130         if (!rc)
    131         {
    132 # ifndef RT_OS_OS2 /* We don't need this on OS/2 and I don't recall if it's actually implemented. */
    133             rc = posix_spawnattr_setflags(&Attr, POSIX_SPAWN_SETPGROUP);
    134             Assert(rc == 0);
    135             if (!rc)
    136             {
    137                 rc = posix_spawnattr_setpgroup(&Attr, 0 /* pg == child pid */);
    138                 Assert(rc == 0);
    139             }
    140 # endif
    141             if (!rc)
    142             {
    143                 rc = posix_spawn(&pid, pszExec, NULL, &Attr, (char * const *)papszArgs,
    144                                  (char * const *)papszEnv);
    145                 if (!rc)
    146                 {
    147                     int rc2 = posix_spawnattr_destroy(&Attr); Assert(rc2 == 0); NOREF(rc2);
    148                     if (pProcess)
    149                         *pProcess = pid;
    150                     return VINF_SUCCESS;
    151                 }
    152             }
    153             int rc2 = posix_spawnattr_destroy(&Attr); Assert(rc2 == 0); NOREF(rc2);
    154         }
    155     }
    156     else
    157 #endif
    158     {
    159         pid = fork();
    160         if (!pid)
    161         {
    162             setpgid(0, 0); /* see comment above */
    163 
    164             if (fFlags & RTPROC_FLAGS_DAEMONIZE)
    165             {
    166                 rc = RTProcDaemonize(true /* fNoChDir */, false /* fNoClose */, NULL /* pszPidFile */);
    167                 AssertReleaseMsgFailed(("RTProcDaemonize returns %Rrc errno=%d\n", rc, errno));
    168                 exit(127);
    169             }
    170             rc = execve(pszExec, (char * const *)papszArgs, (char * const *)papszEnv);
    171             AssertReleaseMsgFailed(("execve returns %d errno=%d\n", rc, errno));
    172             exit(127);
    173         }
    174         if (pid > 0)
    175         {
    176             if (pProcess)
    177                 *pProcess = pid;
    178             return VINF_SUCCESS;
    179         }
    180         rc = errno;
    181     }
    182 
    183     /* failure, errno value in rc. */
    184     AssertMsgFailed(("spawn/exec failed rc=%d\n", rc)); /* this migth be annoying... */
    185     return RTErrConvertFromErrno(rc);
    186 #else
    18770    return RTProcCreateEx(pszExec, papszArgs, Env, fFlags,
    18871                          NULL, NULL, NULL,  /* standard handles */
    18972                          NULL /*pszAsUser*/,
    19073                          pProcess);
    191 #endif
    19274}
    19375
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