我试图改变我的笔记本电脑的电源按钮角色(ASUS Vivobook)。因此,就像在arch上一样,我在/etc/systemd/logind.conf中编辑了该文件。
我修改了条目HandlePowerKey:
HandlePowerKey=suspend
比我跑的还要快:
systemctl杀灭-s systemctl-logind
这应该会重新加载新的配置,但是这样做一点帮助都没有,在优先级较高的目录中没有配置,所以配置应该只从/etc/systemd/logind.conf加载。
当检查systemd的状态时,它显示如下所示:
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.如图所示:Assignment outside of section. Ignoring.
我在网上搜索,发现这可能是由于编码。我使用命令file检查了我的编码,结果如下:
file -bi /etc/systemd/logind.conf
text/plain; charset=us-ascii如果这是ascii比它必须是utf-8,但它仍然不工作。我还应该做些什么才能让它发挥作用?
这是我的logind.conf文件的一部分。它包含带有错误的第8行。
#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发布于 2022-03-16 10:40:06
当时我真的不知道什么对我有用,但正如logind的日志所显示的,assignment outside of section. Ignoring,它只是意味着文件出了问题。在阅读了this answer之后,我认为文件的编码确实有问题。对于我来说,从文件中删除注释对我是有用的,根据对这个问题的回答,注释将编码从utf-8转到了第一位引起问题的其他方面。
因此,如果有人面临同样的问题,删除您的配置文件顶部的注释,它可能成功,也可能不起作用,但这值得一试。我建议在使用配置文件之前备份它。
file -bi /etc/systemd/logind
text/plain; charset=utf-8注意,我的编码从ASCII改为utf-8,您的编码应该是utf-8,因为systemd出于某种原因只支持utf-8 (如上面的答案所示)。
您可以使用此配置文件并根据其工作情况进行相应的修改。
[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=8192https://stackoverflow.com/questions/67615890
复制相似问题