X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsystemctl%2Fsystemctl.c;h=852c4d1a860d55f8c5d7da01b4525f17c5041719;hp=442179d34049c89e6c7610376c0b6e3a431f7ef5;hb=540e7dbe9edeb7a309a89c51f22d27e3a7cd6390;hpb=55c0b89c575fcb2c075286d444ed4fb1cf8c8563 diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 442179d34..852c4d1a8 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,10 +759,7 @@ 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; assert(bus); assert(name); @@ -822,15 +818,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) { @@ -843,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); } } @@ -914,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) { @@ -5310,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;