intgr / ego

Alter Ego: run Linux desktop applications under a different local user
MIT License
127 stars 1 forks source link

XDG_RUNTIME_DIR unset when using sudo #6

Closed intgr closed 4 years ago

intgr commented 4 years ago

Apparently (at least on some distros), using sudo does not trigger the pam_systemd module. This causes issues with software that relies on D-Bus and other session services (e.g. dconf).

It seems that most applications are fine with this, but some functionality may be broken.

An alternative would be to use ssh or "machinectl shell" (https://unix.stackexchange.com/questions/346841/why-does-sudo-i-not-set-xdg-runtime-dir-for-the-target-user)

The downside is that these lack simple configuration for paswordless use.

That also opens a new can of worms: Gnome applications will hang for some seconds on startup because they expect xdg-desktop-portal-gtk, which fails to start, presumably because env vars haven't been injected at that point.

xdg-desktop-portal-gtk[524663]: Unable to init server: Could not connect: Connection refused
xdg-desktop-por[524663]: cannot open display: 

Running /usr/lib/xdg-desktop-portal-gtk manually from the shell solves that issue.

intgr commented 4 years ago

Apparently the correct way to solve this is to set the environment vars early enough, before systemd user session starts xdg-desktop-portal-gtk. Will need to dig deeper into systemd.

Meanwhile, this is a work-around:

ego --machinectl
# [in other user's shell]
dbus-update-activation-environment --systemd WAYLAND_DISPLAY DISPLAY PULSE_SERVER PULSE_COOKIE
systemctl --user start xdg-desktop-portal-gtk