[tracker] all: Make GBusType configurable with TRACKER_BUS_TYPE
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] all: Make GBusType configurable with TRACKER_BUS_TYPE
- Date: Mon, 17 Mar 2014 15:38:30 +0000 (UTC)
commit 8765cbb0bf77d3718624a7d12cc8d7daea97da80
Author: Martyn Russell <martyn lanedo com>
Date: Mon Mar 10 11:13:02 2014 +0000
all: Make GBusType configurable with TRACKER_BUS_TYPE
This works by using G_BUS_TYPE_SESSION if the env var TRACKER_BUS_TYPE is not
set and will allow for "system" to be used as a value. If it is set, the
system bus is used instead.
examples/libtracker-sparql/class-signal.c | 4 +++-
src/libtracker-bus/tracker-bus.vala | 2 +-
src/libtracker-common/libtracker-common.vapi | 6 ++++++
src/libtracker-common/tracker-dbus.c | 15 ++++++++++++++-
src/libtracker-common/tracker-dbus.h | 6 ++++++
src/libtracker-control/tracker-miner-manager.c | 4 ++--
src/libtracker-extract/tracker-extract-client.c | 6 ++++--
src/libtracker-miner/tracker-miner-object.c | 18 +++++++++---------
src/libtracker-miner/tracker-thumbnailer.c | 4 ++--
src/libtracker-sparql-backend/tracker-backend.vala | 17 ++++++++++++++++-
src/miners/fs/tracker-main.c | 3 ++-
src/miners/fs/tracker-miner-files-index.c | 2 +-
src/miners/fs/tracker-miner-files.c | 3 ++-
src/miners/fs/tracker-writeback-dispatcher.c | 2 +-
src/miners/fs/tracker-writeback-listener.c | 2 +-
src/miners/rss/tracker-miner-rss.c | 2 +-
src/plugins/evolution/tracker-evolution-plugin.c | 2 +-
src/tracker-control/tracker-control-general.c | 4 ++--
src/tracker-control/tracker-control-status.c | 2 +-
src/tracker-extract/tracker-extract-decorator.c | 2 +-
src/tracker-needle/tracker-stats.vala | 2 +-
src/tracker-store/tracker-dbus.vala | 2 +-
src/tracker-writeback/tracker-writeback.c | 2 +-
23 files changed, 79 insertions(+), 33 deletions(-)
---
diff --git a/examples/libtracker-sparql/class-signal.c b/examples/libtracker-sparql/class-signal.c
index 3ba2ab3..02a8287 100644
--- a/examples/libtracker-sparql/class-signal.c
+++ b/examples/libtracker-sparql/class-signal.c
@@ -19,6 +19,8 @@
#include <gio/gio.h>
+#include <libtracker-common/tracker-common.h>
+
#include <libtracker-sparql/tracker-sparql.h>
static TrackerSparqlConnection *con;
@@ -87,7 +89,7 @@ main (gint argc, gchar *argv[])
loop = g_main_loop_new (NULL, FALSE);
con = tracker_sparql_connection_get (NULL, &error);
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, NULL);
signal_id = g_dbus_connection_signal_subscribe (connection,
TRACKER_DBUS_SERVICE,
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index 17763d1..4a58dd9 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -21,7 +21,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
DBusConnection bus;
public Connection () throws Sparql.Error, IOError, DBusError {
- bus = GLib.Bus.get_sync (BusType.SESSION);
+ bus = GLib.Bus.get_sync (Tracker.IPC.bus ());
// ensure that error domain is registered with GDBus
new Sparql.Error.INTERNAL ("");
diff --git a/src/libtracker-common/libtracker-common.vapi b/src/libtracker-common/libtracker-common.vapi
index 0475fbe..50506e6 100644
--- a/src/libtracker-common/libtracker-common.vapi
+++ b/src/libtracker-common/libtracker-common.vapi
@@ -71,6 +71,12 @@ namespace Tracker {
}
[Compact]
+ [CCode (cheader_filename = "libtracker-common/tracker-common.h")]
+ namespace IPC {
+ public GLib.BusType bus ();
+ }
+
+ [Compact]
[CCode (ref_function = "", unref_function = "", cheader_filename =
"libtracker-common/tracker-common.h")]
public class DBusRequest {
public static DBusRequest begin (string? sender, string format,...);
diff --git a/src/libtracker-common/tracker-dbus.c b/src/libtracker-common/tracker-dbus.c
index 53da8e7..06b4871 100644
--- a/src/libtracker-common/tracker-dbus.c
+++ b/src/libtracker-common/tracker-dbus.c
@@ -63,11 +63,24 @@ static GDBusConnection *connection;
static void client_data_free (gpointer data);
static gboolean client_clean_up_cb (gpointer data);
+inline GBusType
+tracker_ipc_bus (void)
+{
+ const gchar *bus = g_getenv ("TRACKER_BUS_TYPE");
+
+ if (G_UNLIKELY (bus != NULL &&
+ g_ascii_strcasecmp (bus, "system") == 0)) {
+ return G_BUS_TYPE_SYSTEM;
+ }
+
+ return G_BUS_TYPE_SESSION;
+}
+
static gboolean
clients_init (void)
{
GError *error = NULL;
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &error);
if (error) {
g_critical ("Could not connect to the D-Bus session bus, %s",
diff --git a/src/libtracker-common/tracker-dbus.h b/src/libtracker-common/tracker-dbus.h
index e7c479f..6ea5bb8 100644
--- a/src/libtracker-common/tracker-dbus.h
+++ b/src/libtracker-common/tracker-dbus.h
@@ -28,6 +28,9 @@ G_BEGIN_DECLS
#error "only <libtracker-common/tracker-common.h> must be included directly."
#endif
+/* Allow bus type override by env var TRACKER_BUS_TYPE */
+#define TRACKER_IPC_BUS tracker_ipc_bus()
+
#define TRACKER_DBUS_ERROR_DOMAIN "TrackerDBus"
#define TRACKER_DBUS_ERROR tracker_dbus_error_quark()
@@ -63,6 +66,9 @@ typedef enum {
TRACKER_DBUS_ERROR_BROKEN_PIPE
} TrackerDBusError;
+
+GBusType tracker_ipc_bus (void);
+
GQuark tracker_dbus_error_quark (void);
/* Utils */
diff --git a/src/libtracker-control/tracker-miner-manager.c b/src/libtracker-control/tracker-miner-manager.c
index 595c90a..a2b344e 100644
--- a/src/libtracker-control/tracker-miner-manager.c
+++ b/src/libtracker-control/tracker-miner-manager.c
@@ -404,7 +404,7 @@ miner_manager_initable_init (GInitable *initable,
manager = TRACKER_MINER_MANAGER (initable);
priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager);
- priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &inner_error);
+ priv->connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &inner_error);
if (!priv->connection) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -475,7 +475,7 @@ miner_manager_initable_init (GInitable *initable,
g_hash_table_insert (priv->miner_proxies, proxy, g_strdup (data->dbus_name));
- data->watch_name_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
+ data->watch_name_id = g_bus_watch_name (TRACKER_IPC_BUS,
data->dbus_name,
G_BUS_NAME_WATCHER_FLAGS_NONE,
miner_appears,
diff --git a/src/libtracker-extract/tracker-extract-client.c b/src/libtracker-extract/tracker-extract-client.c
index 200fa40..2bcba92 100644
--- a/src/libtracker-extract/tracker-extract-client.c
+++ b/src/libtracker-extract/tracker-extract-client.c
@@ -26,6 +26,8 @@
#include <gio/gunixfdlist.h>
#include <gio/gunixinputstream.h>
+#include <libtracker-common/tracker-dbus.h>
+
#include "tracker-extract-client.h"
/* Size of buffers used when sending data over a pipe, using DBus FD passing */
@@ -494,7 +496,7 @@ tracker_extract_client_get_metadata (GFile *file,
g_return_if_fail (callback != NULL);
if (G_UNLIKELY (!connection)) {
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, cancellable, &error);
+ connection = g_bus_get_sync (TRACKER_IPC_BUS, cancellable, &error);
if (error) {
g_simple_async_report_gerror_in_idle (G_OBJECT (file), callback, user_data, error);
@@ -556,7 +558,7 @@ tracker_extract_client_cancel_for_prefix (GFile *prefix)
if (G_UNLIKELY (!connection)) {
GError *error = NULL;
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &error);
if (error) {
g_warning ("Couldn't get session bus, cannot cancel extractor tasks: '%s'",
error->message);
diff --git a/src/libtracker-miner/tracker-miner-object.c b/src/libtracker-miner/tracker-miner-object.c
index 9b460d4..8889887 100644
--- a/src/libtracker-miner/tracker-miner-object.c
+++ b/src/libtracker-miner/tracker-miner-object.c
@@ -411,7 +411,7 @@ miner_initable_init (GInitable *initable,
}
/* Try to get DBus connection... */
- miner->priv->d_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &inner_error);
+ miner->priv->d_connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &inner_error);
if (!miner->priv->d_connection) {
g_propagate_error (error, inner_error);
return FALSE;
@@ -496,13 +496,13 @@ miner_initable_init (GInitable *initable,
return FALSE;
}
- miner->priv->watch_name_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
- TRACKER_SERVICE,
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- on_tracker_store_appeared,
- on_tracker_store_disappeared,
- miner,
- NULL);
+ miner->priv->watch_name_id = g_bus_watch_name (TRACKER_IPC_BUS,
+ TRACKER_SERVICE,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ on_tracker_store_appeared,
+ on_tracker_store_disappeared,
+ miner,
+ NULL);
return TRUE;
}
@@ -961,7 +961,7 @@ miner_pause_internal (TrackerMiner *miner,
if (calling_name) {
g_message ("Watching process with name:'%s'", calling_name);
- watch_name_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
+ watch_name_id = g_bus_watch_name (TRACKER_IPC_BUS,
calling_name,
G_BUS_NAME_WATCHER_FLAGS_NONE,
NULL,
diff --git a/src/libtracker-miner/tracker-thumbnailer.c b/src/libtracker-miner/tracker-thumbnailer.c
index 58fc76a..2af4d8b 100644
--- a/src/libtracker-miner/tracker-thumbnailer.c
+++ b/src/libtracker-miner/tracker-thumbnailer.c
@@ -142,9 +142,9 @@ tracker_thumbnailer_initable_init (GInitable *initable,
private->request_id = 1;
private->service_is_available = FALSE;
- g_message ("Thumbnailer connections being set up...");
+ g_message ("Thumbnailer connections being set up... (using same bus as Tracker, i.e. session or
system)");
- private->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+ private->connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, error);
if (!private->connection)
return FALSE;
diff --git a/src/libtracker-sparql-backend/tracker-backend.vala
b/src/libtracker-sparql-backend/tracker-backend.vala
index e9a187d..e4e5488 100644
--- a/src/libtracker-sparql-backend/tracker-backend.vala
+++ b/src/libtracker-sparql-backend/tracker-backend.vala
@@ -26,6 +26,7 @@ class Tracker.Sparql.Backend : Connection {
DIRECT,
BUS
}
+ GLib.BusType bus_type = BusType.SESSION;
public Backend () throws Sparql.Error, IOError, DBusError, SpawnError {
try {
@@ -34,7 +35,7 @@ class Tracker.Sparql.Backend : Connection {
// do not use proxy to work around race condition in GDBus
// NB#259760
- var bus = GLib.Bus.get_sync (BusType.SESSION);
+ var bus = GLib.Bus.get_sync (bus_type);
var msg = new DBusMessage.method_call (TRACKER_DBUS_SERVICE,
TRACKER_DBUS_OBJECT_STATUS, TRACKER_DBUS_INTERFACE_STATUS, "Wait");
bus.send_message_with_reply_sync (msg, 0, /* timeout */ int.MAX, null).to_gerror ();
@@ -164,6 +165,20 @@ class Tracker.Sparql.Backend : Connection {
// Plugin loading functions
private void load_plugins () throws GLib.Error {
+ string env_bus_type = Environment.get_variable ("TRACKER_BUS_TYPE");
+
+ if (env_bus_type != null) {
+ if (env_bus_type.ascii_casecmp ("system") == 0) {
+ bus_type = BusType.SYSTEM;
+ debug ("Using bus = 'SYSTEM'");
+ } else if (env_bus_type.ascii_casecmp ("session") == 0) {
+ bus_type = BusType.SESSION;
+ debug ("Using bus = 'SESSION'");
+ } else {
+ warning ("Environment variable TRACKER_BUS_TYPE set to unknown value '%s'",
env_bus_type);
+ }
+ }
+
string env_backend = Environment.get_variable ("TRACKER_SPARQL_BACKEND");
Backend backend = Backend.AUTO;
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 1204044..6c7752c 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -31,6 +31,7 @@
#include <glib-object.h>
#include <glib/gi18n.h>
+#include <libtracker-common/tracker-dbus.h>
#include <libtracker-common/tracker-ioprio.h>
#include <libtracker-common/tracker-log.h>
#include <libtracker-common/tracker-ontologies.h>
@@ -768,7 +769,7 @@ store_is_available (void)
GDBusProxy *proxy;
gchar *name_owner;
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, NULL);
if (!connection) {
return FALSE;
diff --git a/src/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index 7b6a67d..d5239b2 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -453,7 +453,7 @@ tracker_miner_files_index_new (TrackerMinerFiles *miner_files)
priv = TRACKER_MINER_FILES_INDEX_GET_PRIVATE (miner);
- priv->d_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ priv->d_connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &error);
if (!priv->d_connection) {
g_critical ("Could not connect to the D-Bus session bus, %s",
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index c0904cf..48ac103 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -34,6 +34,7 @@
#include <gio/gunixfdlist.h>
#include <gio/gunixinputstream.h>
+#include <libtracker-common/tracker-dbus.h>
#include <libtracker-common/tracker-date-time.h>
#include <libtracker-common/tracker-ontologies.h>
#include <libtracker-common/tracker-type-utils.h>
@@ -313,7 +314,7 @@ miner_files_initable_init (GInitable *initable,
}
/* Set up extractor and signals */
- mf->private->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &inner_error);
+ mf->private->connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &inner_error);
if (!mf->private->connection) {
g_propagate_error (error, inner_error);
g_prefix_error (error,
diff --git a/src/miners/fs/tracker-writeback-dispatcher.c b/src/miners/fs/tracker-writeback-dispatcher.c
index 7f7400d..4d6d54b 100644
--- a/src/miners/fs/tracker-writeback-dispatcher.c
+++ b/src/miners/fs/tracker-writeback-dispatcher.c
@@ -193,7 +193,7 @@ writeback_dispatcher_initable_init (GInitable *initable,
return FALSE;
}
- priv->d_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &internal_error);
+ priv->d_connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
diff --git a/src/miners/fs/tracker-writeback-listener.c b/src/miners/fs/tracker-writeback-listener.c
index 0ccec24..e37ad99 100644
--- a/src/miners/fs/tracker-writeback-listener.c
+++ b/src/miners/fs/tracker-writeback-listener.c
@@ -190,7 +190,7 @@ writeback_listener_initable_init (GInitable *initable,
return FALSE;
}
- priv->d_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &internal_error);
+ priv->d_connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
diff --git a/src/miners/rss/tracker-miner-rss.c b/src/miners/rss/tracker-miner-rss.c
index 089ebf2..6b26131 100644
--- a/src/miners/rss/tracker-miner-rss.c
+++ b/src/miners/rss/tracker-miner-rss.c
@@ -145,7 +145,7 @@ tracker_miner_rss_init (TrackerMinerRSS *object)
priv = TRACKER_MINER_RSS_GET_PRIVATE (object);
- priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ priv->connection = g_bus_get_sync (TRACKER_BUS_TYPE, NULL, &error);
if (!priv->connection) {
g_critical ("Could not connect to the D-Bus session bus, %s",
diff --git a/src/plugins/evolution/tracker-evolution-plugin.c
b/src/plugins/evolution/tracker-evolution-plugin.c
index db93c05..a5b3bee 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.c
+++ b/src/plugins/evolution/tracker-evolution-plugin.c
@@ -2492,7 +2492,7 @@ miner_start_watching (TrackerMiner *miner)
{
TrackerMinerEvolutionPrivate *priv = TRACKER_MINER_EVOLUTION_GET_PRIVATE (miner);
- priv->watch_name_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
+ priv->watch_name_id = g_bus_watch_name (TRACKER_BUS_TYPE,
TRACKER_SERVICE,
G_BUS_NAME_WATCHER_FLAGS_NONE,
on_tracker_store_appeared,
diff --git a/src/tracker-control/tracker-control-general.c b/src/tracker-control/tracker-control-general.c
index 7304c77..5e33cf5 100644
--- a/src/tracker-control/tracker-control-general.c
+++ b/src/tracker-control/tracker-control-general.c
@@ -1262,7 +1262,7 @@ tracker_control_general_run (void)
g_print ("%s\n", _("Backing up database"));
g_print (" %s\n", uri);
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &error);
if (!connection) {
g_critical ("Could not connect to the D-Bus session bus: %s",
@@ -1334,7 +1334,7 @@ tracker_control_general_run (void)
g_print ("%s\n", _("Restoring database from backup"));
g_print (" %s\n", uri);
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &error);
if (!connection) {
g_critical ("Could not connect to the D-Bus session bus: %s",
diff --git a/src/tracker-control/tracker-control-status.c b/src/tracker-control/tracker-control-status.c
index bbf3227..1fa93af 100644
--- a/src/tracker-control/tracker-control-status.c
+++ b/src/tracker-control/tracker-control-status.c
@@ -459,7 +459,7 @@ store_init (void)
return TRUE;
}
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &error);
if (!connection) {
g_critical ("Could not connect to the D-Bus session bus, %s",
diff --git a/src/tracker-extract/tracker-extract-decorator.c b/src/tracker-extract/tracker-extract-decorator.c
index 6891140..9df4aff 100644
--- a/src/tracker-extract/tracker-extract-decorator.c
+++ b/src/tracker-extract/tracker-extract-decorator.c
@@ -556,7 +556,7 @@ tracker_extract_decorator_initable_init (GInitable *initable,
tracker_extract_dbus_priority_set_supported_rdf_types (priv->iface,
supported_classes);
- conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+ conn = g_bus_get_sync (TRACKER_IPC_BUS, NULL, error);
if (conn == NULL) {
ret = FALSE;
goto out;
diff --git a/src/tracker-needle/tracker-stats.vala b/src/tracker-needle/tracker-stats.vala
index ffe930d..dfb07c4 100644
--- a/src/tracker-needle/tracker-stats.vala
+++ b/src/tracker-needle/tracker-stats.vala
@@ -43,7 +43,7 @@ public class Tracker.Stats : Dialog {
debug ("Setting up statistics D-Bus connection");
try {
- tracker = GLib.Bus.get_proxy_sync (BusType.SESSION,
+ tracker = GLib.Bus.get_proxy_sync (Tracker.Bus.type (),
"org.freedesktop.Tracker1",
"/org/freedesktop/Tracker1/Statistics",
DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
DBusProxyFlags.DO_NOT_CONNECT_SIGNALS);
diff --git a/src/tracker-store/tracker-dbus.vala b/src/tracker-store/tracker-dbus.vala
index 96aed5f..bdfae4b 100644
--- a/src/tracker-store/tracker-dbus.vala
+++ b/src/tracker-store/tracker-dbus.vala
@@ -94,7 +94,7 @@ public class Tracker.DBus {
}
try {
- connection = Bus.get_sync (BusType.SESSION);
+ connection = GLib.Bus.get_sync (Tracker.IPC.bus ());
} catch (Error e) {
critical ("Could not connect to the D-Bus session bus, %s", e.message);
return false;
diff --git a/src/tracker-writeback/tracker-writeback.c b/src/tracker-writeback/tracker-writeback.c
index 7435b0f..faf057b 100644
--- a/src/tracker-writeback/tracker-writeback.c
+++ b/src/tracker-writeback/tracker-writeback.c
@@ -728,7 +728,7 @@ tracker_controller_dbus_start (TrackerController *controller,
return FALSE;
}
- priv->d_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &err);
+ priv->d_connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &err);
if (!priv->d_connection) {
g_propagate_error (error, err);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]