]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44849: Fix os.set_inheritable() on FreeBSD 14 with O_PATH (GH-27623)
authorVictor Stinner <vstinner@python.org>
Fri, 6 Aug 2021 13:15:10 +0000 (15:15 +0200)
committerGitHub <noreply@github.com>
Fri, 6 Aug 2021 13:15:10 +0000 (15:15 +0200)
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.

Misc/NEWS.d/next/Library/2021-08-06-13-00-28.bpo-44849.O78F_f.rst [new file with mode: 0644]
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 (file)
index 0000000..b1f2254
--- /dev/null
@@ -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.
index a8fab00629da41c79a99701162b7ce10c6f366e0..e8a7eda505c7ec07c805becea63333ae09ded0cd 100644 (file)
@@ -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