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