Mailing List Archive

bpo-44849: Fix os.set_inheritable() on FreeBSD 14 with O_PATH (GH-27623) (GH-28978)
https://github.com/python/cpython/commit/67e10be3fee7c69d4ece26e75a0b7a84dab68ce5
commit: 67e10be3fee7c69d4ece26e75a0b7a84dab68ce5
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
committer: ambv <lukasz@langa.pl>
date: 2021-10-19T21:15:29+02:00
summary:

bpo-44849: Fix os.set_inheritable() on FreeBSD 14 with O_PATH (GH-27623) (GH-28978)

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 c24896c0e3b32c8a9f614ef51366007b67d5c665)

Co-authored-by: Victor Stinner <vstinner@python.org>

files:
A Misc/NEWS.d/next/Library/2021-08-06-13-00-28.bpo-44849.O78F_f.rst
M Python/fileutils.c

diff --git a/Misc/NEWS.d/next/Library/2021-08-06-13-00-28.bpo-44849.O78F_f.rst b/Misc/NEWS.d/next/Library/2021-08-06-13-00-28.bpo-44849.O78F_f.rst
new file mode 100644
index 0000000000000..b1f225485ddef
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-08-06-13-00-28.bpo-44849.O78F_f.rst
@@ -0,0 +1,4 @@
+Fix the :func:`os.set_inheritable` function on FreeBSD 14 for file descriptor
+opened with the :data:`~os.O_PATH` flag: ignore the :data:`~errno.EBADF`
+error on ``ioctl()``, fallback on the ``fcntl()`` implementation. Patch by
+Victor Stinner.
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 3e1311c978686..f0bdd9c17371d 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -1205,10 +1205,11 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
return 0;
}

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

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins