1:255.16-alt1
[systemd_ALT.git] / src / analyze / analyze.c
blob021de65bdbfed64960d4db56a83def6f135ecedd
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /***
3 Copyright © 2013 Simon Peeters
4 ***/
6 #include <getopt.h>
7 #include <inttypes.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
12 #include "sd-bus.h"
14 #include "alloc-util.h"
15 #include "analyze.h"
16 #include "analyze-blame.h"
17 #include "analyze-calendar.h"
18 #include "analyze-capability.h"
19 #include "analyze-cat-config.h"
20 #include "analyze-compare-versions.h"
21 #include "analyze-condition.h"
22 #include "analyze-critical-chain.h"
23 #include "analyze-dot.h"
24 #include "analyze-dump.h"
25 #include "analyze-exit-status.h"
26 #include "analyze-fdstore.h"
27 #include "analyze-filesystems.h"
28 #include "analyze-inspect-elf.h"
29 #include "analyze-log-control.h"
30 #include "analyze-malloc.h"
31 #include "analyze-pcrs.h"
32 #include "analyze-plot.h"
33 #include "analyze-security.h"
34 #include "analyze-service-watchdogs.h"
35 #include "analyze-srk.h"
36 #include "analyze-syscall-filter.h"
37 #include "analyze-time.h"
38 #include "analyze-time-data.h"
39 #include "analyze-timespan.h"
40 #include "analyze-timestamp.h"
41 #include "analyze-unit-files.h"
42 #include "analyze-unit-paths.h"
43 #include "analyze-verify.h"
44 #include "analyze-image-policy.h"
45 #include "build.h"
46 #include "bus-error.h"
47 #include "bus-locator.h"
48 #include "bus-map-properties.h"
49 #include "bus-unit-util.h"
50 #include "calendarspec.h"
51 #include "cap-list.h"
52 #include "capability-util.h"
53 #include "conf-files.h"
54 #include "copy.h"
55 #include "constants.h"
56 #include "exit-status.h"
57 #include "extract-word.h"
58 #include "fd-util.h"
59 #include "fileio.h"
60 #include "filesystems.h"
61 #include "format-table.h"
62 #include "glob-util.h"
63 #include "hashmap.h"
64 #include "locale-util.h"
65 #include "log.h"
66 #include "main-func.h"
67 #include "mount-util.h"
68 #include "nulstr-util.h"
69 #include "pager.h"
70 #include "parse-argument.h"
71 #include "parse-util.h"
72 #include "path-util.h"
73 #include "pretty-print.h"
74 #include "rm-rf.h"
75 #if HAVE_SECCOMP
76 # include "seccomp-util.h"
77 #endif
78 #include "sort-util.h"
79 #include "special.h"
80 #include "stat-util.h"
81 #include "string-table.h"
82 #include "strv.h"
83 #include "strxcpyx.h"
84 #include "terminal-util.h"
85 #include "time-util.h"
86 #include "tmpfile-util.h"
87 #include "unit-name.h"
88 #include "verb-log-control.h"
89 #include "verbs.h"
91 DotMode arg_dot = DEP_ALL;
92 char **arg_dot_from_patterns = NULL, **arg_dot_to_patterns = NULL;
93 usec_t arg_fuzz = 0;
94 PagerFlags arg_pager_flags = 0;
95 CatFlags arg_cat_flags = 0;
96 BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
97 const char *arg_host = NULL;
98 RuntimeScope arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
99 RecursiveErrors arg_recursive_errors = _RECURSIVE_ERRORS_INVALID;
100 bool arg_man = true;
101 bool arg_generators = false;
102 char *arg_root = NULL;
103 static char *arg_image = NULL;
104 char *arg_security_policy = NULL;
105 bool arg_offline = false;
106 unsigned arg_threshold = 100;
107 unsigned arg_iterations = 1;
108 usec_t arg_base_time = USEC_INFINITY;
109 char *arg_unit = NULL;
110 JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
111 bool arg_quiet = false;
112 char *arg_profile = NULL;
113 bool arg_legend = true;
114 bool arg_table = false;
115 ImagePolicy *arg_image_policy = NULL;
117 STATIC_DESTRUCTOR_REGISTER(arg_dot_from_patterns, strv_freep);
118 STATIC_DESTRUCTOR_REGISTER(arg_dot_to_patterns, strv_freep);
119 STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
120 STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
121 STATIC_DESTRUCTOR_REGISTER(arg_security_policy, freep);
122 STATIC_DESTRUCTOR_REGISTER(arg_unit, freep);
123 STATIC_DESTRUCTOR_REGISTER(arg_profile, freep);
124 STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep);
126 int acquire_bus(sd_bus **bus, bool *use_full_bus) {
127 int r;
129 if (use_full_bus && *use_full_bus) {
130 r = bus_connect_transport(arg_transport, arg_host, arg_runtime_scope, bus);
131 if (IN_SET(r, 0, -EHOSTDOWN))
132 return r;
134 *use_full_bus = false;
137 return bus_connect_transport_systemd(arg_transport, arg_host, arg_runtime_scope, bus);
140 int bus_get_unit_property_strv(sd_bus *bus, const char *path, const char *property, char ***strv) {
141 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
142 int r;
144 assert(bus);
145 assert(path);
146 assert(property);
147 assert(strv);
149 r = sd_bus_get_property_strv(
150 bus,
151 "org.freedesktop.systemd1",
152 path,
153 "org.freedesktop.systemd1.Unit",
154 property,
155 &error,
156 strv);
157 if (r < 0)
158 return log_error_errno(r, "Failed to get unit property %s: %s", property, bus_error_message(&error, r));
160 return 0;
163 void time_parsing_hint(const char *p, bool calendar, bool timestamp, bool timespan) {
164 if (calendar && calendar_spec_from_string(p, NULL) >= 0)
165 log_notice("Hint: this expression is a valid calendar specification. "
166 "Use 'systemd-analyze calendar \"%s\"' instead?", p);
167 if (timestamp && parse_timestamp(p, NULL) >= 0)
168 log_notice("Hint: this expression is a valid timestamp. "
169 "Use 'systemd-analyze timestamp \"%s\"' instead?", p);
170 if (timespan && parse_time(p, NULL, USEC_PER_SEC) >= 0)
171 log_notice("Hint: this expression is a valid timespan. "
172 "Use 'systemd-analyze timespan \"%s\"' instead?", p);
175 int dump_fd_reply(sd_bus_message *message) {
176 int fd, r;
178 assert(message);
180 r = sd_bus_message_read(message, "h", &fd);
181 if (r < 0)
182 return bus_log_parse_error(r);
184 fflush(stdout);
185 r = copy_bytes(fd, STDOUT_FILENO, UINT64_MAX, 0);
186 if (r < 0)
187 return r;
189 return 1; /* Success */
192 static int help(int argc, char *argv[], void *userdata) {
193 _cleanup_free_ char *link = NULL, *dot_link = NULL;
194 int r;
196 pager_open(arg_pager_flags);
198 r = terminal_urlify_man("systemd-analyze", "1", &link);
199 if (r < 0)
200 return log_oom();
202 /* Not using terminal_urlify_man() for this, since we don't want the "man page" text suffix in this case. */
203 r = terminal_urlify("man:dot(1)", "dot(1)", &dot_link);
204 if (r < 0)
205 return log_oom();
207 printf("%s [OPTIONS...] COMMAND ...\n\n"
208 "%sProfile systemd, show unit dependencies, check unit files.%s\n"
209 "\nCommands:\n"
210 " [time] Print time required to boot the machine\n"
211 " blame Print list of running units ordered by\n"
212 " time to init\n"
213 " critical-chain [UNIT...] Print a tree of the time critical chain\n"
214 " of units\n"
215 " plot Output SVG graphic showing service\n"
216 " initialization\n"
217 " dot [UNIT...] Output dependency graph in %s format\n"
218 " dump [PATTERN...] Output state serialization of service\n"
219 " manager\n"
220 " cat-config NAME|PATH... Show configuration file and drop-ins\n"
221 " unit-files List files and symlinks for units\n"
222 " unit-paths List load directories for units\n"
223 " exit-status [STATUS...] List exit status definitions\n"
224 " capability [CAP...] List capability definitions\n"
225 " syscall-filter [NAME...] List syscalls in seccomp filters\n"
226 " filesystems [NAME...] List known filesystems\n"
227 " condition CONDITION... Evaluate conditions and asserts\n"
228 " compare-versions VERSION1 [OP] VERSION2\n"
229 " Compare two version strings\n"
230 " verify FILE... Check unit files for correctness\n"
231 " calendar SPEC... Validate repetitive calendar time\n"
232 " events\n"
233 " timestamp TIMESTAMP... Validate a timestamp\n"
234 " timespan SPAN... Validate a time span\n"
235 " security [UNIT...] Analyze security of unit\n"
236 " inspect-elf FILE... Parse and print ELF package metadata\n"
237 " malloc [D-BUS SERVICE...] Dump malloc stats of a D-Bus service\n"
238 " fdstore SERVICE... Show file descriptor store contents of service\n"
239 " image-policy POLICY... Analyze image policy string\n"
240 " pcrs [PCR...] Show TPM2 PCRs and their names\n"
241 " srk > FILE Write TPM2 SRK to stdout\n"
242 "\nOptions:\n"
243 " --recursive-errors=MODE Control which units are verified\n"
244 " --offline=BOOL Perform a security review on unit file(s)\n"
245 " --threshold=N Exit with a non-zero status when overall\n"
246 " exposure level is over threshold value\n"
247 " --security-policy=PATH Use custom JSON security policy instead\n"
248 " of built-in one\n"
249 " --json=pretty|short|off Generate JSON output of the security\n"
250 " analysis table, or plot's raw time data\n"
251 " --no-pager Do not pipe output into a pager\n"
252 " --no-legend Disable column headers and hints in plot\n"
253 " with either --table or --json=\n"
254 " --system Operate on system systemd instance\n"
255 " --user Operate on user systemd instance\n"
256 " --global Operate on global user configuration\n"
257 " -H --host=[USER@]HOST Operate on remote host\n"
258 " -M --machine=CONTAINER Operate on local container\n"
259 " --order Show only order in the graph\n"
260 " --require Show only requirement in the graph\n"
261 " --from-pattern=GLOB Show only origins in the graph\n"
262 " --to-pattern=GLOB Show only destinations in the graph\n"
263 " --fuzz=SECONDS Also print services which finished SECONDS\n"
264 " earlier than the latest in the branch\n"
265 " --man[=BOOL] Do [not] check for existence of man pages\n"
266 " --generators[=BOOL] Do [not] run unit generators\n"
267 " (requires privileges)\n"
268 " --iterations=N Show the specified number of iterations\n"
269 " --base-time=TIMESTAMP Calculate calendar times relative to\n"
270 " specified time\n"
271 " --profile=name|PATH Include the specified profile in the\n"
272 " security review of the unit(s)\n"
273 " --table Output plot's raw time data as a table\n"
274 " -h --help Show this help\n"
275 " --version Show package version\n"
276 " -q --quiet Do not emit hints\n"
277 " --tldr Skip comments and empty lines\n"
278 " --root=PATH Operate on an alternate filesystem root\n"
279 " --image=PATH Operate on disk image as filesystem root\n"
280 " --image-policy=POLICY Specify disk image dissection policy\n"
281 "\nSee the %s for details.\n",
282 program_invocation_short_name,
283 ansi_highlight(),
284 ansi_normal(),
285 dot_link,
286 link);
288 /* When updating this list, including descriptions, apply changes to
289 * shell-completion/bash/systemd-analyze and shell-completion/zsh/_systemd-analyze too. */
291 return 0;
294 static int parse_argv(int argc, char *argv[]) {
295 enum {
296 ARG_VERSION = 0x100,
297 ARG_ORDER,
298 ARG_REQUIRE,
299 ARG_ROOT,
300 ARG_IMAGE,
301 ARG_IMAGE_POLICY,
302 ARG_SYSTEM,
303 ARG_USER,
304 ARG_GLOBAL,
305 ARG_DOT_FROM_PATTERN,
306 ARG_DOT_TO_PATTERN,
307 ARG_FUZZ,
308 ARG_NO_PAGER,
309 ARG_MAN,
310 ARG_GENERATORS,
311 ARG_ITERATIONS,
312 ARG_BASE_TIME,
313 ARG_RECURSIVE_ERRORS,
314 ARG_OFFLINE,
315 ARG_THRESHOLD,
316 ARG_SECURITY_POLICY,
317 ARG_JSON,
318 ARG_PROFILE,
319 ARG_TABLE,
320 ARG_NO_LEGEND,
321 ARG_TLDR,
324 static const struct option options[] = {
325 { "help", no_argument, NULL, 'h' },
326 { "version", no_argument, NULL, ARG_VERSION },
327 { "quiet", no_argument, NULL, 'q' },
328 { "order", no_argument, NULL, ARG_ORDER },
329 { "require", no_argument, NULL, ARG_REQUIRE },
330 { "root", required_argument, NULL, ARG_ROOT },
331 { "image", required_argument, NULL, ARG_IMAGE },
332 { "image-policy", required_argument, NULL, ARG_IMAGE_POLICY },
333 { "recursive-errors", required_argument, NULL, ARG_RECURSIVE_ERRORS },
334 { "offline", required_argument, NULL, ARG_OFFLINE },
335 { "threshold", required_argument, NULL, ARG_THRESHOLD },
336 { "security-policy", required_argument, NULL, ARG_SECURITY_POLICY },
337 { "system", no_argument, NULL, ARG_SYSTEM },
338 { "user", no_argument, NULL, ARG_USER },
339 { "global", no_argument, NULL, ARG_GLOBAL },
340 { "from-pattern", required_argument, NULL, ARG_DOT_FROM_PATTERN },
341 { "to-pattern", required_argument, NULL, ARG_DOT_TO_PATTERN },
342 { "fuzz", required_argument, NULL, ARG_FUZZ },
343 { "no-pager", no_argument, NULL, ARG_NO_PAGER },
344 { "man", optional_argument, NULL, ARG_MAN },
345 { "generators", optional_argument, NULL, ARG_GENERATORS },
346 { "host", required_argument, NULL, 'H' },
347 { "machine", required_argument, NULL, 'M' },
348 { "iterations", required_argument, NULL, ARG_ITERATIONS },
349 { "base-time", required_argument, NULL, ARG_BASE_TIME },
350 { "unit", required_argument, NULL, 'U' },
351 { "json", required_argument, NULL, ARG_JSON },
352 { "profile", required_argument, NULL, ARG_PROFILE },
353 { "table", optional_argument, NULL, ARG_TABLE },
354 { "no-legend", optional_argument, NULL, ARG_NO_LEGEND },
355 { "tldr", no_argument, NULL, ARG_TLDR },
359 int r, c;
361 assert(argc >= 0);
362 assert(argv);
364 while ((c = getopt_long(argc, argv, "hH:M:U:q", options, NULL)) >= 0)
365 switch (c) {
367 case 'h':
368 return help(0, NULL, NULL);
370 case ARG_VERSION:
371 return version();
373 case 'q':
374 arg_quiet = true;
375 break;
377 case ARG_RECURSIVE_ERRORS:
378 if (streq(optarg, "help")) {
379 DUMP_STRING_TABLE(recursive_errors, RecursiveErrors, _RECURSIVE_ERRORS_MAX);
380 return 0;
382 r = recursive_errors_from_string(optarg);
383 if (r < 0)
384 return log_error_errno(r, "Unknown mode passed to --recursive-errors='%s'.", optarg);
386 arg_recursive_errors = r;
387 break;
389 case ARG_ROOT:
390 r = parse_path_argument(optarg, /* suppress_root= */ true, &arg_root);
391 if (r < 0)
392 return r;
393 break;
395 case ARG_IMAGE:
396 r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_image);
397 if (r < 0)
398 return r;
399 break;
401 case ARG_IMAGE_POLICY:
402 r = parse_image_policy_argument(optarg, &arg_image_policy);
403 if (r < 0)
404 return r;
405 break;
407 case ARG_SYSTEM:
408 arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
409 break;
411 case ARG_USER:
412 arg_runtime_scope = RUNTIME_SCOPE_USER;
413 break;
415 case ARG_GLOBAL:
416 arg_runtime_scope = RUNTIME_SCOPE_GLOBAL;
417 break;
419 case ARG_ORDER:
420 arg_dot = DEP_ORDER;
421 break;
423 case ARG_REQUIRE:
424 arg_dot = DEP_REQUIRE;
425 break;
427 case ARG_DOT_FROM_PATTERN:
428 if (strv_extend(&arg_dot_from_patterns, optarg) < 0)
429 return log_oom();
431 break;
433 case ARG_DOT_TO_PATTERN:
434 if (strv_extend(&arg_dot_to_patterns, optarg) < 0)
435 return log_oom();
437 break;
439 case ARG_FUZZ:
440 r = parse_sec(optarg, &arg_fuzz);
441 if (r < 0)
442 return r;
443 break;
445 case ARG_NO_PAGER:
446 arg_pager_flags |= PAGER_DISABLE;
447 break;
449 case 'H':
450 arg_transport = BUS_TRANSPORT_REMOTE;
451 arg_host = optarg;
452 break;
454 case 'M':
455 arg_transport = BUS_TRANSPORT_MACHINE;
456 arg_host = optarg;
457 break;
459 case ARG_MAN:
460 r = parse_boolean_argument("--man", optarg, &arg_man);
461 if (r < 0)
462 return r;
463 break;
465 case ARG_GENERATORS:
466 r = parse_boolean_argument("--generators", optarg, &arg_generators);
467 if (r < 0)
468 return r;
469 break;
471 case ARG_OFFLINE:
472 r = parse_boolean_argument("--offline", optarg, &arg_offline);
473 if (r < 0)
474 return r;
475 break;
477 case ARG_THRESHOLD:
478 r = safe_atou(optarg, &arg_threshold);
479 if (r < 0 || arg_threshold > 100)
480 return log_error_errno(r < 0 ? r : SYNTHETIC_ERRNO(EINVAL), "Failed to parse threshold: %s", optarg);
482 break;
484 case ARG_SECURITY_POLICY:
485 r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_security_policy);
486 if (r < 0)
487 return r;
488 break;
490 case ARG_JSON:
491 r = parse_json_argument(optarg, &arg_json_format_flags);
492 if (r <= 0)
493 return r;
494 break;
496 case ARG_ITERATIONS:
497 r = safe_atou(optarg, &arg_iterations);
498 if (r < 0)
499 return log_error_errno(r, "Failed to parse iterations: %s", optarg);
500 break;
502 case ARG_BASE_TIME:
503 r = parse_timestamp(optarg, &arg_base_time);
504 if (r < 0)
505 return log_error_errno(r, "Failed to parse --base-time= parameter: %s", optarg);
506 break;
508 case ARG_PROFILE:
509 if (isempty(optarg))
510 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Profile file name is empty");
512 if (is_path(optarg)) {
513 r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_profile);
514 if (r < 0)
515 return r;
516 if (!endswith(arg_profile, ".conf"))
517 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Profile file name must end with .conf: %s", arg_profile);
518 } else {
519 r = free_and_strdup(&arg_profile, optarg);
520 if (r < 0)
521 return log_oom();
524 break;
526 case 'U': {
527 _cleanup_free_ char *mangled = NULL;
529 r = unit_name_mangle(optarg, UNIT_NAME_MANGLE_WARN, &mangled);
530 if (r < 0)
531 return log_error_errno(r, "Failed to mangle unit name %s: %m", optarg);
533 free_and_replace(arg_unit, mangled);
534 break;
537 case ARG_TABLE:
538 arg_table = true;
539 break;
541 case ARG_NO_LEGEND:
542 arg_legend = false;
543 break;
545 case ARG_TLDR:
546 arg_cat_flags = CAT_TLDR;
547 break;
549 case '?':
550 return -EINVAL;
552 default:
553 assert_not_reached();
556 if (arg_offline && !streq_ptr(argv[optind], "security"))
557 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
558 "Option --offline= is only supported for security right now.");
560 if (arg_json_format_flags != JSON_FORMAT_OFF && !STRPTR_IN_SET(argv[optind], "security", "inspect-elf", "plot", "fdstore", "pcrs"))
561 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
562 "Option --json= is only supported for security, inspect-elf, plot, fdstore, pcrs right now.");
564 if (arg_threshold != 100 && !streq_ptr(argv[optind], "security"))
565 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
566 "Option --threshold= is only supported for security right now.");
568 if (arg_runtime_scope == RUNTIME_SCOPE_GLOBAL &&
569 !STR_IN_SET(argv[optind] ?: "time", "dot", "unit-paths", "verify"))
570 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
571 "Option --global only makes sense with verbs dot, unit-paths, verify.");
573 if (streq_ptr(argv[optind], "cat-config") && arg_runtime_scope == RUNTIME_SCOPE_USER)
574 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
575 "Option --user is not supported for cat-config right now.");
577 if (arg_security_policy && !streq_ptr(argv[optind], "security"))
578 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
579 "Option --security-policy= is only supported for security.");
581 if ((arg_root || arg_image) && (!STRPTR_IN_SET(argv[optind], "cat-config", "verify", "condition")) &&
582 (!(streq_ptr(argv[optind], "security") && arg_offline)))
583 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
584 "Options --root= and --image= are only supported for cat-config, verify, condition and security when used with --offline= right now.");
586 /* Having both an image and a root is not supported by the code */
587 if (arg_root && arg_image)
588 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Please specify either --root= or --image=, the combination of both is not supported.");
590 if (arg_unit && !streq_ptr(argv[optind], "condition"))
591 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --unit= is only supported for condition");
593 if (streq_ptr(argv[optind], "condition") && !arg_unit && optind >= argc - 1)
594 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Too few arguments for condition");
596 if (streq_ptr(argv[optind], "condition") && arg_unit && optind < argc - 1)
597 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No conditions can be passed if --unit= is used.");
599 if ((!arg_legend && !streq_ptr(argv[optind], "plot")) ||
600 (streq_ptr(argv[optind], "plot") && !arg_legend && !arg_table && FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF)))
601 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --no-legend is only supported for plot with either --table or --json=.");
603 if (arg_table && !streq_ptr(argv[optind], "plot"))
604 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --table is only supported for plot right now.");
606 if (arg_table && !FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
607 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--table and --json= are mutually exclusive.");
609 return 1; /* work to do */
612 static int run(int argc, char *argv[]) {
613 _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
614 _cleanup_(umount_and_freep) char *mounted_dir = NULL;
616 static const Verb verbs[] = {
617 { "help", VERB_ANY, VERB_ANY, 0, help },
618 { "time", VERB_ANY, 1, VERB_DEFAULT, verb_time },
619 { "blame", VERB_ANY, 1, 0, verb_blame },
620 { "critical-chain", VERB_ANY, VERB_ANY, 0, verb_critical_chain },
621 { "plot", VERB_ANY, 1, 0, verb_plot },
622 { "dot", VERB_ANY, VERB_ANY, 0, verb_dot },
623 /* ↓ The following seven verbs are deprecated, from here … ↓ */
624 { "log-level", VERB_ANY, 2, 0, verb_log_control },
625 { "log-target", VERB_ANY, 2, 0, verb_log_control },
626 { "set-log-level", 2, 2, 0, verb_log_control },
627 { "get-log-level", VERB_ANY, 1, 0, verb_log_control },
628 { "set-log-target", 2, 2, 0, verb_log_control },
629 { "get-log-target", VERB_ANY, 1, 0, verb_log_control },
630 { "service-watchdogs", VERB_ANY, 2, 0, verb_service_watchdogs },
631 /* ↑ … until here ↑ */
632 { "dump", VERB_ANY, VERB_ANY, 0, verb_dump },
633 { "cat-config", 2, VERB_ANY, 0, verb_cat_config },
634 { "unit-files", VERB_ANY, VERB_ANY, 0, verb_unit_files },
635 { "unit-paths", 1, 1, 0, verb_unit_paths },
636 { "exit-status", VERB_ANY, VERB_ANY, 0, verb_exit_status },
637 { "syscall-filter", VERB_ANY, VERB_ANY, 0, verb_syscall_filters },
638 { "capability", VERB_ANY, VERB_ANY, 0, verb_capabilities },
639 { "filesystems", VERB_ANY, VERB_ANY, 0, verb_filesystems },
640 { "condition", VERB_ANY, VERB_ANY, 0, verb_condition },
641 { "compare-versions", 3, 4, 0, verb_compare_versions },
642 { "verify", 2, VERB_ANY, 0, verb_verify },
643 { "calendar", 2, VERB_ANY, 0, verb_calendar },
644 { "timestamp", 2, VERB_ANY, 0, verb_timestamp },
645 { "timespan", 2, VERB_ANY, 0, verb_timespan },
646 { "security", VERB_ANY, VERB_ANY, 0, verb_security },
647 { "inspect-elf", 2, VERB_ANY, 0, verb_elf_inspection },
648 { "malloc", VERB_ANY, VERB_ANY, 0, verb_malloc },
649 { "fdstore", 2, VERB_ANY, 0, verb_fdstore },
650 { "image-policy", 2, 2, 0, verb_image_policy },
651 { "pcrs", VERB_ANY, VERB_ANY, 0, verb_pcrs },
652 { "srk", VERB_ANY, 1, 0, verb_srk },
656 int r;
658 setlocale(LC_ALL, "");
659 setlocale(LC_NUMERIC, "C"); /* we want to format/parse floats in C style */
661 log_setup();
663 r = parse_argv(argc, argv);
664 if (r <= 0)
665 return r;
667 /* Open up and mount the image */
668 if (arg_image) {
669 assert(!arg_root);
671 r = mount_image_privately_interactively(
672 arg_image,
673 arg_image_policy,
674 DISSECT_IMAGE_GENERIC_ROOT |
675 DISSECT_IMAGE_RELAX_VAR_CHECK |
676 DISSECT_IMAGE_READ_ONLY,
677 &mounted_dir,
678 /* ret_dir_fd= */ NULL,
679 &loop_device);
680 if (r < 0)
681 return r;
683 arg_root = strdup(mounted_dir);
684 if (!arg_root)
685 return log_oom();
688 return dispatch_verb(argc, argv, verbs, NULL);
691 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);