I ran into a problem trying to follow the instructions to run a python file under the sandbox version of pypy-c. See the console log: http://paste.pocoo.org/show/363348
I was following the instructions here: http://codespeak.net/pypy/dist/pypy/doc/sandbox.html I got some help from arigato, ronny and antocuni on IRC (see log below) and they gave me the courage to hack on sandlib.py a little to see if I could get things working. http://www.tismer.com/pypy/irc-logs/pypy/%23pypy.log.20110331 The following patch changes the code so that it tracks the virtual file system nodes that correspond to each virtual file descriptor so that the node.stat() function can be used for fstat the same way it is used for stat. Thanks! diff -r 601862ed288e pypy/translator/sandbox/sandlib.py --- a/pypy/translator/sandbox/sandlib.py Mon Mar 28 13:12:49 2011 +0200 +++ b/pypy/translator/sandbox/sandlib.py Thu Mar 31 16:13:41 2011 -0800 @@ -391,6 +391,7 @@ super(VirtualizedSandboxedProc, self).__init__(*args, **kwds) self.virtual_root = self.build_virtual_root() self.open_fds = {} # {virtual_fd: real_file_object} + self.fd_to_node = {} def build_virtual_root(self): raise NotImplementedError("must be overridden") @@ -425,10 +426,17 @@ def do_ll_os__ll_os_stat(self, vpathname): node = self.get_node(vpathname) return node.stat() + do_ll_os__ll_os_stat.resulttype = s_StatResult do_ll_os__ll_os_lstat = do_ll_os__ll_os_stat + def do_ll_os__ll_os_fstat(self, fd): + node = self.fd_to_node[fd] + return node.stat() + + do_ll_os__ll_os_fstat.resulttype = s_StatResult + def do_ll_os__ll_os_isatty(self, fd): return self.virtual_console_isatty and fd in (0, 1, 2) @@ -452,11 +460,14 @@ raise OSError(errno.EPERM, "write access denied") # all other flags are ignored f = node.open() - return self.allocate_fd(f) + fd = self.allocate_fd(f) + self.fd_to_node[fd] = node + return fd def do_ll_os__ll_os_close(self, fd): f = self.get_file(fd) del self.open_fds[fd] + del self.fd_to_node[fd] f.close() def do_ll_os__ll_os_read(self, fd, size): _______________________________________________ pypy-dev@codespeak.net http://codespeak.net/mailman/listinfo/pypy-dev