summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2024-05-24 11:25:26 +0200
committerGitHub <noreply@github.com>2024-05-24 11:25:26 +0200
commite67129e5e4591ddd5ca396fa9faa655fbedff756 (patch)
tree045650eb2877954e3751ec96da32654a9fac70aa
parentman: mention that NFTSet is only available for system services (diff)
parentshared/conf-parser: do not print "(null)" as section name (diff)
downloadsystemd-e67129e5e4591ddd5ca396fa9faa655fbedff756.tar.xz
systemd-e67129e5e4591ddd5ca396fa9faa655fbedff756.zip
Merge pull request #32994 from keszybz/kernel-install-parsing
Improve parsing of kernel/install.conf
-rw-r--r--src/boot/bootctl-install.c50
-rw-r--r--src/kernel-install/kernel-install.c48
-rw-r--r--src/shared/conf-parser.c6
-rw-r--r--src/shared/kernel-config.c72
-rw-r--r--src/shared/kernel-config.h10
-rw-r--r--src/shared/meson.build1
6 files changed, 110 insertions, 77 deletions
diff --git a/src/boot/bootctl-install.c b/src/boot/bootctl-install.c
index b805fa8f7a..dc46d30c5b 100644
--- a/src/boot/bootctl-install.c
+++ b/src/boot/bootctl-install.c
@@ -14,6 +14,7 @@
#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"
@@ -81,46 +82,19 @@ static int load_etc_machine_info(void) {
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);
@@ -147,7 +121,7 @@ static int settle_make_entry_directory(void) {
if (r < 0)
return r;
- r = load_kernel_install_conf();
+ r = load_kernel_install_layout();
if (r < 0)
return r;
diff --git a/src/kernel-install/kernel-install.c b/src/kernel-install/kernel-install.c
index 6581e80656..5d559a97a8 100644
--- a/src/kernel-install/kernel-install.c
+++ b/src/kernel-install/kernel-install.c
@@ -19,6 +19,7 @@
#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"
@@ -434,48 +435,19 @@ static int context_load_environment(Context *c) {
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");
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 277f4ee42f..fcc45c6e25 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -160,7 +160,11 @@ static int next_assignment(
/* Warn about unknown non-extension fields. */
if (!(flags & CONFIG_PARSE_RELAXED) && !startswith(lvalue, "X-"))
log_syntax(unit, LOG_WARNING, filename, line, 0,
- "Unknown key name '%s' in section '%s', ignoring.", lvalue, section);
+ "Unknown key '%s'%s%s%s, ignoring.",
+ lvalue,
+ section ? " in section [" : "",
+ strempty(section),
+ section ? "]" : "");
return 0;
}
diff --git a/src/shared/kernel-config.c b/src/shared/kernel-config.c
new file mode 100644
index 0000000000..483ca28211
--- /dev/null
+++ b/src/shared/kernel-config.c
@@ -0,0 +1,72 @@
+/* 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. */
+}
diff --git a/src/shared/kernel-config.h b/src/shared/kernel-config.h
new file mode 100644
index 0000000000..568187061c
--- /dev/null
+++ b/src/shared/kernel-config.h
@@ -0,0 +1,10 @@
+/* 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);
diff --git a/src/shared/meson.build b/src/shared/meson.build
index d01367a159..8fb2b7ec7f 100644
--- a/src/shared/meson.build
+++ b/src/shared/meson.build
@@ -98,6 +98,7 @@ shared_sources = files(
'journal-util.c',
'json.c',
'kbd-util.c',
+ 'kernel-config.c',
'kernel-image.c',
'keyring-util.c',
'killall.c',