From 523fc57ab432dfa8671abf7f5977bed9e700e639 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 26 Oct 2022 16:24:11 +0200 Subject: [PATCH] Use an Executable Locator to lookup chmod Signed-off-by: Evan Lezar --- cmd/nvidia-ctk/hook/chmod/chmod.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/nvidia-ctk/hook/chmod/chmod.go b/cmd/nvidia-ctk/hook/chmod/chmod.go index 01567084..cad6edfa 100644 --- a/cmd/nvidia-ctk/hook/chmod/chmod.go +++ b/cmd/nvidia-ctk/hook/chmod/chmod.go @@ -22,6 +22,7 @@ import ( "strings" "syscall" + "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" @@ -116,9 +117,16 @@ func (m command) run(c *cli.Context, cfg *config) error { return nil } - args := append([]string{"/bin/chmod", cfg.mode}, paths...) + locator := lookup.NewExecutableLocator(m.logger, "") + targets, err := locator.Locate("chmod") + if err != nil { + return fmt.Errorf("failed to locate chmod: %v", err) + } + chmodPath := targets[0] - return syscall.Exec(args[0], args, nil) + args := append([]string{filepath.Base(chmodPath), cfg.mode}, paths...) + + return syscall.Exec(chmodPath, args, nil) } // getPaths updates the specified paths relative to the root.