Fixes https://github.com/systemd/systemd/issues/32992.
#include "fs-util.h"
#include "glyph-util.h"
#include "id128-util.h"
+#include "kernel-config.h"
#include "os-util.h"
#include "path-util.h"
#include "rm-rf.h"
return 0;
}
-static int load_kernel_install_conf(void) {
+static int load_kernel_install_layout(void) {
_cleanup_free_ char *layout = NULL;
- const ConfigTableItem items[] = {
- { NULL, "layout", config_parse_string, 0, &layout },
- {}
- };
int r;
- const char *conf_root = getenv("KERNEL_INSTALL_CONF_ROOT");
-
- if (conf_root) {
- _cleanup_free_ char *conf = NULL;
-
- conf = path_join(conf_root, "install.conf");
- if (!conf)
- return log_oom();
-
- r = config_parse_many(
- STRV_MAKE_CONST(conf),
- STRV_MAKE_CONST(conf_root),
- "install.conf.d",
- /* root= */ NULL, /* $KERNEL_INSTALL_CONF_ROOT and --root are independent */
- /* sections= */ NULL,
- config_item_table_lookup, items,
- CONFIG_PARSE_WARN,
- /* userdata = */ NULL,
- /* ret_stats_by_path= */ NULL,
- /* ret_dropin_files= */ NULL);
- } else
- r = config_parse_standard_file_with_dropins_full(
- arg_root,
- "kernel/install.conf",
- /* sections= */ NULL,
- config_item_table_lookup, items,
- CONFIG_PARSE_WARN,
- /* userdata = */ NULL,
- /* ret_stats_by_path= */ NULL,
- /* ret_dropin_files= */ NULL);
- if (r < 0)
- return r == -ENOENT ? 0 : r;
+ r = load_kernel_install_conf(arg_root,
+ getenv("KERNEL_INSTALL_CONF_ROOT"),
+ /* ret_machine_id= */ NULL,
+ /* ret_boot_root= */ NULL,
+ &layout,
+ /* ret_initrd_generator= */ NULL,
+ /* ret_uki_generator= */ NULL);
+ if (r <= 0)
+ return r;
if (!isempty(layout)) {
log_debug("layout=%s is specified in config.", layout);
if (r < 0)
return r;
- r = load_kernel_install_conf();
+ r = load_kernel_install_layout();
if (r < 0)
return r;
#include "fs-util.h"
#include "id128-util.h"
#include "image-policy.h"
+#include "kernel-config.h"
#include "kernel-image.h"
#include "main-func.h"
#include "mkdir.h"
static int context_load_install_conf(Context *c) {
_cleanup_free_ char *machine_id = NULL, *boot_root = NULL, *layout = NULL,
*initrd_generator = NULL, *uki_generator = NULL;
- const ConfigTableItem items[] = {
- { NULL, "MACHINE_ID", config_parse_string, 0, &machine_id },
- { NULL, "BOOT_ROOT", config_parse_string, 0, &boot_root },
- { NULL, "layout", config_parse_string, 0, &layout },
- { NULL, "initrd_generator", config_parse_string, 0, &initrd_generator },
- { NULL, "uki_generator", config_parse_string, 0, &uki_generator },
- {}
- };
int r;
assert(c);
- if (c->conf_root) {
- _cleanup_free_ char *conf = NULL;
-
- conf = path_join(c->conf_root, "install.conf");
- if (!conf)
- return log_oom();
-
- r = config_parse_many(
- STRV_MAKE_CONST(conf),
- STRV_MAKE_CONST(c->conf_root),
- "install.conf.d",
- /* root= */ NULL, /* $KERNEL_INSTALL_CONF_ROOT and --root are independent */
- /* sections= */ NULL,
- config_item_table_lookup, items,
- CONFIG_PARSE_WARN,
- /* userdata = */ NULL,
- /* ret_stats_by_path= */ NULL,
- /* ret_dropin_files= */ NULL);
- } else
- r = config_parse_standard_file_with_dropins_full(
- arg_root,
- "kernel/install.conf",
- /* sections= */ NULL,
- config_item_table_lookup, items,
- CONFIG_PARSE_WARN,
- /* userdata = */ NULL,
- /* ret_stats_by_path= */ NULL,
- /* ret_dropin_files= */ NULL);
- if (r < 0)
- return r == -ENOENT ? 0 : r;
+ r = load_kernel_install_conf(arg_root,
+ c->conf_root,
+ &machine_id,
+ &boot_root,
+ &layout,
+ &initrd_generator,
+ &uki_generator);
+ if (r <= 0)
+ return r;
(void) context_set_machine_id(c, machine_id, "config");
(void) context_set_boot_root(c, boot_root, "config");
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <errno.h>
+
+#include "conf-parser.h"
+#include "kernel-config.h"
+#include "macro.h"
+#include "path-util.h"
+#include "strv.h"
+
+int load_kernel_install_conf(
+ const char *root,
+ const char *conf_root,
+ char **ret_machine_id,
+ char **ret_boot_root,
+ char **ret_layout,
+ char **ret_initrd_generator,
+ char **ret_uki_generator) {
+
+ _cleanup_free_ char *machine_id = NULL, *boot_root = NULL, *layout = NULL,
+ *initrd_generator = NULL, *uki_generator = NULL;
+ const ConfigTableItem items[] = {
+ { NULL, "MACHINE_ID", config_parse_string, 0, &machine_id },
+ { NULL, "BOOT_ROOT", config_parse_string, 0, &boot_root },
+ { NULL, "layout", config_parse_string, 0, &layout },
+ { NULL, "initrd_generator", config_parse_string, 0, &initrd_generator },
+ { NULL, "uki_generator", config_parse_string, 0, &uki_generator },
+ {}
+ };
+ int r;
+
+ if (conf_root) {
+ _cleanup_free_ char *conf = path_join(conf_root, "install.conf");
+ if (!conf)
+ return log_oom();
+
+ r = config_parse_many(
+ STRV_MAKE_CONST(conf),
+ STRV_MAKE_CONST(conf_root),
+ "install.conf.d",
+ /* root= */ NULL, /* $KERNEL_INSTALL_CONF_ROOT and --root are independent */
+ /* sections= */ NULL,
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN,
+ /* userdata= */ NULL,
+ /* ret_stats_by_path= */ NULL,
+ /* ret_dropin_files= */ NULL);
+ } else
+ r = config_parse_standard_file_with_dropins_full(
+ root,
+ "kernel/install.conf",
+ /* sections= */ NULL,
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN,
+ /* userdata= */ NULL,
+ /* ret_stats_by_path= */ NULL,
+ /* ret_dropin_files= */ NULL);
+ if (r < 0 && r != -ENOENT)
+ return r;
+
+ if (ret_machine_id)
+ *ret_machine_id = TAKE_PTR(machine_id);
+ if (ret_boot_root)
+ *ret_boot_root = TAKE_PTR(boot_root);
+ if (ret_layout)
+ *ret_layout = TAKE_PTR(layout);
+ if (ret_initrd_generator)
+ *ret_initrd_generator = TAKE_PTR(initrd_generator);
+ if (ret_uki_generator)
+ *ret_uki_generator = TAKE_PTR(uki_generator);
+ return r >= 0; /* Return 0 if we got -ENOENT above, 1 otherwise. */
+}
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+int load_kernel_install_conf(
+ const char *root,
+ const char *conf_root,
+ char **ret_machine_id,
+ char **ret_boot_root,
+ char **ret_layout,
+ char **ret_initrd_generator,
+ char **ret_uki_generator);
'journal-util.c',
'json.c',
'kbd-util.c',
+ 'kernel-config.c',
'kernel-image.c',
'keyring-util.c',
'killall.c',