From c92f6c0ea4559f1b170e1ca4345dbb0b296e7edb Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 28 Feb 2025 14:44:22 +0200 Subject: [PATCH] Move resolution of LDConfig to utils package Signed-off-by: Evan Lezar --- .../update-ldcache/update-ldcache.go | 11 +------ cmd/nvidia-cdi-hook/utils/ldconfig.go | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 cmd/nvidia-cdi-hook/utils/ldconfig.go diff --git a/cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go b/cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go index c19bc539..4344b51c 100644 --- a/cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go +++ b/cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go @@ -20,12 +20,10 @@ import ( "errors" "fmt" "path/filepath" - "strings" "github.com/urfave/cli/v2" "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-cdi-hook/utils" - "github.com/NVIDIA/nvidia-container-toolkit/internal/config" "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" ) @@ -115,7 +113,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 := utils.ResolveHostLDConfigPath(cfg.ldconfigPath) args := []string{filepath.Base(ldconfigPath)} if containerRootDir != "" { args = append(args, "-r", containerRootDir) @@ -146,10 +144,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/cmd/nvidia-cdi-hook/utils/ldconfig.go b/cmd/nvidia-cdi-hook/utils/ldconfig.go new file mode 100644 index 00000000..58922138 --- /dev/null +++ b/cmd/nvidia-cdi-hook/utils/ldconfig.go @@ -0,0 +1,30 @@ +/** +# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +**/ + +package utils + +import ( + "strings" + + "github.com/NVIDIA/nvidia-container-toolkit/internal/config" +) + +// ResolveHostLDConfigPath 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 ResolveHostLDConfigPath(path string) string { + return strings.TrimPrefix(config.NormalizeLDConfigPath("@"+path), "@") +}