diff options
author | Jakub KulĂk <Kulikjak@gmail.com> | 2023-12-17 05:19:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-17 05:19:05 (GMT) |
commit | 48c907a15ceae7202fcfeb435943addff896c42c (patch) | |
tree | 3a55910a34781c81cc7f4fe2c754f8c1321ae83e /Modules/posixmodule.c | |
parent | cde1335485b7bffb12c378d230ae48ad77d76ab1 (diff) | |
download | cpython-48c907a15ceae7202fcfeb435943addff896c42c.zip cpython-48c907a15ceae7202fcfeb435943addff896c42c.tar.gz cpython-48c907a15ceae7202fcfeb435943addff896c42c.tar.bz2 |
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.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b464a28..2dc5d7d 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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) { |