From 862f0715576eb9cc084b9ed78247db663d724aad Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 29 Jan 2024 15:11:09 +0100 Subject: [PATCH] Fix bug in update-ldcache hook Signed-off-by: Evan Lezar --- .../hook/update-ldcache/update-ldcache.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/nvidia-ctk/hook/update-ldcache/update-ldcache.go b/cmd/nvidia-ctk/hook/update-ldcache/update-ldcache.go index 55ab7116..5a94a834 100644 --- a/cmd/nvidia-ctk/hook/update-ldcache/update-ldcache.go +++ b/cmd/nvidia-ctk/hook/update-ldcache/update-ldcache.go @@ -17,6 +17,7 @@ package ldcache import ( + "errors" "fmt" "os" "path/filepath" @@ -56,6 +57,9 @@ func (m command) build() *cli.Command { c := cli.Command{ Name: "update-ldcache", Usage: "Update ldcache in a container by running ldconfig", + Before: func(c *cli.Context) error { + return m.validateFlags(c, &cfg) + }, Action: func(c *cli.Context) error { return m.run(c, &cfg) }, @@ -71,7 +75,7 @@ func (m command) build() *cli.Command { Name: "ldconfig-path", Usage: "Specify the path to the ldconfig program", Destination: &cfg.ldconfigPath, - DefaultText: "/sbin/ldconfig", + Value: "/sbin/ldconfig", }, &cli.StringFlag{ Name: "container-spec", @@ -83,6 +87,13 @@ func (m command) build() *cli.Command { return &c } +func (m command) validateFlags(c *cli.Context, cfg *options) error { + if cfg.ldconfigPath == "" { + return errors.New("ldconfig-path must be specified") + } + return nil +} + func (m command) run(c *cli.Context, cfg *options) error { s, err := oci.LoadContainerState(cfg.containerSpec) if err != nil {