summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/bus-control.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-04-12 03:08:14 +0200
committerLennart Poettering <lennart@poettering.net>2013-04-12 03:08:50 +0200
commitf08838da225678269945868a71bbdc79de967e1d (patch)
treeb9a94e4a59c8a2c9556d784f73c9ba030d3bf24c /src/libsystemd-bus/bus-control.c
parent8c11aac1d739f5e60822f65f5179d8c4cc212732 (diff)
bus: implement basic name registration with kdbus
Diffstat (limited to 'src/libsystemd-bus/bus-control.c')
-rw-r--r--src/libsystemd-bus/bus-control.c110
1 files changed, 75 insertions, 35 deletions
diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index a0abccf1dd..7c139cfd32 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -54,26 +54,46 @@ int sd_bus_request_name(sd_bus *bus, const char *name, int flags) {
return -EINVAL;
if (!name)
return -EINVAL;
+ if (!bus->bus_client)
+ return -EINVAL;
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.DBus",
- "/",
- "org.freedesktop.DBus",
- "RequestName",
- NULL,
- &reply,
- "su",
- name,
- flags);
- if (r < 0)
- return r;
-
- r = sd_bus_message_read(reply, "u", &ret);
- if (r < 0)
- return r;
-
- return ret;
+ if (bus->is_kernel) {
+ struct kdbus_cmd_name *n;
+ size_t l;
+
+ l = strlen(name);
+ n = alloca(offsetof(struct kdbus_cmd_name, name) + l + 1);
+ n->size = offsetof(struct kdbus_cmd_name, name) + l + 1;
+ n->flags = flags;
+ n->id = 0;
+ memcpy(n->name, name, l+1);
+
+ r = ioctl(bus->input_fd, KDBUS_CMD_NAME_ACQUIRE, n);
+ if (r < 0)
+ return -errno;
+
+ return n->flags;
+ } else {
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.DBus",
+ "/",
+ "org.freedesktop.DBus",
+ "RequestName",
+ NULL,
+ &reply,
+ "su",
+ name,
+ flags);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_read(reply, "u", &ret);
+ if (r < 0)
+ return r;
+
+ return ret;
+ }
}
int sd_bus_release_name(sd_bus *bus, const char *name) {
@@ -85,23 +105,43 @@ int sd_bus_release_name(sd_bus *bus, const char *name) {
return -EINVAL;
if (!name)
return -EINVAL;
+ if (!bus->bus_client)
+ return -EINVAL;
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.DBus",
- "/",
- "org.freedesktop.DBus",
- "ReleaseName",
- NULL,
- &reply,
- "s",
- name);
- if (r < 0)
- return r;
-
- r = sd_bus_message_read(reply, "u", &ret);
- if (r < 0)
- return r;
+ if (bus->is_kernel) {
+ struct kdbus_cmd_name *n;
+ size_t l;
+
+ l = strlen(name);
+ n = alloca(offsetof(struct kdbus_cmd_name, name) + l + 1);
+ n->size = offsetof(struct kdbus_cmd_name, name) + l + 1;
+ n->flags = 0;
+ n->id = 0;
+ memcpy(n->name, name, l+1);
+
+ r = ioctl(bus->input_fd, KDBUS_CMD_NAME_RELEASE, n);
+ if (r < 0)
+ return -errno;
+
+ return n->flags;
+ } else {
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.DBus",
+ "/",
+ "org.freedesktop.DBus",
+ "ReleaseName",
+ NULL,
+ &reply,
+ "s",
+ name);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_read(reply, "u", &ret);
+ if (r < 0)
+ return r;
+ }
return ret;
}