From 733e792bc603f580c7a0e3031917982bb7399994 Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Sat, 16 Sep 2017 14:39:22 +0100 Subject: sd-bus: fix response for GetAll on non-existent objects Before this commit, if you run `loginctl user-status` from debug-shell.service (and you have no login sessions for root), you always see this output: 0 Linger: no because Properties.GetAll is returning success but without any properties, when the only find() callback had returned 0 to mean "no object found". After: Could not get properties: Unknown object: '/org/freedesktop/login1/user/self' BTW I have a fix for more user-friendly messages from logind in this case. It is pending in my local branch for #6829 "fix `loginctl enable-linger`". --- src/libsystemd/sd-bus/bus-objects.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c index bb06d302ca..a4c0cc5db1 100644 --- a/src/libsystemd/sd-bus/bus-objects.c +++ b/src/libsystemd/sd-bus/bus-objects.c @@ -829,6 +829,9 @@ static int property_get_all_callbacks_run( return 0; } + if (!*found_object) + return 0; + if (!found_interface) { r = sd_bus_reply_method_errorf( m, -- cgit v1.2.3 From 00590f8268846f717a77e5f0f8bc3e2a5740855e Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Sat, 16 Sep 2017 12:32:59 +0100 Subject: sd-bus: style nitpick node_vtable_get_userdata() It's confusing to use a single void* to store data with two different types, i.e. a userdata value which is safe to pass to ->find(), and a userdata value which identifies the found object. Name the latter `found_u`. This naming treats (!c->find) as a degenerate case. (I.e. at that point, we know the object has already been found :). --- src/libsystemd/sd-bus/bus-objects.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c index a4c0cc5db1..dcd929b13b 100644 --- a/src/libsystemd/sd-bus/bus-objects.c +++ b/src/libsystemd/sd-bus/bus-objects.c @@ -38,7 +38,7 @@ static int node_vtable_get_userdata( sd_bus_error *error) { sd_bus_slot *s; - void *u; + void *u, *found_u; int r; assert(bus); @@ -50,7 +50,7 @@ static int node_vtable_get_userdata( if (c->find) { bus->current_slot = sd_bus_slot_ref(s); bus->current_userdata = u; - r = c->find(bus, path, c->interface, u, &u, error); + r = c->find(bus, path, c->interface, u, &found_u, error); bus->current_userdata = NULL; bus->current_slot = sd_bus_slot_unref(s); @@ -60,10 +60,11 @@ static int node_vtable_get_userdata( return -sd_bus_error_get_errno(error); if (r == 0) return r; - } + } else + found_u = u; if (userdata) - *userdata = u; + *userdata = found_u; return 1; } -- cgit v1.2.3