diff --git a/cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go b/cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go index 5d152c1a..65dbc270 100644 --- a/cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go +++ b/cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go @@ -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), "@") -} diff --git a/internal/config/cli.go b/internal/config/cli.go index 3621df25..6fb4cc66 100644 --- a/internal/config/cli.go +++ b/internal/config/cli.go @@ -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), "@") +}