Move resolution of host LDConfig to config package

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2025-02-28 14:44:22 +02:00
parent 4088430fc1
commit 15645e6cd5
No known key found for this signature in database
2 changed files with 8 additions and 9 deletions

View File

@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"path/filepath"
"strings"
"github.com/urfave/cli/v2"
@ -115,7 +114,7 @@ func (m command) run(c *cli.Context, cfg *options) error {
return fmt.Errorf("failed to determined container root: %v", err)
}
ldconfigPath := m.resolveLDConfigPath(cfg.ldconfigPath)
ldconfigPath := config.ResolveLDConfigPathOnHost(cfg.ldconfigPath)
args := []string{
filepath.Base(ldconfigPath),
// Run ldconfig in the container root directory on the host.
@ -146,10 +145,3 @@ func (m command) run(c *cli.Context, cfg *options) error {
return m.Exec(ldconfigPath, args, nil)
}
// resolveLDConfigPath determines the LDConfig path to use for the system.
// On systems such as Ubuntu where `/sbin/ldconfig` is a wrapper around
// /sbin/ldconfig.real, the latter is returned.
func (m command) resolveLDConfigPath(path string) string {
return strings.TrimPrefix(config.NormalizeLDConfigPath("@"+path), "@")
}

View File

@ -94,3 +94,10 @@ func (p ldconfigPath) normalize() ldconfigPath {
func NormalizeLDConfigPath(path string) string {
return string(ldconfigPath(path).normalize())
}
// ResolveLDConfigPathOnHost determines the LDConfig path to use for the system.
// The ldconfig path is normalized (i.e. /sbin/ldconfig or /sbin/ldconfig.real is used as required)
// and is guaranteed to resolve on the host.
func ResolveLDConfigPathOnHost(path string) string {
return strings.TrimPrefix(NormalizeLDConfigPath("@"+path), "@")
}