chiark / gitweb /
bus: make bus_print_all_properties work for non machinectl cases
authorSimon Peeters <peeters.simon@gmail.com>
Thu, 7 Nov 2013 07:58:22 +0000 (08:58 +0100)
committerKay Sievers <kay@vrfy.org>
Thu, 7 Nov 2013 13:18:35 +0000 (14:18 +0100)
add a destination parameter and skip properties we can't read

src/libsystemd-bus/bus-util.c
src/libsystemd-bus/bus-util.h
src/machine/machinectl.c

index 13ad444..bf8fb40 100644 (file)
@@ -628,7 +628,7 @@ int bus_print_property(const char *name, sd_bus_message *property, bool all) {
         return 0;
 }
 
         return 0;
 }
 
-int bus_print_all_properties(sd_bus *bus, const char *path, char **filter, bool all) {
+int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, char **filter, bool all) {
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         int r;
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         int r;
@@ -637,7 +637,7 @@ int bus_print_all_properties(sd_bus *bus, const char *path, char **filter, bool
         assert(path);
 
         r = sd_bus_call_method(bus,
         assert(path);
 
         r = sd_bus_call_method(bus,
-                        "org.freedesktop.machine1",
+                        dest,
                         path,
                         "org.freedesktop.DBus.Properties",
                         "GetAll",
                         path,
                         "org.freedesktop.DBus.Properties",
                         "GetAll",
@@ -671,8 +671,14 @@ int bus_print_all_properties(sd_bus *bus, const char *path, char **filter, bool
                         r = bus_print_property(name, reply, all);
                         if (r < 0)
                                 return r;
                         r = bus_print_property(name, reply, all);
                         if (r < 0)
                                 return r;
-                        if (r == 0 && all)
-                                printf("%s=[unprintable]\n", name);
+                        if (r == 0) {
+                                if (all)
+                                        printf("%s=[unprintable]\n", name);
+                                /* skip what we didn't read */
+                                r = sd_bus_message_skip(reply, contents);
+                                if (r < 0)
+                                        return r;
+                        }
 
                         r = sd_bus_message_exit_container(reply);
                         if (r < 0)
 
                         r = sd_bus_message_exit_container(reply);
                         if (r < 0)
@@ -866,7 +872,7 @@ int bus_map_all_properties(sd_bus *bus,
                                 return r;
 
                         v = (uint8_t *)userdata + prop->offset;
                                 return r;
 
                         v = (uint8_t *)userdata + prop->offset;
-                                if (map[i].set)
+                        if (map[i].set)
                                 r = prop->set(bus, member, m, &error, v);
                         else
                                 r = map_basic(bus, member, m, &error, v);
                                 r = prop->set(bus, member, m, &error, v);
                         else
                                 r = map_basic(bus, member, m, &error, v);
index 101a2ec..f982e08 100644 (file)
@@ -67,7 +67,7 @@ int bus_open_system_systemd(sd_bus **_bus);
 int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
 
 int bus_print_property(const char *name, sd_bus_message *property, bool all);
 int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
 
 int bus_print_property(const char *name, sd_bus_message *property, bool all);
-int bus_print_all_properties(sd_bus *bus, const char *path, char **filter, bool all);
+int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, char **filter, bool all);
 
 int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
 int bus_property_get_uid(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
 
 int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
 int bus_property_get_uid(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
index 6234f6a..aa2b098 100644 (file)
@@ -284,7 +284,7 @@ static int show_properties(sd_bus *bus, const char *path, bool *new_line) {
 
         *new_line = true;
 
 
         *new_line = true;
 
-        r = bus_print_all_properties(bus, path, arg_property, arg_all);
+        r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, arg_property, arg_all);
         if (r < 0)
                 log_error("Could not get properties: %s", strerror(-r));
 
         if (r < 0)
                 log_error("Could not get properties: %s", strerror(-r));