Commit Graph

140 Commits

Author SHA1 Message Date
Ryan Lortie
e3c7fdd7a4 GDBus: make use of reliable async cancellation
Call g_simple_async_result_set_check_cancellable() after all
GSimpleAsyncResult creation in order to take advantage of the new
reliable cancellation feature.

The guarantee of reliable cancellation fixes a bug in dbusmenu (which
was already assuming that cancellation was reliable).  See this bug:
https://bugs.launchpad.net/ubuntu/+source/libdbusmenu/+bug/953562

https://bugzilla.gnome.org/show_bug.cgi?id=672013

Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-03-15 14:01:35 -04:00
David Zeuthen
7a4a973cfd GDBusConnection: Don't leak message reply in error path
This was reported in bug 670909.

https://bugzilla.gnome.org/show_bug.cgi?id=670909

Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-02-27 14:53:13 -05:00
David King
8ee2cadd7f docs: Fix some GDBusConnection typos 2012-02-21 01:10:54 +01:00
Will Thompson
7a0bddd768 GDBusConnection: note that exit-on-close is sometimes TRUE
g_bus_get_finish() and g_bus_get_sync() both document that the returned
object will usually have exit-on-close set to TRUE, but the property's
documentation specified that its default is FALSE. While that's
technically true from a GObject perspective, it's not accurate from the
API user's perspective.

https://bugzilla.gnome.org/show_bug.cgi?id=668163

Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <zeuthen@gmail.com>
2012-01-18 16:16:58 +00:00
Simon McVittie
1e09bfc77c GDBusConnection: use GWeakRef to make the singletons thread-safe
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=665211

https://bugzilla.gnome.org/show_bug.cgi?id=548954
2012-01-02 12:23:24 -05:00
David Zeuthen
70dacf83d2 Bug 665733 – GDBusConnection holds lock while calling destroynotify
Fix this problem by always running the destroynotify from an idle.

https://bugzilla.gnome.org/show_bug.cgi?id=665733

Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-12-07 10:30:42 -05:00
Simon McVittie
83d0c8a739 GDBusConnection: propagate error correctly if flags are inappropriate
Previously, this would fail the assertion
"connection->initialization_error != NULL" after the label "out".

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=665067
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-12-05 18:15:19 +00:00
Simon McVittie
c4a11858cf GDBusConnection: don't pass boolean > 1 to _g_dbus_worker_new
This happens to work at the moment (because GDBusWorker.frozen is a
gboolean and not just a 1-bit bitfield), but isn't right: the gboolean
ends up with values 0 or G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING
(which is more than 1).

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=664558
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-11-22 16:08:14 +00:00
Matthias Clasen
6c7387f6d1 Trivial doc typo fix 2011-11-19 16:23:33 -05:00
Simon McVittie
a124562d1b GDBusConnection: document that this object is (meant to be) thread-safe
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-24 10:40:29 +01:00
Simon McVittie
a031bacaac GDBusConnection: make the closed flag atomic (but still lock to write)
Strictly speaking, neither of the two uses that aren't under the lock
*needs* to be atomic, but it seems better to be obviously correct (and
we save another 4 bytes of struct).

One of these uses is in g_dbus_connection_is_closed(), any use of which
is inherently a race condition anyway.

The other is g_dbus_connection_flush_sync, which as far as I can tell
just needs a best-effort check, to not waste effort on a connection that
has been closed for a while (but I could be wrong).

I removed the check for the closed flag altogether in
g_dbus_connection_send_message_with_reply_unlocked, because it turns out
to be redundant with one in g_dbus_connection_send_message_unlocked,
which is called immediately after.

g_dbus_connection_close_sync held the lock to check the closed flag,
which is no longer needed.

As far as I can tell, the only reason why the lock is still desirable
when setting the closed flag is so that remove_match_rule can't fail
by racing with close notification from the worker thread - but
on_worker_closed needs to hold the lock anyway, to deal with other
data structures, so there's no point in trying to eliminate the
requirement to hold the lock.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-24 10:40:26 +01:00
Simon McVittie
9857cf8c46 GDBusConnection: document which properties are protected by @lock
Also, a few that don't need to be.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-24 10:40:23 +01:00
Simon McVittie
8df114f597 GDBusConnection: access the exit-on-close flag atomically
This isn't strictly necessary, because in every location where it's
checked, if the reading thread misses an update from another thread,
it's indistinguishable from the reading thread having been scheduled
before the writing thread, which is an unavoidable race condition that
callers need to cope with anyway. On the other hand, merging exit_on_close
into atomic_flags gives the least astonishing semantics to library users
and saves 4 bytes of struct, and if you're accessing exit-on-close often
enough for it to be a performance concern, you're probably doing it wrong.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-24 10:40:20 +01:00
Simon McVittie
3a0b60647d Annotate GDBusConnection private functions with thread/lock status
The thread shared between all GDBusWorker instances was variously called
the "worker thread" or "message handler thread", which I mostly changed to
"the GDBusWorker thread" to avoid ambiguity.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-24 10:40:06 +01:00
Simon McVittie
848df03e16 GDBusConnection: check for initializedness in most public API
The only exceptions are those of the trivial getters/setters that don't
already need the initialization check for its secondary role as a memory
barrier (this is consistent with GSocket, where trivial getters/setters
don't check):

* g_dbus_connection_set_exit_on_close
* g_dbus_connection_get_exit_on_close
* g_dbus_connection_is_closed

g_dbus_connection_set_exit_on_close needs to be safe for
use before initialization anyway, so it can be set at construct-time.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661689
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-21 16:02:33 +01:00
Simon McVittie
3958a9fc1e GDBusConnection: document use while uninitialized as undefined behaviour
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661689
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=662208
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-21 16:02:31 +01:00
Simon McVittie
a7ea949294 GDBusConnection: check for initialization where needed for thread-safety
Also document which fields require such a check in order to have correct
threading semantics.

This usage doesn't matches the GInitable documentation, which suggests
use of a GError - but using an uninitialized GDBusConnection is
programming error, and not usefully recoverable. (The GInitable
documentation may have been a mistake - GNOME#662208.) Also, not all of
the places where we need it can raise a GError.

The check serves a dual purpose: it turns a non-deterministic crash into
a deterministic critical warning, and is also a memory barrier for
thread-safety. All of these functions dereference or return fields that
are meant to be protected by FLAG_INITIALIZED, so they could crash or
return an undefined value to their caller without this, if called from a
thread that isn't the one that called initable_init() (although I can't
think of any way to do that without encountering a memory barrier,
undefined behaviour, or a race condition that leads to undefined
behaviour if the non-initializing thread wins the race).

One exception is that initable_init() itself makes a synchronous call.
We deal with that by passing new internal flags up the call stack, to
reassure g_dbus_connection_send_message_unlocked() that it can go ahead.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661689
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-21 16:02:27 +01:00
Simon McVittie
245d68be6f GDBusConnection: replace is_initialized with an atomic flag
The comment implied that even failed initialization would set
is_initialized = TRUE, but this wasn't the case - failed initialization
would only set initialization_error, and it was necessary to check both.

It turns out the documented semantics are nicer than the implemented
semantics, since this lets us use atomic operations, which are also
memory barriers, to avoid needing separate memory barriers or locks
for initialization_error (and other members that are read-only after
construction).

I expect to need more than one atomically-accessed flag to fix thread
safety, so instead of a minimal implementation I've turned is_initialized
into a flags word.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661689
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-21 16:02:22 +01:00
Simon McVittie
a7143a0e9f GDBusConnection: warn that direct access to the stream is a bad idea
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661679
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2011-10-15 18:03:19 -04:00
David Zeuthen
3c4d3dec09 GDBusConnection: Make pending calls error when the connection is lost
If the connection to the bus is lost while a method call is ongoing,
the method call does not get cancelled. Instead it just sits around
until it times out.

This is visible here on XO laptops when stopping the display manager
during shutdown. imsettings starts sending a sync message to give up
its bus name (via g_bus_unown_name()), then systemd terminates the
session bus at approximately the same time. imsettings then hangs for
about 20 seconds before timing out the message.

 http://lists.freedesktop.org/archives/dbus/2011-September/014717.html

imsettings behaviour could be improved as described in that thread,
but I think this is a glib bug. I've also come up with the attached
patch which fixes it.

Credits for the bug-fix goes to Daniel Drake <dsd@laptop.org>. The test
case was written by David Zeuthen <zeuthen@gmail.com>.

https://bugzilla.gnome.org/show_bug.cgi?id=660637

Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-10-07 14:23:03 -04:00
Dan Winship
59f1f54655 Add g_main_context_ref_thread_default()
Add g_main_context_ref_thread_default(), which always returns a
reffed GMainContext, rather than sometimes returning a (non-reffed)
GMainContext, and sometimes returning NULL. This simplifies the
bookkeeping in any code that needs to keep a reference to the
thread-default context for a while.

https://bugzilla.gnome.org/show_bug.cgi?id=660994
2011-10-07 10:14:34 -04:00
Ryan Lortie
5f48e2cde5 GDBus: switch to struct-embedded GMutex and GCond
Now that we have those, we should use them.

https://bugzilla.gnome.org/show_bug.cgi?id=660739
2011-10-04 11:13:46 -04:00
Simon McVittie
8097e2de85 GDBusConnection: delegate to the worker to close the stream
We can't safely close the output part of the I/O stream until any
pending write or flush has been completed. In the worst case, this could
lead to an assertion failure in the worker (when the close wins the
race) or not closing the stream at all (when the write wins the race).

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=651268
Bug-NB: NB#271520
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-09-16 12:00:22 -04:00
Matthias Clasen
1b28408b8b Spelling fixes
Spelling fixes in comments and docs, provided by
Kjartan Maraas in bug 657336.
2011-08-29 14:49:32 -04:00
Brian Cameron
b5f1ea4bb1 void functions should not return. Fixes bug #656675. 2011-08-17 03:01:14 -05:00
Martin Pitt
c783bfd4e7 [gi] Add missing (allow-none) annotations to g_dbus_connection_register_object() 2011-08-09 14:52:53 +02:00
David Zeuthen
659ba3d0b3 GDBusConnection: Only apply exit-on-closed semantics if properly initialized
Otherwise there is no point in gracefully handling the error...

https://bugzilla.gnome.org/show_bug.cgi?id=655664

Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-08-01 11:58:05 -04:00
David Zeuthen
32b1349a23 More fixes for non-Unix builds
Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-07-25 10:31:17 -04:00
David Zeuthen
f8b98841ad Fix the build on non-Unix
https://bugzilla.gnome.org/show_bug.cgi?id=655148

Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-07-25 09:56:01 -04:00
Matthias Clasen
1f9e84896b Fix a typo 2011-07-23 21:07:48 -04:00
David Zeuthen
c404dbed11 gdbus-codegen: Add support for new org.gtk.GDBus.C.UnixFD annotation
Also add convenience _with_unix_fd_list variants to GDBusConnection,
GDBusProxy and GDBusMethodInvocation types to easily support this.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-07-21 16:06:18 -04:00
Johan Dahlin
ec98953e42 Pass in NULL instead of g_cclosure_marshal_generic
NULL is now a shortcut for g_cclosure_marshal_generic, so avoid
referencing it directly.

https://bugzilla.gnome.org/show_bug.cgi?id=654917
2011-07-19 14:38:34 -03:00
Ryan Lortie
58c247e51b GVariant: add g_variant_take_ref()
This function implements the following logic:

  if (g_variant_is_floating (value))
    g_variant_ref_sink (value);

which is used for consuming the return value of callbacks that may or
may not return floating references.

This patch also replaces a few instances of the above code with the new
function (GSettings, GDBus) and lifts a long-standing restriction on the
use of floating values as the return value for signal handlers by
improving g_value_take_variant().

https://bugzilla.gnome.org/show_bug.cgi?id=627974
2011-07-12 19:44:21 +02:00
Colin Walters
b74e2a720a Stop using glib-genmarshal at build time
To help cross compilation, don't use glib-genmarshal in our
build.  This is easy now that we have g_cclosure_marshal_generic().

In gobject/, add gmarshal.[ch] to git (making the existing entry
points stubs).

In gio/, simply switch to using g_cclosure_marshal_generic().

https://bugzilla.gnome.org/show_bug.cgi?id=652168
2011-06-20 17:24:07 -04:00
Matthias Clasen
339cac8fc7 Remove unneeded NULL check
We ensure 10 lines up that parameters is not NULL.
2011-06-14 09:53:26 -04:00
Matthias Clasen
01f63b19f9 Fix links in gio docs 2011-06-04 18:48:19 -04:00
David Zeuthen
b9e3e03767 GDBusConnection: Document that sockets are frobbed into non-blocking mode
Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-05-12 15:36:34 -04:00
Martin Pitt
21c2291496 [gi] Add missing allow-none annotations to GDBusConnection 2011-05-08 23:07:40 +02:00
Matthias Clasen
122a53a9bc Fix up some harmless FALSE <> NULL confusions
Reported in bug 643134.
2011-04-26 22:51:54 -04:00
Colin Walters
68b16deb1f gdbusconnection: Avoid tripping assertion if we fail to authenticate twice
If g_bus_get_sync() fails in authentication (because e.g. the process
uid, doesn't match the expected in EXTERNAL), a secondary call to
g_bus_get_sync() would notice we aren't initialized, and try
to initialize.

The assertion here is just wrong; we now explicitly and clearly handle
both cases where we already have an error, or we already succeeded.

https://bugzilla.gnome.org/show_bug.cgi?id=635694
2011-04-13 15:01:28 -04:00
David Zeuthen
0729260141 Silence a bunch of -Wunused-but-set-variable warnings
Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-04-08 15:44:25 -04:00
Matthias Clasen
a2e3a4d150 Add a warning to the g_dbus_connection_set_exit_on_close docs
Tell people to not leak their apps out of the session.
2011-04-07 17:15:41 -04:00
David Zeuthen
91f97ebbaa GDBusConnection: Make interface lookups O(1)
Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-03-28 11:39:22 -04:00
Matthias Clasen
5df049706f Don't report standard interfaces more than once
If they have a custom implementation, don't add the canned
introspection XML, just rely on the generated XML. Fixes
https://bugzilla.gnome.org/show_bug.cgi?id=642042
2011-02-15 19:50:55 -05:00
Peng Huang
735fcf918e Bug 632544 – Cannot send a locked message with PRESERVE_SERIAL flag
https://bugzilla.gnome.org/show_bug.cgi?id=632544

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-12-13 13:09:38 -05:00
Ryan Lortie
71088701af Add G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE
If specified, the signal subscription is setup client-side but the match
rule is not sent to the server.  This allows the caller to manually
register more detailed match rules.
2010-11-06 17:35:10 -04:00
Christian Persch
9e0c07870a Use g_simple_async_result_{new_,}take_error
Bug #633685.
2010-11-03 14:25:35 +01:00
Ryan Lortie
fac2a8278e Bug 633356 - (GDBus) Make G_MAXINT mean no timeout
Don't register a timeout function in the case that G_MAXINT is given for
the timeout length.
2010-10-28 16:47:13 -04:00
Johan Dahlin
30132c44c1 Add a lot of missing annotations 2010-09-24 18:24:41 -03:00
David Zeuthen
4d9ae95ae0 GDBus: Don't use abstract sockets in test code
It doesn't really work right now because of a dbus-daemon(1) bug - see
the comment added in the TODO section of gdbusconnection.c. So revert
to old behavior. The downside is a lot of files in /tmp but right now
that's better than not being able to run tests in a loop.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-09-23 19:16:25 -04:00