nan0s7 / nfancurve

A small and lightweight POSIX script for using a custom fan curve in Linux for those with an Nvidia GPU.
GNU General Public License v3.0
314 stars 57 forks source link

ERROR: The current user does not have permission for operation #53

Open 801k opened 1 year ago

801k commented 1 year ago

Hello! First of all, thank you for your work! I have been using this script for a year, maybe more, without any problems. Without problems it still works, but after the last Arch update it shows "ERROR: The current user does not have permission for operation" on every line when changing the fan speed level. But everything works fine and the fan speed changes. I tried running it as a script or as a service, it's the same in the log. With sudo there is no this error. Because it works well it is not a big problem, but I want to understand what is causing this Error. Thank you!

My specs:

GPU: GTX 1650 Super (Palit StormX) with single fan. OS: Arch Kernel: 6.0.2-arch1-1 Driver version: 520.56.06

AERDU commented 1 year ago

I tried figuring this out yesterday, I think there was another issue opened here which could run it if they ran xorg as root, however it's a pretty ugly workaround. What ended up working for me was adding export DISPLAY=":0" at the top of the shell script, a line after the shebang. I ended up scrapping the old .service file and created another one you run at root:

[Unit]
Description=Nfancurve service
After=multi-user.target

[Service]
ExecStart=/usr/bin/nfancurve -c /etc/nfancurve.conf
KillSignal=SIGINT

[Install]
WantedBy=default.target

The biggest issue with this script is that if you enable the script to run at boot, it will fail. Your graphical environment has to be running before the service will work. There are different options to make this work, depending on what setup you have, here are two options: https://unix.stackexchange.com/questions/397853/how-to-set-a-systemd-unit-to-start-after-loading-the-desktop

I'm using i3, but if you're using a DE you might be able to start it with xsession. My solution is really hacky and would be nice if someone else had a cleaner fix.

**also forgot to add, im using the AUR package, thats why it's called nfancurve instead of temp.sh

801k commented 1 year ago

AERDU, thank you very much for your answer!

I tried your solution and it works just perfect for service autostarting. But I still have in my log:

Oct 20 12:23:02 v01k-desktop systemd[661]: Started Nfancurve service. Oct 20 12:23:02 v01k-desktop nfancurve[668]: Number of Fans detected: Oct 20 12:23:02 v01k-desktop nfancurve[668]: 1 Oct 20 12:23:02 v01k-desktop nfancurve[668]: Number of GPUs detected: Oct 20 12:23:02 v01k-desktop nfancurve[668]: 1 Oct 20 12:23:02 v01k-desktop nfancurve[722]: ERROR: The current user does not have permission for operation Oct 20 12:23:02 v01k-desktop nfancurve[722]: Attribute 'GPUFanControlState' (v01k-desktop:0[gpu:0]) assigned value 1. Oct 20 12:23:02 v01k-desktop nfancurve[668]: Started process for 1 GPU and 1 Fan Oct 20 12:23:02 v01k-desktop nfancurve[724]: ERROR: The current user does not have permission for operation Oct 20 12:23:02 v01k-desktop nfancurve[724]: Attribute 'GPUTargetFanSpeed' (v01k-desktop:0[fan:0]) assigned value 35.

As I said, the fan speed level changes well even with this error.

I'm sorry, but I don't understand a little bit this moment that you wrote: "...and created another one you run at root". I'm not very experienced with Linux services and don't understand how to run service with --user as root. Please clarify this moment for me. Thank you!

P.S. I'm also using i3 and the package from AUR.

AERDU commented 1 year ago

move the .service file to /usr/lib/systemd/system/ instead of /usr/lib/systemd/user/, run systemctl daemon-reload for good meassures, and then load/enable the service with systemctl enable --now nfancurve.service. When you specify --user you run a service file from /usr/lib/systemd/user which has insufficient permission, as it runs it as your current user.

801k commented 1 year ago

Oh, thank you! I thought about it, but wasn't sure it is the right way :) And what do you think about why this error appeared after the last Arch update? Could it be related to the latest Nvidia driver?

AERDU commented 1 year ago

There's another nvidia fan controller at https://github.com/foucault/nvfancontrol that states: "As of version 465 NVIDIA decided that is a security risk for non-root users to have access to cooler control and overclocking capabilities. So you will have to start X11 as root despite almost no distributions and desktop environment doing so for the past years because it is a massive... security risk. Trading one security risk for another!"

keep in mind that my solution does NOT start X11 as root (at least it shouldn't unless setting $DISPLAY to :0 in a root session somehow elevates xorg). I'm also not sure why you got it after a recent update, v465 was awhile ago unless you use DKMS or something.

801k commented 1 year ago

AERDU, thank you very much for clarifying this problem for me. Yes, it is very strange that I got this error after a recent update, because I always update my system, maybe weekly or even more often. But now everything works fine, and then we'll see, maybe the developer will make some changes. Thanks again!

AERDU commented 1 year ago

Tiny improvement I made recently, instead of setting the service on a timer I just set it to restart if it exits with an error code:

[Unit]
Description=Nfancurve service
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/nfancurve -c /etc/nfancurve.conf
Restart=on-failure
RestartSec=60s

[Install]
WantedBy=default.target

This should fix the issue instantly, and don't forget to systemctl daemon-reload.

HanM23 commented 1 year ago

Tiny improvement I made recently, instead of setting the service on a timer I just set it to restart if it exits with an error code:

[Unit]
Description=Nfancurve service
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/nfancurve -c /etc/nfancurve.conf
Restart=on-failure
RestartSec=60s

[Install]
WantedBy=default.target

This should fix the issue instantly, and don't forget to systemctl daemon-reload.

Hello, thanks for your help here. I had the same issue too. I followed what you wrote :

  1. move the .service file to /usr/lib/systemd/system/ instead of /usr/lib/systemd/user/
  2. export DISPLAY=":0" in the shell script.

But i still had the following errors in journalctl

dec. 07 18:33:27 smith sh[49114]: Authorization required, but no authorization protocol specified
dec. 07 18:33:20 smith sh[49087]: Authorization required, but no authorization protocol specified
dec. 07 18:33:20 smith sh[49087]: Authorization required, but no authorization protocol specified
dec. 07 18:33:13 smith sh[49085]: Authorization required, but no authorization protocol specified
dec. 07 18:33:13 smith sh[49085]: Authorization required, but no authorization protocol specified

I resolved it by adding another line in the shell script : export XAUTHORITY='/run/lightdm/root/:0'

Indeed ❯ ps aux | grep Xorg (/run/lightdm/root/:0 is after -auth in the first line)

root        1124  4.1  2.7 25744332 218424 tty7  Ssl+ 12:41  15:29 /usr/lib/Xorg :0 -seat seat0 -auth /run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
<username>     51551  0.0  0.0   6572  2520 pts/4    S+   18:56   0:00 grep Xorg

I do not really like it, because normally (before the export above) XAUTHORITY was equal to /home/<username>/.Xauthority

EDIT : it also works when i add export XAUTHORITY='/home/<username>/.Xauthority' in the shell script (nfancurve.sh, i also get it from AUR), but i do not really understand what is happening with this XAUTHORITY thing.

Have you faced this issue too ? Thanks

AERDU commented 1 year ago

My logs are free from any errors related to ~/.Xauthority. I don't use lightdm, so I suspect lightdm may require Xorg to run with ~/.Xauthority.

ps aux | grep -i xorg returns /usr/lib/Xorg :0 vt2 for me.

I use ly , it probably just runs xinit, which in turn runs /usr/lib/Xorg :0 vt2, which is quite different from the way Xorg was started on your machine.