| 
									
										
										
										
											2010-12-13 07:59:39 +00:00
										 |  |  | """When called as a script, print a comma-separated list of the open
 | 
					
						
							| 
									
										
										
										
											2013-09-01 10:22:41 +02:00
										 |  |  | file descriptors on stdout. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Usage: | 
					
						
							|  |  |  | fd_stats.py: check all file descriptors | 
					
						
							|  |  |  | fd_status.py fd1 fd2 ...: check only specified file descriptors | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											2010-12-13 07:59:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import errno | 
					
						
							|  |  |  | import os | 
					
						
							| 
									
										
										
										
											2013-08-22 01:58:04 +02:00
										 |  |  | import stat | 
					
						
							| 
									
										
										
										
											2013-09-01 10:22:41 +02:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2010-12-13 07:59:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							| 
									
										
										
										
											2011-02-21 21:55:48 +00:00
										 |  |  |     fds = [] | 
					
						
							| 
									
										
										
										
											2013-09-01 10:22:41 +02:00
										 |  |  |     if len(sys.argv) == 1: | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             _MAXFD = os.sysconf("SC_OPEN_MAX") | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             _MAXFD = 256 | 
					
						
							|  |  |  |         test_fds = range(0, _MAXFD) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         test_fds = map(int, sys.argv[1:]) | 
					
						
							|  |  |  |     for fd in test_fds: | 
					
						
							| 
									
										
										
										
											2011-02-21 21:55:48 +00:00
										 |  |  |         try: | 
					
						
							|  |  |  |             st = os.fstat(fd) | 
					
						
							|  |  |  |         except OSError as e: | 
					
						
							|  |  |  |             if e.errno == errno.EBADF: | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             raise | 
					
						
							|  |  |  |         # Ignore Solaris door files | 
					
						
							| 
									
										
										
										
											2013-08-22 01:58:04 +02:00
										 |  |  |         if not stat.S_ISDOOR(st.st_mode): | 
					
						
							| 
									
										
										
										
											2011-02-21 21:55:48 +00:00
										 |  |  |             fds.append(fd) | 
					
						
							|  |  |  |     print(','.join(map(str, fds))) |