Skip to content

Commit

Permalink
Merge pull request #1447 from stgraber/main
Browse files Browse the repository at this point in the history
  • Loading branch information
tych0 authored Dec 2, 2024
2 parents 1cb3a42 + cce2b6b commit 1e6cf48
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/server/device/tpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ func (d *tpm) startVM() (*deviceConfig.RunConfig, error) {
},
}

// Delete any leftover socket.
_ = os.Remove(socketPath)

proc, err := subprocess.NewProcess("swtpm", []string{"socket", "--tpm2", "--tpmstate", fmt.Sprintf("dir=%s", tpmDevPath), "--ctrl", fmt.Sprintf("type=unixio,path=swtpm-%s.sock", d.name)}, "", "")
if err != nil {
return nil, err
Expand All @@ -227,6 +230,21 @@ func (d *tpm) startVM() (*deviceConfig.RunConfig, error) {
return nil, fmt.Errorf("Failed to save swtpm state for device %q: %w", d.name, err)
}

// Wait for the socket to be available.
exists := false
for i := 0; i < 20; i++ {
if util.PathExists(socketPath) {
exists = true
break
}

time.Sleep(100 * time.Millisecond)
}

if !exists {
return nil, fmt.Errorf("swtpm socket didn't appear within 2s")
}

revert.Success()

return &runConf, nil
Expand Down

0 comments on commit 1e6cf48

Please sign in to comment.