Passing file descriptors

David M. Cooke cookedm+news at
Fri Jun 11 18:02:08 CEST 2004

At some point, Josiah Carlson <jcarlson at> wrote:

> I'm trying to write the equivalent of what the author calls "ringd"
> described in the below article, and use it with python 2.3.x on linux
> 2.4:
> The script that I provide at the end of this post is a variation of
> one posted in this thread:
> 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().
> Does anyone have an idea of how to get it working on linux?  I would
> prefer to not have to break into C, if only because I don't want to
> accidentally leak memory (once bitten, twice shy they say).  Certainly
> Pyrex and SWIG are options, but first I'd like to try a pure Python
> version.

Have a look at passfd.c in Neil Schemenauer's SCGI protocol implementation:
It wraps sendmsg/recvmsg to send and receive file descriptors.

It's a C module, but's it's very lightweight. I think it does what you
want to do (the is almost exactly like the script you
posted; showing their common ancestors...) It's supposed to work under
Linux, FreeBSD and Solaris.

|David M. Cooke

More information about the Python-list mailing list