Skip to content

Commit

Permalink
Eval symlinks on XDG_RUNTIME_DIR
Browse files Browse the repository at this point in the history
Partial Fix for #14606

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Oct 19, 2022
1 parent f6053ce commit 7c6bf96
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
12 changes: 9 additions & 3 deletions cmd/podman/registry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@ func setXdgDirs() error {
}

if _, found := os.LookupEnv("DBUS_SESSION_BUS_ADDRESS"); !found {
sessionAddr := filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "bus")
if _, err := os.Stat(sessionAddr); err == nil {
os.Setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path="+sessionAddr)
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
if runtimeDir != "" {
sessionAddr, err := filepath.EvalSymlinks(runtimeDir, "bus")
if err != nil {
return err
}
if _, err := os.Stat(sessionAddr); err == nil {
os.Setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path="+sessionAddr)
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion libpod/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ func (r *Runtime) reset(ctx context.Context) error {
}
}

xdgRuntimeDir := filepath.Clean(os.Getenv("XDG_RUNTIME_DIR"))
xdgRuntimeDir := os.Getenv("XDG_RUNTIME_DIR")
if xdgRuntimeDir != "" {
xdgRuntimeDir, err = filepath.EvalSymlinks(xdgRuntimeDir)
if err != nil {
return err
}
}
_, prevError := r.store.Shutdown(true)
graphRoot := filepath.Clean(r.store.GraphRoot())
if graphRoot == xdgRuntimeDir {
Expand Down
6 changes: 5 additions & 1 deletion pkg/systemd/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ func dbusAuthRootlessConnection(createBus func(opts ...godbus.ConnOption) (*godb
func newRootlessConnection() (*dbus.Conn, error) {
return dbus.NewConnection(func() (*godbus.Conn, error) {
return dbusAuthRootlessConnection(func(opts ...godbus.ConnOption) (*godbus.Conn, error) {
path := filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "systemd/private")
path := filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "systemd", "private")
path, err := filepath.EvalSymlinks(path)
if err != nil {
return nil, err
}
return godbus.Dial(fmt.Sprintf("unix:path=%s", path))
})
})
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/utils_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func GetRuntimeDir() (string, error) {

rootlessRuntimeDirOnce.Do(func() {
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")

if runtimeDir != "" {
rootlessRuntimeDir, rootlessRuntimeDirError = filepath.EvalSymlinks(runtimeDir)
return
}

uid := fmt.Sprintf("%d", rootless.GetRootlessUID())
if runtimeDir == "" {
tmpDir := filepath.Join("/run", "user", uid)
Expand Down

0 comments on commit 7c6bf96

Please sign in to comment.