From: Zbigniew Jędrzejewski-Szmek Date: Wed, 21 Feb 2024 22:44:09 +0000 (+0100) Subject: bootctl: use the full parser too X-Git-Tag: v256-rc1~601^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=088ab887153193cec9561598eac220608ecd22b9;p=thirdparty%2Fsystemd.git bootctl: use the full parser too --- diff --git a/src/boot/bootctl-install.c b/src/boot/bootctl-install.c index a0a474537ef..b805fa8f7ad 100644 --- a/src/boot/bootctl-install.c +++ b/src/boot/bootctl-install.c @@ -81,44 +81,52 @@ static int load_etc_machine_info(void) { return 0; } -static int load_kernel_install_conf_one(const char *dir) { - _cleanup_free_ char *layout = NULL, *p = NULL; +static int load_kernel_install_conf(void) { + _cleanup_free_ char *layout = NULL; + const ConfigTableItem items[] = { + { NULL, "layout", config_parse_string, 0, &layout }, + {} + }; int r; - assert(dir); - - p = path_join(arg_root, dir, "install.conf"); - if (!p) - return log_oom(); - - r = parse_env_file(NULL, p, "layout", &layout); - if (r == -ENOENT) - return 0; + 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 log_error_errno(r, "Failed to parse %s: %m", p); + return r == -ENOENT ? 0 : r; if (!isempty(layout)) { - log_debug("layout=%s is specified in %s.", layout, p); + log_debug("layout=%s is specified in config.", layout); free_and_replace(arg_install_layout, layout); } - return 1; -} - -static int load_kernel_install_conf(void) { - const char *conf_root; - int r; - - conf_root = getenv("KERNEL_INSTALL_CONF_ROOT"); - if (conf_root) - return load_kernel_install_conf_one(conf_root); - - FOREACH_STRING(p, "/etc/kernel", "/usr/lib/kernel") { - r = load_kernel_install_conf_one(p); - if (r != 0) - return r; - } - return 0; }