Skip to content

Commit a734438

Browse files
committed
[no-relnote] Minor edits to update-ldcache
Signed-off-by: Evan Lezar <[email protected]>
1 parent 61d94f7 commit a734438

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
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 || containerRootDir == "" || 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

@@ -182,7 +184,7 @@ func (m command) createLdsoconfdFile(in containerRoot, pattern string, dirs ...s
182184
if added[dir] {
183185
continue
184186
}
185-
_, err = configFile.WriteString(fmt.Sprintf("%s\n", dir))
187+
_, err = fmt.Fprintf(configFile, "%s\n", dir)
186188
if err != nil {
187189
return fmt.Errorf("failed to update config file: %w", err)
188190
}

0 commit comments

Comments
 (0)