mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
to open door files.
This commit is contained in:
		
							parent
							
								
									5ed8b2c737
								
							
						
					
					
						commit
						ce58dc7b16
					
				
					 3 changed files with 15 additions and 19 deletions
				
			
		| 
						 | 
					@ -3,22 +3,22 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import errno
 | 
					import errno
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import fcntl
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
try:
 | 
					try:
 | 
				
			||||||
    _MAXFD = os.sysconf("SC_OPEN_MAX")
 | 
					    _MAXFD = os.sysconf("SC_OPEN_MAX")
 | 
				
			||||||
except:
 | 
					except:
 | 
				
			||||||
    _MAXFD = 256
 | 
					    _MAXFD = 256
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def isopen(fd):
 | 
					 | 
				
			||||||
    """Return True if the fd is open, and False otherwise"""
 | 
					 | 
				
			||||||
    try:
 | 
					 | 
				
			||||||
        fcntl.fcntl(fd, fcntl.F_GETFD, 0)
 | 
					 | 
				
			||||||
    except IOError as e:
 | 
					 | 
				
			||||||
        if e.errno == errno.EBADF:
 | 
					 | 
				
			||||||
            return False
 | 
					 | 
				
			||||||
        raise
 | 
					 | 
				
			||||||
    return True
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    print(','.join(str(fd) for fd in range(0, _MAXFD) if isopen(fd)))
 | 
					    fds = []
 | 
				
			||||||
 | 
					    for fd in range(0, _MAXFD):
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            st = os.fstat(fd)
 | 
				
			||||||
 | 
					        except OSError as e:
 | 
				
			||||||
 | 
					            if e.errno == errno.EBADF:
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					            raise
 | 
				
			||||||
 | 
					        # Ignore Solaris door files
 | 
				
			||||||
 | 
					        if st.st_mode & 0xF000 != 0xd000:
 | 
				
			||||||
 | 
					            fds.append(fd)
 | 
				
			||||||
 | 
					    print(','.join(map(str, fds)))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1156,9 +1156,6 @@ def test_pass_fds(self):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        open_fds = set()
 | 
					        open_fds = set()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if support.verbose:
 | 
					 | 
				
			||||||
            print(" -- maxfd =", subprocess.MAXFD)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for x in range(5):
 | 
					        for x in range(5):
 | 
				
			||||||
            fds = os.pipe()
 | 
					            fds = os.pipe()
 | 
				
			||||||
            self.addCleanup(os.close, fds[0])
 | 
					            self.addCleanup(os.close, fds[0])
 | 
				
			||||||
| 
						 | 
					@ -1173,10 +1170,6 @@ def test_pass_fds(self):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            remaining_fds = set(map(int, output.split(b',')))
 | 
					            remaining_fds = set(map(int, output.split(b',')))
 | 
				
			||||||
            to_be_closed = open_fds - {fd}
 | 
					            to_be_closed = open_fds - {fd}
 | 
				
			||||||
            # Temporary debug output for intermittent failures
 | 
					 | 
				
			||||||
            if support.verbose:
 | 
					 | 
				
			||||||
                print(" -- fds that should have been closed:", to_be_closed)
 | 
					 | 
				
			||||||
                print(" -- fds that remained open:", remaining_fds)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            self.assertIn(fd, remaining_fds, "fd to be passed not passed")
 | 
					            self.assertIn(fd, remaining_fds, "fd to be passed not passed")
 | 
				
			||||||
            self.assertFalse(remaining_fds & to_be_closed,
 | 
					            self.assertFalse(remaining_fds & to_be_closed,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,6 +45,9 @@ Build
 | 
				
			||||||
Tests
 | 
					Tests
 | 
				
			||||||
-----
 | 
					-----
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
 | 
				
			||||||
 | 
					  to open door files.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Issue #10990: Prevent tests from clobbering a set trace function.
 | 
					- Issue #10990: Prevent tests from clobbering a set trace function.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue