Re: GVariant support for Unix fds (Was Re: GDBus/GVariant plans for next GLib release)

On Mon, 2009-11-09 at 08:21 -0500, David Zeuthen wrote:
> Sorry for the lag,

No problems :)

> Hmm, I don't like this approach. It means you'd have to pass this
> GDBusFDSet object around in code you use to build/parse the GVariant. In
> particular, your proposed GTypeSerializer would need support for it.
> That's problematic because that one lives in libgobject, not libgio
> (where GDBusFDSet would live).

I disagree.  I'd actually like to keep support for file descriptors out
of the type serialiser entirely.  It's just a little bit "too magic" for
my tastes.

A file descriptor is not normally considered to be a serialisable

> I still think the approach I described works better.
> For example, suppose I have a C type mapping that maps a{sh} to a
> GHashTable from strings to gint. I'd like to write code like this
>  my_hash = g_hash_table_new (g_str_hash, g_str_equal);
>  g_hash_table_insert (my_hash,
>                       "fd-for-client",
>                       GINT_TO_POINTER (fd_for_client));
>  /* need to keep fd_for_client alive until we hand off the hash */

This, for example, is *way* too magic.  I can't ever think of a case
where I store fds in hash tables, much less want to send a hash table
full of fds over DBus.

>    {
>      fd_for_stream1 = dup (fd);
>    }
>  /* the value destroy notifier on my_hash closes all fds */
>  g_hash_table_unref (my_hash);

I agree with the general idea of file descriptor ownership you expose
here.  Does that imply that if you send a single file descriptor over
DBus to a handler function that takes an 'int' then you'll have to
close() the fd in the same way as you're responsible to free the hash

> Thoughts?

In general, I think that sending file descriptors over DBus is done
sufficiently rarely that it is not worth it to have support for it *this
deeply* integrated.  In particular, I think that it's definitely not
appropriate to support it in the GTypeSerialiser code.

I also can never imagine a (non-hypothetical) case of wanting to send an
entire hash table of file descriptors over DBus.  Even if I could
imagine one, it would be highly specialised, and I wouldn't mind writing
the code to do it myself -- and it wouldn't be hard to do.

One reason that I particularly like the GDBusFdSet approach is that, on
receive, it allows the user to give a NULL pointer for the out
parameter.  In that case, the file descriptors received from the bus
will be automatically closed and the user needn't worry about doing
anything at all (ie: no fd leaks).

I appreciate that doing the GDBusFdSet thing results in some
uglification of the GDBus API (ie: addition of a new type and some new
functions call variants in some places) but I think this is the
reasonable thing to do.  fd-passing is *very* DBus-specific.  Please
remember that GVariant and GTypeSerialiser are general purpose datatypes
with many potential uses (eg: dconf, GSettings, mmap files, etc) and
that for these other uses, serialising a file descriptor makes no sense
at all.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]