1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 Copyright © 2013 Simon Peeters
14 #include "alloc-util.h"
16 #include "analyze-architectures.h"
17 #include "analyze-blame.h"
18 #include "analyze-calendar.h"
19 #include "analyze-capability.h"
20 #include "analyze-cat-config.h"
21 #include "analyze-chid.h"
22 #include "analyze-compare-versions.h"
23 #include "analyze-condition.h"
24 #include "analyze-critical-chain.h"
25 #include "analyze-dot.h"
26 #include "analyze-dump.h"
27 #include "analyze-exit-status.h"
28 #include "analyze-fdstore.h"
29 #include "analyze-filesystems.h"
30 #include "analyze-has-tpm2.h"
31 #include "analyze-image-policy.h"
32 #include "analyze-inspect-elf.h"
33 #include "analyze-log-control.h"
34 #include "analyze-malloc.h"
35 #include "analyze-pcrs.h"
36 #include "analyze-plot.h"
37 #include "analyze-security.h"
38 #include "analyze-service-watchdogs.h"
39 #include "analyze-smbios11.h"
40 #include "analyze-srk.h"
41 #include "analyze-syscall-filter.h"
42 #include "analyze-time.h"
43 #include "analyze-timespan.h"
44 #include "analyze-timestamp.h"
45 #include "analyze-unit-files.h"
46 #include "analyze-unit-gdb.h"
47 #include "analyze-unit-paths.h"
48 #include "analyze-unit-shell.h"
49 #include "analyze-verify.h"
50 #include "analyze-verify-util.h"
52 #include "bus-error.h"
53 #include "bus-unit-util.h"
55 #include "calendarspec.h"
56 #include "dissect-image.h"
57 #include "extract-word.h"
58 #include "image-policy.h"
60 #include "loop-util.h"
61 #include "main-func.h"
62 #include "mount-util.h"
64 #include "parse-argument.h"
65 #include "parse-util.h"
66 #include "path-util.h"
67 #include "pretty-print.h"
68 #include "runtime-scope.h"
69 #include "string-table.h"
70 #include "string-util.h"
72 #include "time-util.h"
74 #include "unit-name.h"
77 DotMode arg_dot
= DEP_ALL
;
78 CapabilityMode arg_capability
= CAPABILITY_LITERAL
;
79 char **arg_dot_from_patterns
= NULL
, **arg_dot_to_patterns
= NULL
;
81 PagerFlags arg_pager_flags
= 0;
82 CatFlags arg_cat_flags
= 0;
83 BusTransport arg_transport
= BUS_TRANSPORT_LOCAL
;
84 char *arg_debugger
= NULL
;
85 char **arg_debugger_args
= NULL
;
86 const char *arg_host
= NULL
;
87 RuntimeScope arg_runtime_scope
= RUNTIME_SCOPE_SYSTEM
;
88 RecursiveErrors arg_recursive_errors
= _RECURSIVE_ERRORS_INVALID
;
90 bool arg_generators
= false;
91 const char *arg_instance
= "test_instance";
92 double arg_svg_timescale
= 1.0;
93 bool arg_detailed_svg
= false;
94 char *arg_root
= NULL
;
95 static char *arg_image
= NULL
;
96 char *arg_security_policy
= NULL
;
97 bool arg_offline
= false;
98 unsigned arg_threshold
= 100;
99 unsigned arg_iterations
= 1;
100 usec_t arg_base_time
= USEC_INFINITY
;
101 char *arg_unit
= NULL
;
102 sd_json_format_flags_t arg_json_format_flags
= SD_JSON_FORMAT_OFF
;
103 bool arg_quiet
= false;
104 char *arg_profile
= NULL
;
105 bool arg_legend
= true;
106 bool arg_table
= false;
107 ImagePolicy
*arg_image_policy
= NULL
;
108 char *arg_drm_device_path
= NULL
;
110 STATIC_DESTRUCTOR_REGISTER(arg_dot_from_patterns
, strv_freep
);
111 STATIC_DESTRUCTOR_REGISTER(arg_dot_to_patterns
, strv_freep
);
112 STATIC_DESTRUCTOR_REGISTER(arg_debugger
, freep
);
113 STATIC_DESTRUCTOR_REGISTER(arg_debugger_args
, 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_drm_device_path
, freep
);
118 STATIC_DESTRUCTOR_REGISTER(arg_unit
, freep
);
119 STATIC_DESTRUCTOR_REGISTER(arg_profile
, freep
);
120 STATIC_DESTRUCTOR_REGISTER(arg_image_policy
, image_policy_freep
);
122 int acquire_bus(sd_bus
**bus
, bool *use_full_bus
) {
125 if (use_full_bus
&& *use_full_bus
) {
126 r
= bus_connect_transport(arg_transport
, arg_host
, arg_runtime_scope
, bus
);
127 if (IN_SET(r
, 0, -EHOSTDOWN
))
130 *use_full_bus
= false;
133 return bus_connect_transport_systemd(arg_transport
, arg_host
, arg_runtime_scope
, bus
);
136 int bus_get_unit_property_strv(sd_bus
*bus
, const char *path
, const char *property
, char ***strv
) {
137 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
145 r
= sd_bus_get_property_strv(
147 "org.freedesktop.systemd1",
149 "org.freedesktop.systemd1.Unit",
154 return log_error_errno(r
, "Failed to get unit property %s: %s", property
, bus_error_message(&error
, r
));
159 void time_parsing_hint(const char *p
, bool calendar
, bool timestamp
, bool timespan
) {
160 if (calendar
&& calendar_spec_from_string(p
, NULL
) >= 0)
161 log_notice("Hint: this expression is a valid calendar specification. "
162 "Use 'systemd-analyze calendar \"%s\"' instead?", p
);
163 if (timestamp
&& parse_timestamp(p
, NULL
) >= 0)
164 log_notice("Hint: this expression is a valid timestamp. "
165 "Use 'systemd-analyze timestamp \"%s\"' instead?", p
);
166 if (timespan
&& parse_time(p
, NULL
, USEC_PER_SEC
) >= 0)
167 log_notice("Hint: this expression is a valid timespan. "
168 "Use 'systemd-analyze timespan \"%s\"' instead?", p
);
171 static int verb_transient_settings(int argc
, char *argv
[], void *userdata
) {
174 pager_open(arg_pager_flags
);
177 STRV_FOREACH(arg
, strv_skip(argv
, 1)) {
180 t
= unit_type_from_string(*arg
);
182 return log_error_errno(t
, "Invalid unit type '%s'.", *arg
);
187 bus_dump_transient_settings(t
);
194 static int help(int argc
, char *argv
[], void *userdata
) {
195 _cleanup_free_
char *link
= NULL
, *dot_link
= NULL
;
198 pager_open(arg_pager_flags
);
200 r
= terminal_urlify_man("systemd-analyze", "1", &link
);
204 /* Not using terminal_urlify_man() for this, since we don't want the "man page" text suffix in this case. */
205 r
= terminal_urlify("man:dot(1)", "dot(1)", &dot_link
);
209 printf("%1$s [OPTIONS...] COMMAND ...\n\n"
210 "%5$sProfile systemd, show unit dependencies, check unit files.%6$s\n"
211 "\n%3$sBoot Analysis:%4$s\n"
212 " [time] Print time required to boot the machine\n"
213 " blame Print list of running units ordered by\n"
215 " critical-chain [UNIT...] Print a tree of the time critical chain\n"
217 "\n%3$sDependency Analysis:%4$s\n"
218 " plot Output SVG graphic showing service\n"
220 " dot [UNIT...] Output dependency graph in %7$s format\n"
221 " dump [PATTERN...] Output state serialization of service\n"
223 "\n%3$sConfiguration Files and Search Paths:%4$s\n"
224 " cat-config NAME|PATH... Show configuration file and drop-ins\n"
225 " unit-files List files and symlinks for units\n"
226 " unit-paths List load directories for units\n"
227 "\n%3$sEnumerate OS Concepts:%4$s\n"
228 " exit-status [STATUS...] List exit status definitions\n"
229 " capability [CAP...] List capability definitions\n"
230 " syscall-filter [NAME...] List syscalls in seccomp filters\n"
231 " filesystems [NAME...] List known filesystems\n"
232 " architectures [NAME...] List known architectures\n"
233 " smbios11 List strings passed via SMBIOS Type #11\n"
234 " chid List local CHIDs\n"
235 " transient-settings TYPE... List transient settings for unit TYPE\n"
236 "\n%3$sExpression Evaluation:%4$s\n"
237 " condition CONDITION... Evaluate conditions and asserts\n"
238 " compare-versions VERSION1 [OP] VERSION2\n"
239 " Compare two version strings\n"
240 " image-policy POLICY... Analyze image policy string\n"
241 "\n%3$sClock & Time:%4$s\n"
242 " calendar SPEC... Validate repetitive calendar time\n"
244 " timestamp TIMESTAMP... Validate a timestamp\n"
245 " timespan SPAN... Validate a time span\n"
246 "\n%3$sUnit & Service Analysis:%4$s\n"
247 " verify FILE... Check unit files for correctness\n"
248 " security [UNIT...] Analyze security of unit\n"
249 " fdstore SERVICE... Show file descriptor store contents of service\n"
250 " malloc [D-BUS SERVICE...] Dump malloc stats of a D-Bus service\n"
251 " unit-gdb SERVICE Attach a debugger to the given running service\n"
252 " unit-shell SERVICE [Command]\n"
253 " Run command on the namespace of the service\n"
254 "\n%3$sExecutable Analysis:%4$s\n"
255 " inspect-elf FILE... Parse and print ELF package metadata\n"
256 "\n%3$sTPM Operations:%4$s\n"
257 " has-tpm2 Report whether TPM2 support is available\n"
258 " pcrs [PCR...] Show TPM2 PCRs and their names\n"
259 " srk [>FILE] Write TPM2 SRK (to FILE)\n"
260 "\n%3$sOptions:%4$s\n"
261 " --recursive-errors=MODE Control which units are verified\n"
262 " --offline=BOOL Perform a security review on unit file(s)\n"
263 " --threshold=N Exit with a non-zero status when overall\n"
264 " exposure level is over threshold value\n"
265 " --security-policy=PATH Use custom JSON security policy instead\n"
267 " --json=pretty|short|off Generate JSON output of the security\n"
268 " analysis table, or plot's raw time data\n"
269 " --no-pager Do not pipe output into a pager\n"
270 " --no-legend Disable column headers and hints in plot\n"
271 " with either --table or --json=\n"
272 " --system Operate on system systemd instance\n"
273 " --user Operate on user systemd instance\n"
274 " --global Operate on global user configuration\n"
275 " -H --host=[USER@]HOST Operate on remote host\n"
276 " -M --machine=CONTAINER Operate on local container\n"
277 " --order Show only order in the graph\n"
278 " --require Show only requirement in the graph\n"
279 " --from-pattern=GLOB Show only origins in the graph\n"
280 " --to-pattern=GLOB Show only destinations in the graph\n"
281 " --fuzz=SECONDS Also print services which finished SECONDS\n"
282 " earlier than the latest in the branch\n"
283 " --man[=BOOL] Do [not] check for existence of man pages\n"
284 " --generators[=BOOL] Do [not] run unit generators\n"
285 " (requires privileges)\n"
286 " --instance=NAME Specify fallback instance name for template units\n"
287 " --iterations=N Show the specified number of iterations\n"
288 " --base-time=TIMESTAMP Calculate calendar times relative to\n"
290 " --profile=name|PATH Include the specified profile in the\n"
291 " security review of the unit(s)\n"
292 " --unit=UNIT Evaluate conditions and asserts of unit\n"
293 " --table Output plot's raw time data as a table\n"
294 " --scale-svg=FACTOR Stretch x-axis of plot by FACTOR (default: 1.0)\n"
295 " --detailed Add more details to SVG plot,\n"
296 " e.g. show activation timestamps\n"
297 " -h --help Show this help\n"
298 " --version Show package version\n"
299 " -q --quiet Do not emit hints\n"
300 " --tldr Skip comments and empty lines\n"
301 " --root=PATH Operate on an alternate filesystem root\n"
302 " --image=PATH Operate on disk image as filesystem root\n"
303 " --image-policy=POLICY Specify disk image dissection policy\n"
304 " -m --mask Parse parameter as numeric capability mask\n"
305 " --drm-device=PATH Use this DRM device sysfs path to get EDID\n"
306 " --debugger=DEBUGGER Use the given debugger\n"
307 " -A --debugger-arguments=ARGS\n"
308 " Pass the given arguments to the debugger\n"
310 "\nSee the %2$s for details.\n",
311 program_invocation_short_name
,
319 /* When updating this list, including descriptions, apply changes to
320 * shell-completion/bash/systemd-analyze and shell-completion/zsh/_systemd-analyze too. */
325 static int parse_argv(int argc
, char *argv
[]) {
336 ARG_DOT_FROM_PATTERN
,
345 ARG_RECURSIVE_ERRORS
,
354 ARG_SCALE_FACTOR_SVG
,
360 static const struct option options
[] = {
361 { "help", no_argument
, NULL
, 'h' },
362 { "version", no_argument
, NULL
, ARG_VERSION
},
363 { "quiet", no_argument
, NULL
, 'q' },
364 { "order", no_argument
, NULL
, ARG_ORDER
},
365 { "require", no_argument
, NULL
, ARG_REQUIRE
},
366 { "root", required_argument
, NULL
, ARG_ROOT
},
367 { "image", required_argument
, NULL
, ARG_IMAGE
},
368 { "image-policy", required_argument
, NULL
, ARG_IMAGE_POLICY
},
369 { "recursive-errors" , required_argument
, NULL
, ARG_RECURSIVE_ERRORS
},
370 { "offline", required_argument
, NULL
, ARG_OFFLINE
},
371 { "threshold", required_argument
, NULL
, ARG_THRESHOLD
},
372 { "security-policy", required_argument
, NULL
, ARG_SECURITY_POLICY
},
373 { "system", no_argument
, NULL
, ARG_SYSTEM
},
374 { "user", no_argument
, NULL
, ARG_USER
},
375 { "global", no_argument
, NULL
, ARG_GLOBAL
},
376 { "from-pattern", required_argument
, NULL
, ARG_DOT_FROM_PATTERN
},
377 { "to-pattern", required_argument
, NULL
, ARG_DOT_TO_PATTERN
},
378 { "fuzz", required_argument
, NULL
, ARG_FUZZ
},
379 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
380 { "man", optional_argument
, NULL
, ARG_MAN
},
381 { "generators", optional_argument
, NULL
, ARG_GENERATORS
},
382 { "instance", required_argument
, NULL
, ARG_INSTANCE
},
383 { "host", required_argument
, NULL
, 'H' },
384 { "machine", required_argument
, NULL
, 'M' },
385 { "iterations", required_argument
, NULL
, ARG_ITERATIONS
},
386 { "base-time", required_argument
, NULL
, ARG_BASE_TIME
},
387 { "unit", required_argument
, NULL
, 'U' },
388 { "json", required_argument
, NULL
, ARG_JSON
},
389 { "profile", required_argument
, NULL
, ARG_PROFILE
},
390 { "table", optional_argument
, NULL
, ARG_TABLE
},
391 { "no-legend", optional_argument
, NULL
, ARG_NO_LEGEND
},
392 { "tldr", no_argument
, NULL
, ARG_TLDR
},
393 { "mask", no_argument
, NULL
, 'm' },
394 { "scale-svg", required_argument
, NULL
, ARG_SCALE_FACTOR_SVG
},
395 { "detailed", no_argument
, NULL
, ARG_DETAILED_SVG
},
396 { "drm-device", required_argument
, NULL
, ARG_DRM_DEVICE_PATH
},
397 { "debugger", required_argument
, NULL
, ARG_DEBUGGER
},
398 { "debugger-arguments", required_argument
, NULL
, 'A' },
402 bool reorder
= false;
403 int r
, c
, unit_shell
= -1;
408 /* Resetting to 0 forces the invocation of an internal initialization routine of getopt_long()
409 * that checks for GNU extensions in optstring ('-' or '+; at the beginning). */
413 static const char option_string
[] = "-hqH:M:U:mA:";
415 c
= getopt_long(argc
, argv
, option_string
+ reorder
, options
, NULL
);
421 case 1: /* getopt_long() returns 1 if "-" was the first character of the option string, and a
422 * non-option argument was discovered. */
426 /* We generally are fine with the fact that getopt_long() reorders the command line, and looks
427 * for switches after the main verb. However, for "unit-shell" we really don't want that, since we
428 * want that switches specified after the service name are passed to the program to execute,
429 * and not processed by us. To make this possible, we'll first invoke getopt_long() with
430 * reordering disabled (i.e. with the "-" prefix in the option string), looking for the first
431 * non-option parameter. If it's the verb "unit-shell" we remember its position and continue
432 * processing options. In this case, as soon as we hit the next non-option argument we found
433 * the service name, and stop further processing. If the first non-option argument is any other
434 * verb than "unit-shell" we switch to normal reordering mode and continue processing arguments
437 if (unit_shell
>= 0) {
438 optind
--; /* don't process this argument, go one step back */
441 if (streq(optarg
, "unit-shell"))
442 /* Remember the position of the "unit_shell" verb, and continue processing normally. */
443 unit_shell
= optind
- 1;
447 /* Ok, this is some other verb. In this case, turn on reordering again, and continue
448 * processing normally. */
451 /* We changed the option string. getopt_long() only looks at it again if we invoke it
452 * at least once with a reset option index. Hence, let's reset the option index here,
453 * then invoke getopt_long() again (ignoring what it has to say, after all we most
454 * likely already processed it), and the bump the option index so that we read the
455 * intended argument again. */
456 saved_optind
= optind
;
458 (void) getopt_long(argc
, argv
, option_string
+ reorder
, options
, NULL
);
459 optind
= saved_optind
- 1; /* go one step back, process this argument again */
465 return help(0, NULL
, NULL
);
474 case ARG_RECURSIVE_ERRORS
:
475 if (streq(optarg
, "help")) {
476 DUMP_STRING_TABLE(recursive_errors
, RecursiveErrors
, _RECURSIVE_ERRORS_MAX
);
479 r
= recursive_errors_from_string(optarg
);
481 return log_error_errno(r
, "Unknown mode passed to --recursive-errors='%s'.", optarg
);
483 arg_recursive_errors
= r
;
487 r
= parse_path_argument(optarg
, /* suppress_root= */ true, &arg_root
);
493 r
= parse_path_argument(optarg
, /* suppress_root= */ false, &arg_image
);
498 case ARG_IMAGE_POLICY
:
499 r
= parse_image_policy_argument(optarg
, &arg_image_policy
);
505 arg_runtime_scope
= RUNTIME_SCOPE_SYSTEM
;
509 arg_runtime_scope
= RUNTIME_SCOPE_USER
;
513 arg_runtime_scope
= RUNTIME_SCOPE_GLOBAL
;
521 arg_dot
= DEP_REQUIRE
;
524 case ARG_DOT_FROM_PATTERN
:
525 if (strv_extend(&arg_dot_from_patterns
, optarg
) < 0)
530 case ARG_DOT_TO_PATTERN
:
531 if (strv_extend(&arg_dot_to_patterns
, optarg
) < 0)
537 r
= parse_sec(optarg
, &arg_fuzz
);
543 arg_pager_flags
|= PAGER_DISABLE
;
547 arg_transport
= BUS_TRANSPORT_REMOTE
;
552 r
= parse_machine_argument(optarg
, &arg_host
, &arg_transport
);
558 r
= parse_boolean_argument("--man", optarg
, &arg_man
);
564 r
= parse_boolean_argument("--generators", optarg
, &arg_generators
);
570 arg_instance
= optarg
;
574 r
= parse_boolean_argument("--offline", optarg
, &arg_offline
);
580 r
= safe_atou(optarg
, &arg_threshold
);
581 if (r
< 0 || arg_threshold
> 100)
582 return log_error_errno(r
< 0 ? r
: SYNTHETIC_ERRNO(EINVAL
), "Failed to parse threshold: %s", optarg
);
586 case ARG_SECURITY_POLICY
:
587 r
= parse_path_argument(optarg
, /* suppress_root= */ false, &arg_security_policy
);
593 r
= parse_json_argument(optarg
, &arg_json_format_flags
);
599 r
= safe_atou(optarg
, &arg_iterations
);
601 return log_error_errno(r
, "Failed to parse iterations: %s", optarg
);
605 r
= parse_timestamp(optarg
, &arg_base_time
);
607 return log_error_errno(r
, "Failed to parse --base-time= parameter: %s", optarg
);
612 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Profile file name is empty");
614 if (is_path(optarg
)) {
615 r
= parse_path_argument(optarg
, /* suppress_root= */ false, &arg_profile
);
618 if (!endswith(arg_profile
, ".conf"))
619 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Profile file name must end with .conf: %s", arg_profile
);
621 r
= free_and_strdup(&arg_profile
, optarg
);
629 _cleanup_free_
char *mangled
= NULL
;
631 r
= unit_name_mangle(optarg
, UNIT_NAME_MANGLE_WARN
, &mangled
);
633 return log_error_errno(r
, "Failed to mangle unit name %s: %m", optarg
);
635 free_and_replace(arg_unit
, mangled
);
648 arg_cat_flags
= CAT_TLDR
;
652 arg_capability
= CAPABILITY_MASK
;
655 case ARG_SCALE_FACTOR_SVG
:
656 arg_svg_timescale
= strtod(optarg
, NULL
);
659 case ARG_DETAILED_SVG
:
660 arg_detailed_svg
= true;
663 case ARG_DRM_DEVICE_PATH
:
664 r
= parse_path_argument(optarg
, /* suppress_root= */ false, &arg_drm_device_path
);
670 r
= free_and_strdup_warn(&arg_debugger
, optarg
);
676 _cleanup_strv_free_
char **l
= NULL
;
677 r
= strv_split_full(&l
, optarg
, WHITESPACE
, EXTRACT_UNQUOTE
);
679 return log_error_errno(r
, "Failed to parse debugger arguments '%s': %m", optarg
);
680 strv_free_and_replace(arg_debugger_args
, l
);
688 assert_not_reached();
693 if (unit_shell
>= 0) {
696 /* We found the "unit-shell" verb while processing the argument list. Since we turned off reordering of the
697 * argument list initially let's readjust it now, and move the "unit-shell" verb to the back. */
699 optind
-= 1; /* place the option index where the "unit-shell" verb will be placed */
701 t
= argv
[unit_shell
];
702 for (int i
= unit_shell
; i
< optind
; i
++)
707 if (arg_offline
&& !streq_ptr(argv
[optind
], "security"))
708 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
709 "Option --offline= is only supported for security right now.");
711 if (arg_offline
&& optind
>= argc
- 1)
712 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
713 "Option --offline= requires one or more units to perform a security review.");
715 if (arg_threshold
!= 100 && !streq_ptr(argv
[optind
], "security"))
716 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
717 "Option --threshold= is only supported for security right now.");
719 if (arg_runtime_scope
== RUNTIME_SCOPE_GLOBAL
&& !streq_ptr(argv
[optind
], "unit-paths"))
720 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
721 "Option --global only makes sense with verb unit-paths.");
723 if (streq_ptr(argv
[optind
], "cat-config") && arg_runtime_scope
== RUNTIME_SCOPE_USER
)
724 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
725 "Option --user is not supported for cat-config right now.");
727 if (arg_security_policy
&& !streq_ptr(argv
[optind
], "security"))
728 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
729 "Option --security-policy= is only supported for security.");
731 if ((arg_root
|| arg_image
) && (!STRPTR_IN_SET(argv
[optind
], "cat-config", "verify", "condition", "inspect-elf", "unit-gdb")) &&
732 (!(streq_ptr(argv
[optind
], "security") && arg_offline
)))
733 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
734 "Options --root= and --image= are only supported for cat-config, verify, condition, unit-gdb, and security when used with --offline= right now.");
736 /* Having both an image and a root is not supported by the code */
737 if (arg_root
&& arg_image
)
738 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Please specify either --root= or --image=, the combination of both is not supported.");
740 if (arg_unit
&& !streq_ptr(argv
[optind
], "condition"))
741 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Option --unit= is only supported for condition");
743 if (streq_ptr(argv
[optind
], "condition") && !arg_unit
&& optind
>= argc
- 1)
744 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Too few arguments for condition");
746 if (streq_ptr(argv
[optind
], "condition") && arg_unit
&& optind
< argc
- 1)
747 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "No conditions can be passed if --unit= is used.");
749 if (arg_table
&& !streq_ptr(argv
[optind
], "plot"))
750 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Option --table is only supported for plot right now.");
752 if (arg_table
&& sd_json_format_enabled(arg_json_format_flags
))
753 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "--table and --json= are mutually exclusive.");
755 if (arg_capability
!= CAPABILITY_LITERAL
&& !streq_ptr(argv
[optind
], "capability"))
756 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Option --mask is only supported for capability.");
758 if (arg_drm_device_path
&& !streq_ptr(argv
[optind
], "chid"))
759 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Option --drm-device is only supported for chid right now.");
761 return 1; /* work to do */
764 static int run(int argc
, char *argv
[]) {
765 _cleanup_(loop_device_unrefp
) LoopDevice
*loop_device
= NULL
;
766 _cleanup_(umount_and_freep
) char *mounted_dir
= NULL
;
768 static const Verb verbs
[] = {
769 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
770 { "time", VERB_ANY
, 1, VERB_DEFAULT
, verb_time
},
771 { "blame", VERB_ANY
, 1, 0, verb_blame
},
772 { "critical-chain", VERB_ANY
, VERB_ANY
, 0, verb_critical_chain
},
773 { "plot", VERB_ANY
, 1, 0, verb_plot
},
774 { "dot", VERB_ANY
, VERB_ANY
, 0, verb_dot
},
775 /* ↓ The following seven verbs are deprecated, from here … ↓ */
776 { "log-level", VERB_ANY
, 2, 0, verb_log_control
},
777 { "log-target", VERB_ANY
, 2, 0, verb_log_control
},
778 { "set-log-level", 2, 2, 0, verb_log_control
},
779 { "get-log-level", VERB_ANY
, 1, 0, verb_log_control
},
780 { "set-log-target", 2, 2, 0, verb_log_control
},
781 { "get-log-target", VERB_ANY
, 1, 0, verb_log_control
},
782 { "service-watchdogs", VERB_ANY
, 2, 0, verb_service_watchdogs
},
783 /* ↑ … until here ↑ */
784 { "dump", VERB_ANY
, VERB_ANY
, 0, verb_dump
},
785 { "cat-config", 2, VERB_ANY
, 0, verb_cat_config
},
786 { "unit-files", VERB_ANY
, VERB_ANY
, 0, verb_unit_files
},
787 { "unit-gdb", 2, VERB_ANY
, 0, verb_unit_gdb
},
788 { "unit-paths", 1, 1, 0, verb_unit_paths
},
789 { "unit-shell", 2, VERB_ANY
, 0, verb_unit_shell
},
790 { "exit-status", VERB_ANY
, VERB_ANY
, 0, verb_exit_status
},
791 { "syscall-filter", VERB_ANY
, VERB_ANY
, 0, verb_syscall_filters
},
792 { "capability", VERB_ANY
, VERB_ANY
, 0, verb_capabilities
},
793 { "filesystems", VERB_ANY
, VERB_ANY
, 0, verb_filesystems
},
794 { "condition", VERB_ANY
, VERB_ANY
, 0, verb_condition
},
795 { "compare-versions", 3, 4, 0, verb_compare_versions
},
796 { "verify", 2, VERB_ANY
, 0, verb_verify
},
797 { "calendar", 2, VERB_ANY
, 0, verb_calendar
},
798 { "timestamp", 2, VERB_ANY
, 0, verb_timestamp
},
799 { "timespan", 2, VERB_ANY
, 0, verb_timespan
},
800 { "security", VERB_ANY
, VERB_ANY
, 0, verb_security
},
801 { "inspect-elf", 2, VERB_ANY
, 0, verb_elf_inspection
},
802 { "malloc", VERB_ANY
, VERB_ANY
, 0, verb_malloc
},
803 { "fdstore", 2, VERB_ANY
, 0, verb_fdstore
},
804 { "image-policy", 2, 2, 0, verb_image_policy
},
805 { "has-tpm2", VERB_ANY
, 1, 0, verb_has_tpm2
},
806 { "pcrs", VERB_ANY
, VERB_ANY
, 0, verb_pcrs
},
807 { "srk", VERB_ANY
, 1, 0, verb_srk
},
808 { "architectures", VERB_ANY
, VERB_ANY
, 0, verb_architectures
},
809 { "smbios11", VERB_ANY
, 1, 0, verb_smbios11
},
810 { "chid", VERB_ANY
, VERB_ANY
, 0, verb_chid
},
811 { "transient-settings", 2, VERB_ANY
, 0, verb_transient_settings
},
817 setlocale(LC_ALL
, "");
818 setlocale(LC_NUMERIC
, "C"); /* we want to format/parse floats in C style */
822 r
= parse_argv(argc
, argv
);
826 /* Open up and mount the image */
830 r
= mount_image_privately_interactively(
833 DISSECT_IMAGE_GENERIC_ROOT
|
834 DISSECT_IMAGE_RELAX_VAR_CHECK
|
835 DISSECT_IMAGE_READ_ONLY
|
836 DISSECT_IMAGE_ALLOW_USERSPACE_VERITY
,
838 /* ret_dir_fd= */ NULL
,
843 arg_root
= strdup(mounted_dir
);
848 return dispatch_verb(argc
, argv
, verbs
, NULL
);
851 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run
);