GNOME Bugzilla – Bug 784392
GDBus can't own names with DO_NOT_QUEUE flag
Last modified: 2018-05-24 19:39:47 UTC
g_bus_own_name() and related functions cannot specify the DO_NOT_QUEUE flag, which means that a GDBus service cannot atomically carry out "take the name if there is no other owner" without resorting to direct method calls. The closest it can get is this pseudocode: result = RequestName(name) if result == IN_QUEUE: ReleaseName(name) result = EXISTS return result which could result in returning EXISTS but briefly owning the name (if we are reported to be in the queue, then the primary owner drops it and we get it moments before we call ReleaseName).
Created attachment 354741 [details] [review] GBusNameOwnerFlags: Note equivalence with D-Bus Specification The implementation passes flags through directly to the RequestName() call, so if any new values break that equivalence, the implementation will have to be changed.
Created attachment 354742 [details] [review] [untested] GBusNameOwnerFlags: Add DO_NOT_QUEUE flag PulseAudio and LibreOffice are among the services that use this flag. Refusing to queue for a name lets you do this transaction, but atomically, avoiding the transient state where you briefly join the queue and then are given the name when its primary owner drops it: result = RequestName(name) if result == IN_QUEUE: ReleaseName(name) result = EXISTS return result
Created attachment 354743 [details] [review] [untested] gdbus: Don't AddMatch() for NameAcquired, NameLost The dbus-daemon delivers these as unicast signals directed to the unique name of the would-be name owner, whether it has added a match rule or not. --- Something I noticed while looking at the patches above.
Created attachment 354744 [details] [review] [untested] gdbus: Check signature of NameAcquired, NameLost Calling g_variant_get (parameters, "(&s)") when parameters has a signature other than (s) is considered to be a programming error. In practice the message bus (dbus-daemon or a reimplementation) should always send the expected type, but be defensive. --- Another thing I noticed while looking at this. Sorry for the untested patches, but I'm shaving too many unrelated yaks right now to test these, and it seemed better to attach something than to attach nothing.
Review of attachment 354741 [details] [review]: ++
Review of attachment 354742 [details] [review]: Needs to be added to the documentation comment just above the enum, including a ‘(Since: 2.54)’ at the end of the new docs line.
Review of attachment 354743 [details] [review]: Are all bus implementations guaranteed to send these signals as unicast? The spec is not abundantly clear about that, unless “This signal is sent to a specific application when it loses ownership of a name” definitely means ‘unicast and only unicast’. I’m happy with this patch if you’re happy that any bus implementation which doesn’t send those signals as unicast is wrong.
Review of attachment 354744 [details] [review]: Good catch. ::: gio/gdbusnameowning.c @@ +274,3 @@ goto out; + if (g_strcmp0 (g_variant_get_type_string (parameters), "(s)") != 0) Would be better to do this as: if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(s)")))
I’ve updated and pushed all of these patches except the AddMatch() one, which I’d still like the question answered for.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/1277.