Skip to content

Fix Help menu links when running as root#113

Draft
Claude wants to merge 2 commits intomainfrom
claude/fix-help-menu-links
Draft

Fix Help menu links when running as root#113
Claude wants to merge 2 commits intomainfrom
claude/fix-help-menu-links

Conversation

@Claude
Copy link
Contributor

@Claude Claude AI commented Mar 6, 2026

gtk_show_uri_on_window() fails when running as root because the user's D-Bus session is inaccessible. Help menu links (Documentation, Support, About dialog URLs) silently fail in gsmartcontrol-root.

Implementation

Added fallback to src/hz/launch_url.h that forks a child process, drops privileges to the original user (via SUDO_UID/PKEXEC_UID env vars), and executes xdg-open:

// When running as root, try privilege-dropping fallback first
bool is_root = (geteuid() == 0);

if (is_root) {
    std::string result = launch_url_as_original_user(link);
    if (result.empty()) {
        return {};  // Success
    }
}

// Fall back to gtk_show_uri_on_window()

The launch_url_as_original_user() helper:

  • Retrieves original UID/GID from environment
  • Restores HOME for proper browser config access
  • Drops privileges via setgid()/setuid() in correct order
  • Executes xdg-open as the original user

Works on both X11 and Wayland. Non-root execution unchanged (continues using GTK method with fallback if needed).

Original prompt

This section details on the original issue you should resolve

<issue_title>Cannot open Help menu links in gsmartcontrol-root</issue_title>
<issue_description>Hi, many thanks for this app. I am using 1.1.3 on Ubuntu Mate 21.04.

I notice that all links in the Help menu (Help, Support, About/Website and the mailto: links in About/Credits) do not work when using gsmartcontrol-root (they work in non-root gsmartcontrol).

Running gsmartcontrol-root -v I see:

<info>  [app] GscMainWindow::on_action_activated(): Action activated: "action_online_documentation"
Running Firefox as root in a regular user's session is not supported.  ($XAUTHORITY is /home/john/.Xauthority which is owned by john.)
<info>  [app] GscMainWindow::on_action_activated(): Action activated: "action_support"
Running Firefox as root in a regular user's session is not supported.  ($XAUTHORITY is /home/john/.Xauthority which is owned by john.)
<info>  [app] GscMainWindow::on_action_activated(): Action activated: "action_about"
Running Firefox as root in a regular user's session is not supported.  ($XAUTHORITY is /home/john/.Xauthority which is owned by john.)
Running Thunderbird as root in a regular user's session is not supported.  ($XAUTHORITY is /home/john/.Xauthority which is owned by john.)
```</issue_description>

<agent_instructions>Implement it for Linux in a way that works for X11 and Wayland.</agent_instructions>

## Comments on the Issue (you are @claude[agent] in this section)

<comments>
<comment_new><author>@ashaduri</author><body>
Hello,
Thanks for the bug report!

GSmartControl uses `gtk_show_uri_on_window()` to open URLs, so it does not have any say in which browser is used to open the URL.
Since GSmartControl itself is launched with root privileges, and Firefox doesn't support running in this mode, I guess the only workaround would be to check whether the launch was successful. If it was not, a dialog with the URL (for the user to copy) would be shown.
I will have to check whether an unsuccessful launch can be detected at all. If not, I'm not sure what else I could do (any help is appreciated!)</body></comment_new>
<comment_new><author>@ashaduri</author><body>
Yes, a helper process with less privileges is one possibility, but the hard part is to make launching it portable (at least across Linux distributions, because the root escalation is also distribution-dependent).</body></comment_new>
<comment_new><author>@ashaduri</author><body>
> It would be good for security in general to launch the GUI as a normal user, then use pkexec to run smartctl when required, with a rule in /usr/share/polkit-1/actions to display an authentication dialog to the user with a nice message about what the privileges are needed for.

While it's a good idea in principle, last time I checked polkit did not allow you to specify the "keep" timeout after gaining the rights. There is only mention of a "brief" period in the specification, which is suggested to be 5 minutes. Asking for a password every 5 minutes while the program is running would be bad.
Also, gsmartcontrol itself needs elevated access to files sometimes, so it's not only for "smartctl" or "twcli" or similar backend commands.

The proper solution would be to have a single privileged subprocess (elevated via pkexec or some other way), let it do everything related to the system, and communicate back and forth with the GUI. Implementing this (especially in a cross-platform way) will take considerable amount of resources though.

</body></comment_new>
</comments>

Implement fallback mechanism to launch URLs as the original user when gsmartcontrol is running with root privileges. This fixes the issue where gtk_show_uri_on_window() fails when running as root due to inaccessible D-Bus session.

Co-authored-by: ashaduri <[email protected]>
@Claude Claude AI changed the title [WIP] Fix Help menu links not working in gsmartcontrol-root Fix Help menu links when running as root Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot open Help menu links in gsmartcontrol-root

2 participants