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

This commit is contained in:
cptpcrd 2021-01-20 09:05:51 -05:00 committed by GitHub
parent e0e398ef18
commit 7dc71c425c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View file

@ -1234,6 +1234,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);