Browse code

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>

Akihiro Suda authored on 2025/12/01 17:22:58
Showing 1 changed files
... ...
@@ -656,6 +656,18 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
656 656
 	if conf.CDISpecDirs == nil {
657 657
 		// If the CDISpecDirs is not set at this stage, we set it to the default.
658 658
 		conf.CDISpecDirs = append([]string(nil), cdi.DefaultSpecDirs...)
659
+		if rootless.RunningWithRootlessKit() {
660
+			// In rootless mode, we add the user-specific CDI spec directory.
661
+			xch, err := homedir.GetConfigHome()
662
+			if err != nil {
663
+				return nil, err
664
+			}
665
+			xrd, err := homedir.GetRuntimeDir()
666
+			if err != nil {
667
+				return nil, err
668
+			}
669
+			conf.CDISpecDirs = append(conf.CDISpecDirs, filepath.Join(xch, "cdi"), filepath.Join(xrd, "cdi"))
670
+		}
659 671
 	} else if len(conf.CDISpecDirs) == 1 && conf.CDISpecDirs[0] == "" {
660 672
 		// If CDISpecDirs is set to an empty string, we clear it to ensure that CDI is disabled.
661 673
 		conf.CDISpecDirs = nil