]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: allow full paths for cat-config
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Apr 2018 10:50:07 +0000 (12:50 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 7 May 2018 16:17:36 +0000 (18:17 +0200)
$ systemd-analyze cat-config systemd/logind.conf
$ systemd-analyze cat-config /etc/systemd/logind.conf
$ systemd-analyze cat-config /usr/lib/systemd/logind.conf
are all equvalent,
$ systemd-analyze cat-config /var/systemd/logind.conf
is an error.

man/systemd-analyze.xml
src/analyze/analyze.c

index 1c435318719065cca57ab423565523dd772ee32b..0d2ccd7bfeb68cdd57210a78a3abe31196ba7527 100644 (file)
@@ -82,7 +82,7 @@
       <command>systemd-analyze</command>
       <arg choice="opt" rep="repeat">OPTIONS</arg>
       <arg choice="plain">cat-config</arg>
-      <arg choice="plain" rep="repeat"><replaceable>NAME</replaceable></arg>
+      <arg choice="plain" rep="repeat"><replaceable>NAME</replaceable>|<replaceable>PATH</replaceable></arg>
     </cmdsynopsis>
     <cmdsynopsis>
       <command>systemd-analyze</command>
     to <command>systemctl cat</command>, but operates on config files.
     It will copy the contents of a config file and any drop-ins to standard
     output, using the usual systemd set of directories and rules for
-    precedence.</para>
+    precedence. Each argument must be either an absolute path including
+    the prefix (such as <filename>/etc/systemd/logind.conf</filename> or
+    <filename>/usr/lib/systemd/logind.conf</filename>), or a name
+    relative to the prefix (such as <filename>systemd/logind.conf</filename>).
+    </para>
 
     <example>
       <title>Showing logind configuration</title>
index b6036acf1c9fe6cb4ca6647b00d58340cf227fcf..ea51453d40dcbdbb7aa433371be6dd6cb992c221 100644 (file)
@@ -19,6 +19,7 @@
 #include "bus-unit-util.h"
 #include "bus-util.h"
 #include "calendarspec.h"
+#include "def.h"
 #include "conf-files.h"
 #include "glob-util.h"
 #include "hashmap.h"
@@ -1322,6 +1323,8 @@ static int cat_config(int argc, char *argv[], void *userdata) {
         (void) pager_open(arg_no_pager, false);
 
         STRV_FOREACH(arg, argv + 1) {
+                const char *t = NULL;
+
                 if (arg != argv + 1)
                         printf("%s%*s%s\n\n",
                                ansi_underline(),
@@ -1329,11 +1332,22 @@ static int cat_config(int argc, char *argv[], void *userdata) {
                                ansi_normal());
 
                 if (path_is_absolute(*arg)) {
-                        log_error("Arguments must be config file names (relative to /etc/");
-                        return -EINVAL;
-                }
+                        const char *dir;
+
+                        NULSTR_FOREACH(dir, CONF_PATHS_NULSTR("")) {
+                                t = path_startswith(*arg, dir);
+                                if (t)
+                                        break;
+                        }
+
+                        if (!t) {
+                                log_error("Path %s does not start with any known prefix.", *arg);
+                                return -EINVAL;
+                        }
+                } else
+                        t = *arg;
 
-                r = conf_files_cat(arg_root, *arg);
+                r = conf_files_cat(arg_root, t);
                 if (r < 0)
                         return r;
         }