cooperative-computing-lab/cctools — pull request #509 by batrick (2014-07-13 02:55:32+00:00)
Title: Add support for native fd in Parrot.

Note, this PR is not ready for merging. There are a few minor FIXMEs in the code left to correct...

--

This change allows tracees to have native file descriptors, which are not
intercepted/interpreted by Parrot in any way. This currently allows sockets and
pipes to be treated natively, as well as ttys already attached when Parrot
bootstraps the root tracee.

Various things to note about this commit:

o select/poll are now executed in the kernel without any interpretation by Parrot.
This is accomplished by having a dummy unique open file (which maps to a pfs_pointer)
for each file descriptor opened in Parrot (e.g. /chirp/host:port/foo). select/poll on
a regular file always sets read/write/error status which is what we want.

o Before considering recvmsg/sendmsg, I had used a dummy "null" file descriptor
(/dev/null) for open Parrot file descriptors. This was duplicated via dup2 to
the desired fd. So if we opened /chirp/host:port/foo and set it to fd 3, we
would have the tracee run dup2(3, ).

Because of recvmsg/sendmsg being capable of sending a file descriptor to
another process (which is fairly common), we need to "track" a Parrot fd that
is sent to another tracee (we ignore a Parrot fd being sent to a process not
being traced by Parrot, which at worst may break the application; we have
never accounted for this possibility). We accomplish tracking an fd sent to
another tracee by having the tracee create a file in the pfs_temp_dir,
obtaining the inode, and then unlinking the file. Using this inode, we can
identify a Parrot file descriptor received via recvmsg by doing stat on

/proc//fd/

We don't need to do anything special for sendmsg. [Except actually we do, we
need to increment the reference count for any Parrot file "in flight". Future
work...]

o All socket/pipe operations fallthrough to the kernel. Sockets and pipes are
always native.

o pfs_poll.* and all tracee wait states are obsolete and removed.

Fixes #48.
Maybe will fix (but does not currently) #346.