]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
vmspawn: don't abort VM launch when an optional swtpm fails to start 42634/head
authorPaul Meyer <katexochen0@gmail.com>
Sat, 13 Jun 2026 10:07:45 +0000 (12:07 +0200)
committerPaul Meyer <katexochen0@gmail.com>
Wed, 17 Jun 2026 08:23:47 +0000 (10:23 +0200)
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 <noreply@anthropic.com>
Signed-off-by: Paul Meyer <katexochen0@gmail.com>
src/vmspawn/vmspawn.c

index 55c650af1b552e99588c58541e9b9d94f23d0024..36966122f4a5420aa79af0d22aa64b90442705d8 100644 (file)
@@ -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) {