106 def extract_fds(self, dir=""):
107 """parse the fds of the processs -> build fds_dict"""
108 import fcntl
109 import os
110
111 msg.info("extract_fds: making snapshot of parent process file descriptors")
112 self.curdir = os.path.abspath(os.curdir)
113 iomode = "<INPUT>"
114
115 procfd = "/proc/self/fd"
116 fds = os.listdir(procfd)
117 for i in fds:
118 fd = int(i)
119 if fd == 1 or fd == 2:
120
121 continue
122 elif fd == 0:
123
124 continue
125
126 try:
127 realname = os.path.realpath(os.path.join(procfd, i))
128 except (OSError, TypeError):
129
130
131 msg.debug("failed to resolve: %s ... skipping", os.path.join(procfd, i))
132 continue
133
134 if os.path.exists(realname):
135 try:
136 flags = fcntl.fcntl(fd, fcntl.F_GETFL)
137 if (flags & _O_ACCMODE) == 0:
138 iomode = "<INPUT>"
139 else:
140 iomode = "<OUTPUT>"
141
142 self.add(fd, realname, iomode, flags)
143 except OSError:
144
145
146 msg.debug("failed access to: %s ... skipping", realname)
147 continue
148
149
150
151
152
153
154 msg.debug(f"extract_fds.fds_dict={self}")
155 return
156