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