18 msg = logging.getLogger(
'FdsRegistry')
33 msg.warning(
"fds_dict:fname: No Key %s" % i)
37 return [i
for i, v
in self.iteritems()
if v[0] == fname]
40 for v
in self.values():
46 def add(self, i, fname, iomode, flags):
47 self[i] = (fname, iomode, flags)
54 msg.warning(
"fds_dict:iomode: No Key %s" % i)
58 return [i
for i
in self.keys()
if self[i][1] ==
'<OUTPUT>']
61 return [i
for i
in self.keys()
if self[i][1] ==
'<INPUT>']
65 if dir ==
"" and self.
curdir is not None:
67 msg.debug(
"get_fds_in_dir(%s)" % dir)
69 i
for i
in self.keys()
70 if os.path.samefile(os.path.dirname(self[i][0]), dir)
75 create necessary symlinks in worker's dir if the fd is <INPUT>
76 otherwise copy <OUTPUT> file
85 dst = os.path.join(wkdir, os.path.basename(src))
86 if iomode ==
"<INPUT>":
87 if os.path.exists(dst):
90 "fds_dict.create_symlink:update_io_registry took care of src=%s"
95 "fds_dict.create_symlink:(symlink) src=%s, iomode=%s" %
99 msg.debug(
"fds_dict.create_symlink: (copy) src=%s, dst=%s" %
101 shutil.copy(src, dst)
106 """parse the fds of the processs -> build fds_dict
111 "extract_fds: making snapshot of parent process file descriptors")
112 self.
curdir = os.path.abspath(os.curdir)
115 procfd =
'/proc/self/fd'
116 fds = os.listdir(procfd)
119 if (fd == 1
or fd == 2):
127 realname = os.path.realpath(os.path.join(procfd, i))
128 except (OSError, IOError, TypeError):
131 msg.debug(
"failed to resolve: %s ... skipping",
132 os.path.join(procfd, i))
135 if os.path.exists(realname):
137 flags = fcntl.fcntl(fd, fcntl.F_GETFL)
138 if (flags & _O_ACCMODE) == 0:
143 self.
add(fd, realname, iomode, flags)
144 except (OSError, IOError):
147 msg.debug(
"failed access to: %s ... skipping", realname)
155 msg.debug(
"extract_fds.fds_dict=%s" % self)