From e3e45d4f82daa5cd85ba40dde9127df900096c0c Mon Sep 17 00:00:00 2001 From: Simon Peeters Date: Sat, 4 Jan 2014 02:35:27 +0100 Subject: strv: multiple cleanups - turn strv_merge into strv_extend_strv. appending strv b to the end of strv a instead of creating a new strv - strv_append: remove in favor of strv_extend and strv_push. - strv_remove: write slightly more elegant - strv_remove_prefix: remove unused function - strv_overlap: use strv_contains - strv_printf: STRV_FOREACH handles NULL correctly --- src/systemctl/systemctl.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/systemctl') diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 01a4489f4d..dd95df14e7 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -1327,7 +1327,7 @@ static int list_dependencies_one( char ***units, unsigned int branches) { - _cleanup_strv_free_ char **deps = NULL, **u; + _cleanup_strv_free_ char **deps = NULL; char **c; int r = 0; @@ -1335,8 +1335,8 @@ static int list_dependencies_one( assert(name); assert(units); - u = strv_append(*units, name); - if (!u) + r = strv_extend(units, name); + if (r < 0) return log_oom(); r = list_dependencies_get_dependencies(bus, name, &deps); @@ -1348,7 +1348,7 @@ static int list_dependencies_one( STRV_FOREACH(c, deps) { int state; - if (strv_contains(u, *c)) { + if (strv_contains(*units, *c)) { if (!arg_plain) { r = list_dependencies_print("...", level + 1, (branches << 1) | (c[1] == NULL ? 0 : 1), 1); if (r < 0) @@ -1368,17 +1368,14 @@ static int list_dependencies_one( return r; if (arg_all || unit_name_to_type(*c) == UNIT_TARGET) { - r = list_dependencies_one(bus, *c, level + 1, &u, (branches << 1) | (c[1] == NULL ? 0 : 1)); + r = list_dependencies_one(bus, *c, level + 1, units, (branches << 1) | (c[1] == NULL ? 0 : 1)); if (r < 0) return r; } } - if (arg_plain) { - strv_free(*units); - *units = u; - u = NULL; - } + if (!arg_plain) + strv_remove(*units, name); return 0; } -- cgit v1.2.3-54-g00ecf