Skip to content

Commit

Permalink
Avoid segfault when not using qemu vmtype
Browse files Browse the repository at this point in the history
Was crashing in regression tests on other platforms

Test also for qemu, in case of new arch or somesuch

Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed May 17, 2024
1 parent 0a19046 commit 76351cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
23 changes: 13 additions & 10 deletions pkg/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,19 +511,22 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
}

// CPU
cpu := *y.CPUType[*y.Arch]
if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" {
switch {
case strings.HasPrefix(cpu, "host"), strings.HasPrefix(cpu, "max"):
if !strings.Contains(cpu, ",-pdpe1gb") {
logrus.Warnf("On Intel Mac, CPU type %q typically needs \",-pdpe1gb\" option (https://stackoverflow.com/a/72863744/5167443)", cpu)
var cpu string
if y.CPUType[*y.Arch] != nil {
cpu = *y.CPUType[*y.Arch]
if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" {
switch {
case strings.HasPrefix(cpu, "host"), strings.HasPrefix(cpu, "max"):
if !strings.Contains(cpu, ",-pdpe1gb") {
logrus.Warnf("On Intel Mac, CPU type %q typically needs \",-pdpe1gb\" option (https://stackoverflow.com/a/72863744/5167443)", cpu)
}
}
}
if !strings.Contains(string(features.CPUHelp), strings.Split(cpu, ",")[0]) {
return "", nil, fmt.Errorf("cpu %q is not supported by %s", cpu, exe)
}
args = appendArgsIfNoConflict(args, "-cpu", cpu)
}
if !strings.Contains(string(features.CPUHelp), strings.Split(cpu, ",")[0]) {
return "", nil, fmt.Errorf("cpu %q is not supported by %s", cpu, exe)
}
args = appendArgsIfNoConflict(args, "-cpu", cpu)

// Machine
switch *y.Arch {
Expand Down
4 changes: 3 additions & 1 deletion pkg/store/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ func Inspect(instName string) (*Instance, error) {
inst.Config = y
inst.Arch = *y.Arch
inst.VMType = *y.VMType
inst.CPUType = *y.CPUType[*y.Arch]
if y.CPUType[*y.Arch] != nil {
inst.CPUType = *y.CPUType[*y.Arch]
}
inst.SSHAddress = "127.0.0.1"
inst.SSHLocalPort = *y.SSH.LocalPort // maybe 0
inst.SSHConfigFile = filepath.Join(instDir, filenames.SSHConfig)
Expand Down

0 comments on commit 76351cc

Please sign in to comment.