summaryrefslogtreecommitdiff
path: root/egg
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2014-03-06 16:11:12 +0100
committerStef Walter <stefw@gnome.org>2014-03-06 18:40:12 +0100
commit636113849f970af6819ef599d207419c4881f8fb (patch)
tree669d50dcd89dc811df9e802c1edb5699137b6c7b /egg
parent3debf372273293ebb247a00a4e70c5ab7a399c13 (diff)
downloadgnome-keyring-636113849f970af6819ef599d207419c4881f8fb.tar.gz
daemon: Exit gnome-keyring-daemon when the DBus connection closes
We don't do this via the standard mechanism, as it means that libdbus just calls _exit() (not even exit()) when the connection goes away. This can lead to inconsistent state. Shutdown should be orderly. https://bugzilla.gnome.org/show_bug.cgi?id=708765
Diffstat (limited to 'egg')
-rw-r--r--egg/egg-dbus.c21
-rw-r--r--egg/egg-dbus.h4
2 files changed, 20 insertions, 5 deletions
diff --git a/egg/egg-dbus.c b/egg/egg-dbus.c
index dca34251..b3bfa9e8 100644
--- a/egg/egg-dbus.c
+++ b/egg/egg-dbus.c
@@ -37,13 +37,21 @@
typedef struct {
GSource source; /* the parent GSource */
DBusConnection *connection; /* the connection to dispatch */
+ GDestroyNotify closed_cb; /* Callback when closed */
} DBusGMessageQueue;
static gboolean
message_queue_prepare (GSource *source, gint *timeout)
{
- DBusConnection *connection = ((DBusGMessageQueue *)source)->connection;
+ DBusGMessageQueue *queue = ((DBusGMessageQueue *)source);
+ DBusConnection *connection = queue->connection;
*timeout = -1;
+ if (queue->closed_cb) {
+ if (!dbus_connection_get_is_connected (connection)) {
+ (queue->closed_cb) (connection);
+ queue->closed_cb = NULL;
+ }
+ }
return (dbus_connection_get_dispatch_status (connection) == DBUS_DISPATCH_DATA_REMAINS);
}
@@ -95,7 +103,9 @@ typedef struct {
} TimeoutHandler;
static ConnectionSetup*
-connection_setup_new (GMainContext *context, DBusConnection *connection)
+connection_setup_new (GMainContext *context,
+ DBusConnection *connection,
+ GDestroyNotify closed_cb)
{
ConnectionSetup *cs = g_new0 (ConnectionSetup, 1);
g_assert (context != NULL);
@@ -108,6 +118,7 @@ connection_setup_new (GMainContext *context, DBusConnection *connection)
cs->message_queue_source = g_source_new ((GSourceFuncs *) &message_queue_funcs,
sizeof (DBusGMessageQueue));
((DBusGMessageQueue*)cs->message_queue_source)->connection = connection;
+ ((DBusGMessageQueue*)cs->message_queue_source)->closed_cb = closed_cb;
g_source_attach (cs->message_queue_source, cs->context);
}
@@ -368,13 +379,15 @@ wakeup_main (void *data)
}
void
-egg_dbus_connect_with_mainloop (DBusConnection *connection, GMainContext *context)
+egg_dbus_connect_with_mainloop (DBusConnection *connection,
+ GMainContext *context,
+ GDestroyNotify close_callback)
{
ConnectionSetup *cs;
if (context == NULL)
context = g_main_context_default ();
- cs = connection_setup_new (context, connection);
+ cs = connection_setup_new (context, connection, close_callback);
the_setup = cs;
if (!dbus_connection_set_watch_functions (connection, add_watch,
diff --git a/egg/egg-dbus.h b/egg/egg-dbus.h
index 81dc2e94..91b7ab3f 100644
--- a/egg/egg-dbus.h
+++ b/egg/egg-dbus.h
@@ -27,7 +27,9 @@
#include <glib.h>
#include <dbus/dbus.h>
-void egg_dbus_connect_with_mainloop (DBusConnection *connection, GMainContext *context);
+void egg_dbus_connect_with_mainloop (DBusConnection *connection,
+ GMainContext *context,
+ GDestroyNotify close_callback);
void egg_dbus_disconnect_from_mainloop (DBusConnection *connection, GMainContext *context);