Skip to content

Commit 6a3fd82

Browse files
vstinnermiss-islington
authored andcommitted
bpo-44849: Fix os.set_inheritable() on FreeBSD 14 with O_PATH (pythonGH-27623)
Fix the os.set_inheritable() function on FreeBSD 14 for file descriptor opened with the O_PATH flag: ignore the EBADF error on ioctl(), fallback on the fcntl() implementation. (cherry picked from commit c24896c) Co-authored-by: Victor Stinner <[email protected]>
1 parent 7dad033 commit 6a3fd82

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix the :func:`os.set_inheritable` function on FreeBSD 14 for file descriptor
2+
opened with the :data:`~os.O_PATH` flag: ignore the :data:`~errno.EBADF`
3+
error on ``ioctl()``, fallback on the ``fcntl()`` implementation. Patch by
4+
Victor Stinner.

Python/fileutils.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,10 +1314,11 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
13141314
return 0;
13151315
}
13161316

1317-
#ifdef __linux__
1317+
#ifdef O_PATH
13181318
if (errno == EBADF) {
1319-
// On Linux, ioctl(FIOCLEX) will fail with EBADF for O_PATH file descriptors
1320-
// Fall through to the fcntl() path
1319+
// bpo-44849: On Linux and FreeBSD, ioctl(FIOCLEX) fails with EBADF
1320+
// on O_PATH file descriptors. Fall through to the fcntl()
1321+
// implementation.
13211322
}
13221323
else
13231324
#endif

0 commit comments

Comments
 (0)