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