]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: add unit-paths verb
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 9 Feb 2018 11:27:27 +0000 (12:27 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 9 Feb 2018 11:27:27 +0000 (12:27 +0100)
man/systemd-analyze.xml
src/analyze/analyze.c

index 526d5d19192982a20992e92df28bfdd4e1361ebc..97a9b2cca7821db745565004b78fc13887b9358c 100644 (file)
       <arg choice="opt" rep="repeat">OPTIONS</arg>
       <arg choice="plain">dump</arg>
     </cmdsynopsis>
+    <cmdsynopsis>
+      <command>systemd-analyze</command>
+      <arg choice="opt" rep="repeat">OPTIONS</arg>
+      <arg choice="plain">unit-paths</arg>
+    </cmdsynopsis>
     <cmdsynopsis>
       <command>systemd-analyze</command>
       <arg choice="opt" rep="repeat">OPTIONS</arg>
     state. Its format is subject to change without notice and should
     not be parsed by applications.</para>
 
+    <para><command>systemd-analyze unit-paths</command> outputs a list of all
+    directories from which unit files, <filename>.d</filename> overrides, and
+    <filename>.wants</filename>, <filename>.requires</filename> symlinks may be
+    loaded. Combine with <option>--user</option> to retrieve the list for the user
+    manager instance, and <option>--global</option> for the global configuration of
+    user manager instances. Note that this verb prints the list that is compiled into
+    <command>systemd-analyze</command> itself, and does not comunicate with the
+    running manager. Use
+    <programlisting>systemctl [--user] [--global] show -p UnitPath --value</programlisting>
+    to retrieve the actual list that the manager uses, with any empty directories
+    omitted.</para>
+
     <para><command>systemd-analyze log-level</command>
     prints the current log level of the <command>systemd</command> daemon.
     If an optional argument <replaceable>LEVEL</replaceable> is provided, then the command changes the current log
index 790c6578b46d7cc1daa5de7fdd7fddda56564fe1..0415bb38a17047fcc6ce6cf938fa368a925c4a36 100644 (file)
@@ -1416,6 +1416,21 @@ static int get_or_set_log_target(int argc, char *argv[], void *userdata) {
         return (argc == 1) ? get_log_target(argc, argv, userdata) : set_log_target(argc, argv, userdata);
 }
 
+static int dump_unit_paths(int argc, char *argv[], void *userdata) {
+        _cleanup_lookup_paths_free_ LookupPaths paths = {};
+        int r;
+        char **p;
+
+        r = lookup_paths_init(&paths, arg_scope, 0, NULL);
+        if (r < 0)
+                return log_error_errno(r, "lookup_paths_init() failed: %m");
+
+        STRV_FOREACH(p, paths.search_path)
+                puts(*p);
+
+        return 0;
+}
+
 #if HAVE_SECCOMP
 static void dump_syscall_filter(const SyscallFilterSet *set) {
         const char *syscall;
@@ -1620,6 +1635,7 @@ static int help(int argc, char *argv[], void *userdata) {
                "  log-level [LEVEL]        Get/set logging threshold for manager\n"
                "  log-target [TARGET]      Get/set logging target for manager\n"
                "  dump                     Output state serialization of service manager\n"
+               "  unit-paths               List load directories for units\n"
                "  syscall-filter [NAME...] Print list of syscalls in seccomp filter\n"
                "  verify FILE...           Check unit files for correctness\n"
                "  calendar SPEC...         Validate repetitive calendar time events\n"
@@ -1769,6 +1785,12 @@ static int parse_argv(int argc, char *argv[]) {
                         assert_not_reached("Unhandled option code.");
                 }
 
+        if (arg_scope == UNIT_FILE_GLOBAL &&
+            !STR_IN_SET(argv[optind] ?: "time", "dot", "unit-paths", "verify")) {
+                log_error("Option --global only makes sense with verbs dot, unit-paths, verify.");
+                return -EINVAL;
+        }
+
         return 1; /* work to do */
 }
 
@@ -1789,6 +1811,7 @@ int main(int argc, char *argv[]) {
                 { "set-log-target",    2,        2,        0,            set_log_target         },
                 { "get-log-target",    VERB_ANY, 1,        0,            get_log_target         },
                 { "dump",              VERB_ANY, 1,        0,            dump                   },
+                { "unit-paths",        1,        1,        0,            dump_unit_paths        },
                 { "syscall-filter",    VERB_ANY, VERB_ANY, 0,            dump_syscall_filters   },
                 { "verify",            2,        VERB_ANY, 0,            do_verify              },
                 { "calendar",          2,        VERB_ANY, 0,            test_calendar          },