]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: make list-dependencies take multiple arguments 15013/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 4 Mar 2020 08:55:29 +0000 (09:55 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 5 Mar 2020 07:27:58 +0000 (08:27 +0100)
Other similar commands do, no reason not to do this here too.

man/systemctl.xml
src/systemctl/systemctl.c

index ceec7b0479d4c04492513ec403b4ea1cb389d920..e8d5f9f4d8e2b16cfb9e2b3efeb08887974b1121 100644 (file)
@@ -507,17 +507,17 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
         <varlistentry>
           <term>
             <command>list-dependencies</command>
-            <optional><replaceable>UNIT</replaceable></optional>
+            <optional><replaceable>UNIT</replaceable>...</optional>
           </term>
 
           <listitem>
             <para>Shows units required and wanted by the specified
-            unit. This recursively lists units following the
+            units. This recursively lists units following the
             <varname>Requires=</varname>,
             <varname>Requisite=</varname>,
             <varname>ConsistsOf=</varname>,
             <varname>Wants=</varname>, <varname>BindsTo=</varname>
-            dependencies. If no unit is specified,
+            dependencies. If no units are specified,
             <filename>default.target</filename> is implied.</para>
 
             <para>By default, only target units are recursively
index e02677d54168e5a21a4c7c5bb3a0582bbe33c4ac..146e2263f3b5c6fe1b53fb834db3ff8b6ebbd936 100644 (file)
@@ -1788,30 +1788,39 @@ static int list_dependencies_one(
 }
 
 static int list_dependencies(int argc, char *argv[], void *userdata) {
-        _cleanup_strv_free_ char **units = NULL;
-        _cleanup_free_ char *unit = NULL;
-        const char *u;
+        _cleanup_strv_free_ char **units = NULL, **done = NULL;
+        char **u, **patterns;
         sd_bus *bus;
         int r;
 
-        if (argv[1]) {
-                r = unit_name_mangle(argv[1], arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, &unit);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to mangle unit name: %m");
-
-                u = unit;
-        } else
-                u = SPECIAL_DEFAULT_TARGET;
-
         r = acquire_bus(BUS_MANAGER, &bus);
         if (r < 0)
                 return r;
 
+        patterns = strv_skip(argv, 1);
+        if (strv_isempty(patterns)) {
+                units = strv_new(SPECIAL_DEFAULT_TARGET);
+                if (!units)
+                        return log_oom();
+        } else {
+                r = expand_names(bus, patterns, NULL, &units, NULL);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to expand names: %m");
+        }
+
         (void) pager_open(arg_pager_flags);
 
-        puts(u);
+        STRV_FOREACH(u, units) {
+                if (u != units)
+                        puts("");
+
+                puts(*u);
+                r = list_dependencies_one(bus, *u, 0, &done, 0);
+                if (r < 0)
+                        return r;
+        }
 
-        return list_dependencies_one(bus, u, 0, &units, 0);
+        return 0;
 }
 
 struct machine_info {
@@ -7817,9 +7826,9 @@ static int systemctl_help(void) {
                "  help PATTERN...|PID...              Show manual for one or more units\n"
                "  reset-failed [PATTERN...]           Reset failed state for all, one, or more\n"
                "                                      units\n"
-               "  list-dependencies [UNIT]            Recursively show units which are required\n"
-               "                                      or wanted by this unit or by which this\n"
-               "                                      unit is required or wanted"
+               "  list-dependencies [UNIT...]         Recursively show units which are required\n"
+               "                                      or wanted by the units or by which those\n"
+               "                                      units are required or wanted"
                "\n%3$sUnit File Commands:%4$s\n"
                "  list-unit-files [PATTERN...]        List installed unit files\n"
                "  enable [UNIT...|PATH...]            Enable one or more unit files\n"
@@ -9118,7 +9127,7 @@ static int systemctl_main(int argc, char *argv[]) {
                 { "link",                  2,        VERB_ANY, 0,                enable_unit             },
                 { "revert",                2,        VERB_ANY, 0,                enable_unit             },
                 { "switch-root",           2,        VERB_ANY, VERB_ONLINE_ONLY, switch_root             },
-                { "list-dependencies",     VERB_ANY, 2,        VERB_ONLINE_ONLY, list_dependencies       },
+                { "list-dependencies",     VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, list_dependencies       },
                 { "set-default",           2,        2,        0,                set_default             },
                 { "get-default",           VERB_ANY, 1,        0,                get_default             },
                 { "set-property",          3,        VERB_ANY, VERB_ONLINE_ONLY, set_property            },