Passing file descriptors in Python?

Viktor Fougstedt viktor at dtek.chalmers.se
Sun Oct 3 07:27:46 EDT 1999


Guido van Rossum <guido at cnri.reston.va.us> writes:

>puter_programmer at yahoo.com (Dan) writes:

>> I'm currently needing the module for a project that will run on a
>> Linux machine and unfortunately Linux does appear to support the
>> System-V approach.  There is no I_SENDFD or I_RECVFD in the ioctl()

>My guess is that those examples use socketpair() because it's
>convenient, not because it's necessary.  I would guess that creating a
>server AF_UNIX socket in the parent and a client AF_UNIX socket in the
>child, connecting the latter to the former, would allow you to do the
>same thing.  You might even be able to do this between unrelated
>processes.  Of course, this is pure speculation...

It should definately work without socketpair(), and even between
unrelated processes. But I do not think it will work without
sendmsg()/recvmsg(), which are needed to be able to set the message
type to a proper value. Even then it's kind of a thin line to walk
down, since the msghdr struct looks different on different UNIX
dialects... 

But if one were to implement sendmsg()/recvmsg() in the socket module,
which shouldn't be much work I suppose, it is very probable that it
would be possible to pack()/unpack() a struct that could be used to
pass open filedescriptors on Linux. The simplest implementation of
sendmsg()/recvmsg() could just pass a pack()ed struct as a msghdr, and
then it's up to the Python user to make sure it's a correct msghdr.


/Viktor...


-- 
--|     Viktor Fougstedt, system administrator at dtek.chalmers.se     |--
--|                http://www.dtek.chalmers.se/~viktor/                |--
--| ...soon we'll be sliding down the razor blade of life. /Tom Lehrer |--




More information about the Python-list mailing list