From cd4397b4dc9bd732f20c7576d0ca43cb33c09f9c Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Mon, 1 Dec 2025 17:22:58 +0900 Subject: [PATCH] cdi: read XDG_CONFIG_HOME/cdi and XDG_RUNTIME_DIR/cdi for rootless Fix issue 51601 Signed-off-by: Akihiro Suda --- daemon/command/daemon.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/daemon/command/daemon.go b/daemon/command/daemon.go index 7e0430ab25..67a11ad9f3 100644 --- a/daemon/command/daemon.go +++ b/daemon/command/daemon.go @@ -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