[systemd-commits] 3 commits - src/analyze src/timedate

Thomas H.P. Andersen phomes at kemper.freedesktop.org
Thu Oct 31 23:16:12 CET 2013


 src/analyze/analyze.c      |  202 ++++++++++++++++++++-------------------------
 src/timedate/timedatectl.c |    2 
 2 files changed, 92 insertions(+), 112 deletions(-)

New commits:
commit 6e6ca4a5cca704da63ccf7ffa7d7e8a9e6e934f0
Author: Thomas Hindoe Paaboel Andersen <phomes at gmail.com>
Date:   Thu Oct 31 23:11:39 2013 +0100

    analyze: share code to read a string array from sd-bus

diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 144e821..6bfe13d 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -196,6 +196,41 @@ static int bus_parse_unit_info(sd_bus_message *message, struct unit_info *u) {
         return r;
 }
 
+static int bus_get_unit_property_strv(sd_bus *bus, const char *unit_path, const char *prop, char ***strv) {
+        _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+        int r;
+        const char *s;
+
+        r = sd_bus_get_property(
+                        bus,
+                        "org.freedesktop.systemd1",
+                        unit_path,
+                        "org.freedesktop.systemd1.Unit",
+                        prop,
+                        &error,
+                        &reply,
+                        "as");
+        if (r < 0) {
+                log_error("Failed to get unit property: %s %s", prop, bus_error_message(&error, -r));
+                return r;
+        }
+
+        r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "s");
+        if (r < 0)
+            return r;
+
+        while ((r = sd_bus_message_read(reply, "s", &s)) > 0) {
+                r = strv_extend(strv, s);
+                if (r < 0) {
+                        log_oom();
+                        return r;
+                }
+        }
+
+        return r;
+}
+
 static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
@@ -650,11 +685,8 @@ static int list_dependencies_print(const char *name, unsigned int level, unsigne
 
 static int list_dependencies_get_dependencies(sd_bus *bus, const char *name, char ***deps) {
         _cleanup_free_ char *path;
-        _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
-        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 
         int r = 0;
-        const char *s;
         char **ret = NULL;
 
         assert(bus);
@@ -662,36 +694,11 @@ static int list_dependencies_get_dependencies(sd_bus *bus, const char *name, cha
         assert(deps);
 
         path = unit_dbus_path_from_name(name);
-        if (path == NULL) {
-                r = -EINVAL;
-                goto finish;
-        }
+        if (path == NULL)
+                return -EINVAL;
 
-        r = sd_bus_get_property(bus,
-                                "org.freedesktop.systemd1",
-                                path,
-                                "org.freedesktop.systemd1.Unit",
-                                "After",
-                                &error,
-                                &reply,
-                                "as");
-        if (r < 0) {
-                log_error("Failed to parse reply: %s", bus_error_message(&error, -r));
-                goto finish;
-        }
+        r = bus_get_unit_property_strv(bus, path, "After", &ret);
 
-        r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "s");
-        if (r < 0)
-            goto finish;
-
-        while ((r = sd_bus_message_read(reply, "s", &s)) > 0) {
-                r = strv_extend(&ret, s);
-                if (r < 0) {
-                        log_oom();
-                        goto finish;
-                }
-        }
-finish:
         if (r < 0)
                 strv_free(ret);
         else
@@ -929,10 +936,7 @@ static int analyze_time(sd_bus *bus) {
 }
 
 static int graph_one_property(sd_bus *bus, const struct unit_info *u, const char* prop, const char *color, char* patterns[]) {
-        _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
-        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_strv_free_ char **units = NULL;
-        const char *s;
         char **unit;
         int r;
 
@@ -940,31 +944,11 @@ static int graph_one_property(sd_bus *bus, const struct unit_info *u, const char
         assert(prop);
         assert(color);
 
-        r = sd_bus_get_property(bus,
-                                "org.freedesktop.systemd1",
-                                u->unit_path,
-                                "org.freedesktop.systemd1.Unit",
-                                prop,
-                                &error,
-                                &reply,
-                                "as");
+        r = bus_get_unit_property_strv(bus, u->unit_path, prop, &units);
         if (r < 0) {
-            log_error("Failed to parse reply: %s", bus_error_message(&error, -r));
             return -r;
         }
 
-        r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "s");
-        if (r < 0)
-            return -r;
-
-        while ((r = sd_bus_message_read(reply, "s", &s)) > 0) {
-                r = strv_extend(&units, s);
-                if (r < 0) {
-                        log_oom();
-                        return -r;
-                }
-        }
-
         STRV_FOREACH(unit, units) {
                 char **p;
                 bool match_found;

commit a936124f7ac441b7b32ea9f04fae02a573dbd954
Author: Thomas Hindoe Paaboel Andersen <phomes at gmail.com>
Date:   Thu Oct 31 23:08:16 2013 +0100

    analyze: use sd_bus_get_propery_trivial and indentation

diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 35778ea..144e821 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -118,30 +118,23 @@ static void pager_open_if_enabled(void) {
 }
 
 static int bus_get_uint64_property(sd_bus *bus, const char *path, const char *interface, const char *property, uint64_t *val) {
-        _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         int r;
 
-        r = sd_bus_get_property(bus,
-                                "org.freedesktop.systemd1",
-                                path,
-                                interface,
-                                property,
-                                &error,
-                                &reply,
-                                "t");
+        r = sd_bus_get_property_trivial(
+                        bus,
+                        "org.freedesktop.systemd1",
+                        path,
+                        interface,
+                        property,
+                        &error,
+                        't', val);
 
         if (r < 0) {
                 log_error("Failed to parse reply: %s", bus_error_message(&error, -r));
                 return r;
         }
 
-        r = sd_bus_message_read(reply, "t", val);
-        if (r < 0) {
-                log_error("Failed to parse reply.");
-                return r;
-        }
-
         return 0;
 }
 
@@ -210,14 +203,15 @@ static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
         struct unit_times *unit_times = NULL;
         struct unit_info u;
 
-        r = sd_bus_call_method(bus,
-                               "org.freedesktop.systemd1",
-                               "/org/freedesktop/systemd1",
-                               "org.freedesktop.systemd1.Manager",
-                               "ListUnits",
-                               &error,
-                               &reply,
-                               "");
+        r = sd_bus_call_method(
+                        bus,
+                       "org.freedesktop.systemd1",
+                       "/org/freedesktop/systemd1",
+                       "org.freedesktop.systemd1.Manager",
+                       "ListUnits",
+                       &error,
+                       &reply,
+                       "");
         if (r < 0) {
             log_error("Failed to parse reply: %s", bus_error_message(&error, -r));
             goto fail;
@@ -821,14 +815,15 @@ static int list_dependencies(sd_bus *bus, const char *name) {
         if (path == NULL)
                 return -EINVAL;
 
-        r = sd_bus_get_property(bus,
-                                "org.freedesktop.systemd1",
-                                path,
-                                "org.freedesktop.systemd1.Unit",
-                                "Id",
-                                &error,
-                                &reply,
-                                "s");
+        r = sd_bus_get_property(
+                        bus,
+                        "org.freedesktop.systemd1",
+                        path,
+                        "org.freedesktop.systemd1.Unit",
+                        "Id",
+                        &error,
+                        &reply,
+                        "s");
         if (r < 0) {
                 log_error("Failed to parse reply: %s", bus_error_message(&error, -r));
                 return r;
@@ -1060,14 +1055,15 @@ static int dot(sd_bus *bus, char* patterns[]) {
         int r;
         struct unit_info u;
 
-        r = sd_bus_call_method(bus,
-                               "org.freedesktop.systemd1",
-                               "/org/freedesktop/systemd1",
-                               "org.freedesktop.systemd1.Manager",
-                               "ListUnits",
-                               &error,
-                               &reply,
-                               "");
+        r = sd_bus_call_method(
+                        bus,
+                       "org.freedesktop.systemd1",
+                       "/org/freedesktop/systemd1",
+                       "org.freedesktop.systemd1.Manager",
+                       "ListUnits",
+                       &error,
+                       &reply,
+                       "");
         if (r < 0) {
             log_error("Failed to parse reply: %s", bus_error_message(&error, -r));
             return r;
@@ -1112,14 +1108,15 @@ static int dump(sd_bus *bus, char **args) {
 
         pager_open_if_enabled();
 
-        r = sd_bus_call_method(bus,
-                               "org.freedesktop.systemd1",
-                               "/org/freedesktop/systemd1",
-                               "org.freedesktop.systemd1.Manager",
-                               "Dump",
-                               &error,
-                               &reply,
-                               "");
+        r = sd_bus_call_method(
+                        bus,
+                       "org.freedesktop.systemd1",
+                       "/org/freedesktop/systemd1",
+                       "org.freedesktop.systemd1.Manager",
+                       "Dump",
+                       &error,
+                       &reply,
+                       "");
         if (r < 0) {
             log_error("Failed to parse reply: %s", bus_error_message(&error, -r));
             return r;
@@ -1150,14 +1147,15 @@ static int set_log_level(sd_bus *bus, char **args) {
 
         value = args[0];
 
-        r = sd_bus_set_property(bus,
-                                "org.freedesktop.systemd1",
-                                "/org/freedesktop/systemd1",
-                                "org.freedesktop.systemd1.Manager",
-                                "LogLevel",
-                                &error,
-                                "s",
-                                value);
+        r = sd_bus_set_property(
+                        bus,
+                        "org.freedesktop.systemd1",
+                        "/org/freedesktop/systemd1",
+                        "org.freedesktop.systemd1.Manager",
+                        "LogLevel",
+                        &error,
+                        "s",
+                        value);
         if (r < 0) {
                 log_error("Failed to issue method call: %s", bus_error_message(&error, -r));
                 return -EIO;

commit 0068027e86d2c35f79a700a6ef5c06c56c528baa
Author: Thomas Hindoe Paaboel Andersen <phomes at gmail.com>
Date:   Thu Oct 31 22:02:29 2013 +0100

    timedatectl: remove unused variable

diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 7054a02..b63f1f5 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -191,7 +191,6 @@ static void print_status_info(StatusInfo *i) {
 }
 
 static int get_timedate_property_bool(sd_bus *bus, const char *name, bool *target) {
-        _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         int r, b;
 
@@ -215,7 +214,6 @@ static int get_timedate_property_bool(sd_bus *bus, const char *name, bool *targe
 }
 
 static int get_timedate_property_usec(sd_bus *bus, const char *name, usec_t *target) {
-        _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         int r;
 



More information about the systemd-commits mailing list