From d3825ab2a040c1bd1b523794984bc918997d921a Mon Sep 17 00:00:00 2001 From: Morten Linderud Date: Sun, 7 Aug 2022 22:36:06 +0200 Subject: [PATCH] default: look up init binary in helper_binaries_dir Some Linux distributions does not install files into `/usr/libexec` and would fail to lookup the init binary. This change first checks if the file exists in the default location, else we look for the binary in helper_binaries_dir as they should encompass all the possible installation directories. Fixes https://github.com/containers/common/issues/1110 Signed-off-by: Morten Linderud --- pkg/config/config.go | 14 ++++++++++++++ pkg/config/default.go | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 3d90268cd..0c15f508f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -824,6 +824,20 @@ func (c *EngineConfig) findRuntime() string { return "" } +func (c *EngineConfig) findInit() string { + if _, err := os.Stat(DefaultInitPath); err == nil { + return DefaultInitPath + } + for _, dir := range c.HelperBinariesDir { + path := filepath.Join(dir, DefaultInitBinaryName) + if _, err := os.Stat(path); err == nil { + logrus.Debugf("Found init binary %s in helper binary directory %s", DefaultInitBinaryName, dir) + return path + } + } + return "" +} + // Validate is the main entry point for Engine configuration validation // It returns an `error` on validation failure, otherwise // `nil`. diff --git a/pkg/config/default.go b/pkg/config/default.go index 161a9c8d6..1b400cf17 100644 --- a/pkg/config/default.go +++ b/pkg/config/default.go @@ -49,6 +49,9 @@ const ( ) var ( + // DefaultInitBinaryName is the default name of the container-init binary. + // TODO: Expose this? + DefaultInitBinaryName = "catatonit" // DefaultInitPath is the default path to the container-init binary. DefaultInitPath = "/usr/libexec/podman/catatonit" // DefaultInfraImage is the default image to run as infrastructure containers in pods. @@ -381,7 +384,8 @@ func defaultConfigFromMemory() (*EngineConfig, error) { } c.RuntimeSupportsNoCgroups = []string{"crun", "krun"} c.RuntimeSupportsKVM = []string{"kata", "kata-runtime", "kata-qemu", "kata-fc", "krun"} - c.InitPath = DefaultInitPath + c.InitPath = c.findInit() + c.NoPivotRoot = false c.InfraImage = DefaultInfraImage