summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/sd-bus.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-01-22 16:09:59 +0100
committerLennart Poettering <lennart@poettering.net>2014-01-22 16:09:59 +0100
commit5972fe953ec56c77936a1e612ca87d8a0e6c0c64 (patch)
tree515ee99fed073c4184a84eb5ee7cdb55bdf43900 /src/libsystemd/sd-bus/sd-bus.c
parent7f96b1d8147b164bc7c8ce119aeea5fed6ceecb7 (diff)
bus: add support for attaching name to bus connections for debugging purposes
Diffstat (limited to 'src/libsystemd/sd-bus/sd-bus.c')
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index edea7c0ef6..a8295b2778 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -144,6 +144,7 @@ static void bus_free(sd_bus *b) {
free(b->machine);
free(b->fake_label);
free(b->cgroup_root);
+ free(b->connection_name);
free(b->exec_path);
strv_free(b->exec_argv);
@@ -334,6 +335,24 @@ _public_ int sd_bus_set_trusted(sd_bus *bus, int b) {
return 0;
}
+_public_ int sd_bus_set_name(sd_bus *bus, const char *name) {
+ char *n;
+
+ assert_return(bus, -EINVAL);
+ assert_return(name, -EINVAL);
+ assert_return(bus->state == BUS_UNSET, -EPERM);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ n = strdup(name);
+ if (!n)
+ return -ENOMEM;
+
+ free(bus->connection_name);
+ bus->connection_name = n;
+
+ return 0;
+}
+
static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
const char *s;
int r;
@@ -1053,6 +1072,7 @@ _public_ int sd_bus_open_system(sd_bus **ret) {
goto fail;
b->bus_client = true;
+ b->is_system = true;
/* Let's do per-method access control on the system bus. We
* need the caller's UID and capability set for that. */
@@ -1118,6 +1138,7 @@ _public_ int sd_bus_open_user(sd_bus **ret) {
}
b->bus_client = true;
+ b->is_user = true;
/* We don't do any per-method access control on the user
* bus. */
@@ -3034,3 +3055,12 @@ _public_ int sd_bus_try_close(sd_bus *bus) {
sd_bus_close(bus);
return 0;
}
+
+_public_ int sd_bus_get_name(sd_bus *bus, const char **name) {
+ assert_return(bus, -EINVAL);
+ assert_return(name, -EINVAL);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ *name = bus->connection_name;
+ return 0;
+}