Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ubuntu][Debian][Wayland][Delayed Timeout While Using pkexec] #122

Open
maniacx opened this issue Dec 21, 2024 · 1 comment
Open

[Ubuntu][Debian][Wayland][Delayed Timeout While Using pkexec] #122

maniacx opened this issue Dec 21, 2024 · 1 comment

Comments

@maniacx
Copy link
Owner

maniacx commented Dec 21, 2024

Bug with Polkit on Ubuntu/Debian running Wayland

  • Users have reported a 2.5-minute delay when setting the threshold using pkexec.
  • Troubleshooting indicates this issue occurs on Ubuntu (Wayland) and Debian (Wayland) systems running polkit version 124 or greater.
  • When the extension runs the pkexec command to set the threshold, the execution takes 2.5 minutes.
  • This causes the extension to either start after a 2.5-minute delay or take the same time to apply the threshold. (Newer extension versions will display a timeout message after 5 seconds.)
  • I have created a script to use sudo instead of pkexec command as a workaround for this issue.

Systems Affected by the Delay in pkexec Execution

  • ** Known Affected Systems:**

    • Ubuntu-based systems with polkit >= 124 running Wayland.
    • Debian-based systems with polkit >= 124 running Wayland.
  • Known Non-Affected Systems:

    • Ubuntu-based systems with polkit >= 124 running Xorg.
    • Debian-based systems with polkit >= 124 running Xorg.
    • Fedora systems (both Wayland and Xorg).

Workaround: Use sudo Instead of pkexec

To resolve this issue, replace pkexec with sudo for commands setting the threshold. This requires creating an exemption to allow batteryhealthchargingctl to run with sudo without requiring a password. This can be done manually or using the provided bash script.


Workaround Using the Script

Download script

bhc_patch.zip

Note

Some systems, like Debian, do not add users to the sudo group by default. If prompted, use su instead of sudo to update the configuration.

Steps

Run the script using:

bash bhc_patch.sh

If running the script for the first time, use Option A to perform all operations.

Options Available

  • Option 1: Install Polkit rules and batteryhealthchargingctl (if not already installed).
  • Option 2: Modify the sudo configuration to allow batteryhealthchargingctl to run without a password. This creates the sudo configuration file /etc/sudoers.d/batteryhealthcharging-{username}.
  • Option 3: Patch the Battery Health Charging extension by replacing pkexec with sudo in driver.js and helper.js.
  • Option A: Perform all the above operations.
  • Option 4: Remove the sudo configuration, deleting the /etc/sudoers.d/batteryhealthcharging-{username} file.

Workaround: Do it yourself

If you do no want to run the script, you can edit files yourself.

Important Notes

  • Replace {USERNAME} with your actual username in all the following steps below. example instead of
  • If unsure of your username, run the command whoami in the terminal.

1. Edit Sudoer Configuration

Rather than modifying /etc/sudoers directly, create a file in the /etc/sudoers.d/ directory to leave the original file untouched for easier upgrades.

  1. Create a sudo configuration file:
   sudo visudo -f /etc/sudoers.d/batteryhealthcharging-{USERNAME}
  1. Add the following line to the file:
   %{USERNAME} ALL=NOPASSWD:/usr/local/bin/batteryhealthchargingctl-{USERNAME}

Replace {USERNAME} with your username.

This will allow batteryhealthchargingctl to execute with sudo without requiring a password.

2. Edit the Battery Health Charging Extension

Replace pkexec with sudo in the following files:
~/.local/share/gnome-shell/extensions/[email protected]/lib/driver.js

~ /home/abc123/.local/share/gnome-shell/extensions/[email protected]/lib/helper.js

Example: Modifying driver.js

Change this line:

const argv = ['pkexec', ctlPath, 'CHECKINSTALLATION', resourceDir, user];

To:

const argv = ['sudo', ctlPath, 'CHECKINSTALLATION', resourceDir, user];
@maniacx
Copy link
Owner Author

maniacx commented Dec 21, 2024

@Umang-Chaurasia
@seffs
@petr-fischer
@nicolastaffin
@paulvt

Kindly test the script that changes the extension to use sudo and install configuration for sudo to run batteryhealthchargingctl without password.
Let me know how it goes.

Thank you.

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

No branches or pull requests

1 participant