summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-08 17:33:25 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-30 14:01:46 +0200
commite67cd21d7d174cdafd12beca4cfb6e19e61f6fb5 (patch)
treee7a175f576e1fc8d7a7847b26f1d69568828f530 /src
parente8630e695232bdfcd16b55f3faafb4329c961104 (diff)
downloadsystemd-e67cd21d7d174cdafd12beca4cfb6e19e61f6fb5.tar.gz
analyze: add "unit-files" to dump the unit fragment map
I'm not convinced that this is useful enough to be included... But it is certainly nice when debugging.
Diffstat (limited to 'src')
-rw-r--r--src/analyze/analyze.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 92727974d6..a28b27a3a0 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -1545,6 +1545,53 @@ 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 bool strv_fnmatch_strv_or_empty(char* const* patterns, char **strv, int flags) {
+ char **s;
+ STRV_FOREACH(s, strv)
+ if (strv_fnmatch_or_empty(patterns, *s, flags))
+ return true;
+
+ return false;
+}
+
+static int do_unit_files(int argc, char *argv[], void *userdata) {
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
+ _cleanup_hashmap_free_ Hashmap *unit_ids = NULL;
+ _cleanup_hashmap_free_ Hashmap *unit_names = NULL;
+ char **patterns = strv_skip(argv, 1);
+ Iterator i;
+ const char *k, *dst;
+ char **v;
+ int r;
+
+ r = lookup_paths_init(&lp, arg_scope, 0, NULL);
+ if (r < 0)
+ return log_error_errno(r, "lookup_paths_init() failed: %m");
+
+ r = unit_file_build_name_map(&lp, &unit_ids, &unit_names, NULL);
+ if (r < 0)
+ return log_error_errno(r, "unit_file_build_name_map() failed: %m");
+
+ HASHMAP_FOREACH_KEY(dst, k, unit_ids, i) {
+ if (!strv_fnmatch_or_empty(patterns, k, FNM_NOESCAPE) &&
+ !strv_fnmatch_or_empty(patterns, dst, FNM_NOESCAPE))
+ continue;
+
+ printf("ids: %s → %s\n", k, dst);
+ }
+
+ HASHMAP_FOREACH_KEY(v, k, unit_names, i) {
+ if (!strv_fnmatch_or_empty(patterns, k, FNM_NOESCAPE) &&
+ !strv_fnmatch_strv_or_empty(patterns, v, FNM_NOESCAPE))
+ continue;
+
+ _cleanup_free_ char *j = strv_join(v, ", ");
+ printf("aliases: %s ← %s\n", k, j);
+ }
+
+ return 0;
+}
+
static int dump_unit_paths(int argc, char *argv[], void *userdata) {
_cleanup_(lookup_paths_free) LookupPaths paths = {};
int r;
@@ -2164,6 +2211,7 @@ static int help(int argc, char *argv[], void *userdata) {
" log-target [TARGET] Get/set logging target for manager\n"
" dump Output state serialization of service manager\n"
" cat-config Show configuration file and drop-ins\n"
+ " unit-files List files and symlinks for units\n"
" unit-paths List load directories for units\n"
" syscall-filter [NAME...] Print list of syscalls in seccomp filter\n"
" condition CONDITION... Evaluate conditions and asserts\n"
@@ -2365,8 +2413,10 @@ static int run(int argc, char *argv[]) {
{ "get-log-level", VERB_ANY, 1, 0, get_log_level },
{ "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 },
{ "cat-config", 2, VERB_ANY, 0, cat_config },
+ { "unit-files", VERB_ANY, VERB_ANY, 0, do_unit_files },
{ "unit-paths", 1, 1, 0, dump_unit_paths },
{ "syscall-filter", VERB_ANY, VERB_ANY, 0, dump_syscall_filters },
{ "condition", 2, VERB_ANY, 0, do_condition },