Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3116cc4

Browse files
committed
Fix os.set_inheritable() on Android
Issue #27057: Fix os.set_inheritable() on Android, ioctl() is blocked by SELinux and fails with EACCESS. The function now falls back to fcntl(). Patch written by Michał Bednarski.
1 parent 4962141 commit 3116cc4

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Neal Becker
110110
Robin Becker
111111
Torsten Becker
112112
Bill Bedford
113+
Michał Bednarski
113114
Ian Beer
114115
Stefan Behnel
115116
Reimer Behrends

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ Core and Builtins
123123
Library
124124
-------
125125

126+
- Issue #27057: Fix os.set_inheritable() on Android, ioctl() is blocked by
127+
SELinux and fails with EACCESS. The function now falls back to fcntl().
128+
Patch written by Michał Bednarski.
129+
126130
- Issue #27014: Fix infinite recursion using typing.py. Thanks to Kalle Tuure!
127131

128132
- Issue #14132: Fix urllib.request redirect handling when the target only has

Python/fileutils.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
856856
return 0;
857857
}
858858

859-
if (errno != ENOTTY) {
859+
if (errno != ENOTTY && errno != EACCES) {
860860
if (raise)
861861
PyErr_SetFromErrno(PyExc_OSError);
862862
return -1;
@@ -865,7 +865,12 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
865865
/* Issue #22258: Here, ENOTTY means "Inappropriate ioctl for
866866
device". The ioctl is declared but not supported by the kernel.
867867
Remember that ioctl() doesn't work. It is the case on
868-
Illumos-based OS for example. */
868+
Illumos-based OS for example.
869+
870+
Issue #27057: When SELinux policy disallows ioctl it will fail
871+
with EACCES. While FIOCLEX is safe operation it may be
872+
unavailable because ioctl was denied altogether.
873+
This can be the case on Android. */
869874
ioctl_works = 0;
870875
}
871876
/* fallback to fcntl() if ioctl() does not work */

0 commit comments

Comments
 (0)