summaryrefslogtreecommitdiff
path: root/src/boot/bless-boot.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-02-11 22:23:37 +0100
committerLennart Poettering <lennart@poettering.net>2022-02-14 16:24:04 +0100
commitf63b5ad93592ff64b5e8a83b63f2a3daade28114 (patch)
treef8e2b4b98686412a3f667a727ffac4d2c830e7b7 /src/boot/bless-boot.c
parent56350400918c6979c60d46b7825e9671ee31f09c (diff)
downloadsystemd-f63b5ad93592ff64b5e8a83b63f2a3daade28114.tar.gz
boot: suppress XBOOTLDR if same device as ESP when enumerating entries
On my local system I linked up the ESP and XBOOTLDR partitions, and ended up with duplicate entries being listed. Try hard to detect that and only enumerate entries in the ESP if it turns out that both dirs have the same dev_t. This should detect both bind mounted and symlinked cases and should make our list output less confusing.
Diffstat (limited to 'src/boot/bless-boot.c')
-rw-r--r--src/boot/bless-boot.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/boot/bless-boot.c b/src/boot/bless-boot.c
index 9e4b0d1f72..2cbabc6c59 100644
--- a/src/boot/bless-boot.c
+++ b/src/boot/bless-boot.c
@@ -14,6 +14,7 @@
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
+#include "stat-util.h"
#include "sync-util.h"
#include "terminal-util.h"
#include "util.h"
@@ -98,17 +99,18 @@ static int parse_argv(int argc, char *argv[]) {
static int acquire_path(void) {
_cleanup_free_ char *esp_path = NULL, *xbootldr_path = NULL;
+ dev_t esp_devid = 0, xbootldr_devid = 0;
char **a;
int r;
if (!strv_isempty(arg_path))
return 0;
- r = find_esp_and_warn(NULL, false, &esp_path, NULL, NULL, NULL, NULL);
+ r = find_esp_and_warn(NULL, /* unprivileged_mode= */ false, &esp_path, NULL, NULL, NULL, NULL, &esp_devid);
if (r < 0 && r != -ENOKEY) /* ENOKEY means not found, and is the only error the function won't log about on its own */
return r;
- r = find_xbootldr_and_warn(NULL, false, &xbootldr_path, NULL);
+ r = find_xbootldr_and_warn(NULL, /* unprivileged_mode= */ false, &xbootldr_path, NULL, &xbootldr_devid);
if (r < 0 && r != -ENOKEY)
return r;
@@ -117,8 +119,10 @@ static int acquire_path(void) {
"Couldn't find $BOOT partition. It is recommended to mount it to /boot.\n"
"Alternatively, use --path= to specify path to mount point.");
- if (esp_path)
+ if (esp_path && xbootldr_path && !devid_set_and_equal(esp_devid, xbootldr_devid)) /* in case the two paths refer to the same inode, suppress one */
a = strv_new(esp_path, xbootldr_path);
+ else if (esp_path)
+ a = strv_new(esp_path);
else
a = strv_new(xbootldr_path);
if (!a)
@@ -130,7 +134,7 @@ static int acquire_path(void) {
_cleanup_free_ char *j = NULL;
j = strv_join(arg_path, ":");
- log_debug("Using %s as boot loader drop-in search path.", j);
+ log_debug("Using %s as boot loader drop-in search path.", strna(j));
}
return 0;