Skip to content

Commit 76351cc

Browse files
committed
Avoid segfault when not using qemu vmtype
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]>
1 parent 0a19046 commit 76351cc

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

pkg/qemu/qemu.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -511,19 +511,22 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
511511
}
512512

513513
// CPU
514-
cpu := *y.CPUType[*y.Arch]
515-
if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" {
516-
switch {
517-
case strings.HasPrefix(cpu, "host"), strings.HasPrefix(cpu, "max"):
518-
if !strings.Contains(cpu, ",-pdpe1gb") {
519-
logrus.Warnf("On Intel Mac, CPU type %q typically needs \",-pdpe1gb\" option (https://stackoverflow.com/a/72863744/5167443)", cpu)
514+
var cpu string
515+
if y.CPUType[*y.Arch] != nil {
516+
cpu = *y.CPUType[*y.Arch]
517+
if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" {
518+
switch {
519+
case strings.HasPrefix(cpu, "host"), strings.HasPrefix(cpu, "max"):
520+
if !strings.Contains(cpu, ",-pdpe1gb") {
521+
logrus.Warnf("On Intel Mac, CPU type %q typically needs \",-pdpe1gb\" option (https://stackoverflow.com/a/72863744/5167443)", cpu)
522+
}
520523
}
521524
}
525+
if !strings.Contains(string(features.CPUHelp), strings.Split(cpu, ",")[0]) {
526+
return "", nil, fmt.Errorf("cpu %q is not supported by %s", cpu, exe)
527+
}
528+
args = appendArgsIfNoConflict(args, "-cpu", cpu)
522529
}
523-
if !strings.Contains(string(features.CPUHelp), strings.Split(cpu, ",")[0]) {
524-
return "", nil, fmt.Errorf("cpu %q is not supported by %s", cpu, exe)
525-
}
526-
args = appendArgsIfNoConflict(args, "-cpu", cpu)
527530

528531
// Machine
529532
switch *y.Arch {

pkg/store/instance.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ func Inspect(instName string) (*Instance, error) {
9595
inst.Config = y
9696
inst.Arch = *y.Arch
9797
inst.VMType = *y.VMType
98-
inst.CPUType = *y.CPUType[*y.Arch]
98+
if y.CPUType[*y.Arch] != nil {
99+
inst.CPUType = *y.CPUType[*y.Arch]
100+
}
99101
inst.SSHAddress = "127.0.0.1"
100102
inst.SSHLocalPort = *y.SSH.LocalPort // maybe 0
101103
inst.SSHConfigFile = filepath.Join(instDir, filenames.SSHConfig)

0 commit comments

Comments
 (0)