From eb77d24baa64a9b35858366e7b83709496544c43 Mon Sep 17 00:00:00 2001 From: Sam Leonard Date: Wed, 28 Feb 2024 17:39:05 +0000 Subject: [PATCH] vmspawn: only add to cmdline if tpm was started --- src/vmspawn/vmspawn.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index ce7f1ef2e3e..5473d1464cb 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -1560,8 +1560,6 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { _cleanup_free_ char *tpm_state_tempdir = NULL; if (swtpm) { - _cleanup_free_ char *escaped_state_dir = NULL; - r = start_tpm(bus, trans_scope, swtpm, &tpm_state_tempdir); if (r < 0) { /* only bail if the user asked for a tpm */ @@ -1569,6 +1567,10 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { return log_error_errno(r, "Failed to start tpm: %m"); log_debug_errno(r, "Failed to start tpm, ignoring: %m"); } + } + + if (tpm_state_tempdir) { + _cleanup_free_ char *escaped_state_dir = NULL; escaped_state_dir = escape_qemu_value(tpm_state_tempdir); if (!escaped_state_dir) -- 2.47.3