Passing file descriptors

Donn Cave donn at
Thu Jun 10 18:35:28 CEST 2004

In article <ca8rlq$c8$1 at>,
 Josiah Carlson <jcarlson at> wrote:

[... evidently wishing to pass a file descriptor over a
     local socket connection ...]

> Certainly I need a two things:
> 1. Unix domain socket, local socket (standard socket connected locally), 
> or pipe
> 2. sendmsg/recvmsg, fcntl.ioctl, or equivalent file descriptor manipulation
> In the script listed at the end of this post, I use a file descriptor 
> pair returned by os.pipe(), which should be sufficient.  I also use 
> fcntl.ioctl().
> As stated previously, this works properly on SunOS 5.8:
> It does not work on the linux machine I'm testing it on:
>      IOError: [Errno 22] Invalid argument

> Seemingly this is because I_SENDFD/I_RECVFD is not properly implemented 
> on linux 2.4, but maybe I'm doing something wrong.

I'd say it's a fair bet that I_SENDFD is not implemented on Linux,
properly or otherwise.  It looks to me like an AT&T STREAMS function,
as opposed to Berkeley socket.  Casual look around the include files
doesn't suggest any support on Linux for any STREAMS stuff.

As usual, there's a parallel Berkeley way to do this, using as
already mentioned a UNIX domain socket, and sendmsg, and SCM_RIGHTS.

If Python's socketmodule.c doesn't directly support sendmsg and
the attendant data structures, you'll have to add that in C, either
in socketmodule.c or your own module.   That means mainly getting
the msghdr struct together (I think the control object you want
to pass, with SCM_RIGHTS and the fds can be packed up in Python.)

   Donn Cave, donn at

More information about the Python-list mailing list