bpo-42780: Fix set_inheritable() for O_PATH file descriptors on Linux (GH-24172) (GH-24278)

(cherry picked from commit 7dc71c425c)
This commit is contained in:
cptpcrd 2021-01-21 05:46:35 -05:00 committed by GitHub
parent 0654c4c4cc
commit 6893523bed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View file

@ -1165,6 +1165,13 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
return 0;
}
#ifdef __linux__
if (errno == EBADF) {
// On Linux, ioctl(FIOCLEX) will fail with EBADF for O_PATH file descriptors
// Fall through to the fcntl() path
}
else
#endif
if (errno != ENOTTY && errno != EACCES) {
if (raise)
PyErr_SetFromErrno(PyExc_OSError);