]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: Load entry-token and layout.conf from /usr/lib/kernel/ as well
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 15 Jan 2024 12:46:49 +0000 (13:46 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 16 Jan 2024 05:54:04 +0000 (14:54 +0900)
src/boot/bootctl-install.c
src/boot/bootctl-util.c
src/boot/bootctl-util.h
src/kernel-install/kernel-install.c
src/shared/boot-entry.c
src/shared/boot-entry.h

index 58470385df27025fa3ff51a005ae3f8819e1617e..a0a474537effe39f69ca36ded84b0d09ab072a59 100644 (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();
 
index 3cab875fa0647ee2b43f31f49686225c5b04c400..448e868a4241cd4d6b0aa25fe4b1e23f95c40537 100644 (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,
index 147455e2411acbc1c7198186a6c3cee3c8325d87..6f2c1630de2f9e7619b27ce40ffcd83f46652dc7 100644 (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/";
-}
index a93b4e688fe1e69929ecaca8e1b8eea29417048c..675e9d806e9f311704dfbf134f8d2ad947ab1ca8 100644 (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;
index e726073b646a51f74f0a8c833c49c619f26066a3..72d3cbea987d5b08a10afff12c5c9c7c4a36e47f 100644 (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) {
index f3a6f28417668520fa01094c83571bd448db9b09..836b63733a9b5494440e0f4873467b4b4f46eb37 100644 (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,