diff -r 3811995aad73 Python/fileutils.c --- a/Python/fileutils.c Wed May 18 15:54:24 2016 -0700 +++ b/Python/fileutils.c Thu May 19 15:34:55 2016 +0200 @@ -860,7 +860,7 @@ return 0; } - if (errno != ENOTTY) { + if (errno != ENOTTY && errno != EACCES) { if (raise) PyErr_SetFromErrno(PyExc_OSError); return -1; @@ -869,7 +869,12 @@ /* Issue #22258: Here, ENOTTY means "Inappropriate ioctl for device". The ioctl is declared but not supported by the kernel. Remember that ioctl() doesn't work. It is the case on - Illumos-based OS for example. */ + Illumos-based OS for example. + + Issue #27057: When SELinux policy disallows ioctl it will fail + with EACCES. While FIOCLEX is safe operation it may be + unavailable because ioctl was denied altogether. + This can be the case on Android. */ ioctl_works = 0; } /* fallback to fcntl() if ioctl() does not work */