File tree 3 files changed +16
-12
lines changed
3 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -3382,6 +3382,15 @@ def test_dup(self):
3382
3382
self .addCleanup (os .close , fd2 )
3383
3383
self .assertEqual (os .get_inheritable (fd2 ), False )
3384
3384
3385
+ @unittest .skipUnless (sys .platform == 'win32' , 'win32-specific test' )
3386
+ def test_dup_nul (self ):
3387
+ # os.dup() was creating inheritable fds for character files.
3388
+ fd1 = os .open ('NUL' , os .O_RDONLY )
3389
+ self .addCleanup (os .close , fd1 )
3390
+ fd2 = os .dup (fd1 )
3391
+ self .addCleanup (os .close , fd2 )
3392
+ self .assertFalse (os .get_inheritable (fd2 ))
3393
+
3385
3394
@unittest .skipUnless (hasattr (os , 'dup2' ), "need os.dup2()" )
3386
3395
def test_dup2 (self ):
3387
3396
fd = os .open (__file__ , os .O_RDONLY )
Original file line number Diff line number Diff line change
1
+ On Windows, :func: `os.dup ` no longer creates an inheritable fd when handling
2
+ a character file.
Original file line number Diff line number Diff line change @@ -1776,7 +1776,6 @@ _Py_dup(int fd)
1776
1776
{
1777
1777
#ifdef MS_WINDOWS
1778
1778
HANDLE handle ;
1779
- DWORD ftype ;
1780
1779
#endif
1781
1780
1782
1781
assert (PyGILState_Check ());
@@ -1790,9 +1789,6 @@ _Py_dup(int fd)
1790
1789
return -1 ;
1791
1790
}
1792
1791
1793
- /* get the file type, ignore the error if it failed */
1794
- ftype = GetFileType (handle );
1795
-
1796
1792
Py_BEGIN_ALLOW_THREADS
1797
1793
_Py_BEGIN_SUPPRESS_IPH
1798
1794
fd = dup (fd );
@@ -1803,14 +1799,11 @@ _Py_dup(int fd)
1803
1799
return -1 ;
1804
1800
}
1805
1801
1806
- /* Character files like console cannot be make non-inheritable */
1807
- if (ftype != FILE_TYPE_CHAR ) {
1808
- if (_Py_set_inheritable (fd , 0 , NULL ) < 0 ) {
1809
- _Py_BEGIN_SUPPRESS_IPH
1810
- close (fd );
1811
- _Py_END_SUPPRESS_IPH
1812
- return -1 ;
1813
- }
1802
+ if (_Py_set_inheritable (fd , 0 , NULL ) < 0 ) {
1803
+ _Py_BEGIN_SUPPRESS_IPH
1804
+ close (fd );
1805
+ _Py_END_SUPPRESS_IPH
1806
+ return -1 ;
1814
1807
}
1815
1808
#elif defined(HAVE_FCNTL_H ) && defined(F_DUPFD_CLOEXEC )
1816
1809
Py_BEGIN_ALLOW_THREADS
You can’t perform that action at this time.
0 commit comments