I have a python program that's run with pkexec and I guess because of that I'm having a really hard time getting os.environ.get('XDG_CURRENT_DESKTOP') or os.environ.get('DESKTOP_SESSION') to output anything. One of the program's function is to get the Linux Desktop environment, and that's mainly what I'm trying to accomplish right now. I've decided to use os.setupid('my_username') getting it from pwd to switch to my user and try to get the environment variables since would no longer be root but the problem is I can not go back and run the script as root for other functions. How can I go back to being root after all that?
In order to get the environment variables I'm trying this:
def getDesktopEnvironment(self):
os.seteuid(self.uidChange)
desktops = subprocess.Popen(['bash', 'desktopenv.sh'], stdout=subprocess.PIPE)
desktops.wait()
a = desktops.stdout.read()
print a
if a == "X-Cinnamon":
#do this
elif a == "Unity":
#do that
The bash script is below
#!/bin/bash
echo $XDG_CURRENT_DESKTOP
trying to go back to root get me this: os.seteuid(0)OSError: [Errno 1] Operation not permitted
os.forkto start a child process, and in that process callos.setuid. Use a pipe to pass any information back to the parent. See, e.g., stackoverflow.com/questions/218935/…