summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-10-11 04:52:38 +0200
committerLennart Poettering <lennart@poettering.net>2013-10-11 04:52:38 +0200
commit5d12cc3e286c8515f18c8417d67e26e4e2b2e7cb (patch)
tree503a5b61b0bcdf32b7735f1d48e07a23a03a9919
parent46e8c8257f5dd0bcf964eb1f5cbb9ce43aac5201 (diff)
bus: make GetManagedObjects() work
-rw-r--r--src/libsystemd-bus/sd-bus.c16
-rw-r--r--src/libsystemd-bus/test-bus-objects.c25
2 files changed, 31 insertions, 10 deletions
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 795007acc4..342af4d1d5 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2499,6 +2499,7 @@ static int object_manager_serialize_vtable(
static int object_manager_serialize_path(
sd_bus *bus,
sd_bus_message *reply,
+ const char *prefix,
const char *path,
bool require_fallback,
sd_bus_error *error) {
@@ -2509,10 +2510,11 @@ static int object_manager_serialize_path(
assert(bus);
assert(reply);
+ assert(prefix);
assert(path);
assert(error);
- n = hashmap_get(bus->nodes, path);
+ n = hashmap_get(bus->nodes, prefix);
if (!n)
return 0;
@@ -2566,7 +2568,7 @@ static int object_manager_serialize_path_and_fallbacks(
assert(error);
/* First, add all vtables registered for this path */
- r = object_manager_serialize_path(bus, reply, path, false, error);
+ r = object_manager_serialize_path(bus, reply, path, path, false, error);
if (r < 0)
return r;
if (sd_bus_error_is_set(error))
@@ -2587,7 +2589,7 @@ static int object_manager_serialize_path_and_fallbacks(
*e = 0;
- r = object_manager_serialize_path(bus, reply, p, true, error);
+ r = object_manager_serialize_path(bus, reply, p, path, true, error);
if (r < 0)
return r;
@@ -2687,7 +2689,13 @@ static int process_get_managed_objects(
return 1;
}
-static int object_find_and_run(sd_bus *bus, sd_bus_message *m, const char *p, bool require_fallback, bool *found_object) {
+static int object_find_and_run(
+ sd_bus *bus,
+ sd_bus_message *m,
+ const char *p,
+ bool require_fallback,
+ bool *found_object) {
+
struct node *n;
struct vtable_member vtable_key, *v;
int r;
diff --git a/src/libsystemd-bus/test-bus-objects.c b/src/libsystemd-bus/test-bus-objects.c
index a95789fe9c..f3571cb3c4 100644
--- a/src/libsystemd-bus/test-bus-objects.c
+++ b/src/libsystemd-bus/test-bus-objects.c
@@ -36,7 +36,6 @@
/* Test:
*
- * sd_bus_add_object_manager()
* sd_bus_emit_properties_changed()
*
* Add in:
@@ -179,6 +178,7 @@ static void *server(void *p) {
assert_se(sd_bus_add_object_vtable(bus, "/foo", "org.freedesktop.systemd.test2", vtable, c) >= 0);
assert_se(sd_bus_add_fallback_vtable(bus, "/value", "org.freedesktop.systemd.ValueTest", vtable2, NULL, UINT_TO_PTR(20)) >= 0);
assert_se(sd_bus_add_node_enumerator(bus, "/value", enumerator_callback, NULL) >= 0);
+ assert_se(sd_bus_add_object_manager(bus, "/value") >= 0);
assert_se(sd_bus_start(bus) >= 0);
@@ -272,7 +272,7 @@ static int client(struct context *c) {
reply = NULL;
r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
- assert_se(r <= 0);
+ assert_se(r >= 0);
r = sd_bus_message_read(reply, "s", &s);
assert_se(r >= 0);
@@ -292,7 +292,7 @@ static int client(struct context *c) {
reply = NULL;
r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
- assert_se(r <= 0);
+ assert_se(r >= 0);
r = sd_bus_message_read(reply, "s", &s);
assert_se(r >= 0);
@@ -302,7 +302,7 @@ static int client(struct context *c) {
reply = NULL;
r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
- assert_se(r <= 0);
+ assert_se(r >= 0);
r = sd_bus_message_read(reply, "s", &s);
assert_se(r >= 0);
@@ -312,7 +312,7 @@ static int client(struct context *c) {
reply = NULL;
r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value/a", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
- assert_se(r <= 0);
+ assert_se(r >= 0);
r = sd_bus_message_read(reply, "s", &s);
assert_se(r >= 0);
@@ -322,7 +322,7 @@ static int client(struct context *c) {
reply = NULL;
r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.DBus.Properties", "GetAll", &error, &reply, "s", "");
- assert_se(r <= 0);
+ assert_se(r >= 0);
bus_message_dump(reply);
@@ -334,6 +334,19 @@ static int client(struct context *c) {
assert_se(sd_bus_error_has_name(&error, "org.freedesktop.DBus.Error.UnknownInterface"));
sd_bus_error_free(&error);
+ r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects", &error, &reply, "");
+ assert_se(r < 0);
+ assert_se(sd_bus_error_has_name(&error, "org.freedesktop.DBus.Error.UnknownMethod"));
+ sd_bus_error_free(&error);
+
+ r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects", &error, &reply, "");
+ assert_se(r >= 0);
+
+ bus_message_dump(reply);
+
+ sd_bus_message_unref(reply);
+ reply = NULL;
+
r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "Exit", &error, NULL, "");
assert_se(r >= 0);