summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-09-19 12:11:23 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-09-19 12:14:19 +0200
commitd5a7f3b7d4bae2c7efde945f6dc21589f744c8f6 (patch)
tree85da96c3535a924f0dce3ec3d39c5dc1adfa1718 /src/shared
parentshell-completion/analyze: add has-tpm2 (diff)
downloadsystemd-d5a7f3b7d4bae2c7efde945f6dc21589f744c8f6.tar.xz
systemd-d5a7f3b7d4bae2c7efde945f6dc21589f744c8f6.zip
tpm2-util: colorize output of 'systemd-analyze has-tpm2'
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/tpm2-util.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c
index 9f5618c162..a9f6620a67 100644
--- a/src/shared/tpm2-util.c
+++ b/src/shared/tpm2-util.c
@@ -3,6 +3,7 @@
#include <sys/file.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "constants.h"
#include "creds-util.h"
#include "cryptsetup-util.h"
@@ -7909,6 +7910,10 @@ Tpm2Support tpm2_support_full(Tpm2Support mask) {
return support & mask;
}
+static void print_field(const char *s, bool supported) {
+ printf("%s%s%s%s\n", supported ? ansi_green() : ansi_red(), plus_minus(supported), s, ansi_normal());
+}
+
int verb_has_tpm2_generic(bool quiet) {
Tpm2Support s;
@@ -7916,22 +7921,17 @@ int verb_has_tpm2_generic(bool quiet) {
if (!quiet) {
if (s == TPM2_SUPPORT_FULL)
- puts("yes");
+ printf("%syes%s\n", ansi_green(), ansi_normal());
else if (s == TPM2_SUPPORT_NONE)
- puts("no");
+ printf("%sno%s\n", ansi_red(), ansi_normal());
else
- puts("partial");
-
- printf("%sfirmware\n"
- "%sdriver\n"
- "%ssystem\n"
- "%ssubsystem\n"
- "%slibraries\n",
- plus_minus(s & TPM2_SUPPORT_FIRMWARE),
- plus_minus(s & TPM2_SUPPORT_DRIVER),
- plus_minus(s & TPM2_SUPPORT_SYSTEM),
- plus_minus(s & TPM2_SUPPORT_SUBSYSTEM),
- plus_minus(s & TPM2_SUPPORT_LIBRARIES));
+ printf("%spartial%s\n", ansi_yellow(), ansi_normal());
+
+ print_field("firmware", FLAGS_SET(s, TPM2_SUPPORT_FIRMWARE));
+ print_field("driver", FLAGS_SET(s, TPM2_SUPPORT_DRIVER));
+ print_field("system", FLAGS_SET(s, TPM2_SUPPORT_SYSTEM));
+ print_field("subsystem", FLAGS_SET(s, TPM2_SUPPORT_SUBSYSTEM));
+ print_field("libraries", FLAGS_SET(s, TPM2_SUPPORT_LIBRARIES));
}
/* Return inverted bit flags. So that TPM2_SUPPORT_FULL becomes EXIT_SUCCESS and the other values