vmspawn: make "-m" value formatting independent of locale

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.
This commit is contained in:
Lennart Poettering 2024-01-19 23:12:05 +01:00
parent dbb2718f92
commit 3df61bf00c

View 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(