tree-wide: Load entry-token and layout.conf from /usr/lib/kernel/ as well

This commit is contained in:
Daan De Meyer
2024-01-16 14:54:04 +09:00
committed by Yu Watanabe
parent 0e2f18eedd
commit 16e4efa7d3
6 changed files with 55 additions and 41 deletions
+23 -4
View File
@@ -81,11 +81,13 @@ static int load_etc_machine_info(void) {
return 0;
}
static int load_etc_kernel_install_conf(void) {
static int load_kernel_install_conf_one(const char *dir) {
_cleanup_free_ char *layout = NULL, *p = NULL;
int r;
p = path_join(arg_root, etc_kernel(), "install.conf");
assert(dir);
p = path_join(arg_root, dir, "install.conf");
if (!p)
return log_oom();
@@ -100,6 +102,23 @@ static int load_etc_kernel_install_conf(void) {
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;
}
@@ -120,7 +139,7 @@ static int settle_make_entry_directory(void) {
if (r < 0)
return r;
r = load_etc_kernel_install_conf();
r = load_kernel_install_conf();
if (r < 0)
return r;
@@ -557,7 +576,7 @@ static int install_entry_token(void) {
if (!arg_make_entry_directory && arg_entry_token_type == BOOT_ENTRY_TOKEN_MACHINE_ID)
return 0;
p = path_join(arg_root, etc_kernel(), "entry-token");
p = path_join(arg_root, getenv("KERNEL_INSTALL_CONF_ROOT") ?: "/etc/kernel/", "entry-token");
if (!p)
return log_oom();
+1 -1
View File
@@ -119,7 +119,7 @@ int settle_entry_token(void) {
r = boot_entry_token_ensure(
arg_root,
etc_kernel(),
getenv("KERNEL_INSTALL_CONF_ROOT"),
arg_machine_id,
/* machine_id_is_random = */ false,
&arg_entry_token_type,
-4
View File
@@ -8,7 +8,3 @@ const char *get_efi_arch(void);
int get_file_version(int fd, char **ret);
int settle_entry_token(void);
static inline const char* etc_kernel(void) {
return getenv("KERNEL_INSTALL_CONF_ROOT") ?: "/etc/kernel/";
}
+2 -21
View File
@@ -428,21 +428,6 @@ static int context_load_environment(Context *c) {
return 0;
}
static int context_ensure_conf_root(Context *c) {
int r;
assert(c);
if (c->conf_root)
return 0;
r = chaseat(c->rfd, "/etc/kernel", CHASE_AT_RESOLVE_IN_ROOT, &c->conf_root, /* ret_fd = */ NULL);
if (r < 0)
log_debug_errno(r, "Failed to chase /etc/kernel, ignoring: %m");
return 0;
}
static int context_load_install_conf_one(Context *c, const char *path) {
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char
@@ -495,8 +480,8 @@ static int context_load_install_conf(Context *c) {
return r;
}
STRV_FOREACH(p, STRV_MAKE("/etc/kernel", "/usr/lib/kernel")) {
r = context_load_install_conf_one(c, *p);
FOREACH_STRING(p, "/etc/kernel", "/usr/lib/kernel") {
r = context_load_install_conf_one(c, p);
if (r != 0)
return r;
}
@@ -730,10 +715,6 @@ static int context_init(Context *c) {
if (r < 0)
return r;
r = context_ensure_conf_root(c);
if (r < 0)
return r;
r = context_load_install_conf(c);
if (r < 0)
return r;
+27 -9
View File
@@ -15,20 +15,18 @@ bool boot_entry_token_valid(const char *p) {
return utf8_is_valid(p) && string_is_safe(p) && filename_is_valid(p);
}
static int entry_token_load(int rfd, const char *etc_kernel, BootEntryTokenType *type, char **token) {
static int entry_token_load_one(int rfd, const char *dir, BootEntryTokenType *type, char **token) {
_cleanup_free_ char *buf = NULL, *p = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
assert(rfd >= 0 || rfd == AT_FDCWD);
assert(dir);
assert(type);
assert(*type == BOOT_ENTRY_TOKEN_AUTO);
assert(token);
if (!etc_kernel)
return 0;
p = path_join(etc_kernel, "entry-token");
p = path_join(dir, "entry-token");
if (!p)
return log_oom();
@@ -55,6 +53,26 @@ static int entry_token_load(int rfd, const char *etc_kernel, BootEntryTokenType
return 1;
}
static int entry_token_load(int rfd, const char *conf_root, BootEntryTokenType *type, char **token) {
int r;
assert(rfd >= 0 || rfd == AT_FDCWD);
assert(type);
assert(*type == BOOT_ENTRY_TOKEN_AUTO);
assert(token);
if (conf_root)
return entry_token_load_one(rfd, conf_root, type, token);
FOREACH_STRING(path, "/etc/kernel", "/usr/lib/kernel") {
r = entry_token_load_one(rfd, path, type, token);
if (r != 0)
return r;
}
return 0;
}
static int entry_token_from_machine_id(sd_id128_t machine_id, BootEntryTokenType *type, char **token) {
char *p;
@@ -123,7 +141,7 @@ static int entry_token_from_os_release(int rfd, BootEntryTokenType *type, char *
int boot_entry_token_ensure_at(
int rfd,
const char *etc_kernel,
const char *conf_root,
sd_id128_t machine_id,
bool machine_id_is_random,
BootEntryTokenType *type,
@@ -141,7 +159,7 @@ int boot_entry_token_ensure_at(
switch (*type) {
case BOOT_ENTRY_TOKEN_AUTO:
r = entry_token_load(rfd, etc_kernel, type, token);
r = entry_token_load(rfd, conf_root, type, token);
if (r != 0)
return r;
@@ -198,7 +216,7 @@ int boot_entry_token_ensure_at(
int boot_entry_token_ensure(
const char *root,
const char *etc_kernel,
const char *conf_root,
sd_id128_t machine_id,
bool machine_id_is_random,
BootEntryTokenType *type,
@@ -215,7 +233,7 @@ int boot_entry_token_ensure(
if (rfd < 0)
return -errno;
return boot_entry_token_ensure_at(rfd, etc_kernel, machine_id, machine_id_is_random, type, token);
return boot_entry_token_ensure_at(rfd, conf_root, machine_id, machine_id_is_random, type, token);
}
int parse_boot_entry_token_type(const char *s, BootEntryTokenType *type, char **token) {
+2 -2
View File
@@ -17,14 +17,14 @@ bool boot_entry_token_valid(const char *p);
int boot_entry_token_ensure(
const char *root,
const char *etc_kernel, /* will be prefixed with root, typically /etc/kernel. */
const char *conf_root, /* will be prefixed with root, typically /etc/kernel. */
sd_id128_t machine_id,
bool machine_id_is_random,
BootEntryTokenType *type, /* input and output */
char **token); /* output, but do not pass uninitialized value. */
int boot_entry_token_ensure_at(
int rfd,
const char *etc_kernel,
const char *conf_root,
sd_id128_t machine_id,
bool machine_id_is_random,
BootEntryTokenType *type,