summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-08-06 13:40:44 (GMT)
committerGitHub <noreply@github.com>2021-08-06 13:40:44 (GMT)
commit2ae2235c7a7627725df40c7875245cd17d90f39f (patch)
tree043b86247eb9ce8e3f487984f8a65d4b80632693
parenta11158ecef8cff795f7db8f4047cbd20cc9cf37e (diff)
downloadcpython-2ae2235c7a7627725df40c7875245cd17d90f39f.zip
cpython-2ae2235c7a7627725df40c7875245cd17d90f39f.tar.gz
cpython-2ae2235c7a7627725df40c7875245cd17d90f39f.tar.bz2
bpo-44849: Fix os.set_inheritable() on FreeBSD 14 with O_PATH (GH-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 c24896c0e3b32c8a9f614ef51366007b67d5c665) Co-authored-by: Victor Stinner <vstinner@python.org>
-rw-r--r--Misc/NEWS.d/next/Library/2021-08-06-13-00-28.bpo-44849.O78F_f.rst4
-rw-r--r--Python/fileutils.c7
2 files changed, 8 insertions, 3 deletions
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 0000000..b1f2254
--- /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 a8fab00..e8a7eda 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -1374,10 +1374,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