Passing file descriptors

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


At some point, Josiah Carlson <jcarlson at uci.edu> 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:
> http://www.remote.org/jochen/work/pub/zero-downtime.pdf
>
> The script that I provide at the end of this post is a variation of
> one posted in this thread:
> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=7t5i40%241pn%241%40nyheter.chalmers.se&rnum=8
[...]
> 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:
http://www.mems-exchange.org/software/scgi/
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 test_passfd.py 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
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list