From 2fe6ada8547dd46bdf8f3f1ae10b02c4e903d94b Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 10 Jan 2019 13:19:51 -0500 Subject: Use defaults if paths are not specified in storage.conf For rootless Podman, if storage.conf exists but does not specify one or both of RunRoot and GraphRoot, set them to rootless defaults so we don't end up with an unusable configuration. Fixes #2125 Signed-off-by: Matthew Heon --- pkg/util/utils.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 2b752afe1..e0b94b011 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -316,8 +316,20 @@ func GetDefaultStoreOptions() (storage.StoreOptions, string, error) { storageConf := StorageConfigFile() if _, err := os.Stat(storageConf); err == nil { + defaultRootlessRunRoot := storageOpts.RunRoot + defaultRootlessGraphRoot := storageOpts.GraphRoot storageOpts = storage.StoreOptions{} storage.ReloadConfigurationFile(storageConf, &storageOpts) + + // If the file did not specify a graphroot or runroot, + // set sane defaults so we don't try and use root-owned + // directories + if storageOpts.RunRoot == "" { + storageOpts.RunRoot = defaultRootlessRunRoot + } + if storageOpts.GraphRoot == "" { + storageOpts.GraphRoot = defaultRootlessGraphRoot + } } else if os.IsNotExist(err) { os.MkdirAll(filepath.Dir(storageConf), 0755) file, err := os.OpenFile(storageConf, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) -- cgit v1.2.3-54-g00ecf