]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Drop use of xpool_print/SPrint
authorJan Janssen <medhefgo@web.de>
Sun, 5 Jun 2022 13:08:07 +0000 (15:08 +0200)
committerJan Janssen <medhefgo@web.de>
Wed, 18 Jan 2023 16:47:57 +0000 (17:47 +0100)
src/boot/efi/boot.c
src/boot/efi/cpio.c
src/boot/efi/drivers.c
src/boot/efi/stub.c
src/boot/efi/util.h
src/boot/efi/vmm.c

index 98c49e96cec51c501bf503f9d0f797f9b294fa43..4dc39219909cf0f796b5daba15a4de720742d877 100644 (file)
@@ -3,6 +3,7 @@
 #include <efi.h>
 #include <efigpt.h>
 #include <efilib.h>
+#include <inttypes.h>
 
 #include "bcd.h"
 #include "bootspec-fundamental.h"
@@ -427,7 +428,7 @@ static char16_t *update_timeout_efivar(uint32_t *t, bool inc) {
         case TIMEOUT_MENU_HIDDEN:
                 return xstrdup16(u"Menu disabled. Hold down key at bootup to show menu.");
         default:
-                return xpool_print(L"Menu timeout set to %u s.", *t);
+                return xasprintf("Menu timeout set to %u s.", *t);
         }
 }
 
@@ -761,7 +762,7 @@ static bool menu_run(
 
                 if (timeout_remain > 0) {
                         free(status);
-                        status = xpool_print(L"Boot in %u s.", timeout_remain);
+                        status = xasprintf("Boot in %u s.", timeout_remain);
                 }
 
                 if (status) {
@@ -940,9 +941,9 @@ static bool menu_run(
                         break;
 
                 case KEYPRESS(0, 0, 'v'):
-                        status = xpool_print(
-                                        L"systemd-boot " GIT_VERSION L" (" EFI_MACHINE_TYPE_NAME L"), "
-                                        L"UEFI Specification %u.%02u, Vendor %s %u.%02u",
+                        status = xasprintf(
+                                        "systemd-boot " GIT_VERSION " (" EFI_MACHINE_TYPE_NAME "), "
+                                        "UEFI Specification %u.%02u, Vendor %ls %u.%02u",
                                         ST->Hdr.Revision >> 16,
                                         ST->Hdr.Revision & 0xffff,
                                         ST->FirmwareVendor,
@@ -964,10 +965,12 @@ static bool menu_run(
                 case KEYPRESS(0, 0, 'r'):
                         err = console_set_mode(CONSOLE_MODE_NEXT);
                         if (err != EFI_SUCCESS)
-                                status = xpool_print(L"Error changing console mode: %r", err);
+                                status = xasprintf_status(err, "Error changing console mode: %m");
                         else {
                                 config->console_mode_efivar = ST->ConOut->Mode->Mode;
-                                status = xpool_print(L"Console mode changed to %ld.", config->console_mode_efivar);
+                                status = xasprintf(
+                                                "Console mode changed to %" PRIi64 ".",
+                                                config->console_mode_efivar);
                         }
                         new_mode = true;
                         break;
@@ -977,10 +980,13 @@ static bool menu_run(
                         err = console_set_mode(config->console_mode == CONSOLE_MODE_KEEP ?
                                                console_mode_initial : config->console_mode);
                         if (err != EFI_SUCCESS)
-                                status = xpool_print(L"Error resetting console mode: %r", err);
+                                status = xasprintf_status(err, "Error resetting console mode: %m");
                         else
-                                status = xpool_print(L"Console mode reset to %s default.",
-                                                     config->console_mode == CONSOLE_MODE_KEEP ? L"firmware" : L"configuration file");
+                                status = xasprintf(
+                                                "Console mode reset to %s default.",
+                                                config->console_mode == CONSOLE_MODE_KEEP ?
+                                                                "firmware" :
+                                                                "configuration file");
                         new_mode = true;
                         break;
 
@@ -993,9 +999,9 @@ static bool menu_run(
                         if (FLAGS_SET(get_os_indications_supported(), EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) {
                                 firmware_setup = true;
                                 /* Let's make sure the user really wants to do this. */
-                                status = xpool_print(L"Press Enter to reboot into firmware interface.");
+                                status = xstrdup16(u"Press Enter to reboot into firmware interface.");
                         } else
-                                status = xpool_print(L"Reboot into firmware interface not supported.");
+                                status = xstrdup16(u"Reboot into firmware interface not supported.");
                         break;
 
                 default:
@@ -1329,9 +1335,9 @@ static void config_entry_parse_tries(
         entry->tries_done = tries_done;
         entry->path = xstrdup16(path);
         entry->current_name = xstrdup16(file);
-        entry->next_name = xpool_print(
-                        L"%.*s%u-%u%s",
-                        prefix_len,
+        entry->next_name = xasprintf(
+                        "%.*ls%" PRIu64 "-%" PRIu64 "%ls",
+                        (int) prefix_len,
                         file,
                         LESS_BY(tries_left, 1u),
                         MIN(tries_done + 1, (uint64_t) INT_MAX),
@@ -1354,7 +1360,7 @@ static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) {
         if (!entry->path || !entry->current_name || !entry->next_name)
                 return;
 
-        old_path = xpool_print(L"%s\\%s", entry->path, entry->current_name);
+        old_path = xasprintf("%ls\\%ls", entry->path, entry->current_name);
 
         err = root_dir->Open(root_dir, &handle, old_path, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0ULL);
         if (err != EFI_SUCCESS)
@@ -1377,7 +1383,7 @@ static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) {
 
         /* Let's tell the OS that we renamed this file, so that it knows what to rename to the counter-less name on
          * success */
-        new_path = xpool_print(L"%s\\%s", entry->path, entry->next_name);
+        new_path = xasprintf("%ls\\%ls", entry->path, entry->next_name);
         efivar_set(LOADER_GUID, L"LoaderBootCountPath", new_path, 0);
 
         /* If the file we just renamed is the loader path, then let's update that. */
@@ -1491,7 +1497,7 @@ static void config_entry_add_type1(
 
                         new = xstr8_to_16(value);
                         if (entry->options) {
-                                char16_t *s = xpool_print(L"%s %s", entry->options, new);
+                                char16_t *s = xasprintf("%ls %ls", entry->options, new);
                                 free(entry->options);
                                 entry->options = s;
                         } else
@@ -1808,7 +1814,7 @@ static void config_title_generate(Config *config) {
                         continue;
 
                 _cleanup_free_ char16_t *t = config->entries[i]->title_show;
-                config->entries[i]->title_show = xpool_print(L"%s (%s)", t, config->entries[i]->version);
+                config->entries[i]->title_show = xasprintf("%ls (%ls)", t, config->entries[i]->version);
         }
 
         if (entries_unique(config->entries, unique, config->entry_count))
@@ -1825,11 +1831,7 @@ static void config_title_generate(Config *config) {
                         continue;
 
                 _cleanup_free_ char16_t *t = config->entries[i]->title_show;
-                config->entries[i]->title_show = xpool_print(
-                        L"%s (%.*s)",
-                        t,
-                        strnlen16(config->entries[i]->machine_id, 8),
-                        config->entries[i]->machine_id);
+                config->entries[i]->title_show = xasprintf("%ls (%.8ls)", t, config->entries[i]->machine_id);
         }
 
         if (entries_unique(config->entries, unique, config->entry_count))
@@ -1841,7 +1843,7 @@ static void config_title_generate(Config *config) {
                         continue;
 
                 _cleanup_free_ char16_t *t = config->entries[i]->title_show;
-                config->entries[i]->title_show = xpool_print(L"%s (%s)", t, config->entries[i]->id);
+                config->entries[i]->title_show = xasprintf("%ls (%ls)", t, config->entries[i]->id);
         }
 }
 
@@ -2006,10 +2008,9 @@ static EFI_STATUS boot_windows_bitlocker(void) {
 
         for (UINTN i = 0; i < boot_order_size / sizeof(uint16_t); i++) {
                 _cleanup_free_ char *buf = NULL;
-                char16_t name[sizeof(L"Boot0000")];
                 UINTN buf_size;
 
-                SPrint(name, sizeof(name), L"Boot%04x", (uint32_t) boot_order[i]);
+                _cleanup_free_ char16_t *name = xasprintf("Boot%04x", boot_order[i]);
                 err = efivar_get_raw(EFI_GLOBAL_GUID, name, &buf, &buf_size);
                 if (err != EFI_SUCCESS)
                         continue;
@@ -2202,7 +2203,7 @@ static void config_entry_add_unified(
                         .title = xstrdup16(good_name),
                         .version = xstrdup16(good_version),
                         .device = device,
-                        .loader = xpool_print(L"\\EFI\\Linux\\%s", f->FileName),
+                        .loader = xasprintf("\\EFI\\Linux\\%ls", f->FileName),
                         .sort_key = xstrdup16(good_sort_key),
                         .key = 'l',
                         .tries_done = -1,
@@ -2281,9 +2282,9 @@ static EFI_STATUS initrd_prepare(
         STRV_FOREACH(i, entry->initrd) {
                 _cleanup_free_ char16_t *o = options;
                 if (o)
-                        options = xpool_print(L"%s initrd=%s", o, *i);
+                        options = xasprintf("%ls initrd=%ls", o, *i);
                 else
-                        options = xpool_print(L"initrd=%s", *i);
+                        options = xasprintf("initrd=%ls", *i);
 
                 _cleanup_(file_closep) EFI_FILE *handle = NULL;
                 err = root->Open(root, &handle, *i, EFI_FILE_MODE_READ, 0);
@@ -2314,7 +2315,7 @@ static EFI_STATUS initrd_prepare(
 
         if (entry->options) {
                 _cleanup_free_ char16_t *o = options;
-                options = xpool_print(L"%s %s", o, entry->options);
+                options = xasprintf("%ls %ls", o, entry->options);
         }
 
         *ret_options = TAKE_PTR(options);
@@ -2496,9 +2497,9 @@ static EFI_STATUS secure_boot_discover_keys(Config *config, EFI_FILE *root_dir)
 
                 entry = xnew(ConfigEntry, 1);
                 *entry = (ConfigEntry) {
-                        .id = xpool_print(L"secure-boot-keys-%s", dirent->FileName),
-                        .title = xpool_print(L"Enroll Secure Boot keys: %s", dirent->FileName),
-                        .path = xpool_print(L"\\loader\\keys\\%s", dirent->FileName),
+                        .id = xasprintf("secure-boot-keys-%ls", dirent->FileName),
+                        .title = xasprintf("Enroll Secure Boot keys: %ls", dirent->FileName),
+                        .path = xasprintf("\\loader\\keys\\%ls", dirent->FileName),
                         .type = LOADER_SECURE_BOOT_KEYS,
                         .tries_done = -1,
                         .tries_left = -1,
@@ -2541,10 +2542,10 @@ static void export_variables(
         efivar_set_time_usec(LOADER_GUID, L"LoaderTimeInitUSec", init_usec);
         efivar_set(LOADER_GUID, L"LoaderInfo", L"systemd-boot " GIT_VERSION, 0);
 
-        infostr = xpool_print(L"%s %u.%02u", ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
+        infostr = xasprintf("%ls %u.%02u", ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
         efivar_set(LOADER_GUID, L"LoaderFirmwareInfo", infostr, 0);
 
-        typestr = xpool_print(L"UEFI %u.%02u", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
+        typestr = xasprintf("UEFI %u.%02u", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
         efivar_set(LOADER_GUID, L"LoaderFirmwareType", typestr, 0);
 
         (void) efivar_set_uint64_le(LOADER_GUID, L"LoaderFeatures", loader_features, 0);
index 7c29beb7592c7098d588a3e2e07dc83d685ddecc..9c33e33e9cff8d8448ae55e5d65d6989002de253 100644 (file)
@@ -318,7 +318,7 @@ static char16_t *get_dropin_dir(const EFI_DEVICE_PATH *file_path) {
                 return NULL;
 
         convert_efi_path(file_path_str);
-        return xpool_print(u"%s.extra.d", file_path_str);
+        return xasprintf("%ls.extra.d", file_path_str);
 }
 
 EFI_STATUS pack_cpio(
index ab360f201ce064d2f8f87d3a9b35a1ad53cd4a86..5962b48366a39f1f0909fd765ca8d627bf4cc13c 100644 (file)
@@ -20,7 +20,7 @@ static EFI_STATUS load_one_driver(
         assert(loaded_image);
         assert(fname);
 
-        spath = xpool_print(L"\\EFI\\systemd\\drivers\\%s", fname);
+        spath = xasprintf("\\EFI\\systemd\\drivers\\%ls", fname);
         err = make_file_device_path(loaded_image->DeviceHandle, spath, &path);
         if (err != EFI_SUCCESS)
                 return log_error_status(err, "Error making file device path: %m");
index bb647f1d78d925a9798de207dd9e53ce400308f4..675878f47869fa560160a442a5bcb8fbb3cb6c74 100644 (file)
@@ -114,14 +114,14 @@ static void export_variables(EFI_LOADED_IMAGE_PROTOCOL *loaded_image) {
         /* if LoaderFirmwareInfo is not set, let's set it */
         if (efivar_get_raw(LOADER_GUID, L"LoaderFirmwareInfo", NULL, NULL) != EFI_SUCCESS) {
                 _cleanup_free_ char16_t *s = NULL;
-                s = xpool_print(L"%s %u.%02u", ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
+                s = xasprintf("%ls %u.%02u", ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
                 efivar_set(LOADER_GUID, L"LoaderFirmwareInfo", s, 0);
         }
 
         /* ditto for LoaderFirmwareType */
         if (efivar_get_raw(LOADER_GUID, L"LoaderFirmwareType", NULL, NULL) != EFI_SUCCESS) {
                 _cleanup_free_ char16_t *s = NULL;
-                s = xpool_print(L"UEFI %u.%02u", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
+                s = xasprintf("UEFI %u.%02u", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
                 efivar_set(LOADER_GUID, L"LoaderFirmwareType", s, 0);
         }
 
@@ -173,7 +173,7 @@ static bool use_load_options(
         *ret = xstrdup16(shell->Argv[1]);
         for (size_t i = 2; i < shell->Argc; i++) {
                 _cleanup_free_ char16_t *old = *ret;
-                *ret = xpool_print(u"%s %s", old, shell->Argv[i]);
+                *ret = xasprintf("%ls %ls", old, shell->Argv[i]);
         }
 
         mangle_stub_cmdline(*ret);
index 101eee17182ff176897a4ccff49ed9cb5428048b..a8652e6d8e9e0b6aa4a89a4af1872d8cbd8b0fb1 100644 (file)
@@ -68,7 +68,6 @@ static inline void *xrealloc(void *p, size_t old_size, size_t new_size) {
         return t;
 }
 
-#define xpool_print(fmt, ...) ((char16_t *) ASSERT_SE_PTR(PoolPrint((fmt), ##__VA_ARGS__)))
 #define xnew(type, n) ((type *) xmalloc_multiply(sizeof(type), (n)))
 
 typedef struct {
index 3dfa92b58d4b9905e4e92b83f3c665631533f7a3..b24d556700ee55e402f894ab3fcb98716a67d24a 100644 (file)
@@ -97,9 +97,8 @@ EFI_STATUS vmm_open(EFI_HANDLE *ret_vmm_dev, EFI_FILE **ret_vmm_dir) {
 
         for (size_t order = 0;; order++) {
                 _cleanup_free_ EFI_DEVICE_PATH *dp = NULL;
-                char16_t order_str[STRLEN("VMMBootOrder") + 4 + 1];
 
-                SPrint(order_str, sizeof(order_str), u"VMMBootOrder%04x", order);
+                _cleanup_free_ char16_t *order_str = xasprintf("VMMBootOrder%04zx", order);
                 dp_err = efivar_get_raw(&(EFI_GUID)VMM_BOOT_ORDER_GUID, order_str, (char**)&dp, NULL);
 
                 for (size_t i = 0; i < n_handles; i++) {