Skip to content

Commit 263195c

Browse files
yuwatapoettering
authored andcommitted
bootspec: drop ".conf" from BootEntry.filename
The boot loader systemd-boot removes ".conf" from file name of entry configs, and determine which entry is the default entry. However, bootspec, which is used by systemctl and bootctl did not remove ".conf", then sometimes bootctl marks wrong entry as default. This fixes the logic to choose the default entry in bootspec, to match the logic used in systemd-boot boot loader. Fixes systemd#7727.
1 parent 7629744 commit 263195c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/shared/bootspec.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,30 @@ void boot_entry_free(BootEntry *entry) {
5252
}
5353

5454
int boot_entry_load(const char *path, BootEntry *entry) {
55+
_cleanup_(boot_entry_free) BootEntry tmp = {};
5556
_cleanup_fclose_ FILE *f = NULL;
5657
unsigned line = 1;
57-
_cleanup_(boot_entry_free) BootEntry tmp = {};
58+
char *b, *c;
5859
int r;
5960

6061
assert(path);
6162
assert(entry);
6263

63-
f = fopen(path, "re");
64-
if (!f)
65-
return log_error_errno(errno, "Failed to open \"%s\": %m", path);
64+
c = endswith_no_case(path, ".conf");
65+
if (!c) {
66+
log_error("Invalid loader entry filename: %s", path);
67+
return -EINVAL;
68+
}
6669

67-
tmp.filename = strdup(basename(path));
70+
b = basename(path);
71+
tmp.filename = strndup(b, c - b);
6872
if (!tmp.filename)
6973
return log_oom();
7074

75+
f = fopen(path, "re");
76+
if (!f)
77+
return log_error_errno(errno, "Failed to open \"%s\": %m", path);
78+
7179
for (;;) {
7280
_cleanup_free_ char *buf = NULL;
7381
char *p;

0 commit comments

Comments
 (0)