cdi: read XDG_CONFIG_HOME/cdi and XDG_RUNTIME_DIR/cdi for rootless

Fix issue 51601

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda
2025-12-01 17:22:58 +09:00
parent 4ff8942d0d
commit cd4397b4dc

View File

@@ -656,6 +656,18 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
if conf.CDISpecDirs == nil {
// If the CDISpecDirs is not set at this stage, we set it to the default.
conf.CDISpecDirs = append([]string(nil), cdi.DefaultSpecDirs...)
if rootless.RunningWithRootlessKit() {
// In rootless mode, we add the user-specific CDI spec directory.
xch, err := homedir.GetConfigHome()
if err != nil {
return nil, err
}
xrd, err := homedir.GetRuntimeDir()
if err != nil {
return nil, err
}
conf.CDISpecDirs = append(conf.CDISpecDirs, filepath.Join(xch, "cdi"), filepath.Join(xrd, "cdi"))
}
} else if len(conf.CDISpecDirs) == 1 && conf.CDISpecDirs[0] == "" {
// If CDISpecDirs is set to an empty string, we clear it to ensure that CDI is disabled.
conf.CDISpecDirs = nil