mirror of
https://github.com/python/cpython.git
synced 2025-09-18 22:50:26 +00:00
gh-113119 fix environment handling in subprocess.Popen when posix_spawn is used (#113120)
* Allow posix_spawn to inherit environment form parent environ variable. With this change, posix_spawn call can behave similarly to execv with regards to environments when used in subprocess functions.
This commit is contained in:
parent
cde1335485
commit
48c907a15c
5 changed files with 21 additions and 10 deletions
|
@ -7129,9 +7129,9 @@ py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *a
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyMapping_Check(env)) {
|
||||
if (!PyMapping_Check(env) && env != Py_None) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%s: environment must be a mapping object", func_name);
|
||||
"%s: environment must be a mapping object or None", func_name);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
@ -7145,9 +7145,13 @@ py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *a
|
|||
goto exit;
|
||||
}
|
||||
|
||||
envlist = parse_envlist(env, &envc);
|
||||
if (envlist == NULL) {
|
||||
goto exit;
|
||||
if (env == Py_None) {
|
||||
envlist = environ;
|
||||
} else {
|
||||
envlist = parse_envlist(env, &envc);
|
||||
if (envlist == NULL) {
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_actions != NULL && file_actions != Py_None) {
|
||||
|
@ -7210,7 +7214,7 @@ exit:
|
|||
if (attrp) {
|
||||
(void)posix_spawnattr_destroy(attrp);
|
||||
}
|
||||
if (envlist) {
|
||||
if (envlist && envlist != environ) {
|
||||
free_string_array(envlist, envc);
|
||||
}
|
||||
if (argvlist) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue