From: Lennart Poettering Date: Fri, 19 Jan 2024 22:12:05 +0000 (+0100) Subject: vmspawn: make "-m" value formatting independent of locale X-Git-Tag: v256-rc1~1083^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3df61bf00cee67f93fe31dffde9e8df3a83a411d;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index b2c040b037a..d93b6b29c92 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -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(