From dce98698a12920cebb3ef3486b77c78b5efb58b6 Mon Sep 17 00:00:00 2001 From: Radoslaw Pajak Date: Fri, 18 Oct 2013 11:42:21 +0200 Subject: [PATCH] [daemon-dev][lib-opt] Bus making in daemon distinguishes bus type, lib optimalization - daemon now distinguish type of the bus when he creates it - library (transport) optimalization Change-Id: I55fa7a1c283a16e8b97cb747bf557a8358de9927 Signed-off-by: Radoslaw Pajak --- autogen.sh | 2 +- bus/kdbus-d.c | 5 +++-- dbus/dbus-transport-kdbus.c | 32 ++++++++++++++++---------------- dbus/kdbus-common.c | 2 +- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/autogen.sh b/autogen.sh index a450272..ab3afed 100755 --- a/autogen.sh +++ b/autogen.sh @@ -102,7 +102,7 @@ fi #--enable-developer --enable-verbose-mode if $run_configure; then - $srcdir/configure --enable-abstract-sockets --config-cache "$@" || exit $? + $srcdir/configure --enable-abstract-sockets --enable-verbose-mode --config-cache "$@" || exit $? echo echo "Now type 'make' to compile $PROJECT." else diff --git a/bus/kdbus-d.c b/bus/kdbus-d.c index 789730e..9f5c756 100644 --- a/bus/kdbus-d.c +++ b/bus/kdbus-d.c @@ -51,8 +51,6 @@ char* make_kdbus_bus(DBusBusType type, DBusError *error) int fdc, ret; char *bus; - /*TODO Distinguish session and system bus make*/ - _dbus_verbose("Opening /dev/kdbus/control\n"); fdc = open("/dev/kdbus/control", O_RDWR|O_CLOEXEC); if (fdc < 0) @@ -68,8 +66,11 @@ char* make_kdbus_bus(DBusBusType type, DBusError *error) if(type == DBUS_BUS_SYSTEM) snprintf(bus_make.name, sizeof(bus_make.name), "%u-kdbus-%s", getuid(), "system"); + else if(type == DBUS_BUS_SESSION) + snprintf(bus_make.name, sizeof(bus_make.name), "%u-kdbus", getuid()); else snprintf(bus_make.name, sizeof(bus_make.name), "%u-kdbus-%u", getuid(), getpid()); + bus_make.n_type = KDBUS_MAKE_NAME; bus_make.n_size = KDBUS_PART_HEADER_SIZE + strlen(bus_make.name) + 1; bus_make.head.size = sizeof(struct kdbus_cmd_bus_make) + bus_make.n_size; diff --git a/dbus/dbus-transport-kdbus.c b/dbus/dbus-transport-kdbus.c index da5dd63..6e48d4a 100644 --- a/dbus/dbus-transport-kdbus.c +++ b/dbus/dbus-transport-kdbus.c @@ -264,11 +264,10 @@ static struct kdbus_msg* kdbus_init_msg(const char* name, __u64 dst_id, uint64_t * @param encoded flag if the message is encoded * @return size of data sent */ -static int kdbus_write_msg(DBusTransportSocket *transport, DBusMessage *message, dbus_bool_t encoded) +static int kdbus_write_msg(DBusTransportSocket *transport, DBusMessage *message, const char* destination, dbus_bool_t encoded) { struct kdbus_msg *msg; struct kdbus_item *item; - const char *name; uint64_t dst_id = KDBUS_DST_ID_BROADCAST; const DBusString *header; const DBusString *body; @@ -280,14 +279,14 @@ static int kdbus_write_msg(DBusTransportSocket *transport, DBusMessage *message, unsigned fds_count; dbus_bool_t autostart; - // determine name and destination id - if((name = dbus_message_get_destination(message))) + // determine destination and destination id + if(destination) { dst_id = KDBUS_DST_ID_WELL_KNOWN_NAME; - if((name[0] == ':') && (name[1] == '1') && (name[2] == '.')) /* if name starts with ":1." it is a unique name and should be send as number */ + if((destination[0] == ':') && (destination[1] == '1') && (destination[2] == '.')) /* if name starts with ":1." it is a unique name and should be send as number */ { - dst_id = strtoull(&name[3], NULL, 10); - name = NULL; + dst_id = strtoull(&destination[3], NULL, 10); + destination = NULL; } } @@ -309,7 +308,7 @@ static int kdbus_write_msg(DBusTransportSocket *transport, DBusMessage *message, _dbus_message_get_unix_fds(message, &unix_fds, &fds_count); // init basic message fields - msg = kdbus_init_msg(name, dst_id, body_size, use_memfd, fds_count, transport); + msg = kdbus_init_msg(destination, dst_id, body_size, use_memfd, fds_count, transport); msg->cookie = dbus_message_get_serial(message); autostart = dbus_message_get_auto_start (message); if(!autostart) @@ -387,12 +386,12 @@ static int kdbus_write_msg(DBusTransportSocket *transport, DBusMessage *message, memcpy(item->fds, unix_fds, sizeof(int) * fds_count); } - if (name) + if (destination) { item = KDBUS_PART_NEXT(item); item->type = KDBUS_MSG_DST_NAME; - item->size = KDBUS_PART_HEADER_SIZE + strlen(name) + 1; - memcpy(item->str, name, item->size - KDBUS_PART_HEADER_SIZE); + item->size = KDBUS_PART_HEADER_SIZE + strlen(destination) + 1; + memcpy(item->str, destination, item->size - KDBUS_PART_HEADER_SIZE); } else if (dst_id == KDBUS_DST_ID_BROADCAST) { @@ -428,7 +427,8 @@ static int kdbus_write_msg(DBusTransportSocket *transport, DBusMessage *message, } out: free(msg); - close(transport->memfd); + if(use_memfd) + close(transport->memfd); return ret_size; } @@ -2115,7 +2115,7 @@ do_writing (DBusTransport *transport) message = _dbus_connection_get_message_to_send (transport->connection); _dbus_assert (message != NULL); - if(dbus_message_get_sender(message) == NULL) //needed for daemon +// if(dbus_message_get_sender(message) == NULL) //needed for daemon todo check if really needed { dbus_message_unlock(message); dbus_message_set_sender(message, socket_transport->sender); @@ -2127,7 +2127,7 @@ do_writing (DBusTransport *transport) if(pDestination) { - if(!strcmp(pDestination, "org.freedesktop.DBus")) + if(!strcmp(pDestination, DBUS_SERVICE_DBUS)) { if(!strcmp(dbus_message_get_interface(message), DBUS_INTERFACE_DBUS)) { @@ -2172,14 +2172,14 @@ do_writing (DBusTransport *transport) if(total_bytes_to_write > socket_transport->max_bytes_written_per_iteration) return -E2BIG; - bytes_written = kdbus_write_msg(socket_transport, message, TRUE); + bytes_written = kdbus_write_msg(socket_transport, message, pDestination, TRUE); } else { if(total_bytes_to_write > socket_transport->max_bytes_written_per_iteration) return -E2BIG; - bytes_written = kdbus_write_msg(socket_transport, message, FALSE); + bytes_written = kdbus_write_msg(socket_transport, message, pDestination, FALSE); } written: diff --git a/dbus/kdbus-common.c b/dbus/kdbus-common.c index fe04a2e..de618ed 100644 --- a/dbus/kdbus-common.c +++ b/dbus/kdbus-common.c @@ -107,7 +107,7 @@ dbus_bool_t register_kdbus_policy(const char* name, int fd) if (ioctl(fd, KDBUS_CMD_EP_POLICY_SET, cmd_policy) < 0) { - _dbus_verbose ("Error setting policy: %m, %d", errno); + _dbus_verbose ("Error setting policy: %m, %d\n", errno); return FALSE; } -- 2.7.4