1
0
mirror of https://github.com/systemd/systemd synced 2024-07-08 20:15:55 +00:00

analyze: add "architectures" verb that lists all known architectures

This commit is contained in:
Lennart Poettering 2023-11-16 16:08:15 +01:00
parent fb45185d98
commit fb8cc599ed
7 changed files with 142 additions and 3 deletions

View File

@ -179,6 +179,12 @@
<arg choice="opt" rep="repeat">OPTIONS</arg>
<arg choice="plain">srk</arg> &gt;<arg choice="plain"><replaceable>FILE</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>systemd-analyze</command>
<arg choice="opt" rep="repeat">OPTIONS</arg>
<arg choice="plain">architectures</arg>
<arg choice="opt" rep="repeat"><replaceable>NAME</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
@ -941,6 +947,32 @@ NR NAME SHA256
<programlisting>systemd-analyze srk &gt; srk.tpm2b_public</programlisting>
</refsect2>
<refsect2>
<title><command>systemd-analyze architectures <optional><replaceable>NAME</replaceable>...</optional></command></title>
<para>Lists all known CPU architectures, and which ones are native. The listed architecture names are
those <varname>ConditionArchitecture=</varname> supports, see
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
details. If architecture names are specified only those specified are listed.</para>
<example>
<title>Table output</title>
<programlisting>$ systemd-analyze architectures
NAME SUPPORT
alpha foreign
arc foreign
arc-be foreign
arm foreign
arm64 foreign
sparc foreign
sparc64 foreign
tilegx foreign
x86 secondary
x86-64 native</programlisting>
</example>
</refsect2>
</refsect1>
<refsect1>

View File

@ -1321,6 +1321,10 @@
<literal>arc-be</literal>, or
<literal>native</literal>.</para>
<para>Use
<citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry>
for the complete list of known architectures.</para>
<para>The architecture is determined from the information returned by
<citerefentry project='man-pages'><refentrytitle>uname</refentrytitle><manvolnum>2</manvolnum></citerefentry>
and is thus subject to

View File

@ -0,0 +1,88 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "analyze.h"
#include "analyze-architectures.h"
#include "format-table.h"
static int add_arch(Table *t, Architecture a) {
const char *c, *color;
int r;
assert(t);
if (a == native_architecture()) {
c = "native";
color = ANSI_HIGHLIGHT_GREEN;
} else if (a == uname_architecture()) {
c = "uname";
color = ANSI_HIGHLIGHT;
#ifdef ARCHITECTURE_SECONDARY
} else if (a == ARCHITECTURE_SECONDARY) {
c = "secondary";
color = NULL;
#endif
} else {
c = "foreign";
color = ANSI_GREY;
}
r = table_add_many(t,
TABLE_INT, (int) a,
TABLE_STRING, architecture_to_string(a),
TABLE_STRING, c,
TABLE_SET_COLOR, color);
if (r < 0)
return table_log_add_error(r);
return 0;
}
int verb_architectures(int argc, char *argv[], void *userdata) {
_cleanup_(table_unrefp) Table *table = NULL;
int r;
table = table_new("id", "name", "support");
if (!table)
return log_oom();
(void) table_hide_column_from_display(table, (size_t) 0);
if (strv_isempty(strv_skip(argv, 1)))
for (Architecture a = 0; a < _ARCHITECTURE_MAX; a++) {
r = add_arch(table, a);
if (r < 0)
return r;
}
else {
STRV_FOREACH(as, strv_skip(argv, 1)) {
Architecture a;
if (streq(*as, "native"))
a = native_architecture();
else if (streq(*as, "uname"))
a = uname_architecture();
else if (streq(*as, "secondary")) {
#ifdef ARCHITECTURE_SECONDARY
a = ARCHITECTURE_SECONDARY;
#else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No secondary architecture.");
#endif
} else
a = architecture_from_string(*as);
if (a < 0)
return log_error_errno(a, "Architecture \"%s\" not known.", *as);
r = add_arch(table, a);
if (r < 0)
return r;
}
(void) table_set_sort(table, (size_t) 0);
}
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
if (r < 0)
return log_error_errno(r, "Failed to output table: %m");
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,4 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
int verb_architectures(int argc, char *argv[], void *userdata);

View File

@ -13,6 +13,7 @@
#include "alloc-util.h"
#include "analyze.h"
#include "analyze-architectures.h"
#include "analyze-blame.h"
#include "analyze-calendar.h"
#include "analyze-capability.h"
@ -25,6 +26,7 @@
#include "analyze-exit-status.h"
#include "analyze-fdstore.h"
#include "analyze-filesystems.h"
#include "analyze-image-policy.h"
#include "analyze-inspect-elf.h"
#include "analyze-log-control.h"
#include "analyze-malloc.h"
@ -41,7 +43,6 @@
#include "analyze-unit-files.h"
#include "analyze-unit-paths.h"
#include "analyze-verify.h"
#include "analyze-image-policy.h"
#include "build.h"
#include "bus-error.h"
#include "bus-locator.h"
@ -224,6 +225,7 @@ static int help(int argc, char *argv[], void *userdata) {
" capability [CAP...] List capability definitions\n"
" syscall-filter [NAME...] List syscalls in seccomp filters\n"
" filesystems [NAME...] List known filesystems\n"
" architectures [NAME...] List known architectures\n"
" condition CONDITION... Evaluate conditions and asserts\n"
" compare-versions VERSION1 [OP] VERSION2\n"
" Compare two version strings\n"
@ -556,9 +558,9 @@ static int parse_argv(int argc, char *argv[]) {
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Option --offline= is only supported for security right now.");
if (arg_json_format_flags != JSON_FORMAT_OFF && !STRPTR_IN_SET(argv[optind], "security", "inspect-elf", "plot", "fdstore", "pcrs"))
if (arg_json_format_flags != JSON_FORMAT_OFF && !STRPTR_IN_SET(argv[optind], "security", "inspect-elf", "plot", "fdstore", "pcrs", "architectures"))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Option --json= is only supported for security, inspect-elf, plot, fdstore, pcrs right now.");
"Option --json= is only supported for security, inspect-elf, plot, fdstore, pcrs, architectures right now.");
if (arg_threshold != 100 && !streq_ptr(argv[optind], "security"))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
@ -649,6 +651,7 @@ static int run(int argc, char *argv[]) {
{ "image-policy", 2, 2, 0, verb_image_policy },
{ "pcrs", VERB_ANY, VERB_ANY, 0, verb_pcrs },
{ "srk", VERB_ANY, 1, 0, verb_srk },
{ "architectures", VERB_ANY, VERB_ANY, 0, verb_architectures },
{}
};

View File

@ -1,6 +1,7 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
systemd_analyze_sources = files(
'analyze-architectures.c',
'analyze-blame.c',
'analyze-calendar.c',
'analyze-capability.c',

View File

@ -866,6 +866,13 @@ systemd-analyze pcrs
systemd-analyze pcrs --json=pretty
systemd-analyze pcrs 14 7 0 ima
systemd-analyze architectures
systemd-analyze architectures --json=pretty
systemd-analyze architectures x86
systemd-analyze architectures x86-64
systemd-analyze architectures native
systemd-analyze architectures uname
systemd-analyze log-level info
touch /testok