From 76351cc6092592ecf73f04e1f7963f1997d1c8b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Fri, 17 May 2024 12:07:47 +0200 Subject: [PATCH] Avoid segfault when not using qemu vmtype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pkg/qemu/qemu.go | 23 +++++++++++++---------- pkg/store/instance.go | 4 +++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pkg/qemu/qemu.go b/pkg/qemu/qemu.go index 9179def85be..c293c99720b 100644 --- a/pkg/qemu/qemu.go +++ b/pkg/qemu/qemu.go @@ -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 { diff --git a/pkg/store/instance.go b/pkg/store/instance.go index 102f05d3b0d..c643a2e4839 100644 --- a/pkg/store/instance.go +++ b/pkg/store/instance.go @@ -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)