4 * Created on: Sep 4, 2013
7 * kdbus add-on to dbus daemon
12 #include <dbus/kdbus.h>
13 #include <dbus/dbus-connection-internal.h>
21 char* make_kdbus_bus(DBusBusType type, DBusError *error)
24 struct kdbus_cmd_bus_make head;
28 } __attribute__ ((__aligned__(8))) bus_make;
33 /*TODO Distinguish session and system bus make*/
34 /*TODO Add dbus_set_error(error, DBUS_ERROR_FAILED, "...") (?)*/
36 _dbus_verbose("Opening /dev/kdbus/control\n");
37 fdc = open("/dev/kdbus/control", O_RDWR|O_CLOEXEC);
40 _dbus_verbose("--- error %d (%m)\n", fdc);
44 memset(&bus_make, 0, sizeof(bus_make));
45 bus_make.head.bloom_size = 64;
46 bus_make.head.flags = KDBUS_MAKE_ACCESS_WORLD;
48 snprintf(bus_make.name, sizeof(bus_make.name), "%u-kdbus", getuid());
49 bus_make.n_type = KDBUS_MAKE_NAME;
50 bus_make.n_size = KDBUS_PART_HEADER_SIZE + strlen(bus_make.name) + 1;
51 bus_make.head.size = sizeof(struct kdbus_cmd_bus_make) + bus_make.n_size;
53 _dbus_verbose("Creating bus '%s'\n", bus_make.name);
54 ret = ioctl(fdc, KDBUS_CMD_BUS_MAKE, &bus_make);
57 _dbus_verbose("--- error %d (%m)\n", ret);
61 if (asprintf(&bus, "kdbus:path=/dev/kdbus/%s/bus", bus_make.name) < 0)
67 _dbus_verbose("Return value '%s'\n", bus);
71 DBusConnection* daemon_as_client(DBusBusType type, DBusError *error)
73 DBusConnection* connection;
75 connection = dbus_bus_get(type, error);
76 if(connection == NULL)
79 if(dbus_bus_request_name(connection, DBUS_SERVICE_DBUS, 0, error) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
82 dbus_bus_add_match(connection, "type='signal', member='NameAcquired'", error);
83 dbus_bus_add_match(connection, "type='signal', member='NameLost'", error);
84 if(dbus_error_is_set(error))
90 _dbus_connection_close_possibly_shared (connection);
91 dbus_connection_unref (connection);