summaryrefslogtreecommitdiff
path: root/src/boot/bootctl.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-07-28 10:48:16 +0200
committerLennart Poettering <lennart@poettering.net>2022-08-02 10:28:49 +0200
commit51470e1e5601c8fb5371fbc9e1b3ed69ca61c7a0 (patch)
tree467ce63495422bf2115cd990df586c4482fb5404 /src/boot/bootctl.c
parent84be9b63ebac1d320b1e39ccf6e0895e621af887 (diff)
downloadsystemd-51470e1e5601c8fb5371fbc9e1b3ed69ca61c7a0.tar.gz
bootctl: suppress "Boot Loaders Listed in EFI Variables" section header if section empty
Some more cosmetics.
Diffstat (limited to 'src/boot/bootctl.c')
-rw-r--r--src/boot/bootctl.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c
index 5ac742ef29..f04463157a 100644
--- a/src/boot/bootctl.c
+++ b/src/boot/bootctl.c
@@ -566,23 +566,30 @@ static int status_binaries(const char *esp_path, sd_id128_t partition) {
return 0;
}
-static int print_efi_option(uint16_t id, bool in_order) {
+static int print_efi_option(uint16_t id, int *n_printed, bool in_order) {
_cleanup_free_ char *title = NULL;
_cleanup_free_ char *path = NULL;
sd_id128_t partition;
bool active;
int r;
+ assert(n_printed);
+
r = efi_get_boot_option(id, &title, &partition, &path, &active);
if (r < 0)
- return r;
+ return log_error_errno(r, "Failed to read boot option %u: %m", id);
/* print only configured entries with partition information */
- if (!path || sd_id128_is_null(partition))
+ if (!path || sd_id128_is_null(partition)) {
+ log_debug("Ignoring boot entry %u without partition information.", id);
return 0;
+ }
efi_tilt_backslashes(path);
+ if (*n_printed == 0) /* Print section title before first entry */
+ printf("%sBoot Loaders Listed in EFI Variables:%s\n", ansi_underline(), ansi_normal());
+
printf(" Title: %s%s%s\n", ansi_highlight(), strna(title), ansi_normal());
printf(" ID: 0x%04X\n", id);
printf(" Status: %sactive%s\n", active ? "" : "in", in_order ? ", boot-order" : "");
@@ -591,12 +598,13 @@ static int print_efi_option(uint16_t id, bool in_order) {
printf(" File: %s%s\n", special_glyph(SPECIAL_GLYPH_TREE_RIGHT), path);
printf("\n");
- return 0;
+ (*n_printed)++;
+ return 1;
}
static int status_variables(void) {
_cleanup_free_ uint16_t *options = NULL, *order = NULL;
- int n_options, n_order;
+ int n_options, n_order, n_printed = 0;
n_options = efi_get_boot_options(&options);
if (n_options == -ENOENT)
@@ -613,9 +621,8 @@ static int status_variables(void) {
return log_error_errno(n_order, "Failed to read EFI boot order: %m");
/* print entries in BootOrder first */
- printf("%sBoot Loaders Listed in EFI Variables:%s\n", ansi_underline(), ansi_normal());
for (int i = 0; i < n_order; i++)
- print_efi_option(order[i], true);
+ (void) print_efi_option(order[i], &n_printed, /* in_order= */ true);
/* print remaining entries */
for (int i = 0; i < n_options; i++) {
@@ -623,12 +630,15 @@ static int status_variables(void) {
if (options[i] == order[j])
goto next_option;
- print_efi_option(options[i], false);
+ (void) print_efi_option(options[i], &n_printed, /* in_order= */ false);
next_option:
continue;
}
+ if (n_printed == 0)
+ printf("No boot loaders listed in EFI Variables.\n\n");
+
return 0;
}