From 644f7cd9be6db369c33a9803b8d2bea11f062187 Mon Sep 17 00:00:00 2001 From: Doug Rabson Date: Sun, 2 Jul 2023 14:05:17 +0100 Subject: [PATCH] pkg/specgen: properly identify image OS on FreeBSD When working on Linux emulation on FreeBSD, I assumed that SpecGenerator.ImageOS was always populated from the image's OS value but in fact, this value comes from the CLI --os flag if set, otherwise "". This broke running FreeBSD native containers unless --os=freebsd was also set. Fix the problem by getting the value from the image itself. This is a strong incentive for me to complete a stalled project to enable podman system tests on FreeBSD. [NO NEW TESTS NEEDED] Signed-off-by: Doug Rabson --- pkg/specgen/generate/oci_freebsd.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/specgen/generate/oci_freebsd.go b/pkg/specgen/generate/oci_freebsd.go index 282165f3f1..9d1c266214 100644 --- a/pkg/specgen/generate/oci_freebsd.go +++ b/pkg/specgen/generate/oci_freebsd.go @@ -18,11 +18,17 @@ import ( // SpecGenToOCI returns the base configuration for the container. func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runtime, rtc *config.Config, newImage *libimage.Image, mounts []spec.Mount, pod *libpod.Pod, finalCmd []string, compatibleOptions *libpod.InfraInherit) (*spec.Spec, error) { - if s.ImageOS != "freebsd" && s.ImageOS != "linux" { - return nil, fmt.Errorf("unsupported image OS: %s", s.ImageOS) + inspectData, err := newImage.Inspect(ctx, nil) + if err != nil { + return nil, err + } + imageOs := inspectData.Os + + if imageOs != "freebsd" && imageOs != "linux" { + return nil, fmt.Errorf("unsupported image OS: %s", imageOs) } - g, err := generate.New(s.ImageOS) + g, err := generate.New(imageOs) if err != nil { return nil, err } @@ -55,7 +61,7 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt } // Linux emulatioon - if s.ImageOS == "linux" { + if imageOs == "linux" { var mounts []spec.Mount for _, m := range configSpec.Mounts { switch m.Destination {