]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-47151: Fallback to fork when vfork fails in subprocess. (GH-32186)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 31 Mar 2022 21:09:50 +0000 (14:09 -0700)
committerGitHub <noreply@github.com>
Thu, 31 Mar 2022 21:09:50 +0000 (14:09 -0700)
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.
(cherry picked from commit 4a08c4c469d36f99d3a5e0f17ad82ab35dcf2835)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Misc/NEWS.d/next/Library/2022-03-30-01-17-43.bpo-47151.z-nQkR.rst [new file with mode: 0644]
Modules/_posixsubprocess.c

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 (file)
index 0000000..d4d0245
--- /dev/null
@@ -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.
index a58159a277bea8fb703aa6a74f1db4502b2e7c7a..18a81c6ed8b353e35e3953033f43f34bfb2b7316 100644 (file)
@@ -681,6 +681,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
     {