]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
vmspawn: make "-m" value formatting independent of locale
authorLennart Poettering <lennart@poettering.net>
Fri, 19 Jan 2024 22:12:05 +0000 (23:12 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 22 Jan 2024 15:24:00 +0000 (16:24 +0100)
We cannot format the memory string via printf() %f format strings, since
that's locale dependent and qemu doesn't like that. hence format this as
an integer. We'll lose sub-MiB accuracy, but systems with less than 1
MiB memory don't really make much sense anyway.

src/vmspawn/vmspawn.c

index b2c040b037a06575d36649a89e3239ede3391377..d93b6b29c923a62208c57fe5ad5c0b1c98f76169 100644 (file)
@@ -41,7 +41,7 @@ static PagerFlags arg_pager_flags = 0;
 static char *arg_image = NULL;
 static char *arg_machine = NULL;
 static char *arg_qemu_smp = NULL;
-static uint64_t arg_qemu_mem = 2ULL * 1024ULL * 1024ULL * 1024ULL;
+static uint64_t arg_qemu_mem = UINT64_C(2) * U64_GB;
 static int arg_qemu_kvm = -1;
 static int arg_qemu_vsock = -1;
 static unsigned arg_vsock_cid = VMADDR_CID_ANY;
@@ -523,7 +523,7 @@ static int run_virtual_machine(void) {
         if (r < 0)
                 return log_error_errno(r, "Failed to find QEMU binary: %m");
 
-        if (asprintf(&mem, "%.4fM", (double)arg_qemu_mem / (1024.0 * 1024.0)) < 0)
+        if (asprintf(&mem, "%" PRIu64, DIV_ROUND_UP(arg_qemu_mem, U64_MB)) < 0)
                 return log_oom();
 
         cmdline = strv_new(