mirror of
https://github.com/containers/podman.git
synced 2025-05-20 00:27:03 +08:00
Merge pull request #1580 from giuseppe/rootless-always-set-XDG_RUNTIME_DIR
rootless: always set XDG_RUNTIME_DIR
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
|||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/hooks"
|
"github.com/containers/libpod/pkg/hooks"
|
||||||
_ "github.com/containers/libpod/pkg/hooks/0.1.0"
|
_ "github.com/containers/libpod/pkg/hooks/0.1.0"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
@ -109,6 +110,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.Before = func(c *cli.Context) error {
|
app.Before = func(c *cli.Context) error {
|
||||||
|
if err := libpod.SetXdgRuntimeDir(""); err != nil {
|
||||||
|
logrus.Errorf(err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
args := c.Args()
|
args := c.Args()
|
||||||
if args.Present() {
|
if args.Present() {
|
||||||
if _, notRequireRootless := cmdsNotRequiringRootless[args.First()]; !notRequireRootless {
|
if _, notRequireRootless := cmdsNotRequiringRootless[args.First()]; !notRequireRootless {
|
||||||
|
@ -261,6 +261,25 @@ func getDefaultTmpDir() (string, error) {
|
|||||||
return filepath.Join(rootlessRuntimeDir, "libpod", "tmp"), nil
|
return filepath.Join(rootlessRuntimeDir, "libpod", "tmp"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetXdgRuntimeDir ensures the XDG_RUNTIME_DIR env variable is set
|
||||||
|
// containers/image uses XDG_RUNTIME_DIR to locate the auth file.
|
||||||
|
func SetXdgRuntimeDir(val string) error {
|
||||||
|
if !rootless.IsRootless() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if val == "" {
|
||||||
|
var err error
|
||||||
|
val, err = GetRootlessRuntimeDir()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := os.Setenv("XDG_RUNTIME_DIR", val); err != nil {
|
||||||
|
return errors.Wrapf(err, "cannot set XDG_RUNTIME_DIR")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// NewRuntime creates a new container runtime
|
// NewRuntime creates a new container runtime
|
||||||
// Options can be passed to override the default configuration for the runtime
|
// Options can be passed to override the default configuration for the runtime
|
||||||
func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
|
func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
|
||||||
@ -297,7 +316,7 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
|
|||||||
|
|
||||||
// containers/image uses XDG_RUNTIME_DIR to locate the auth file.
|
// containers/image uses XDG_RUNTIME_DIR to locate the auth file.
|
||||||
// So make sure the env variable is set.
|
// So make sure the env variable is set.
|
||||||
err = os.Setenv("XDG_RUNTIME_DIR", runtimeDir)
|
err = SetXdgRuntimeDir(runtimeDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "cannot set XDG_RUNTIME_DIR")
|
return nil, errors.Wrapf(err, "cannot set XDG_RUNTIME_DIR")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user