Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
kulikjak committed Dec 14, 2023
commit 0abca3465b85b9e295ee23fbb54833514a285408
3 changes: 0 additions & 3 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1756,9 +1756,6 @@ def _posix_spawn(self, args, executable, env, restore_signals,
c2pread, c2pwrite,
errread, errwrite):
"""Execute program using os.posix_spawn()."""
if env is None:
env = os.environ

kwargs = {}
if restore_signals:
# See _Py_RestoreSignals() in Python/pylifecycle.c
Expand Down
16 changes: 10 additions & 6 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -7082,9 +7082,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;
}

Expand All @@ -7098,9 +7098,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) {
Expand Down Expand Up @@ -7163,7 +7167,7 @@ py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *a
if (attrp) {
(void)posix_spawnattr_destroy(attrp);
}
if (envlist) {
if (envlist && envlist != environ) {
free_string_array(envlist, envc);
}
if (argvlist) {
Expand Down