Skip to content
Merged
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
Prev Previous commit
Next Next commit
Simplify: avoid -Wclobbered the compiler warning.
Don't write to the vfork_tstate_save pointer local after vfork.
  • Loading branch information
gpshead committed May 24, 2023
commit eb385733ce276040999187f711a6520e2578c828
15 changes: 6 additions & 9 deletions Modules/_posixsubprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ do_fork_exec(char *const exec_array[],
pid_t pid;

#ifdef VFORK_USABLE
PyThreadState *vfork_tstate_save = NULL;
PyThreadState *vfork_tstate_save;
if (child_sigmask) {
/* These are checked by our caller; verify them in debug builds. */
assert(uid == (uid_t)-1);
Expand All @@ -808,7 +808,7 @@ do_fork_exec(char *const exec_array[],

/* Drop the GIL so that other threads can continue execution while this
* thread in the parent remains blocked per vfork-semantics on the
* child's exec syscall outcome. Exec requires filesystem access which
* child's exec syscall outcome. Exec does filesystem access which
* can take an arbitrarily long time. This addresses GH-104372.
*
* The vfork'ed child still runs in our address space. Per POSIX it
Expand All @@ -817,9 +817,11 @@ do_fork_exec(char *const exec_array[],
*/
vfork_tstate_save = PyEval_SaveThread();
pid = vfork();
if (pid == (pid_t)-1) {
if (pid != 0) {
// Not in the child process, reacquire the GIL.
PyEval_RestoreThread(vfork_tstate_save);
vfork_tstate_save = NULL;
}
if (pid == (pid_t)-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. */
Expand All @@ -833,11 +835,6 @@ do_fork_exec(char *const exec_array[],

if (pid != 0) {
// Parent process.
#ifdef VFORK_USABLE
if (vfork_tstate_save != NULL) {
PyEval_RestoreThread(vfork_tstate_save);
}
#endif
return pid;
}

Expand Down