[systemd-commits] 6 commits - man/systemctl.xml src/shared src/systemctl

Lennart Poettering lennart at kemper.freedesktop.org
Thu Jan 17 15:55:10 PST 2013


 man/systemctl.xml         |   14 +++++----
 src/shared/strv.c         |   17 +++++++++--
 src/systemctl/systemctl.c |   68 +++++++++++++++++++---------------------------
 3 files changed, 51 insertions(+), 48 deletions(-)

New commits:
commit d54110d11d5ea3381cfdd129356b91669b547216
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 18 00:53:06 2013 +0100

    systemctl: it's probably a good idea not to alter return parameters if we fail
    
    We generally follow the rule not to touch return values unless we
    succeed, so for the sake of uniformity do the same here.

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index de1a022..cac7067 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -842,8 +842,9 @@ static int list_dependencies_get_dependencies(DBusConnection *bus, const char *n
         }
 finish:
         if (r < 0)
-                strv_freep(&ret);
-        *deps = ret;
+                strv_free(ret);
+        else
+                *deps = ret;
         return r;
 }
 

commit 52a2ab41e029728ef0a4303d7aafc9d47f116004
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 18 00:52:45 2013 +0100

    systemctl: no need to check this explicitly, we already checked it a few lines up anyway, so let's just assert

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 852c4d1..de1a022 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -797,12 +797,7 @@ static int list_dependencies_get_dependencies(DBusConnection *bus, const char *n
         while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
                 const char *prop;
 
-                if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_DICT_ENTRY) {
-                        log_error("Failed to parse reply.");
-                        r = -EIO;
-                        goto finish;
-                }
-
+                assert(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_DICT_ENTRY);
                 dbus_message_iter_recurse(&sub, &sub2);
 
                 if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &prop, true) < 0) {

commit 540e7dbe9edeb7a309a89c51f22d27e3a7cd6390
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 18 00:51:46 2013 +0100

    systemctl: we can make this faster and shorten it a bit with strv_extend()
    
    Now that strv_extend() is not so slow anymore, we can make use of it, to
    shorten our code a bit.

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 3568543..852c4d1 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -760,7 +760,6 @@ static int list_dependencies_get_dependencies(DBusConnection *bus, const char *n
 
         int r = 0;
         char **ret = NULL;
-        char **c;
 
         assert(bus);
         assert(name);
@@ -834,13 +833,13 @@ static int list_dependencies_get_dependencies(DBusConnection *bus, const char *n
 
                                         assert(dbus_message_iter_get_arg_type(&sub4) == DBUS_TYPE_STRING);
                                         dbus_message_iter_get_basic(&sub4, &s);
-                                        c = strv_append(ret, s);
-                                        if (c == NULL) {
-                                                r = log_oom();
+
+                                        r = strv_extend(&ret, s);
+                                        if (r < 0) {
+                                                log_oom();
                                                 goto finish;
                                         }
-                                        strv_free(ret);
-                                        ret = c;
+
                                         dbus_message_iter_next(&sub4);
                                 }
                         }

commit 82dde599ed2b8aa4877900d84e7a2ddc31ef8da2
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 18 00:47:19 2013 +0100

    strv: make strv_extend() smarter

diff --git a/src/shared/strv.c b/src/shared/strv.c
index aed45d2..2d556f4 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -372,15 +372,26 @@ fail:
 
 int strv_extend(char ***l, const char *value) {
         char **c;
+        char *v;
+        unsigned n;
 
         if (!value)
                 return 0;
 
-        c = strv_append(*l, value);
-        if (!c)
+        v = strdup(value);
+        if (!v)
                 return -ENOMEM;
 
-        strv_free(*l);
+        n = strv_length(*l);
+        c = realloc(*l, sizeof(char*) * (n + 2));
+        if (!c) {
+                free(v);
+                return -ENOMEM;
+        }
+
+        c[n] = v;
+        c[n+1] = NULL;
+
         *l = c;
         return 0;
 }

commit e31165b26212b45e135fd4cd7d618a081d50bd28
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 18 00:36:12 2013 +0100

    systemctl: make list-dependencies default to default.target

diff --git a/man/systemctl.xml b/man/systemctl.xml
index f223383..60a0f40 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -999,12 +999,14 @@
                         <varlistentry>
                                 <term><command>list-dependencies [NAME]</command></term>
 
-                                <listitem><para>
-                                Shows required and wanted units of given unit.
-                                Target units are recursively expanded.
-                                When <option>--all</option> is passed
-                                dependency tree is generated for all
-                                subsidiary units.</para>
+                                <listitem><para> Shows required and
+                                wanted units of the specified unit. If
+                                no unit is specified
+                                <filename>default.target</filename> is
+                                implied. Target units are recursively
+                                expanded.  When <option>--all</option>
+                                is passed all other units aare
+                                recursively expanded as well.</para>
                                 </listitem>
                         </varlistentry>
                         <varlistentry>
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 003b706..3568543 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -905,20 +905,24 @@ finish:
 }
 
 static int list_dependencies(DBusConnection *bus, char **args) {
-        int r = 0;
         _cleanup_free_ char *unit = NULL;
+        const char *u;
 
         assert(bus);
-        assert(args[1]);
 
-        unit = unit_name_mangle(args[1]);
-        if (!unit)
-                return log_oom();
+        if (args[1]) {
+                unit = unit_name_mangle(args[1]);
+                if (!unit)
+                        return log_oom();
+                u = unit;
+        } else
+                u = SPECIAL_DEFAULT_TARGET;
 
         pager_open_if_enabled();
-        printf("%s\n", unit);
-        r = list_dependencies_one(bus, unit, 0, NULL, 0);
-        return r;
+
+        puts(u);
+
+        return list_dependencies_one(bus, u, 0, NULL, 0);
 }
 
 static int dot_one_property(const char *name, const char *prop, DBusMessageIter *iter) {
@@ -5301,7 +5305,7 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
                 { "unmask",                MORE,  2, enable_unit       },
                 { "link",                  MORE,  2, enable_unit       },
                 { "switch-root",           MORE,  2, switch_root       },
-                { "list-dependencies",     EQUAL, 2, list_dependencies },
+                { "list-dependencies",     LESS,  2, list_dependencies },
         };
 
         int left;

commit e608b38a87fde7fd0b882c96ff235b26660ce074
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 18 00:29:47 2013 +0100

    systemctl: we can use nulstr_contains() for this lookup
    
    It's a bit easier to read...

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 442179d..003b706 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -745,13 +745,12 @@ static int list_dependencies_print(const char *name, int level, unsigned int bra
 }
 
 static int list_dependencies_get_dependencies(DBusConnection *bus, const char *name, char ***deps) {
-        static const char * const dependencies[] = {
-                "Requires",
-                "RequiresOverridable",
-                "Requisite",
-                "RequisiteOverridable",
-                "Wants"
-        };
+        static const char dependencies[] =
+                "Requires\0"
+                "RequiresOverridable\0"
+                "Requisite\0"
+                "RequisiteOverridable\0"
+                "Wants\0";
 
         _cleanup_free_ char *path;
         const char *interface = "org.freedesktop.systemd1.Unit";
@@ -760,8 +759,6 @@ static int list_dependencies_get_dependencies(DBusConnection *bus, const char *n
         DBusMessageIter iter, sub, sub2, sub3;
 
         int r = 0;
-        unsigned int i;
-
         char **ret = NULL;
         char **c;
 
@@ -822,15 +819,9 @@ static int list_dependencies_get_dependencies(DBusConnection *bus, const char *n
                 }
 
                 dbus_message_iter_recurse(&sub2, &sub3);
-
                 dbus_message_iter_next(&sub);
 
-                for (i = 0; i < ELEMENTSOF(dependencies); i++)
-                        if (streq(dependencies[i], prop)) {
-                                break;
-                        }
-
-                if (i == ELEMENTSOF(dependencies))
+                if (!nulstr_contains(dependencies, prop))
                         continue;
 
                 if (dbus_message_iter_get_arg_type(&sub3) == DBUS_TYPE_ARRAY) {



More information about the systemd-commits mailing list