summaryrefslogtreecommitdiffstats
path: root/src/shared/kernel-config.c
blob: 483ca28211bc1b97e700303644b4afc2e6bcc750 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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. */
}