From: Zbigniew Jędrzejewski-Szmek Date: Fri, 27 Apr 2018 10:50:07 +0000 (+0200) Subject: analyze: allow full paths for cat-config X-Git-Tag: v239~281^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=971f6ea5511a204165a7bc2f8da92f5a465dad57;p=thirdparty%2Fsystemd.git analyze: allow full paths for cat-config $ 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. --- diff --git a/man/systemd-analyze.xml b/man/systemd-analyze.xml index 1c435318719..0d2ccd7bfeb 100644 --- a/man/systemd-analyze.xml +++ b/man/systemd-analyze.xml @@ -82,7 +82,7 @@ systemd-analyze OPTIONS cat-config - NAME + NAME|PATH systemd-analyze @@ -190,7 +190,11 @@ to systemctl cat, 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. + precedence. Each argument must be either an absolute path including + the prefix (such as /etc/systemd/logind.conf or + /usr/lib/systemd/logind.conf), or a name + relative to the prefix (such as systemd/logind.conf). + Showing logind configuration diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index b6036acf1c9..ea51453d40d 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -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; }