From 673523d21eaf5cefc162d93686a8203160bc23e5 Mon Sep 17 00:00:00 2001 From: Radoslaw Pajak Date: Fri, 6 Sep 2013 08:59:16 +0200 Subject: [PATCH] [daemon-dev][lib-fix] Daemon with kdbus early development - dbus-daemon with kdbus development continues - fix in library for sending messages locally generated during kdbus reading/decoding Change-Id: I8a13b1b820d44be69f4a03228a8a2c97493e7c6d --- bus/bus.c | 24 +++++++++++++++++++++--- bus/kdbus-d.c | 27 ++++++++++++++++++--------- bus/kdbus-d.h | 7 ++++--- dbus/dbus-bus.c | 9 +++++++-- dbus/dbus-bus.h | 3 +++ dbus/dbus-server.c | 23 +++++++++++++++++++++++ dbus/dbus-server.h | 2 ++ dbus/dbus-transport-kdbus.c | 2 +- 8 files changed, 79 insertions(+), 18 deletions(-) diff --git a/bus/bus.c b/bus/bus.c index dd9072a..572beff 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -39,7 +39,8 @@ #include #include #include -#include +#include "kdbus-d.h" +#include #ifdef DBUS_CYGWIN #include @@ -429,6 +430,8 @@ process_config_first_time_only (BusContext *context, if(!strcmp(_dbus_string_get_const_data(address), "kdbus")) { DBusBusType type; + DBusServer* server; + char* bus_address; context->is_kdbus = TRUE; @@ -439,12 +442,27 @@ process_config_first_time_only (BusContext *context, else type = DBUS_BUS_STARTER; - if(!make_kdbus_bus(type, error)) + bus_address = make_kdbus_bus(type, error); + if(bus_address == NULL) goto failed; - context->myConnection = daemon_as_client(type, error); + server = fake_server(bus_address); + if(server == NULL) + { + free(bus_address); + goto failed; + } + + if (!_dbus_list_append (&context->servers, server)) + { + free(bus_address); + goto oom; + } + + context->myConnection = daemon_as_client(type, bus_address, error); if(context->myConnection == NULL) goto failed; + } else { diff --git a/bus/kdbus-d.c b/bus/kdbus-d.c index 033eb2b..229d9ae 100644 --- a/bus/kdbus-d.c +++ b/bus/kdbus-d.c @@ -8,9 +8,10 @@ * */ -#include +#include "kdbus-d.h" #include #include +#include #include #include @@ -68,10 +69,17 @@ char* make_kdbus_bus(DBusBusType type, DBusError *error) return bus; } -DBusConnection* daemon_as_client(DBusBusType type, DBusError *error) +DBusServer* fake_server(char* address) +{ + return dbus_server_init_mini(address); +} + +DBusConnection* daemon_as_client(DBusBusType type, char* address, DBusError *error) { DBusConnection* connection; + dbus_bus_set_bus_connection_address(type, address); + connection = dbus_bus_get(type, error); if(connection == NULL) return NULL; @@ -82,13 +90,14 @@ DBusConnection* daemon_as_client(DBusBusType type, DBusError *error) dbus_bus_add_match(connection, "type='signal', member='NameAcquired'", error); dbus_bus_add_match(connection, "type='signal', member='NameLost'", error); if(dbus_error_is_set(error)) - goto failed; + { +failed: + _dbus_connection_close_possibly_shared (connection); + dbus_connection_unref (connection); + connection = NULL; + } + else + _dbus_verbose ("Daemon connected as kdbus client.\n"); return connection; - -failed: - _dbus_connection_close_possibly_shared (connection); - dbus_connection_unref (connection); - connection = NULL; - return NULL; } diff --git a/bus/kdbus-d.h b/bus/kdbus-d.h index 63331e8..f386b0b 100644 --- a/bus/kdbus-d.h +++ b/bus/kdbus-d.h @@ -13,11 +13,12 @@ #include -#include - +#include "bus.h" +#include char* make_kdbus_bus(DBusBusType type, DBusError *error); -DBusConnection* daemon_as_client(DBusBusType type, DBusError *error); +DBusServer* fake_server(char* address); +DBusConnection* daemon_as_client(DBusBusType type, char* address, DBusError *error); #endif /* KDBUS_H_ */ diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c index ed2b3a0..8fc60a7 100644 --- a/dbus/dbus-bus.c +++ b/dbus/dbus-bus.c @@ -139,6 +139,13 @@ get_from_env (char **connection_p, } } +void dbus_bus_set_bus_connection_address(DBusBusType address_type, char* address) +{ + if(bus_connection_addresses[address_type] != NULL) + free(bus_connection_addresses[address_type]); + bus_connection_addresses[address_type] = address; +} + static dbus_bool_t init_session_address (void) { @@ -490,8 +497,6 @@ internal_bus_get (DBusBusType type, goto out; } - _dbus_verbose (" !!! dbus_connection_open finished successfully !!!! \n"); //todo RP to be removed - if (!dbus_bus_register (connection, error)) { _dbus_connection_close_possibly_shared (connection); diff --git a/dbus/dbus-bus.h b/dbus/dbus-bus.h index 9e5a412..35ab21d 100644 --- a/dbus/dbus-bus.h +++ b/dbus/dbus-bus.h @@ -38,6 +38,9 @@ DBUS_BEGIN_DECLS */ DBUS_EXPORT +void dbus_bus_set_bus_connection_address(DBusBusType address_type, char* address); + +DBUS_EXPORT DBusConnection *dbus_bus_get (DBusBusType type, DBusError *error); DBUS_EXPORT diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c index 19d8590..a607605 100644 --- a/dbus/dbus-server.c +++ b/dbus/dbus-server.c @@ -183,6 +183,29 @@ _dbus_server_init_base (DBusServer *server, return FALSE; } +DBusServer* +dbus_server_init_mini (char* address) +{ + DBusServer *server; + + server = dbus_new0(struct DBusServer, 1); + if(server == NULL) + return NULL; + + memset(server, 0, sizeof(struct DBusServer)); + _dbus_rmutex_new_at_location (&server->mutex); + if (server->mutex == NULL) + goto failed; + server->address = address; + + return server; + +failed: + dbus_free(server); + return NULL; +} + + /** * Finalizes the members of the DBusServer base class. * Chained up to by subclass finalizers. diff --git a/dbus/dbus-server.h b/dbus/dbus-server.h index bdbefa0..8c81495 100644 --- a/dbus/dbus-server.h +++ b/dbus/dbus-server.h @@ -47,6 +47,8 @@ typedef struct DBusServer DBusServer; typedef void (* DBusNewConnectionFunction) (DBusServer *server, DBusConnection *new_connection, void *data); +DBUS_EXPORT +DBusServer* dbus_server_init_mini (char* address); DBUS_EXPORT DBusServer* dbus_server_listen (const char *address, diff --git a/dbus/dbus-transport-kdbus.c b/dbus/dbus-transport-kdbus.c index 3afbd08..20c3887 100644 --- a/dbus/dbus-transport-kdbus.c +++ b/dbus/dbus-transport-kdbus.c @@ -854,6 +854,7 @@ static int put_message_into_data(DBusMessage *message, char* data) const DBusString *body; int size; + dbus_message_set_serial(message, 1); dbus_message_lock (message); _dbus_message_get_network_data (message, &header, &body); ret_size = _dbus_string_get_length(header); @@ -862,7 +863,6 @@ static int put_message_into_data(DBusMessage *message, char* data) size = _dbus_string_get_length(body); memcpy(data, _dbus_string_get_const_data(body), size); ret_size += size; - dbus_message_unref(message); return ret_size; } -- 2.7.4