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)
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;
* @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;
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;
}
}
_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)
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)
{
}
out:
free(msg);
- close(transport->memfd);
+ if(use_memfd)
+ close(transport->memfd);
return ret_size;
}
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);
if(pDestination)
{
- if(!strcmp(pDestination, "org.freedesktop.DBus"))
+ if(!strcmp(pDestination, DBUS_SERVICE_DBUS))
{
if(!strcmp(dbus_message_get_interface(message), DBUS_INTERFACE_DBUS))
{
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: