Debian Codegraph @

src/shared/kernel-config.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "alloc-util.h"
4 #include "conf-parser.h"
5 #include "fd-util.h"
6 #include "kernel-config.h"
7 #include "path-util.h"
8
9 int load_kernel_install_conf_at(
10 const char *root,
11 int root_fd,
12 const char *conf_root,
13 char **ret_machine_id,
14 char **ret_boot_root,
15 char **ret_layout,
16 char **ret_initrd_generator,
17 char **ret_uki_generator) {
18
19 _cleanup_free_ char *machine_id = NULL, *boot_root = NULL, *layout = NULL,
20 *initrd_generator = NULL, *uki_generator = NULL;
21 const ConfigTableItem items[] = {
22 { NULL, "MACHINE_ID", config_parse_string, 0, &machine_id },
23 { NULL, "BOOT_ROOT", config_parse_string, 0, &boot_root },
24 { NULL, "layout", config_parse_string, 0, &layout },
25 { NULL, "initrd_generator", config_parse_string, 0, &initrd_generator },
26 { NULL, "uki_generator", config_parse_string, 0, &uki_generator },
27 {}
28 };
29 int r;
30
31 assert(wildcard_fd_is_valid(root_fd));
32
33 if (conf_root) {
34 _cleanup_free_ char *conf = path_join(conf_root, "install.conf");
35 if (!conf)
36 return log_oom();
37
38 r = config_parse_many_full(
39 STRV_MAKE_CONST(conf),
40 STRV_MAKE_CONST(conf_root),
41 "install.conf.d",
42 root,
43 root_fd,
44 /* sections= */ NULL,
45 config_item_table_lookup, items,
46 CONFIG_PARSE_WARN,
47 /* userdata= */ NULL,
48 /* ret_stats_by_path= */ NULL,
49 /* ret_dropin_files= */ NULL);
50 } else
51 r = config_parse_standard_file_with_dropins_full(
52 root,
53 root_fd,
54 "kernel/install.conf",
55 /* sections= */ NULL,
56 config_item_table_lookup, items,
57 CONFIG_PARSE_WARN,
58 /* userdata= */ NULL,
59 /* ret_stats_by_path= */ NULL,
60 /* ret_dropin_files= */ NULL);
61 if (r < 0 && r != -ENOENT)
62 return r;
63
64 if (ret_machine_id)
65 *ret_machine_id = TAKE_PTR(machine_id);
66 if (ret_boot_root)
67 *ret_boot_root = TAKE_PTR(boot_root);
68 if (ret_layout)
69 *ret_layout = TAKE_PTR(layout);
70 if (ret_initrd_generator)
71 *ret_initrd_generator = TAKE_PTR(initrd_generator);
72 if (ret_uki_generator)
73 *ret_uki_generator = TAKE_PTR(uki_generator);
74 return r >= 0; /* Return 0 if we got -ENOENT above, 1 otherwise. */
75 }