I have a service running as root in a linux system that is launched via systemd. This service at some point might spawn a GUI in the current login environment of a user (I get the values of Display and Xauth from Logind via DBUS). The launching of the gui works, but the environment is messed up.
Currently the gui is launched via fork
and execvp
. Before calling execvp
privileges are dropped using setuid
and setgid
.
What would be the appropriate way to launch a process with correct environment variables? Currently when trying to use for example policykit
from the application i get an error, that the current /dev/tty
could not be found and so on.
Is is appropriate to use su -l
? Or are there other ways to launch a process as different user?
su
lets you specify the user to run as, like: