[tracker/gdbus-fix: 3/4] miner-fs: Handle errors when requesting bus names
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/gdbus-fix: 3/4] miner-fs: Handle errors when requesting bus names
- Date: Tue, 25 Jan 2011 12:34:41 +0000 (UTC)
commit d0cd85ef4d23ca66e6dc9ff8be23ef2ee4bf3917
Author: Jürg Billeter <j bitron ch>
Date: Tue Jan 25 12:59:40 2011 +0100
miner-fs: Handle errors when requesting bus names
src/miners/fs/tracker-miner-files-index.c | 41 ++++++++++++++++++++++-------
1 files changed, 31 insertions(+), 10 deletions(-)
---
diff --git a/src/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index 59cd491..d2c7cc5 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -58,7 +58,6 @@ typedef struct {
GDBusConnection *d_connection;
GDBusNodeInfo *introspection_data;
guint registration_id;
- guint own_id;
gchar *full_name;
gchar *full_path;
} TrackerMinerFilesIndexPrivate;
@@ -150,10 +149,6 @@ index_finalize (GObject *object)
{
TrackerMinerFilesIndexPrivate *priv = TRACKER_MINER_FILES_INDEX_GET_PRIVATE (object);
- if (priv->own_id != 0) {
- g_bus_unown_name (priv->own_id);
- }
-
if (priv->registration_id != 0) {
g_dbus_connection_unregister_object (priv->d_connection,
priv->registration_id);
@@ -524,6 +519,8 @@ tracker_miner_files_index_new (TrackerMinerFiles *miner_files)
GObject *miner;
TrackerMinerFilesIndexPrivate *priv;
gchar *full_path, *full_name;
+ GVariant *reply;
+ guint32 rval;
GError *error = NULL;
GDBusInterfaceVTable interface_vtable = {
handle_method_call,
@@ -550,11 +547,6 @@ tracker_miner_files_index_new (TrackerMinerFiles *miner_files)
priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
full_name = g_strconcat (TRACKER_MINER_DBUS_NAME_PREFIX, "Files.Index", NULL);
-
- priv->own_id = g_bus_own_name_on_connection (priv->d_connection,
- full_name,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL, NULL, NULL, NULL);
priv->full_name = full_name;
/* Register the service name for the miner */
@@ -582,6 +574,35 @@ tracker_miner_files_index_new (TrackerMinerFiles *miner_files)
return NULL;
}
+ reply = g_dbus_connection_call_sync (priv->d_connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "RequestName",
+ g_variant_new ("(su)", full_name, 0x4 /* DBUS_NAME_FLAG_DO_NOT_QUEUE */),
+ G_VARIANT_TYPE ("(u)"),
+ 0, -1, NULL, &error);
+
+ if (error) {
+ g_critical ("Could not acquire name:'%s', %s",
+ full_name,
+ error->message);
+ g_clear_error (&error);
+ g_object_unref (miner);
+ return NULL;
+ }
+
+ g_variant_get (reply, "(u)", &rval);
+ g_variant_unref (reply);
+
+ if (rval != 1 /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */) {
+ g_critical ("D-Bus service name:'%s' is already taken, "
+ "perhaps the daemon is already running?",
+ full_name);
+ g_object_unref (miner);
+ return NULL;
+ }
+
priv->full_path = full_path;
return (TrackerMinerFilesIndex *) miner;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]