chiark / gitweb /
systemctl: we can make this faster and shorten it a bit with strv_extend()
[elogind.git] / src / systemctl / systemctl.c
index 003b70647efa9fc3e24c27949a5b9f4a540ade60..852c4d1a860d55f8c5d7da01b4525f17c5041719 100644 (file)
@@ -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);
                                 }
                         }
@@ -905,20 +904,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 +5304,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;