moving file descriptor passing into a header

Ryan Lortie desrt at desrt.ca
Tue Apr 13 15:01:12 PDT 2010


On Tue, 2010-04-13 at 23:50 +0200, Thiago Macieira wrote:
> Em Terça-feira 13. Abril 2010, às 23.27.25, Colin Walters escreveu:
> > We were discussing some DBus related stuff at this GSettings hackfest,
> > and related to the GVariant/GBus work, we were thinking it'd be good
> > to take the file descriptor bits out of the type system, and move them
> > into a message header.  This makes things significantly saner for
> > GVariant and anyone else reimplementing the protocol.
> > 
> > The API would be something like:
> > 
> > int dbus_message_get_unix_file_descriptor (DBusMessage *message, int
> > index); int dbus_message_append_unix_file_descriptor (DBusMessage
> > *message, int fd);
> 
> How would this work?
> 
> The data payload would contain the indices, right? So when you are 
> demarshalling from the stream, you get ints that are the indices. Then you'd 
> call the header API to get the actual FD?

Yes.  Exactly.  Probably we'd want some file descriptor duping going on
here when you get the fd from the header (unless we have a 'steal' call
as well).

> And when marshalling, you'd insert into the header, then you'd marshall the 
> index?

Yes.  Probably also we dup() your copy of the fd unless we have some
_give_fd() call.

> I'm sorry, but how is this indirection any better than the current code? By 
> adding this indirection, it also means that file descriptors are no longer 
> basic types -- you need to take extra action to copy the type from one message 
> to another (i.e., "trans-marshalling").

File descriptors really are not basic types.

If we are copying a DBusMessage as a whole, we can still copy the header
field (pretty much exactly as it is done now, in fact).

Since you mention it though, another problem is if you try to do
dbus_message_marshal() followed by dbus_message_demarshal() as a way to
copy a message.  Up to this point, this copies the entire payload of the
message without fail.  Now, if you try to do this with file descriptors
in the message you will end up with an inconsistent result.

If by "trans-marshalling" you mean iterating over the structure of a
DBusMessage and copying it into a new DBusMessage then you can still
copy file descriptors manually.  If you want to be able to do this over
the structure of an arbitrary message with an unknown type then you can
still do it -- and just copy the entire file descriptor header between
DBusMessages.  We could probably add a call to make this easier if you
have a concrete use case for it.

David raised another interesting point:  putting file descriptors into
the header has the advantage of not requiring you to explicit mention
them somewhere in the body.  ie: no need to essentially send the indexes
(0, 1, 2) in the message if you know that a particular function call
will always be returning 3 fds -- just use them directly.


Cheers



More information about the dbus mailing list