diff options
Diffstat (limited to 'src/analyze')
-rw-r--r-- | src/analyze/analyze-dump.c | 43 | ||||
-rw-r--r-- | src/analyze/analyze.c | 4 |
2 files changed, 45 insertions, 2 deletions
diff --git a/src/analyze/analyze-dump.c b/src/analyze/analyze-dump.c index 448ce09bd7..220218e2fe 100644 --- a/src/analyze/analyze-dump.c +++ b/src/analyze/analyze-dump.c @@ -29,6 +29,46 @@ static int dump_fallback(sd_bus *bus) { return 0; } +static int dump_patterns(sd_bus *bus, char **patterns) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL, *m = NULL; + _cleanup_strv_free_ char **mangled = NULL; + const char *text; + int r; + + r = bus_message_new_method_call(bus, &m, bus_systemd_mgr, "DumpPatterns"); + if (r < 0) + return bus_log_create_error(r); + + STRV_FOREACH(pattern, patterns) { + char *t; + + r = unit_name_mangle_with_suffix(*pattern, NULL, UNIT_NAME_MANGLE_GLOB, ".service", &t); + if (r < 0) + return log_error_errno(r, "Failed to mangle name: %m"); + + r = strv_consume(&mangled, t); + if (r < 0) + return log_oom(); + } + + r = sd_bus_message_append_strv(m, mangled); + if (r < 0) + return bus_log_create_error(r); + + r = sd_bus_call(bus, m, 0, &error, &reply); + if (r < 0) + return log_error_errno(r, "Failed to issue method call DumpPatterns: %s", + bus_error_message(&error, r)); + + r = sd_bus_message_read(reply, "s", &text); + if (r < 0) + return bus_log_parse_error(r); + + fputs(text, stdout); + return r; +} + int verb_dump(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; @@ -42,6 +82,9 @@ int verb_dump(int argc, char *argv[], void *userdata) { pager_open(arg_pager_flags); + if (argc > 1) + return dump_patterns(bus, strv_skip(argv, 1)); + if (!sd_bus_can_send(bus, SD_BUS_TYPE_UNIX_FD)) return dump_fallback(bus); diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 6215f50fac..4a276f66ba 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -190,7 +190,7 @@ static int help(int argc, char *argv[], void *userdata) { " plot Output SVG graphic showing service\n" " initialization\n" " dot [UNIT...] Output dependency graph in %s format\n" - " dump Output state serialization of service\n" + " dump [PATTERN...] Output state serialization of service\n" " manager\n" " cat-config Show configuration file and drop-ins\n" " unit-files List files and symlinks for units\n" @@ -557,7 +557,7 @@ static int run(int argc, char *argv[]) { { "get-log-target", VERB_ANY, 1, 0, verb_log_control }, { "service-watchdogs", VERB_ANY, 2, 0, verb_service_watchdogs }, /* ↑ … until here ↑ */ - { "dump", VERB_ANY, 1, 0, verb_dump }, + { "dump", VERB_ANY, VERB_ANY, 0, verb_dump }, { "cat-config", 2, VERB_ANY, 0, verb_cat_config }, { "unit-files", VERB_ANY, VERB_ANY, 0, verb_unit_files }, { "unit-paths", 1, 1, 0, verb_unit_paths }, |