summaryrefslogtreecommitdiffstats
path: root/src/analyze/analyze-architectures.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:40 +0000
commitfc53809803cd2bc2434e312b19a18fa36776da12 (patch)
treeb4b43bd6538f51965ce32856e9c053d0f90919c8 /src/analyze/analyze-architectures.c
parentAdding upstream version 255.5. (diff)
downloadsystemd-fc53809803cd2bc2434e312b19a18fa36776da12.tar.xz
systemd-fc53809803cd2bc2434e312b19a18fa36776da12.zip
Adding upstream version 256.upstream/256
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/analyze/analyze-architectures.c')
-rw-r--r--src/analyze/analyze-architectures.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/analyze/analyze-architectures.c b/src/analyze/analyze-architectures.c
new file mode 100644
index 0000000..2d155d5
--- /dev/null
+++ b/src/analyze/analyze-architectures.c
@@ -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;
+}