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