]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootspec: drop ".conf" from BootEntry.filename
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 26 Dec 2017 00:35:35 +0000 (09:35 +0900)
committerLennart Poettering <lennart@poettering.net>
Tue, 26 Dec 2017 11:12:36 +0000 (12:12 +0100)
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 #7727.

src/shared/bootspec.c

index c0a10417d8b11905c8b56474bbea41487662b1fb..e97b5cdb79732226bd92dd4c548e855cb765c732 100644 (file)
@@ -52,22 +52,30 @@ void boot_entry_free(BootEntry *entry) {
 }
 
 int boot_entry_load(const char *path, BootEntry *entry) {
+        _cleanup_(boot_entry_free) BootEntry tmp = {};
         _cleanup_fclose_ FILE *f = NULL;
         unsigned line = 1;
-        _cleanup_(boot_entry_free) BootEntry tmp = {};
+        char *b, *c;
         int r;
 
         assert(path);
         assert(entry);
 
-        f = fopen(path, "re");
-        if (!f)
-                return log_error_errno(errno, "Failed to open \"%s\": %m", path);
+        c = endswith_no_case(path, ".conf");
+        if (!c) {
+                log_error("Invalid loader entry filename: %s", path);
+                return -EINVAL;
+        }
 
-        tmp.filename = strdup(basename(path));
+        b = basename(path);
+        tmp.filename = strndup(b, c - b);
         if (!tmp.filename)
                 return log_oom();
 
+        f = fopen(path, "re");
+        if (!f)
+                return log_error_errno(errno, "Failed to open \"%s\": %m", path);
+
         for (;;) {
                 _cleanup_free_ char *buf = NULL;
                 char *p;