From ba1203562ef20f84ca746113ad182336c430d2c4 Mon Sep 17 00:00:00 2001 From: Paul Meyer Date: Sat, 13 Jun 2026 12:07:45 +0200 Subject: [PATCH] vmspawn: don't abort VM launch when an optional swtpm fails to start When start_tpm() failed under TPM autodetect (arg_tpm <= 0), the swtpm block logged "Failed to start tpm, ignoring" but then fell through to event_add_child_pidref() with the still-unset child PidRef. That returns -ESRCH (PIDREF_NULL fails its pidref_is_set() guard), and the VM launch fails. Register the child only on start_tpm() success. Co-developed-by: Claude Opus 4.8 Signed-off-by: Paul Meyer --- src/vmspawn/vmspawn.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index 55c650af1b5..36966122f4a 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -3383,15 +3383,15 @@ 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"); - } - - _cleanup_(sd_event_source_unrefp) sd_event_source *source = NULL; - r = event_add_child_pidref(event, &source, &child, WEXITED, on_child_exit, /* userdata= */ NULL); - if (r < 0) - return r; + } else { + _cleanup_(sd_event_source_unrefp) sd_event_source *source = NULL; + r = event_add_child_pidref(event, &source, &child, WEXITED, on_child_exit, /* userdata= */ NULL); + if (r < 0) + return r; - pidref_done(&child); - children[n_children++] = TAKE_PTR(source); + pidref_done(&child); + children[n_children++] = TAKE_PTR(source); + } } if (tpm_socket_address) { -- 2.47.3