Skip to content

Commit a923f1e

Browse files
committed
Fix update-ldcache arguments
This change updates how the lconfig arguments are constructed. This makes the update-ldcache more robust and ensures that folders are specified last if at al. Checks are also included for empty container roots at the start of the hook to simplify later checks. Signed-off-by: Evan Lezar <[email protected]>
1 parent e7a0067 commit a923f1e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,20 @@ func (m command) run(c *cli.Context, cfg *options) error {
109109
}
110110

111111
containerRootDir, err := s.GetContainerRoot()
112-
if err != nil {
112+
if err != nil || string(containerRootDir) == "" || string(containerRootDir) == "/" {
113113
return fmt.Errorf("failed to determined container root: %v", err)
114114
}
115115

116116
ldconfigPath := m.resolveLDConfigPath(cfg.ldconfigPath)
117-
args := []string{filepath.Base(ldconfigPath)}
118-
if containerRootDir != "" {
119-
args = append(args, "-r", containerRootDir)
117+
args := []string{
118+
filepath.Base(ldconfigPath),
119+
// Run ldconfig in the container root directory on the host.
120+
"-r", containerRootDir,
121+
// Explicitly specify using /etc/ld.so.conf since the host's ldconfig may
122+
// be configured to use a different config file by default.
123+
// Note that since we apply the `-r {{ .containerRootDir }}` argument, /etc/ld.so.conf is
124+
// in the container.
125+
"-f", "/etc/ld.so.conf",
120126
}
121127

122128
containerRoot := containerRoot(containerRootDir)
@@ -138,10 +144,6 @@ func (m command) run(c *cli.Context, cfg *options) error {
138144
args = append(args, folders...)
139145
}
140146

141-
// Explicitly specify using /etc/ld.so.conf since the host's ldconfig may
142-
// be configured to use a different config file by default.
143-
args = append(args, "-f", "/etc/ld.so.conf")
144-
145147
return m.SafeExec(ldconfigPath, args, nil)
146148
}
147149

0 commit comments

Comments
 (0)