summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/bus-kernel.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-11-28 15:59:05 +0100
committerLennart Poettering <lennart@poettering.net>2014-11-28 16:17:33 +0100
commit3acc1dafd14420872f7f13319260eeb5d62c2533 (patch)
tree376044a15fe091db6e6b712a462b7dfe2c91c582 /src/libsystemd/sd-bus/bus-kernel.c
parent52cfc0379a9d63f99cdb3d9f63c839bbc8889b4c (diff)
sd-bus: add new call sd_bus_get_scope() for querying whether one is connected to a system or a user bus
Diffstat (limited to 'src/libsystemd/sd-bus/bus-kernel.c')
-rw-r--r--src/libsystemd/sd-bus/bus-kernel.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index c86ed6ae42..58f011ff86 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -1845,3 +1845,39 @@ int bus_kernel_fix_attach_mask(void) {
return 0;
}
+
+int bus_kernel_get_bus_name(sd_bus *bus, char **name) {
+ struct kdbus_cmd_info cmd = {
+ .size = sizeof(struct kdbus_cmd_info),
+ };
+ struct kdbus_info *info;
+ struct kdbus_item *item;
+ char *n = NULL;
+ int r;
+
+ assert(bus);
+ assert(name);
+ assert(bus->is_kernel);
+
+ r = ioctl(bus->input_fd, KDBUS_CMD_BUS_CREATOR_INFO, &cmd);
+ if (r < 0)
+ return -errno;
+
+ info = (struct kdbus_info*) ((uint8_t*) bus->kdbus_buffer + cmd.offset);
+
+ KDBUS_ITEM_FOREACH(item, info, items)
+ if (item->type == KDBUS_ITEM_MAKE_NAME) {
+ r = free_and_strdup(&n, item->str);
+ break;
+ }
+
+ bus_kernel_cmd_free(bus, cmd.offset);
+
+ if (r < 0)
+ return r;
+ if (!n)
+ return -EIO;
+
+ *name = n;
+ return 0;
+}