From 57f4149a87ab7fd44a614658bd3d5ebc725285cd Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 1 Oct 2019 23:06:00 +0200 Subject: rootless: set DBUS_SESSION_BUS_ADDRESS if it is not set if the variable is not set, make sure it has a sane value so that go-dbus won't try to connect to the wrong user session. Closes: https://github.com/containers/libpod/issues/4162 Closes: https://github.com/containers/libpod/issues/4164 Signed-off-by: Giuseppe Scrivano --- libpod/runtime.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libpod') diff --git a/libpod/runtime.go b/libpod/runtime.go index 675c92b7a..9f3549e00 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -387,6 +387,13 @@ func SetXdgDirs() error { return errors.Wrapf(err, "cannot set XDG_RUNTIME_DIR") } + if rootless.IsRootless() && os.Getenv("DBUS_SESSION_BUS_ADDRESS") == "" { + sessionAddr := filepath.Join(runtimeDir, "bus") + if _, err := os.Stat(sessionAddr); err == nil { + os.Setenv("DBUS_SESSION_BUS_ADDRESS", fmt.Sprintf("unix:path=%s", sessionAddr)) + } + } + // Setup XDG_CONFIG_HOME if cfgHomeDir := os.Getenv("XDG_CONFIG_HOME"); cfgHomeDir == "" { if cfgHomeDir, err = util.GetRootlessConfigHomeDir(); err != nil { -- cgit v1.2.3-54-g00ecf