Skip to content

Commit 9ed179b

Browse files
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. (cherry picked from commit 4a08c4c) Co-authored-by: Gregory P. Smith <greg@krypto.org>
1 parent 625f670 commit 9ed179b

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
When subprocess tries to use vfork, it now falls back to fork if vfork
2+
returns an error. This allows use in situations where vfork isn't allowed
3+
by the OS kernel.

‎Modules/_posixsubprocess.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,12 @@ do_fork_exec(char *const exec_array[],
681681
assert(preexec_fn == Py_None);
682682

683683
pid = vfork();
684+
if (pid == -1) {
685+
/* If vfork() fails, fall back to using fork(). When it isn't
686+
* allowed in a process by the kernel, vfork can return -1
687+
* with errno EINVAL. https://bugs.python.org/issue47151. */
688+
pid = fork();
689+
}
684690
} else
685691
#endif
686692
{

0 commit comments

Comments
 (0)