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