Commit 20902f3e authored by Lennart Poettering's avatar Lennart Poettering

bus: also finish connection before returning from sd_bus_get_unique_name()

parent ed205a6b
......@@ -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) {
......
......@@ -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);
......@@ -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;
......
......@@ -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);
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment