diff options
author | Alexey Izbyshev <izbyshev@users.noreply.github.com> | 2018-02-06 06:09:34 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2018-02-06 06:09:34 (GMT) |
commit | c1e46e94de38a92f98736af9a42d89c3975a9919 (patch) | |
tree | 90fdbdc92f2b0e90d5bb889b6f921995b51dd43d /Modules/_posixsubprocess.c | |
parent | 22864bc8e4a076bbac748ccda6c27f1ec41b53e7 (diff) | |
download | cpython-c1e46e94de38a92f98736af9a42d89c3975a9919.zip cpython-c1e46e94de38a92f98736af9a42d89c3975a9919.tar.gz cpython-c1e46e94de38a92f98736af9a42d89c3975a9919.tar.bz2 |
bpo-32777: Fix _Py_set_inheritable async-safety in subprocess (GH-5560)
Fix a rare but potential pre-exec child process deadlock in subprocess on POSIX systems when marking file descriptors inheritable on exec in the child process. This bug appears to have been introduced in 3.4 with the inheritable file descriptors support.
This also changes Python/fileutils.c `set_inheritable` to use the "slow" two `fcntl` syscall path instead of the "fast" single `ioctl` syscall path when asked to be async signal safe (by way of being asked not to raise exceptions). `ioctl` is not a POSIX async-signal-safe approved function.
ref: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html
Diffstat (limited to 'Modules/_posixsubprocess.c')
-rw-r--r-- | Modules/_posixsubprocess.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index ea7a3d6..dc43ffc 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -169,7 +169,7 @@ make_inheritable(PyObject *py_fds_to_keep, int errpipe_write) called. */ continue; } - if (_Py_set_inheritable((int)fd, 1, NULL) < 0) + if (_Py_set_inheritable_async_safe((int)fd, 1, NULL) < 0) return -1; } return 0; @@ -431,21 +431,21 @@ child_exec(char *const exec_array[], dup2() removes the CLOEXEC flag but we must do it ourselves if dup2() would be a no-op (issue #10806). */ if (p2cread == 0) { - if (_Py_set_inheritable(p2cread, 1, NULL) < 0) + if (_Py_set_inheritable_async_safe(p2cread, 1, NULL) < 0) goto error; } else if (p2cread != -1) POSIX_CALL(dup2(p2cread, 0)); /* stdin */ if (c2pwrite == 1) { - if (_Py_set_inheritable(c2pwrite, 1, NULL) < 0) + if (_Py_set_inheritable_async_safe(c2pwrite, 1, NULL) < 0) goto error; } else if (c2pwrite != -1) POSIX_CALL(dup2(c2pwrite, 1)); /* stdout */ if (errwrite == 2) { - if (_Py_set_inheritable(errwrite, 1, NULL) < 0) + if (_Py_set_inheritable_async_safe(errwrite, 1, NULL) < 0) goto error; } else if (errwrite != -1) |