summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2022-03-31 20:42:28 (GMT)
committerGitHub <noreply@github.com>2022-03-31 20:42:28 (GMT)
commit4a08c4c469d36f99d3a5e0f17ad82ab35dcf2835 (patch)
tree6da76ad3a8b61d447317a7ba86bc29a0712a7b32
parente7bb7c2f047b4f97e4426c42ae209c969808069d (diff)
downloadcpython-4a08c4c469d36f99d3a5e0f17ad82ab35dcf2835.zip
cpython-4a08c4c469d36f99d3a5e0f17ad82ab35dcf2835.tar.gz
cpython-4a08c4c469d36f99d3a5e0f17ad82ab35dcf2835.tar.bz2
bpo-47151: Fallback to fork when vfork fails in subprocess. (GH-32186)
bpo-47151: Fallback to fork when vfork fails in subprocess. An OS kernel can specifically decide to disallow vfork() in a process. No need for that to prevent us from launching subprocesses.
-rw-r--r--Misc/NEWS.d/next/Library/2022-03-30-01-17-43.bpo-47151.z-nQkR.rst3
-rw-r--r--Modules/_posixsubprocess.c6
2 files changed, 9 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Library/2022-03-30-01-17-43.bpo-47151.z-nQkR.rst b/Misc/NEWS.d/next/Library/2022-03-30-01-17-43.bpo-47151.z-nQkR.rst
new file mode 100644
index 0000000..d4d0245
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-03-30-01-17-43.bpo-47151.z-nQkR.rst
@@ -0,0 +1,3 @@
+When subprocess tries to use vfork, it now falls back to fork if vfork
+returns an error. This allows use in situations where vfork isn't allowed
+by the OS kernel.
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
index de599f8..440c7c5 100644
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -685,6 +685,12 @@ do_fork_exec(char *const exec_array[],
assert(preexec_fn == Py_None);
pid = vfork();
+ if (pid == -1) {
+ /* If vfork() fails, fall back to using fork(). When it isn't
+ * allowed in a process by the kernel, vfork can return -1
+ * with errno EINVAL. https://bugs.python.org/issue47151. */
+ pid = fork();
+ }
} else
#endif
{