chiark / gitweb /
sd-bus: add new sd_bus_get_address() for querying the current bus address
authorLennart Poettering <lennart@poettering.net>
Fri, 28 Nov 2014 15:51:45 +0000 (16:51 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 28 Nov 2014 19:29:43 +0000 (20:29 +0100)
Also, update "busctl" to show this in its output.

src/libsystemd/sd-bus/busctl.c
src/libsystemd/sd-bus/sd-bus.c
src/systemd/sd-bus.h

index f75a9dc..1ba4e8a 100644 (file)
@@ -1176,12 +1176,16 @@ static int status(sd_bus *bus, char *argv[]) {
                                         pid,
                                         _SD_BUS_CREDS_ALL);
         } else {
-                const char *scope;
+                const char *scope, *address;
                 sd_id128_t bus_id;
 
+                r = sd_bus_get_address(bus, &address);
+                if (r >= 0)
+                        printf("BusAddress=%s%s%s\n", ansi_highlight(), address, ansi_highlight_off());
+
                 r = sd_bus_get_scope(bus, &scope);
                 if (r >= 0)
-                        printf("Scope=%s%s%s\n", ansi_highlight(), scope, ansi_highlight_off());
+                        printf("BusScope=%s%s%s\n", ansi_highlight(), scope, ansi_highlight_off());
 
                 r = sd_bus_get_bus_id(bus, &bus_id);
                 if (r >= 0)
index 5947cd7..6b35036 100644 (file)
@@ -3396,24 +3396,38 @@ _public_ int sd_bus_get_scope(sd_bus *bus, const char **scope) {
 
                 if (streq(n, "0-system")) {
                         *scope = "system";
-                        return 1;
+                        return 0;
                 }
 
                 dash = strchr(n, '-');
                 if (streq(dash, "-user")) {
                         *scope = "user";
-                        return 1;
+                        return 0;
                 }
         }
 
         if (bus->is_user) {
                 *scope = "user";
-                return 1;
+                return 0;
         }
 
         if (bus->is_system) {
                 *scope = "system";
-                return 1;
+                return 0;
+        }
+
+        return -ENODATA;
+}
+
+_public_ int sd_bus_get_address(sd_bus *bus, const char **address) {
+
+        assert_return(bus, -EINVAL);
+        assert_return(address, -EINVAL);
+        assert_return(!bus_pid_changed(bus), -ECHILD);
+
+        if (bus->address) {
+                *address = bus->address;
+                return 0;
         }
 
         return -ENODATA;
index 78a81a9..daa3484 100644 (file)
@@ -120,7 +120,7 @@ int sd_bus_set_address(sd_bus *bus, const char *address);
 int sd_bus_set_fd(sd_bus *bus, int input_fd, int output_fd);
 int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[]);
 int sd_bus_set_bus_client(sd_bus *bus, int b);
-int sd_bus_set_server(sd_bus *bus, int b, sd_id128_t owner_id);
+int sd_bus_set_server(sd_bus *bus, int b, sd_id128_t bus_id);
 int sd_bus_set_anonymous(sd_bus *bus, int b);
 int sd_bus_set_trusted(sd_bus *bus, int b);
 int sd_bus_set_description(sd_bus *bus, const char *description);
@@ -138,6 +138,7 @@ sd_bus *sd_bus_unref(sd_bus *bus);
 
 int sd_bus_is_open(sd_bus *bus);
 int sd_bus_can_send(sd_bus *bus, char type);
+int sd_bus_get_address(sd_bus *bus, const char **address);
 int sd_bus_get_bus_id(sd_bus *bus, sd_id128_t *id);
 int sd_bus_get_owner_creds(sd_bus *bus, uint64_t creds_mask, sd_bus_creds **ret);
 int sd_bus_get_scope(sd_bus *bus, const char **scope);