Skip to content

bpo-35823: subprocess: Fix handling of pthread_sigmask() errors #22944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2020
Merged
Changes from all commits
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
19 changes: 15 additions & 4 deletions Modules/_posixsubprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,9 @@ child_exec(char *const exec_array[],
#ifdef VFORK_USABLE
if (child_sigmask) {
reset_signal_handlers(child_sigmask);
POSIX_CALL(pthread_sigmask(SIG_SETMASK, child_sigmask, NULL));
if ((errno = pthread_sigmask(SIG_SETMASK, child_sigmask, NULL))) {
goto error;
}
}
#endif

Expand Down Expand Up @@ -1007,7 +1009,11 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
*/
sigset_t all_sigs;
sigfillset(&all_sigs);
pthread_sigmask(SIG_BLOCK, &all_sigs, &old_sigs);
if ((saved_errno = pthread_sigmask(SIG_BLOCK, &all_sigs, &old_sigs))) {
errno = saved_errno;
PyErr_SetFromErrno(PyExc_OSError);
goto cleanup;
}
old_sigmask = &old_sigs;
}
#endif
Expand All @@ -1034,8 +1040,13 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
* Note that in environments where vfork() is implemented as fork(),
* such as QEMU user-mode emulation, the parent won't be blocked,
* but it won't share the address space with the child,
* so it's still safe to unblock the signals. */
pthread_sigmask(SIG_SETMASK, old_sigmask, NULL);
* so it's still safe to unblock the signals.
*
* We don't handle errors here because this call can't fail
* if valid arguments are given, and because there is no good
* way for the caller to deal with a failure to restore
* the thread signal mask. */
(void) pthread_sigmask(SIG_SETMASK, old_sigmask, NULL);
}
#endif

Expand Down