19 msg = logging.getLogger(
"FdsRegistry")
34 msg.warning(
"fds_dict:fname: No Key %s" % i)
38 return [i
for i, v
in self.iteritems()
if v[0] == fname]
41 for v
in self.values():
47 def add(self, i, fname, iomode, flags):
48 self[i] = (fname, iomode, flags)
55 msg.warning(
"fds_dict:iomode: No Key %s" % i)
59 return [i
for i
in self.keys()
if self[i][1] ==
"<OUTPUT>"]
62 return [i
for i
in self.keys()
if self[i][1] ==
"<INPUT>"]
67 if dir ==
"" and self.
curdir is not None:
69 msg.debug(
"get_fds_in_dir(%s)" % dir)
71 i
for i
in self.keys()
if os.path.samefile(os.path.dirname(self[i][0]), dir)
76 create necessary symlinks in worker's dir if the fd is <INPUT>
77 otherwise copy <OUTPUT> file
87 dst = os.path.join(wkdir, os.path.basename(src))
88 if iomode ==
"<INPUT>":
89 if os.path.exists(dst):
92 "fds_dict.create_symlink:update_io_registry took care of src=%s"
98 "fds_dict.create_symlink:(symlink) src=%s, iomode=%s"
103 msg.debug(
"fds_dict.create_symlink: (copy) src=%s, dst=%s" % (src, dst))
104 shutil.copy(src, dst)
109 """parse the fds of the processs -> build fds_dict"""
113 msg.info(
"extract_fds: making snapshot of parent process file descriptors")
114 self.
curdir = os.path.abspath(os.curdir)
117 procfd =
"/proc/self/fd"
118 fds = os.listdir(procfd)
121 if fd == 1
or fd == 2:
129 realname = os.path.realpath(os.path.join(procfd, i))
130 except (OSError, IOError, TypeError):
133 msg.debug(
"failed to resolve: %s ... skipping", os.path.join(procfd, i))
136 if os.path.exists(realname):
138 flags = fcntl.fcntl(fd, fcntl.F_GETFL)
139 if (flags & _O_ACCMODE) == 0:
144 self.
add(fd, realname, iomode, flags)
145 except (OSError, IOError):
148 msg.debug(
"failed access to: %s ... skipping", realname)
156 msg.debug(
"extract_fds.fds_dict=%s" % self)