Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(29591)

Side by Side Diff: Python/fileutils.c

Issue 27057: os.set_inheritable(): fall back to fcntl() if ioctl() fails with EACCES
Patch Set: Created 3 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "Python.h" 1 #include "Python.h"
2 #include "osdefs.h" 2 #include "osdefs.h"
3 #include <locale.h> 3 #include <locale.h>
4 4
5 #ifdef MS_WINDOWS 5 #ifdef MS_WINDOWS
6 # include <malloc.h> 6 # include <malloc.h>
7 # include <windows.h> 7 # include <windows.h>
8 extern int winerror_to_errno(int); 8 extern int winerror_to_errno(int);
9 #endif 9 #endif
10 10
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 if (inheritable) 853 if (inheritable)
854 request = FIONCLEX; 854 request = FIONCLEX;
855 else 855 else
856 request = FIOCLEX; 856 request = FIOCLEX;
857 err = ioctl(fd, request, NULL); 857 err = ioctl(fd, request, NULL);
858 if (!err) { 858 if (!err) {
859 ioctl_works = 1; 859 ioctl_works = 1;
860 return 0; 860 return 0;
861 } 861 }
862 862
863 if (errno != ENOTTY) { 863 if (errno != ENOTTY && errno != EACCES) {
864 if (raise) 864 if (raise)
865 PyErr_SetFromErrno(PyExc_OSError); 865 PyErr_SetFromErrno(PyExc_OSError);
866 return -1; 866 return -1;
867 } 867 }
868 else { 868 else {
869 /* Issue #22258: Here, ENOTTY means "Inappropriate ioctl for 869 /* Issue #22258: Here, ENOTTY means "Inappropriate ioctl for
870 device". The ioctl is declared but not supported by the kernel. 870 device". The ioctl is declared but not supported by the kernel.
871 Remember that ioctl() doesn't work. It is the case on 871 Remember that ioctl() doesn't work. It is the case on
872 Illumos-based OS for example. */ 872 Illumos-based OS for example.
873
874 Issue #27057: When SELinux policy disallows ioctl it will fail
875 with EACCES. While FIOCLEX is safe operation it may be
876 unavailable because ioctl was denied altogether.
877 This can be the case on Android. */
873 ioctl_works = 0; 878 ioctl_works = 0;
874 } 879 }
875 /* fallback to fcntl() if ioctl() does not work */ 880 /* fallback to fcntl() if ioctl() does not work */
876 } 881 }
877 #endif 882 #endif
878 883
879 /* slow-path: fcntl() requires two syscalls */ 884 /* slow-path: fcntl() requires two syscalls */
880 flags = fcntl(fd, F_GETFD); 885 flags = fcntl(fd, F_GETFD);
881 if (flags < 0) { 886 if (flags < 0) {
882 if (raise) 887 if (raise)
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 return 1; 1698 return 1;
1694 } 1699 }
1695 } 1700 }
1696 } 1701 }
1697 fail: 1702 fail:
1698 errno = EBADF; 1703 errno = EBADF;
1699 return 0; 1704 return 0;
1700 } 1705 }
1701 1706
1702 #endif /* defined _MSC_VER && _MSC_VER >= 1400 && _MSC_VER < 1900 */ 1707 #endif /* defined _MSC_VER && _MSC_VER >= 1400 && _MSC_VER < 1900 */
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+