mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
bpo-35674: Add os.posix_spawnp() (GH-11554)
Add a new os.posix_spawnp() function.
This commit is contained in:
parent
9daecf37a5
commit
92b8322e7e
9 changed files with 322 additions and 112 deletions
|
|
@ -5381,39 +5381,12 @@ fail:
|
|||
return -1;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
||||
os.posix_spawn
|
||||
path: path_t
|
||||
Path of executable file.
|
||||
argv: object
|
||||
Tuple or list of strings.
|
||||
env: object
|
||||
Dictionary of strings mapping to strings.
|
||||
/
|
||||
*
|
||||
file_actions: object(c_default='NULL') = ()
|
||||
A sequence of file action tuples.
|
||||
setpgroup: object = NULL
|
||||
The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.
|
||||
resetids: bool(accept={int}) = False
|
||||
If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.
|
||||
setsigmask: object(c_default='NULL') = ()
|
||||
The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.
|
||||
setsigdef: object(c_default='NULL') = ()
|
||||
The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.
|
||||
scheduler: object = NULL
|
||||
A tuple with the scheduler policy (optional) and parameters.
|
||||
|
||||
Execute the program specified by path in a new process.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
|
||||
PyObject *env, PyObject *file_actions,
|
||||
PyObject *setpgroup, int resetids, PyObject *setsigmask,
|
||||
PyObject *setsigdef, PyObject *scheduler)
|
||||
/*[clinic end generated code: output=45dfa4c515d09f2c input=2891c2f1d457e39b]*/
|
||||
py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *argv,
|
||||
PyObject *env, PyObject *file_actions,
|
||||
PyObject *setpgroup, int resetids, PyObject *setsigmask,
|
||||
PyObject *setsigdef, PyObject *scheduler)
|
||||
{
|
||||
EXECV_CHAR **argvlist = NULL;
|
||||
EXECV_CHAR **envlist = NULL;
|
||||
|
|
@ -5489,9 +5462,19 @@ os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
|
|||
attrp = &attr;
|
||||
|
||||
_Py_BEGIN_SUPPRESS_IPH
|
||||
err_code = posix_spawn(&pid, path->narrow,
|
||||
file_actionsp, attrp, argvlist, envlist);
|
||||
#ifdef HAVE_POSIX_SPAWNP
|
||||
if (use_posix_spawnp) {
|
||||
err_code = posix_spawnp(&pid, path->narrow,
|
||||
file_actionsp, attrp, argvlist, envlist);
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_POSIX_SPAWNP */
|
||||
{
|
||||
err_code = posix_spawn(&pid, path->narrow,
|
||||
file_actionsp, attrp, argvlist, envlist);
|
||||
}
|
||||
_Py_END_SUPPRESS_IPH
|
||||
|
||||
if (err_code) {
|
||||
errno = err_code;
|
||||
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path->object);
|
||||
|
|
@ -5518,7 +5501,90 @@ exit:
|
|||
Py_XDECREF(temp_buffer);
|
||||
return result;
|
||||
}
|
||||
#endif /* HAVE_POSIX_SPAWN */
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
|
||||
os.posix_spawn
|
||||
path: path_t
|
||||
Path of executable file.
|
||||
argv: object
|
||||
Tuple or list of strings.
|
||||
env: object
|
||||
Dictionary of strings mapping to strings.
|
||||
/
|
||||
*
|
||||
file_actions: object(c_default='NULL') = ()
|
||||
A sequence of file action tuples.
|
||||
setpgroup: object = NULL
|
||||
The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.
|
||||
resetids: bool(accept={int}) = False
|
||||
If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.
|
||||
setsigmask: object(c_default='NULL') = ()
|
||||
The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.
|
||||
setsigdef: object(c_default='NULL') = ()
|
||||
The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.
|
||||
scheduler: object = NULL
|
||||
A tuple with the scheduler policy (optional) and parameters.
|
||||
|
||||
Execute the program specified by path in a new process.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
|
||||
PyObject *env, PyObject *file_actions,
|
||||
PyObject *setpgroup, int resetids, PyObject *setsigmask,
|
||||
PyObject *setsigdef, PyObject *scheduler)
|
||||
/*[clinic end generated code: output=45dfa4c515d09f2c input=2891c2f1d457e39b]*/
|
||||
{
|
||||
return py_posix_spawn(0, module, path, argv, env, file_actions,
|
||||
setpgroup, resetids, setsigmask, setsigdef,
|
||||
scheduler);
|
||||
}
|
||||
#endif /* HAVE_POSIX_SPAWN */
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_POSIX_SPAWNP
|
||||
/*[clinic input]
|
||||
|
||||
os.posix_spawnp
|
||||
path: path_t
|
||||
Path of executable file.
|
||||
argv: object
|
||||
Tuple or list of strings.
|
||||
env: object
|
||||
Dictionary of strings mapping to strings.
|
||||
/
|
||||
*
|
||||
file_actions: object(c_default='NULL') = ()
|
||||
A sequence of file action tuples.
|
||||
setpgroup: object = NULL
|
||||
The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.
|
||||
resetids: bool(accept={int}) = False
|
||||
If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.
|
||||
setsigmask: object(c_default='NULL') = ()
|
||||
The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.
|
||||
setsigdef: object(c_default='NULL') = ()
|
||||
The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.
|
||||
scheduler: object = NULL
|
||||
A tuple with the scheduler policy (optional) and parameters.
|
||||
|
||||
Execute the program specified by path in a new process.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
|
||||
PyObject *env, PyObject *file_actions,
|
||||
PyObject *setpgroup, int resetids, PyObject *setsigmask,
|
||||
PyObject *setsigdef, PyObject *scheduler)
|
||||
/*[clinic end generated code: output=7955dc0edc82b8c3 input=b7576eb25b1ed9eb]*/
|
||||
{
|
||||
return py_posix_spawn(1, module, path, argv, env, file_actions,
|
||||
setpgroup, resetids, setsigmask, setsigdef,
|
||||
scheduler);
|
||||
}
|
||||
#endif /* HAVE_POSIX_SPAWNP */
|
||||
|
||||
|
||||
#if defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)
|
||||
|
|
@ -13084,6 +13150,7 @@ static PyMethodDef posix_methods[] = {
|
|||
OS_GETPRIORITY_METHODDEF
|
||||
OS_SETPRIORITY_METHODDEF
|
||||
OS_POSIX_SPAWN_METHODDEF
|
||||
OS_POSIX_SPAWNP_METHODDEF
|
||||
OS_READLINK_METHODDEF
|
||||
OS_RENAME_METHODDEF
|
||||
OS_REPLACE_METHODDEF
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue