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