]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/bootspec: also export boot_config_load_type1()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 6 May 2022 12:44:05 +0000 (14:44 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 8 May 2022 15:57:57 +0000 (17:57 +0200)
The reallocation of memory and counter incrementation is moved from
the only caller to the function. This way the callers can remain oblivious
of the BootConfig internals.

src/shared/bootspec.c
src/shared/bootspec.h

index 7215c9fc14264b9ec60411633a63592e6c8aea9f..50875021d42c6c95a8daef344948cdc8385095c9 100644 (file)
@@ -168,6 +168,31 @@ static int boot_entry_load_type1(
         return 0;
 }
 
+int boot_config_load_type1(
+                BootConfig *config,
+                FILE *f,
+                const char *root,
+                const char *dir,
+                const char *id) {
+        int r;
+
+        assert(config);
+        assert(f);
+        assert(root);
+        assert(dir);
+        assert(id);
+
+        if (!GREEDY_REALLOC0(config->entries, config->n_entries + 1))
+                return log_oom();
+
+        r = boot_entry_load_type1(f, root, dir, id, config->entries + config->n_entries);
+        if (r < 0)
+                return r;
+
+        config->n_entries++;
+        return 0;
+}
+
 void boot_config_free(BootConfig *config) {
         assert(config);
 
@@ -397,14 +422,9 @@ static int boot_entries_find_type1(
                 if (r == 0) /* inode already seen or otherwise not relevant */
                         continue;
 
-                if (!GREEDY_REALLOC0(config->entries, config->n_entries + 1))
-                        return log_oom();
-
-                r = boot_entry_load_type1(f, root, dir, de->d_name, config->entries + config->n_entries);
-                if (r < 0)
-                        continue;
-
-                config->n_entries++;
+                r = boot_config_load_type1(config, f, root, dir, de->d_name);
+                if (r == -ENOMEM)
+                        return r;
         }
 
         return 0;
index 3ff593a23f70e41ebcfbd567b4e4dcb9dd78f655..ff54cc2e84801d682d7bca497b95fd5dfcda154e 100644 (file)
@@ -88,6 +88,13 @@ void boot_config_free(BootConfig *config);
 
 int boot_loader_read_conf(BootConfig *config, FILE *file, const char *path);
 
+int boot_config_load_type1(
+                BootConfig *config,
+                FILE *f,
+                const char *root,
+                const char *dir,
+                const char *id);
+
 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);