]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
find-esp: introduce _full() flavour of ESP/XBOOTLDR discovery functions
authorLennart Poettering <lennart@amutable.com>
Fri, 13 Mar 2026 10:53:57 +0000 (11:53 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 18 Mar 2026 10:25:59 +0000 (10:25 +0000)
These functions take so many return paramaters, and in many of our cases
we don't actually needt them. Hence introduce _full() flavours of the
funcs, and hide the params by default.

src/bless-boot/bless-boot.c
src/bootctl/bootctl-install.c
src/bootctl/bootctl-random-seed.c
src/bootctl/bootctl.c
src/kernel-install/kernel-install.c
src/shared/bootspec.c
src/shared/creds-util.c
src/shared/find-esp.c
src/shared/find-esp.h
src/sysupdate/sysupdate-resource.c

index ac989630aff0da3fddab2abcad8b49a1c1148322..1df341cf59baf9d78e188ae6b6684acccf4f6e7a 100644 (file)
@@ -107,11 +107,26 @@ static int acquire_path(void) {
         if (!strv_isempty(arg_path))
                 return 0;
 
-        r = find_esp_and_warn(NULL, NULL, /* unprivileged_mode= */ false, &esp_path, NULL, NULL, NULL, NULL, &esp_devid);
+        r = find_esp_and_warn_full(
+                        /* root= */ NULL,
+                        /* path= */ NULL,
+                        /* unprivileged_mode= */ false,
+                        &esp_path,
+                        /* ret_part= */ NULL,
+                        /* ret_pstart= */ NULL,
+                        /* ret_psize= */ NULL,
+                        /* ret_uuid= */ NULL,
+                        &esp_devid);
         if (r < 0 && r != -ENOKEY) /* ENOKEY means not found, and is the only error the function won't log about on its own */
                 return r;
 
-        r = find_xbootldr_and_warn(NULL, NULL, /* unprivileged_mode= */ false, &xbootldr_path, NULL, &xbootldr_devid);
+        r = find_xbootldr_and_warn_full(
+                        /* root= */ NULL,
+                        /* path= */ NULL,
+                        /* unprivileged_mode= */ false,
+                        &xbootldr_path,
+                        /* ret_uuid= */ NULL,
+                        &xbootldr_devid);
         if (r < 0 && r != -ENOKEY)
                 return r;
 
index 1a8d5ffb30cb270b27cd1b6dca273f8b989ee16f..4d56c6874e9ca4824723b1a355c4105aab5c9eb9 100644 (file)
@@ -2062,7 +2062,7 @@ int vl_method_install(
         if (p.context.entry_token_type < 0)
                 p.context.entry_token_type = BOOT_ENTRY_TOKEN_AUTO;
 
-        r = find_esp_and_warn_at(
+        r = find_esp_and_warn_at_full(
                         p.context.root_fd,
                         /* path= */ NULL,
                         /* unprivileged_mode= */ false,
@@ -2081,9 +2081,7 @@ int vl_method_install(
                         p.context.root_fd,
                         /* path= */ NULL,
                         /* unprivileged_mode= */ false,
-                        &p.context.xbootldr_path,
-                        /* ret_uuid= */ NULL,
-                        /* ret_devid= */ NULL);
+                        &p.context.xbootldr_path);
         if (r == -ENOKEY)
                 log_debug_errno(r, "Didn't find an XBOOTLDR partition, using ESP as $BOOT.");
         else if (r < 0)
index 62ff8fa07ffe24ecb95071efea2ebe85be4e4869..6f5249aeeb4c4bf7cc5a546ef4d604888e57ca62 100644 (file)
@@ -204,7 +204,7 @@ int install_random_seed(const char *esp) {
 int verb_random_seed(int argc, char *argv[], void *userdata) {
         int r;
 
-        r = find_esp_and_warn(arg_root, arg_esp_path, false, &arg_esp_path, NULL, NULL, NULL, NULL, NULL);
+        r = find_esp_and_warn(arg_root, arg_esp_path, /* unprivileged_mode= */ false, &arg_esp_path);
         if (r == -ENOKEY) {
                 /* find_esp_and_warn() doesn't warn about ENOKEY, so let's do that on our own */
                 if (arg_graceful() == ARG_GRACEFUL_NO)
index da4592a7240a89956447c7a91a40fcbe45ed4623..65a5da3358fafcdfbe5858d8ef11af9fbca9703a 100644 (file)
@@ -117,7 +117,7 @@ int acquire_esp(
          * we simply eat up the error here, so that --list and --status work too, without noise about
          * this). */
 
-        r = find_esp_and_warn(arg_root, arg_esp_path, unprivileged_mode, &np, ret_part, ret_pstart, ret_psize, ret_uuid, ret_devid);
+        r = find_esp_and_warn_full(arg_root, arg_esp_path, unprivileged_mode, &np, ret_part, ret_pstart, ret_psize, ret_uuid, ret_devid);
         if (r == -ENOKEY) {
                 if (graceful)
                         return log_full_errno(arg_quiet ? LOG_DEBUG : LOG_INFO, r,
@@ -144,7 +144,7 @@ int acquire_xbootldr(
         char *np;
         int r;
 
-        r = find_xbootldr_and_warn(arg_root, arg_xbootldr_path, unprivileged_mode, &np, ret_uuid, ret_devid);
+        r = find_xbootldr_and_warn_full(arg_root, arg_xbootldr_path, unprivileged_mode, &np, ret_uuid, ret_devid);
         if (r == -ENOKEY || path_equal(np, arg_esp_path)) {
                 log_debug("Didn't find an XBOOTLDR partition, using the ESP as $BOOT.");
                 arg_xbootldr_path = mfree(arg_xbootldr_path);
index a38dcaab8b55668d79cc07196dba839f13a2a092..9046e82e921a80fe141f3157ec4f226645d9f786 100644 (file)
@@ -570,9 +570,7 @@ static int context_acquire_xbootldr(Context *c) {
                         /* rfd= */ c->rfd,
                         /* path= */ arg_xbootldr_path,
                         /* unprivileged_mode= */ -1,
-                        /* ret_path= */ &c->boot_root,
-                        /* ret_uuid= */ NULL,
-                        /* ret_devid= */ NULL);
+                        /* ret_path= */ &c->boot_root);
         if (r == -ENOKEY) {
                 log_debug_errno(r, "Couldn't find an XBOOTLDR partition.");
                 return 0;
@@ -596,12 +594,7 @@ static int context_acquire_esp(Context *c) {
                         /* rfd= */ c->rfd,
                         /* path= */ arg_esp_path,
                         /* unprivileged_mode= */ -1,
-                        /* ret_path= */ &c->boot_root,
-                        /* ret_part= */ NULL,
-                        /* ret_pstart= */ NULL,
-                        /* ret_psize= */ NULL,
-                        /* ret_uuid= */ NULL,
-                        /* ret_devid= */ NULL);
+                        /* ret_path= */ &c->boot_root);
         if (r == -ENOKEY) {
                 log_debug_errno(r, "Couldn't find EFI system partition, ignoring.");
                 return 0;
index 5901729e8845d5d104e583400401507758b64d17..a341b0729bd1ee58b44be7a2780443d2117dc2b8 100644 (file)
@@ -1587,11 +1587,26 @@ int boot_config_load_auto(
                                                "Failed to determine whether /run/boot-loader-entries/ exists: %m");
         }
 
-        r = find_esp_and_warn(NULL, override_esp_path, /* unprivileged_mode= */ false, &esp_where, NULL, NULL, NULL, NULL, &esp_devid);
+        r = find_esp_and_warn_full(
+                        /* root= */ NULL,
+                        override_esp_path,
+                        /* unprivileged_mode= */ false,
+                        &esp_where,
+                        /* ret_part= */ NULL,
+                        /* ret_pstart= */ NULL,
+                        /* ret_psize= */ NULL,
+                        /* ret_uuid= */ NULL,
+                        &esp_devid);
         if (r < 0) /* we don't log about ENOKEY here, but propagate it, leaving it to the caller to log */
                 return r;
 
-        r = find_xbootldr_and_warn(NULL, override_xbootldr_path, /* unprivileged_mode= */ false, &xbootldr_where, NULL, &xbootldr_devid);
+        r = find_xbootldr_and_warn_full(
+                        /* root= */ NULL,
+                        override_xbootldr_path,
+                        /* unprivileged_mode= */ false,
+                        &xbootldr_where,
+                        /* ret_uuid= */ NULL,
+                        &xbootldr_devid);
         if (r < 0 && r != -ENOKEY)
                 return r; /* It's fine if the XBOOTLDR partition doesn't exist, hence we ignore ENOKEY here */
 
index 2aac4d253bb760a6569df2a46a7bae2a5f5aa838..54ae368fdfb09bfaaa1940c3efcd6f489af68402 100644 (file)
@@ -1689,9 +1689,7 @@ int get_global_boot_credentials_path(char **ret) {
                         /* root= */ NULL,
                         /* path= */ NULL,
                         /* unprivileged_mode= */ false,
-                        &path,
-                        /* ret_uuid= */ NULL,
-                        /* ret_devid= */ NULL);
+                        &path);
         if (r < 0) {
                 if (r != -ENOKEY)
                         return log_error_errno(r, "Failed to find XBOOTLDR partition: %m");
@@ -1700,12 +1698,7 @@ int get_global_boot_credentials_path(char **ret) {
                                 /* root= */ NULL,
                                 /* path= */ NULL,
                                 /* unprivileged_mode= */ false,
-                                &path,
-                                /* ret_part= */ NULL,
-                                /* ret_pstart= */ NULL,
-                                /* ret_psize= */ NULL,
-                                /* ret_uuid= */ NULL,
-                                /* ret_devid= */ NULL);
+                                &path);
                 if (r < 0) {
                         if (r != -ENOKEY)
                                 return log_error_errno(r, "Failed to find ESP partition: %m");
index a2a2093fafb935a344d4807ba7823faf9b9a0498..3f490ced714cf00e377ee89f0a7f9093d7c1b574 100644 (file)
@@ -429,7 +429,7 @@ finish:
         return 0;
 }
 
-int find_esp_and_warn_at(
+int find_esp_and_warn_at_full(
                 int rfd,
                 const char *path,
                 int unprivileged_mode,
@@ -509,7 +509,7 @@ int find_esp_and_warn_at(
         return -ENOKEY;
 }
 
-int find_esp_and_warn(
+int find_esp_and_warn_full(
                 const char *root,
                 const char *path,
                 int unprivileged_mode,
@@ -536,7 +536,7 @@ int find_esp_and_warn(
                         return -errno;
         }
 
-        r = find_esp_and_warn_at(
+        r = find_esp_and_warn_at_full(
                         rfd,
                         path,
                         unprivileged_mode,
@@ -792,7 +792,7 @@ finish:
         return 0;
 }
 
-int find_xbootldr_and_warn_at(
+int find_xbootldr_and_warn_at_full(
                 int rfd,
                 const char *path,
                 int unprivileged_mode,
@@ -853,7 +853,7 @@ int find_xbootldr_and_warn_at(
         return 0;
 }
 
-int find_xbootldr_and_warn(
+int find_xbootldr_and_warn_full(
                 const char *root,
                 const char *path,
                 int unprivileged_mode,
@@ -875,7 +875,7 @@ int find_xbootldr_and_warn(
                         return -errno;
         }
 
-        r = find_xbootldr_and_warn_at(
+        r = find_xbootldr_and_warn_at_full(
                         rfd,
                         path,
                         unprivileged_mode,
index ac62e6c51e51993c77ef551d85493eed87f0f946..30b7c4a76117ef4bef6d7a6b94bfb7dcafb58145 100644 (file)
@@ -4,8 +4,22 @@
 
 #include "shared-forward.h"
 
-int find_esp_and_warn_at(int rfd, const char *path, int unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid, dev_t *ret_devid);
-int find_esp_and_warn(const char *root, const char *path, int unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid, dev_t *ret_devid);
+int find_esp_and_warn_at_full(int rfd, const char *path, int unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid, dev_t *ret_devid);
+int find_esp_and_warn_full(const char *root, const char *path, int unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid, dev_t *ret_devid);
 
-int find_xbootldr_and_warn_at(int rfd, const char *path, int unprivileged_mode, char **ret_path, sd_id128_t *ret_uuid, dev_t *ret_devid);
-int find_xbootldr_and_warn(const char *root, const char *path, int unprivileged_mode, char **ret_path, sd_id128_t *ret_uuid, dev_t *ret_devid);
+static inline int find_esp_and_warn_at(int rfd, const char *path, int unprivileged_mode, char **ret_path) {
+        return find_esp_and_warn_at_full(rfd, path, unprivileged_mode, ret_path, NULL, NULL, NULL, NULL, NULL);
+}
+static inline int find_esp_and_warn(const char *root, const char *path, int unprivileged_mode, char **ret_path) {
+        return find_esp_and_warn_full(root, path, unprivileged_mode, ret_path, NULL, NULL, NULL, NULL, NULL);
+}
+
+int find_xbootldr_and_warn_at_full(int rfd, const char *path, int unprivileged_mode, char **ret_path, sd_id128_t *ret_uuid, dev_t *ret_devid);
+int find_xbootldr_and_warn_full(const char *root, const char *path, int unprivileged_mode, char **ret_path, sd_id128_t *ret_uuid, dev_t *ret_devid);
+
+static inline int find_xbootldr_and_warn_at(int rfd, const char *path, int unprivileged_mode, char **ret_path) {
+        return find_xbootldr_and_warn_at_full(rfd, path, unprivileged_mode, ret_path, NULL, NULL);
+}
+static inline int find_xbootldr_and_warn(const char *root, const char *path, int unprivileged_mode, char **ret_path) {
+        return find_xbootldr_and_warn_full(root, path, unprivileged_mode, ret_path, NULL, NULL);
+}
index 3be0943e4c0a3dd59fd1384b90330b22605fe2dc..1cc48201efabed884b26310506318e6d352c3ec1 100644 (file)
@@ -852,9 +852,9 @@ int resource_resolve_path(
                 } else { /* boot, esp, or xbootldr */
                         r = 0;
                         if (IN_SET(rr->path_relative_to, PATH_RELATIVE_TO_BOOT, PATH_RELATIVE_TO_XBOOTLDR))
-                                r = find_xbootldr_and_warn(root, NULL, /* unprivileged_mode= */ -1, &relative_to, NULL, NULL);
+                                r = find_xbootldr_and_warn(root, /* path= */ NULL, /* unprivileged_mode= */ -1, &relative_to);
                         if (r == -ENOKEY || rr->path_relative_to == PATH_RELATIVE_TO_ESP)
-                                r = find_esp_and_warn(root, NULL, -1, &relative_to, NULL, NULL, NULL, NULL, NULL);
+                                r = find_esp_and_warn(root, /* path= */ NULL, /* unprivileged_mode= */ -1, &relative_to);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to resolve $BOOT: %m");
                         log_debug("Resolved $BOOT to '%s'", relative_to);