Question about implementation of Unix FD passing

Georg Reinke guelfey at
Sun Feb 10 05:34:38 PST 2013

Hello everyone,

I recently got into the Go programming language[1]. About a month ago, I
searched if there are any Go bindings for DBus because I needed it for a
little project of mine, and as I didn't find an actively maintained
project, I started it on my own. I figured that writing a native
implementation would be the better choice compared to wrapping libdbus
because while linking to C code in Go is possible, it's not really nice
and I thought it would be a good way to improve my knowing of the

I got along quite well by following the spec. The package is available
on GitHub[2], and although I haven't announced it anywhere yet and don't
want to call it "stable", it's usable and already has some nice features.

Next, I looked into Unix FD passing, which is the only thing from the
message protocol which I haven't implemented yet. After reading the
spec, I was stumped because if I understand everything correctly, the
following problem appears:

The file descriptors are transferred out-of-band. They can be sent at
any point in the message. This means that they are possibly sent before
the UNIX_FDS header is transferred. So, the implementation is required
to read data that it doesn't always know the size of. (I didn't look
into the source code, but using strace I found out that dbus-daemon
sends the whole message and the file descriptors with one call to
sendmsg, so this is actually the case here.)

However, because of the special semantics of out-of-band data on Unix
sockets, one has to read all data in one operation as remaining data is
discarded. That means that the buffer for the out-of-band data must big
enough to hold the greatest number of file descriptors that can be
possibly transferred, which is 2^32 (according to the spec), in order
to guarantee that no data is discarded.

While the actual size probably is much lower because of some kernel
limit, this behaviour still seems odd to me. So my question is: Is this
intended or have I misunderstood anything or made wrong assumptions



More information about the dbus mailing list