summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/dbus.c25
-rw-r--r--common/dbus.h2
-rw-r--r--hcid/dbus-common.c20
-rw-r--r--input/input-service.c2
4 files changed, 23 insertions, 26 deletions
diff --git a/common/dbus.c b/common/dbus.c
index 5ef1725e..c8ed07e4 100644
--- a/common/dbus.c
+++ b/common/dbus.c
@@ -483,19 +483,18 @@ static void dispatch_status_cb(DBusConnection *conn,
g_timeout_add(DISPATCH_TIMEOUT, message_dispatch_cb, data);
}
-DBusConnection *init_dbus(void (*disconnect_cb)(void *), void *user_data)
+DBusConnection *init_dbus(const char *name, void (*disconnect_cb)(void *), void *user_data)
{
+ struct disconnect_data *dc_data;
DBusConnection *conn;
DBusError err;
- struct disconnect_data *dc_data;
dbus_error_init(&err);
conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
if (dbus_error_is_set(&err)) {
- error("Can't open system message bus connection: %s",
- err.message);
+ error("Can't connect to system message bus: %s", err.message);
dbus_error_free(&err);
return NULL;
}
@@ -507,7 +506,23 @@ DBusConnection *init_dbus(void (*disconnect_cb)(void *), void *user_data)
timeout_toggled, conn, NULL);
dbus_connection_set_dispatch_status_function(conn, dispatch_status_cb,
- conn, NULL);
+ conn, NULL);
+
+ if (name) {
+ dbus_error_init(&err);
+
+ if (dbus_bus_request_name(conn, name, 0, &err) !=
+ DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER ) {
+ error("Could not become the primary owner of %s.", name);
+ return NULL;
+ }
+
+ if (dbus_error_is_set(&err)) {
+ error("Can't get bus name %s: %s", name, err.message);
+ dbus_error_free(&err);
+ return NULL;
+ }
+ }
if (!disconnect_cb)
return conn;
diff --git a/common/dbus.h b/common/dbus.h
index 59afd6e6..39d3cd88 100644
--- a/common/dbus.h
+++ b/common/dbus.h
@@ -26,7 +26,7 @@
#include <dbus/dbus.h>
-DBusConnection *init_dbus(void (*disconnect_cb)(void *), void *user_data);
+DBusConnection *init_dbus(const char *name, void (*disconnect_cb)(void *), void *user_data);
typedef void (*name_cb_t)(const char *name, void *user_data);
diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c
index c25156af..b6313f7b 100644
--- a/hcid/dbus-common.c
+++ b/hcid/dbus-common.c
@@ -351,30 +351,12 @@ done:
int hcid_dbus_init(void)
{
- DBusError err;
DBusConnection *conn;
- int ret_val;
- conn = init_dbus(disconnect_callback, NULL);
+ conn = init_dbus(BLUEZ_NAME, disconnect_callback, NULL);
if (!conn)
return -1;
- dbus_error_init(&err);
-
- ret_val = dbus_bus_request_name(conn, BLUEZ_NAME, 0, &err);
-
- if (ret_val != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER ) {
- error("Could not become the primary owner of %s.", BLUEZ_NAME);
- return -1;
- }
-
- if (dbus_error_is_set(&err)) {
- error("Can't get system bus name %s: %s", BLUEZ_NAME,
- err.message);
- dbus_error_free(&err);
- return -1;
- }
-
if (!dbus_connection_register_fallback(conn, BASE_PATH,
&manager_vtable, NULL)) {
error("D-Bus failed to register %s fallback", BASE_PATH);
diff --git a/input/input-service.c b/input/input-service.c
index b036bf70..14bce1c3 100644
--- a/input/input-service.c
+++ b/input/input-service.c
@@ -127,7 +127,7 @@ int input_dbus_init(void)
const char *description = "A service for input devices";
const char *input_path = INPUT_PATH;
- connection = init_dbus(NULL, NULL);
+ connection = init_dbus(NULL, NULL, NULL);
if (!connection)
return -1;