Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

system tray icon missing when running as root



  • Hi everybody,

    I have a tiny application that I need to have running as root (it controls a systemd service). It does not have any 'proper' window, but only lives in the system tray with context menu. If I run it as normal user, then the system tray icon shows up just fine. However, if I run it as root (typically by using kdesu), then nothing shows up in the system tray (though the application is running). I would assume that this is by design, but I also know that there are applications out there that successfully do something along these lines... What is the proper way to handle this scenario?

    Thanks,
    aran


  • Lifetime Qt Champion

    Hi,

    Quick idea: run your application as standard user and ask for the credentials when you actually need it.



  • Hi,

    It is typically a bad Idea to run applications with root privileges. I have a similar setup from a php Minecraft configuration script that needs to read write and execute code as other users as well as run root privileged system commands. What I did was utilized sudo to handle this. You can configure all sorts of access and privileges from within /etc/sudoers for a more automatic under hood approach. The sudoers man pages should be able to help you out in this type of setup.

    Chris--



  • Thanks @SGaist and @Chrisw01! I now do it using sudo, it works just fine...


  • Lifetime Qt Champion

    Good

    Then please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)



  • Well, I was considering that. However, the initial problem isn't actually solved, I just ended up doing it differently. So, marking it as "Solved" might be misleading to others searching for this problem...


  • Lifetime Qt Champion

    I'd say yes and no. Having an application running permanently as root in a user session is pretty dangerous therefor having implemented it as a normal application requesting for elevated rights when needed is a better solution and solves the problem at hand even if it can be seen as a workaround for that specific part.



  • Good point, marked thread as solved...



  • @SGaist said in system tray icon missing when running as root:

    Hi,

    Quick idea: run your application as standard user and ask for the credentials when you actually need it.

    Sorry for reply in such old topic but I am facing this problem too. Can you tell me how to ask for credentials/elevated rights for specifics action in qt application? I have googled around but still not clear how to do it especially for Ubuntu target OS. Can you give me some reference links, hints or keywords to search more?



  • @ngochm
    You should start by explaining exactly what it is you need to do when that requires root privilege. The best approach depends on what that is.



  • @JonB I am facing the same problem as the topic owner. When I run my application as root, my systemtray icon will not display and that is not good. My application actually do not need to be run as root. It may allow normal users to run application, see data, receive notify (via systemtray) but will require root privileged if users want to change settings via GUI. So I think @SGaist 's suggestion is perfectly fit my need and I really appreciate some references about that idea.


  • Lifetime Qt Champion

    What kind of settings are you thinking about ?



  • @SGaist said in system tray icon missing when running as root:

    What kind of settings are you thinking about ?

    Some settings may change the app behaviors and for security reason normal user can only see what the settings are but cannot change them. I know it would be better if those settings are throw away from GUI, placed in some config files and only allow root to modify. But in my case, it is a requirement to display those settings and allow users to change them if they have privileged. So I think your suggestion above "run your application as standard user and ask for the credentials when you actually need it" can solve my problem but just don't know how to implement it.



  • @ngochm
    You do not explain what this has to do with root. You talk about "privilege". Do you actually run a some (other) process as root from your app? Do you attempt to read from/write to a file in the file system which only allows root access? Or what?


Log in to reply