]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: split out cat-config verb
authorLennart Poettering <lennart@poettering.net>
Mon, 21 Feb 2022 12:40:45 +0000 (13:40 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 21 Feb 2022 16:22:23 +0000 (17:22 +0100)
src/analyze/analyze-cat-config.c [new file with mode: 0644]
src/analyze/analyze-cat-config.h [new file with mode: 0644]
src/analyze/analyze.c
src/analyze/analyze.h
src/analyze/meson.build

diff --git a/src/analyze/analyze-cat-config.c b/src/analyze/analyze-cat-config.c
new file mode 100644 (file)
index 0000000..e7cc331
--- /dev/null
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "analyze.h"
+#include "analyze-cat-config.h"
+#include "conf-files.h"
+#include "def.h"
+#include "nulstr-util.h"
+#include "path-util.h"
+#include "pretty-print.h"
+#include "strv.h"
+
+int cat_config(int argc, char *argv[], void *userdata) {
+        char **arg, **list;
+        int r;
+
+        pager_open(arg_pager_flags);
+
+        list = strv_skip(argv, 1);
+        STRV_FOREACH(arg, list) {
+                const char *t = NULL;
+
+                if (arg != list)
+                        print_separator();
+
+                if (path_is_absolute(*arg)) {
+                        const char *dir;
+
+                        NULSTR_FOREACH(dir, CONF_PATHS_NULSTR("")) {
+                                t = path_startswith(*arg, dir);
+                                if (t)
+                                        break;
+                        }
+
+                        if (!t)
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                       "Path %s does not start with any known prefix.", *arg);
+                } else
+                        t = *arg;
+
+                r = conf_files_cat(arg_root, t);
+                if (r < 0)
+                        return r;
+        }
+
+        return 0;
+}
diff --git a/src/analyze/analyze-cat-config.h b/src/analyze/analyze-cat-config.h
new file mode 100644 (file)
index 0000000..8c16c2d
--- /dev/null
@@ -0,0 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+int cat_config(int argc, char *argv[], void *userdata);
index 90d1eb13495b060f1801b41ca988a73f4d0f7031..dc3bf9c17ec48e71b389551de3e554227c1b19f8 100644 (file)
@@ -16,6 +16,7 @@
 #include "analyze-blame.h"
 #include "analyze-calendar.h"
 #include "analyze-capability.h"
+#include "analyze-cat-config.h"
 #include "analyze-condition.h"
 #include "analyze-dot.h"
 #include "analyze-dump.h"
@@ -87,7 +88,7 @@ UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
 static RecursiveErrors arg_recursive_errors = RECURSIVE_ERRORS_YES;
 static bool arg_man = true;
 static bool arg_generators = false;
-static char *arg_root = NULL;
+char *arg_root = NULL;
 static char *arg_image = NULL;
 static char *arg_security_policy = NULL;
 static bool arg_offline = false;
@@ -434,42 +435,6 @@ static int analyze_time(int argc, char *argv[], void *userdata) {
         return 0;
 }
 
-static int cat_config(int argc, char *argv[], void *userdata) {
-        char **arg, **list;
-        int r;
-
-        pager_open(arg_pager_flags);
-
-        list = strv_skip(argv, 1);
-        STRV_FOREACH(arg, list) {
-                const char *t = NULL;
-
-                if (arg != list)
-                        print_separator();
-
-                if (path_is_absolute(*arg)) {
-                        const char *dir;
-
-                        NULSTR_FOREACH(dir, CONF_PATHS_NULSTR("")) {
-                                t = path_startswith(*arg, dir);
-                                if (t)
-                                        break;
-                        }
-
-                        if (!t)
-                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                                       "Path %s does not start with any known prefix.", *arg);
-                } else
-                        t = *arg;
-
-                r = conf_files_cat(arg_root, t);
-                if (r < 0)
-                        return r;
-        }
-
-        return 0;
-}
-
 static int verb_log_control(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
         int r;
index 97b43da0caf69dc2e85d2c03596b0c823325b583..7d4b0d408f7ef17bbe6b25a5765528c4df104af1 100644 (file)
@@ -20,6 +20,7 @@ extern PagerFlags arg_pager_flags;
 extern BusTransport arg_transport;
 extern const char *arg_host;
 extern UnitFileScope arg_scope;
+extern char *arg_root;
 extern unsigned arg_iterations;
 extern usec_t arg_base_time;
 extern bool arg_quiet;
index 7b4bf4eee7bdf6dbfdc609a111f2fd5ca0128352..3f7eb9522ee82522c5d1e3fd6b5fceda02dc4769 100644 (file)
@@ -7,6 +7,8 @@ systemd_analyze_sources = files('''
         analyze-calendar.h
         analyze-capability.c
         analyze-capability.h
+        analyze-cat-config.c
+        analyze-cat-config.h
         analyze-condition.c
         analyze-condition.h
         analyze-dot.c