]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: add --root option for cat-config
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Apr 2018 06:55:16 +0000 (08:55 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Apr 2018 08:06:24 +0000 (10:06 +0200)
man/systemd-analyze.xml
src/analyze/analyze.c
src/basic/conf-files.c
src/basic/conf-files.h

index 70f87f47862bcf7711e256327ce797018b17950d..1c435318719065cca57ab423565523dd772ee32b 100644 (file)
@@ -367,6 +367,13 @@ NAutoVTs=8
         generators enabled will generally result in some warnings.</para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>--root=<replaceable>PATH</replaceable></option></term>
+
+        <listitem><para>With <command>cat-files</command>, show config files underneath
+        the specified root path <replaceable>PATH</replaceable>.</para></listitem>
+      </varlistentry>
+
       <xi:include href="user-system-options.xml" xpointer="host" />
       <xi:include href="user-system-options.xml" xpointer="machine" />
 
index 0b0925d18c2cad9bd0f9afe275ef9ba672834fed..19e6e83c6ffde191d5fd0b86e6f62fae3eaa43d4 100644 (file)
@@ -72,6 +72,7 @@ static const char *arg_host = NULL;
 static UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
 static bool arg_man = true;
 static bool arg_generators = false;
+static const char *arg_root = NULL;
 
 struct boot_times {
         usec_t firmware_time;
@@ -1329,7 +1330,7 @@ static int cat_config(int argc, char *argv[], void *userdata) {
                         return -EINVAL;
                 }
 
-                r = conf_files_cat(*arg);
+                r = conf_files_cat(arg_root, *arg);
                 if (r < 0)
                         return r;
         }
@@ -1688,6 +1689,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_VERSION = 0x100,
                 ARG_ORDER,
                 ARG_REQUIRE,
+                ARG_ROOT,
                 ARG_SYSTEM,
                 ARG_USER,
                 ARG_GLOBAL,
@@ -1704,6 +1706,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "version",      no_argument,       NULL, ARG_VERSION          },
                 { "order",        no_argument,       NULL, ARG_ORDER            },
                 { "require",      no_argument,       NULL, ARG_REQUIRE          },
+                { "root",         required_argument, NULL, ARG_ROOT             },
                 { "system",       no_argument,       NULL, ARG_SYSTEM           },
                 { "user",         no_argument,       NULL, ARG_USER             },
                 { "global",       no_argument,       NULL, ARG_GLOBAL           },
@@ -1732,6 +1735,10 @@ static int parse_argv(int argc, char *argv[]) {
                 case ARG_VERSION:
                         return version();
 
+                case ARG_ROOT:
+                        arg_root = optarg;
+                        break;
+
                 case ARG_SYSTEM:
                         arg_scope = UNIT_FILE_SYSTEM;
                         break;
@@ -1825,6 +1832,11 @@ static int parse_argv(int argc, char *argv[]) {
                 return -EINVAL;
         }
 
+        if (arg_root && !streq_ptr(argv[optind], "cat-config")) {
+                log_error("Option --root is only supported for cat-config right now.");
+                return -EINVAL;
+        }
+
         return 1; /* work to do */
 }
 
index 29a85c018a86cd4c57bca78abc1b1d6049c09c6c..00e4629668310e2b3a35090c27afcea8755a622f 100644 (file)
@@ -294,8 +294,9 @@ int conf_files_list_with_replacement(
         return 0;
 }
 
-int conf_files_cat(const char *name) {
+int conf_files_cat(const char *root, const char *name) {
         _cleanup_strv_free_ char **dirs = NULL, **files = NULL;
+        _cleanup_free_ char *path = NULL;
         const char *dir;
         char **t;
         int r;
@@ -307,19 +308,21 @@ int conf_files_cat(const char *name) {
                         return log_error("Failed to build directory list: %m");
         }
 
-        r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char* const*) dirs);
+        r = conf_files_list_strv(&files, ".conf", root, 0, (const char* const*) dirs);
         if (r < 0)
                 return log_error_errno(r, "Failed to query file list: %m");
 
-        name = strjoina("/etc/", name);
+        path = path_join(root, "/etc", name);
+        if (!path)
+                return log_oom();
 
         if (DEBUG_LOGGING) {
                 log_debug("Looking for configuration in:");
-                log_debug("   %s", name);
+                log_debug("   %s", path);
                 STRV_FOREACH(t, dirs)
                         log_debug("   %s/*.conf", *t);
         }
 
         /* show */
-        return cat_files(name, files, CAT_FLAGS_MAIN_FILE_OPTIONAL);
+        return cat_files(path, files, CAT_FLAGS_MAIN_FILE_OPTIONAL);
 }
index 7eb8739ee135b08e358c9090d92f7cf6b9f4d85a..2dd1b272caa8130e551079856a277d279540a65a 100644 (file)
@@ -23,4 +23,4 @@ int conf_files_list_with_replacement(
                 const char *replacement,
                 char ***files,
                 char **replace_file);
-int conf_files_cat(const char *name);
+int conf_files_cat(const char *root, const char *name);