summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/sd-bus.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/sd-bus.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/sd-bus.c')
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 8f97a582d7..9ce6bfab8f 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -1283,6 +1283,7 @@ _public_ int sd_bus_open_system_remote(sd_bus **ret, const char *host) {
bus->bus_client = true;
bus->trusted = false;
+ bus->is_system = true;
r = sd_bus_start(bus);
if (r < 0)
@@ -1335,6 +1336,7 @@ _public_ int sd_bus_open_system_container(sd_bus **ret, const char *machine) {
bus->bus_client = true;
bus->trusted = false;
+ bus->is_system = true;
r = sd_bus_start(bus);
if (r < 0)
@@ -3376,3 +3378,43 @@ int bus_get_root_path(sd_bus *bus) {
return r;
}
+
+_public_ int sd_bus_get_scope(sd_bus *bus, const char **scope) {
+ int r;
+
+ assert_return(bus, -EINVAL);
+ assert_return(scope, -EINVAL);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ if (bus->is_kernel) {
+ _cleanup_free_ char *n = NULL;
+ const char *dash;
+
+ r = bus_kernel_get_bus_name(bus, &n);
+ if (r < 0)
+ return r;
+
+ if (streq(n, "0-system")) {
+ *scope = "system";
+ return 1;
+ }
+
+ dash = strchr(n, '-');
+ if (streq(dash, "-user")) {
+ *scope = "user";
+ return 1;
+ }
+ }
+
+ if (bus->is_user) {
+ *scope = "user";
+ return 1;
+ }
+
+ if (bus->is_system) {
+ *scope = "system";
+ return 1;
+ }
+
+ return -ENODATA;
+}