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