]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/bootspec: expose more parts of the config parsing
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 5 May 2022 20:44:35 +0000 (22:44 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 8 May 2022 15:56:12 +0000 (17:56 +0200)
src/shared/bootspec.c
src/shared/bootspec.h

index 6647aade042986f3879d33ddf958ef1a8794f20c..7215c9fc14264b9ec60411633a63592e6c8aea9f 100644 (file)
@@ -191,27 +191,19 @@ void boot_config_free(BootConfig *config) {
         set_free(config->inodes_seen);
 }
 
-static int boot_loader_read_conf(const char *path, BootConfig *config) {
-        _cleanup_fclose_ FILE *f = NULL;
+int boot_loader_read_conf(BootConfig *config, FILE *file, const char *path) {
         unsigned line = 1;
         int r;
 
-        assert(path);
         assert(config);
-
-        f = fopen(path, "re");
-        if (!f) {
-                if (errno == ENOENT)
-                        return 0;
-
-                return log_error_errno(errno, "Failed to open \"%s\": %m", path);
-        }
+        assert(file);
+        assert(path);
 
         for (;;) {
                 _cleanup_free_ char *buf = NULL, *field = NULL;
                 const char *p;
 
-                r = read_line(f, LONG_LINE_MAX, &buf);
+                r = read_line(file, LONG_LINE_MAX, &buf);
                 if (r == 0)
                         break;
                 if (r == -ENOBUFS)
@@ -262,6 +254,23 @@ static int boot_loader_read_conf(const char *path, BootConfig *config) {
         return 1;
 }
 
+static int boot_loader_read_conf_path(BootConfig *config, const char *path) {
+        _cleanup_fclose_ FILE *f = NULL;
+
+        assert(config);
+        assert(path);
+
+        f = fopen(path, "re");
+        if (!f) {
+                if (errno == ENOENT)
+                        return 0;
+
+                return log_error_errno(errno, "Failed to open \"%s\": %m", path);
+        }
+
+        return boot_loader_read_conf(config, f, path);
+}
+
 static int boot_entry_compare(const BootEntry *a, const BootEntry *b) {
         int r;
 
@@ -847,6 +856,18 @@ int boot_config_select_special_entries(BootConfig *config) {
         return 0;
 }
 
+int boot_config_finalize(BootConfig *config) {
+        int r;
+
+        typesafe_qsort(config->entries, config->n_entries, boot_entry_compare);
+
+        r = boot_entries_uniquify(config->entries, config->n_entries);
+        if (r < 0)
+                return log_error_errno(r, "Failed to uniquify boot entries: %m");
+
+        return 0;
+}
+
 int boot_config_load(
                 BootConfig *config,
                 const char *esp_path,
@@ -859,7 +880,7 @@ int boot_config_load(
 
         if (esp_path) {
                 p = strjoina(esp_path, "/loader/loader.conf");
-                r = boot_loader_read_conf(p, config);
+                r = boot_loader_read_conf_path(config, p);
                 if (r < 0)
                         return r;
 
@@ -886,13 +907,7 @@ int boot_config_load(
                         return r;
         }
 
-        typesafe_qsort(config->entries, config->n_entries, boot_entry_compare);
-
-        r = boot_entries_uniquify(config->entries, config->n_entries);
-        if (r < 0)
-                return log_error_errno(r, "Failed to uniquify boot entries: %m");
-
-        return 0;
+        return boot_config_finalize(config);
 }
 
 int boot_config_load_auto(
index f235830c3c0eb89299f8808fe269dd7e4bf229ea..3ff593a23f70e41ebcfbd567b4e4dcb9dd78f655 100644 (file)
@@ -86,6 +86,9 @@ static inline const BootEntry* boot_config_default_entry(const BootConfig *confi
 
 void boot_config_free(BootConfig *config);
 
+int boot_loader_read_conf(BootConfig *config, FILE *file, const char *path);
+
+int boot_config_finalize(BootConfig *config);
 int boot_config_load(BootConfig *config, const char *esp_path, const char *xbootldr_path);
 int boot_config_load_auto(BootConfig *config, const char *override_esp_path, const char *override_xbootldr_path);
 int boot_config_augment_from_loader(BootConfig *config, char **list, bool only_auto);