I am trying to change the powerbutton role of my laptop (ASUS Vivobook). So as on arch wiki I edited the file in /etc/systemd/logind.conf
I modified the entry HandlePowerKey:
HandlePowerKey=suspend
Than I ran:
systemctl kill -s HUP systemd-logind
Which should reload the new configurations, but doing all this isn't helping at all, there are no configuration in directories with higher precedence, so configurations should only load from /etc/systemd/logind.conf
.
When checking status of the systemd-logind it shows something like this below:
systemd-logind.service - User Login Management
Loaded: loaded (/usr/lib/systemd/system/systemd-logind.service; static)
Active: active (running) since Thu 2021-05-20 12:14:58 IST; 34min ago
Docs: man:sd-login(3)
man:systemd-logind.service(8)
man:logind.conf(5)
man:org.freedesktop.login1(5)
Main PID: 366 (systemd-logind)
Status: "Processing requests..."
Tasks: 1 (limit: 9345)
Memory: 1.6M
CPU: 99ms
CGroup: /system.slice/systemd-logind.service
└─366 /usr/lib/systemd/systemd-logind
May 20 12:21:35 archlinux systemd-logind[366]: Config file reloaded.
May 20 12:21:50 archlinux systemd[1]: systemd-logind.service: Sent signal SIGHUP to main process 366 (systemd-logind) >
May 20 12:21:50 archlinux systemd-logind[366]: /etc/systemd/logind.conf:8: Assignment outside of section. Ignoring.
May 20 12:21:50 archlinux systemd-logind[366]: Config file reloaded.
May 20 12:22:28 archlinux systemd[1]: systemd-logind.service: Sent signal SIGHUP to main process 366 (systemd-logind) >
May 20 12:22:28 archlinux systemd-logind[366]: /etc/systemd/logind.conf:8: Assignment outside of section. Ignoring.
May 20 12:22:28 archlinux systemd-logind[366]: Config file reloaded.
May 20 12:22:37 archlinux systemd[1]: systemd-logind.service: Sent signal SIGHUP to main process 366 (systemd-logind) >
May 20 12:22:37 archlinux systemd-logind[366]: /etc/systemd/logind.conf:8: Assignment outside of section. Ignoring.
May 20 12:22:37 archlinux systemd-logind[366]: Config file reloaded.
Here it is showing: Assignment outside of section. Ignoring.
I searched on web and found that this may occur due to encoding. I checked my encoding with the command file
and these are the results:
file -bi /etc/systemd/logind.conf
text/plain; charset=us-ascii
If this is ascii than it must be utf-8, but it still doesn't work. What else I should do to make it work?
This is portion of my logind.conf file. It containing line 8 with error.
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#UserStopDelaySec=10
HandlePowerKey=suspend
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend-then-hibernate
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
#HandleRebootKey=reboot
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
I don't really know what worked for me at that time but as the logs for logind showing, assignment outside of section. Ignoring
, it simply means file had something wrong. After reading this answer i think something was really wrong with encoding of file. For me removing comments from file worked for me, and according to answer on this question, comments turned the encoding from utf-8 to something else which caused the problem in the 1st place.
So if someone is facing the same problem remove comments on top of your config file it may or may not work, but this worth a try. I suggest to backup your config file before doing anything with it.
file -bi /etc/systemd/logind
text/plain; charset=utf-8
Notice my encoding changed from ASCII to utf-8, your should be utf-8 to as well because systemd for some reason supports utf-8 only (as per above answer)
You can use this config file and modify accordingly if it works
[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#UserStopDelaySec=10
HandlePowerKey=suspend
HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend-then-hibernate
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
#HandleRebootKey=reboot
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=no
#RebootKeyIgnoreInhibited=no
#HoldoffTimeoutSec=30s
IdleAction=lock
#IdleActionSec=5Min
#RuntimeDirectorySize=10%
#RuntimeDirectoryInodes=400k
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192