summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-06-27 15:15:38 +0200
committerGitHub <noreply@github.com>2019-06-27 15:15:38 +0200
commit5e3d63a53c0762c99c5eb7863ef7fc8d0b2e8eec (patch)
treeb137a74b2571c3f78121d5a1408275874071014a
parentfccf4ad50327d6b74b3d3fa54bce449ea93a85cf (diff)
parent7e3c27eb9d9a3cc05bf3717650097a0dc4fb5f6a (diff)
downloadpodman-5e3d63a53c0762c99c5eb7863ef7fc8d0b2e8eec.tar.gz
podman-5e3d63a53c0762c99c5eb7863ef7fc8d0b2e8eec.tar.bz2
podman-5e3d63a53c0762c99c5eb7863ef7fc8d0b2e8eec.zip
Merge pull request #3446 from giuseppe/fix-rootless-conf
rootless: use the correct conf file
-rw-r--r--libpod/runtime.go52
1 files changed, 30 insertions, 22 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go
index 97eb565cc..8290965f7 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -373,7 +373,7 @@ func NewRuntimeFromConfig(ctx context.Context, userConfigPath string, options ..
func homeDir() (string, error) {
home := os.Getenv("HOME")
if home == "" {
- usr, err := user.Current()
+ usr, err := user.LookupId(fmt.Sprintf("%d", rootless.GetRootlessUID()))
if err != nil {
return "", errors.Wrapf(err, "unable to resolve HOME directory")
}
@@ -391,28 +391,33 @@ func getRootlessConfigPath() (string, error) {
return filepath.Join(home, ".config/containers/libpod.conf"), nil
}
-func getConfigPath() string {
+func getConfigPath() (string, error) {
if rootless.IsRootless() {
- rootlessConfigPath, err := getRootlessConfigPath()
+ path, err := getRootlessConfigPath()
if err != nil {
- if _, err := os.Stat(rootlessConfigPath); err == nil {
- return rootlessConfigPath
- }
+ return "", err
+ }
+ if _, err := os.Stat(path); err == nil {
+ return path, nil
}
+ return "", err
}
if _, err := os.Stat(OverrideConfigPath); err == nil {
// Use the override configuration path
- return OverrideConfigPath
+ return OverrideConfigPath, nil
}
if _, err := os.Stat(ConfigPath); err == nil {
- return ConfigPath
+ return ConfigPath, nil
}
- return ""
+ return "", nil
}
// DefaultRuntimeConfig reads default config path and returns the RuntimeConfig
func DefaultRuntimeConfig() (*RuntimeConfig, error) {
- configPath := getConfigPath()
+ configPath, err := getConfigPath()
+ if err != nil {
+ return nil, err
+ }
contents, err := ioutil.ReadFile(configPath)
if err != nil {
@@ -460,8 +465,10 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options ..
runtime.config.StaticDir = filepath.Join(storageConf.GraphRoot, "libpod")
runtime.config.VolumePath = filepath.Join(storageConf.GraphRoot, "volumes")
- configPath := getConfigPath()
- rootlessConfigPath := ""
+ configPath, err := getConfigPath()
+ if err != nil {
+ return nil, err
+ }
if rootless.IsRootless() {
home, err := homeDir()
if err != nil {
@@ -474,11 +481,6 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options ..
}
}
- rootlessConfigPath, err = getRootlessConfigPath()
- if err != nil {
- return nil, err
- }
-
runtimeDir, err := util.GetRootlessRuntimeDir()
if err != nil {
return nil, err
@@ -599,7 +601,13 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options ..
return nil, errors.Wrapf(err, "error configuring runtime")
}
}
- if rootlessConfigPath != "" {
+
+ if rootless.IsRootless() && configPath == "" {
+ configPath, err := getRootlessConfigPath()
+ if err != nil {
+ return nil, err
+ }
+
// storage.conf
storageConfFile, err := storage.DefaultConfigFile(rootless.IsRootless())
if err != nil {
@@ -612,16 +620,16 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options ..
}
if configPath != "" {
- os.MkdirAll(filepath.Dir(rootlessConfigPath), 0755)
- file, err := os.OpenFile(rootlessConfigPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
+ os.MkdirAll(filepath.Dir(configPath), 0755)
+ file, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
if err != nil && !os.IsExist(err) {
- return nil, errors.Wrapf(err, "cannot open file %s", rootlessConfigPath)
+ return nil, errors.Wrapf(err, "cannot open file %s", configPath)
}
if err == nil {
defer file.Close()
enc := toml.NewEncoder(file)
if err := enc.Encode(runtime.config); err != nil {
- os.Remove(rootlessConfigPath)
+ os.Remove(configPath)
}
}
}