diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-bus/bus-control.c | 15 | ||||
-rw-r--r-- | src/libsystemd-bus/bus-internal.h | 2 | ||||
-rw-r--r-- | src/libsystemd-bus/sd-bus.c | 11 | ||||
-rw-r--r-- | src/libsystemd-bus/sd-bus.h | 2 | ||||
-rw-r--r-- | src/libsystemd-bus/test-bus-chat.c | 9 |
5 files changed, 28 insertions, 11 deletions
diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c index 9d242dc413..06afaf3c76 100644 --- a/src/libsystemd-bus/bus-control.c +++ b/src/libsystemd-bus/bus-control.c @@ -28,11 +28,20 @@ #include "bus-internal.h" #include "bus-message.h" -const char *sd_bus_get_unique_name(sd_bus *bus) { +int sd_bus_get_unique_name(sd_bus *bus, const char **unique) { + int r; + if (!bus) - return NULL; + return -EINVAL; + if (!unique) + return -EINVAL; - return bus->unique_name; + r = bus_ensure_running(bus); + if (r < 0) + return r; + + *unique = bus->unique_name; + return 0; } int sd_bus_request_name(sd_bus *bus, const char *name, int flags) { diff --git a/src/libsystemd-bus/bus-internal.h b/src/libsystemd-bus/bus-internal.h index d0b7b5658d..c5bd3788b4 100644 --- a/src/libsystemd-bus/bus-internal.h +++ b/src/libsystemd-bus/bus-internal.h @@ -130,3 +130,5 @@ bool service_name_is_valid(const char *p); bool member_name_is_valid(const char *p); #define error_name_is_valid interface_name_is_valid + +int bus_ensure_running(sd_bus *bus); diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c index 9408806a4e..09ea01b951 100644 --- a/src/libsystemd-bus/sd-bus.c +++ b/src/libsystemd-bus/sd-bus.c @@ -35,7 +35,6 @@ #include "bus-message.h" #include "bus-type.h" -static int ensure_running(sd_bus *bus); static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec); static void bus_free(sd_bus *b) { @@ -789,7 +788,7 @@ int sd_bus_can_send(sd_bus *bus, char type) { return -EINVAL; if (type == SD_BUS_TYPE_UNIX_FD) { - r = ensure_running(bus); + r = bus_ensure_running(bus); if (r < 0) return r; @@ -807,7 +806,7 @@ int sd_bus_get_peer(sd_bus *bus, sd_id128_t *peer) { if (!peer) return -EINVAL; - r = ensure_running(bus); + r = bus_ensure_running(bus); if (r < 0) return r; @@ -1252,7 +1251,7 @@ int sd_bus_send_with_reply_cancel(sd_bus *bus, uint64_t serial) { return 1; } -static int ensure_running(sd_bus *bus) { +int bus_ensure_running(sd_bus *bus) { int r; assert(bus); @@ -1300,7 +1299,7 @@ int sd_bus_send_with_reply_and_block( if (bus_error_is_dirty(error)) return -EINVAL; - r = ensure_running(bus); + r = bus_ensure_running(bus); if (r < 0) return r; @@ -1747,7 +1746,7 @@ int sd_bus_flush(sd_bus *bus) { if (bus->fd < 0) return -ENOTCONN; - r = ensure_running(bus); + r = bus_ensure_running(bus); if (r < 0) return r; diff --git a/src/libsystemd-bus/sd-bus.h b/src/libsystemd-bus/sd-bus.h index 8af1e85aae..60f2913d69 100644 --- a/src/libsystemd-bus/sd-bus.h +++ b/src/libsystemd-bus/sd-bus.h @@ -128,7 +128,7 @@ int sd_bus_message_rewind(sd_bus_message *m, int complete); /* Bus management */ -const char *sd_bus_get_unique_name(sd_bus *bus); +int sd_bus_get_unique_name(sd_bus *bus, const char **unique); int sd_bus_request_name(sd_bus *bus, const char *name, int flags); int sd_bus_release_name(sd_bus *bus, const char *name); int sd_bus_list_names(sd_bus *bus, char ***l); diff --git a/src/libsystemd-bus/test-bus-chat.c b/src/libsystemd-bus/test-bus-chat.c index 5f533cc6d0..24a194327e 100644 --- a/src/libsystemd-bus/test-bus-chat.c +++ b/src/libsystemd-bus/test-bus-chat.c @@ -35,6 +35,7 @@ static int server_init(sd_bus **_bus) { sd_bus *bus = NULL; sd_id128_t id; int r; + const char *unique; assert(_bus); @@ -50,9 +51,15 @@ static int server_init(sd_bus **_bus) { goto fail; } + r = sd_bus_get_unique_name(bus, &unique); + if (r < 0) { + log_error("Failed to get unique name: %s", strerror(-r)); + goto fail; + } + log_info("Peer ID is " SD_ID128_FORMAT_STR ".", SD_ID128_FORMAT_VAL(id)); + log_info("Unique ID: %s", unique); log_info("Can send file handles: %i", sd_bus_can_send(bus, 'h')); - log_info("Unique ID: %s", strna(sd_bus_get_unique_name(bus))); r = sd_bus_request_name(bus, "org.freedesktop.systemd.test", 0); if (r < 0) { |