Skip to content

Commit

Permalink
rootless: set DBUS_SESSION_BUS_ADDRESS if it is not set
Browse files Browse the repository at this point in the history
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: containers#4162
Closes: containers#4164

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Oct 1, 2019
1 parent 7a56963 commit fbee8e7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ func SetXdgDirs() error {
return errors.Wrapf(err, "cannot set XDG_RUNTIME_DIR")
}

if rootless.IsRootless() && os.Getenv("DBUS_SESSION_BUS_ADDRESS") == "" {
if _, err := os.Stat(fmt.Sprintf("/run/user/%d/bus", rootless.GetRootlessUID())); err == nil {
os.Setenv("DBUS_SESSION_BUS_ADDRESS", fmt.Sprintf("unix:path=/run/user/%d/bus", rootless.GetRootlessUID()))
}
}

// Setup XDG_CONFIG_HOME
if cfgHomeDir := os.Getenv("XDG_CONFIG_HOME"); cfgHomeDir == "" {
if cfgHomeDir, err = util.GetRootlessConfigHomeDir(); err != nil {
Expand Down

0 comments on commit fbee8e7

Please sign in to comment.