Recover XDG_CURRENT_DESKTOP's value?
-
On linux (a weird private distro moified after Ubuntu):
pkexec myprog
gets myprog running as root, but loses environment variables.
I made a org.myorg.myprog.policy under /usr/share/polkit-1/actions, specified allow_gui to true, and myprog gets DISPLAY and XAUTHORITY back.
Question: myprog's GUI theme looks different from when it's not sudo-ed due to absence of XDG_CURRENT_DESKTOP variable. Can I recover it WITHOUT use of argv or some IPC trick?(Also, I don't want to
pkexec env VAR=VALUE myprog
because it's too ugly, and the password dialog would be showing the user's launching env instead of myprog.)
-
Hi,
Since it's an environment variable you can use
qEnvironmentVariable. -
-
@jsulm Didn't I say that pkexec-ing myprog peels the environment variables off?
candy@vbuntv:~/T$ more T.cpp #include <iostream> #include <string> int main(int argc, char **argv, char **envp){ std::string keys[]={"DISPLAY=", "XAUTHORITY=", "XDG_CURRENT_DESKTOP="}; while(envp && *envp){ for(const std::string &key: keys){ std::string var=*envp; if(var.starts_with(key)){ std::cout<<var<<std::endl; break; } } envp++; } return 0; } candy@vbuntv:~/T$ g++ -std=c++20 T.cpp && ./a.out XDG_CURRENT_DESKTOP=ubuntu:GNOME DISPLAY=:10.0 candy@vbuntv:~/T$ pkexec `pwd`/a.out #No output at all.
candy@vbuntv:~/T$ env | grep -E "DISPLAY|XAUTHORITY|XDG_CURRENT_DESKTOP" XDG_CURRENT_DESKTOP=ubuntu:GNOME DISPLAY=:10.0 candy@vbuntv:~/T$ pkexec env | grep -E "DISPLAY|XAUTHORITY|XDG_CURRENT_DESKTOP" #Nothing.
-
If I'm not mistaken @SGaist wanted to suggest that your application changes/sets the env variable using https://doc.qt.io/qt-5/qtglobal.html#qputenv
-
Based on the pkexec documentation you can't do what you are trying. The environment is set to a minimal state that excludes the variables you are interested in.
If you want their values in your application, you will have to pass them as command line parameters.
However, based on the variable you are looking for, it seems you want to run a GUI as root, which is usually a bad idea.