Changeset 14999 in vbox
- Timestamp:
- Dec 4, 2008 5:12:09 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/process.h
r11337 r14999 131 131 * @param papszArgs Pointer to an array of arguments to the child. The array terminated by an entry containing NULL. 132 132 * @param Env Handle to the environment block for the child. 133 * @param fFlags Flags . This is currently reserved and must be 0.133 * @param fFlags Flags, one of the RTPROC_FLAGS_* defines. 134 134 * @param pProcess Where to store the process identifier on successful return. 135 135 * The content is not changed on failure. NULL is allowed. 136 136 */ 137 137 RTR3DECL(int) RTProcCreate(const char *pszExec, const char * const *papszArgs, RTENV Env, unsigned fFlags, PRTPROCESS pProcess); 138 139 /** @name RTProcCreate flags 140 * @{ */ 141 /** Daemonize the child process, without changing the directory. 142 * @remarks Not implemented on all platforms yet... */ 143 #define RTPROC_FLAGS_DAEMONIZE RT_BIT(0) 144 /** @} */ 145 138 146 139 147 /** -
trunk/src/VBox/Runtime/r3/posix/process-posix.cpp
r13837 r14999 64 64 RTR3DECL(int) RTProcCreate(const char *pszExec, const char * const *papszArgs, RTENV Env, unsigned fFlags, PRTPROCESS pProcess) 65 65 { 66 int rc; 67 66 68 /* 67 69 * Validate input. … … 69 71 AssertPtrReturn(pszExec, VERR_INVALID_POINTER); 70 72 AssertReturn(*pszExec, VERR_INVALID_PARAMETER); 71 AssertReturn( !fFlags, VERR_INVALID_PARAMETER);73 AssertReturn(fFlags & ~RTPROC_FLAGS_DAEMONIZE, VERR_INVALID_PARAMETER); 72 74 AssertReturn(Env != NIL_RTENV, VERR_INVALID_PARAMETER); 73 75 const char * const *papszEnv = RTEnvGetExecEnvP(Env); … … 110 112 pid_t pid; 111 113 #ifdef HAVE_POSIX_SPAWN 112 /** @todo check if it requires any of those two attributes, don't remember atm. */ 113 int rc = posix_spawn(&pid, pszExec, NULL, NULL, (char * const *)papszArgs, 114 if (!(fFlags & RTPROC_FLAGS_DAEMONIZE)) 115 { 116 /** @todo check if it requires any of those two attributes, don't remember atm. */ 117 rc = posix_spawn(&pid, pszExec, NULL, NULL, (char * const *)papszArgs, 114 118 (char * const *)papszEnv); 115 if (!rc) 116 { 117 if (pProcess) 118 *pProcess = pid; 119 return VINF_SUCCESS; 120 } 121 122 #else 123 124 pid = fork(); 125 if (!pid) 126 { 127 int rc; 128 rc = execve(pszExec, (char * const *)papszArgs, (char * const *)papszEnv); 129 AssertReleaseMsgFailed(("execve returns %d errno=%d\n", rc, errno)); 130 exit(127); 131 } 132 if (pid > 0) 133 { 134 if (pProcess) 135 *pProcess = pid; 136 return VINF_SUCCESS; 137 } 138 int rc = errno; 139 #endif 119 if (!rc) 120 { 121 if (pProcess) 122 *pProcess = pid; 123 return VINF_SUCCESS; 124 } 125 } 126 else 127 #endif 128 { 129 pid = fork(); 130 if (!pid) 131 { 132 if (fFlags & RTPROC_FLAGS_DAEMONIZE) 133 { 134 rc = RTProcDaemonize(true /* fNoChDir */, false /* fNoClose */, NULL /* pszPidFile */); 135 AssertReleaseMsgFailed(("RTProcDaemonize returns %Rrc errno=%d\n", rc, errno)); 136 exit(127); 137 } 138 rc = execve(pszExec, (char * const *)papszArgs, (char * const *)papszEnv); 139 AssertReleaseMsgFailed(("execve returns %d errno=%d\n", rc, errno)); 140 exit(127); 141 } 142 if (pid > 0) 143 { 144 if (pProcess) 145 *pProcess = pid; 146 return VINF_SUCCESS; 147 } 148 int rc = errno; 149 } 140 150 141 151 /* failure, errno value in rc. */
Note:
See TracChangeset
for help on using the changeset viewer.