summaryrefslogtreecommitdiff
path: root/src/libelogind/sd-bus
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-02-07 22:28:42 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:58:54 +0200
commitaa593c9d880456820a90d731e63abaa75083b93d (patch)
tree9bd9e4b6b18a99fbdab0df1d5e0518786d1608c8 /src/libelogind/sd-bus
parent7db510fe3be07ec1c3d7ba4728f57418a0f85278 (diff)
sd-bus: synthesize a description for user/system bus if otherwise unset
Let's make debugging easier, by synthesizing a name when we have some indication what kind of bus this is.
Diffstat (limited to 'src/libelogind/sd-bus')
-rw-r--r--src/libelogind/sd-bus/sd-bus.c63
1 files changed, 36 insertions, 27 deletions
diff --git a/src/libelogind/sd-bus/sd-bus.c b/src/libelogind/sd-bus/sd-bus.c
index eaa028f50..157f0ed25 100644
--- a/src/libelogind/sd-bus/sd-bus.c
+++ b/src/libelogind/sd-bus/sd-bus.c
@@ -293,8 +293,7 @@ _public_ int sd_bus_set_address(sd_bus *bus, const char *address) {
if (!a)
return -ENOMEM;
- free(bus->address);
- bus->address = a;
+ free_and_replace(bus->address, a);
return 0;
}
@@ -332,10 +331,9 @@ _public_ int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[])
return -ENOMEM;
}
- free(bus->exec_path);
- strv_free(bus->exec_argv);
+ free_and_replace(bus->exec_path, p);
- bus->exec_path = p;
+ strv_free(bus->exec_argv);
bus->exec_argv = a;
return 0;
@@ -358,7 +356,7 @@ _public_ int sd_bus_set_monitor(sd_bus *bus, int b) {
assert_return(bus->state == BUS_UNSET, -EPERM);
assert_return(!bus_pid_changed(bus), -ECHILD);
- bus->is_monitor = b;
+ bus->is_monitor = !!b;
return 0;
}
@@ -368,7 +366,7 @@ _public_ int sd_bus_negotiate_fds(sd_bus *bus, int b) {
assert_return(bus->state == BUS_UNSET, -EPERM);
assert_return(!bus_pid_changed(bus), -ECHILD);
- bus->accept_fd = b;
+ bus->accept_fd = !!b;
return 0;
}
@@ -380,7 +378,7 @@ _public_ int sd_bus_negotiate_timestamp(sd_bus *bus, int b) {
/* This is not actually supported by any of our transports these days, but we do honour it for synthetic
* replies, and maybe one day classic D-Bus learns this too */
- bus->attach_timestamp = b;
+ bus->attach_timestamp = !!b;
return 0;
}
@@ -464,7 +462,7 @@ _public_ int sd_bus_set_watch_bind(sd_bus *bus, int b) {
assert_return(bus->state == BUS_UNSET, -EPERM);
assert_return(!bus_pid_changed(bus), -ECHILD);
- bus->watch_bind = b;
+ bus->watch_bind = !!b;
return 0;
}
@@ -482,7 +480,7 @@ _public_ int sd_bus_set_connected_signal(sd_bus *bus, int b) {
assert_return(bus->state == BUS_UNSET, -EPERM);
assert_return(!bus_pid_changed(bus), -ECHILD);
- bus->connected_signal = b;
+ bus->connected_signal = !!b;
return 0;
}
@@ -563,6 +561,7 @@ void bus_set_state(sd_bus *bus, enum bus_state state) {
static int hello_callback(sd_bus_message *reply, void *userdata, sd_bus_error *error) {
const char *s;
+ char *t;
sd_bus *bus;
int r;
@@ -582,10 +581,12 @@ static int hello_callback(sd_bus_message *reply, void *userdata, sd_bus_error *e
if (!service_name_is_valid(s) || s[0] != ':')
return -EBADMSG;
- bus->unique_name = strdup(s);
- if (!bus->unique_name)
+ t = strdup(s);
+ if (!t)
return -ENOMEM;
+ free_and_replace(bus->unique_name, t);
+
if (bus->state == BUS_HELLO) {
bus_set_state(bus, BUS_RUNNING);
@@ -656,8 +657,8 @@ int bus_start_running(sd_bus *bus) {
static int parse_address_key(const char **p, const char *key, char **value) {
size_t l, n = 0, allocated = 0;
+ _cleanup_free_ char *r = NULL;
const char *a;
- char *r = NULL;
assert(p);
assert(*p);
@@ -685,16 +686,12 @@ static int parse_address_key(const char **p, const char *key, char **value) {
int x, y;
x = unhexchar(a[1]);
- if (x < 0) {
- free(r);
+ if (x < 0)
return x;
- }
y = unhexchar(a[2]);
- if (y < 0) {
- free(r);
+ if (y < 0)
return y;
- }
c = (char) ((x << 4) | y);
a += 3;
@@ -721,8 +718,7 @@ static int parse_address_key(const char **p, const char *key, char **value) {
*p = a;
- free(*value);
- *value = r;
+ free_and_replace(*value, r);
return 1;
}
@@ -1403,7 +1399,7 @@ fail:
int bus_set_address_system_remote(sd_bus *b, const char *host) {
_cleanup_free_ char *e = NULL;
- char *m = NULL, *c = NULL;
+ char *m = NULL, *c = NULL, *a;
assert(b);
assert(host);
@@ -1434,10 +1430,12 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) {
return -ENOMEM;
}
- b->address = strjoin("unixexec:path=ssh,argv1=-xT,argv2=--,argv3=", e, ",argv4=elogind-stdio-bridge", c);
- if (!b->address)
+ a = strjoin("unixexec:path=ssh,argv1=-xT,argv2=--,argv3=", e, ",argv4=elogind-stdio-bridge", c);
+ if (!a)
return -ENOMEM;
+ free_and_replace(b->address, a);
+
return 0;
}
@@ -1475,6 +1473,7 @@ fail:
int bus_set_address_system_machine(sd_bus *b, const char *machine) {
_cleanup_free_ char *e = NULL;
+ char *a;
assert(b);
assert(machine);
@@ -1483,10 +1482,12 @@ int bus_set_address_system_machine(sd_bus *b, const char *machine) {
if (!e)
return -ENOMEM;
- b->address = strjoin("x-machine-unix:machine=", e);
- if (!b->address)
+ a = strjoin("x-machine-unix:machine=", e);
+ if (!a)
return -ENOMEM;
+ free_and_replace(b->address, a);
+
return 0;
}
@@ -3945,7 +3946,15 @@ _public_ int sd_bus_get_description(sd_bus *bus, const char **description) {
assert_return(bus->description, -ENXIO);
assert_return(!bus_pid_changed(bus), -ECHILD);
- *description = bus->description;
+ if (bus->description)
+ *description = bus->description;
+ else if (bus->is_system)
+ *description = "system";
+ else if (bus->is_user)
+ *description = "user";
+ else
+ *description = NULL;
+
return 0;
}