Ubuntu 22.04+下Wayland环境配置Emacs守护进程为Systemd用户服务的启动授权问题咨询
我在Ubuntu 23.10(Wayland环境)上配置Emacs 29.1作为systemd用户守护进程时遇到了权限问题,想请教大家怎么解决。
先说说我的配置基础:Emacs 29.1默认的systemd用户服务文件是这样的:
[Unit] Description=Emacs text editor Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/ [Service] Type=notify ExecStart=/usr/bin/emacs --fg-daemon # ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)" # Emacs will exit with status 15 after having received SIGTERM, which # is the default "KillSignal" value systemd uses to stop services. SuccessExitStatus=15 # The location of the SSH auth socket varies by distribution, and some # set it from PAM, so don't override by default. # Environment=SSH_AUTH_SOCK=%t/keyring/ssh Restart=on-failure [Install] WantedBy=default.target
遇到的问题
每次电脑开机登录后,我运行emacsclient -c完全没反应,查看用户级systemd日志journalctl -u emacs -f --user,会看到错误:
Authorization required, but no authorization protocol specified
但如果手动重启Emacs服务systemctl --user restart emacs,再运行emacsclient -c就一切正常,窗口能正常打开。可每次开机都要手动重启服务,完全失去了配置systemd守护进程的意义。
我试过的解决方案
我查了不少资料,一开始看到说要让Emacs在GNOME启动后再启动,需要在[Unit]段添加:
Requires=org.gnome.Shell@wayland.service After=org.gnome.Shell@wayland.service
但Ubuntu 22.04+根本没有org.gnome.Shell@wayland.service这个单元。我还试过替换成gdm.service、user@%U.service,都没用。
后来我又尝试添加graphical-session.target的依赖,写了一个drop-in文件:
[Unit] After=graphical-session.target
执行systemctl --user daemon-reload后重启系统,问题还是一样。
另外我也看过相关的技术讨论,里面提到的针对GNOME/X11/Fedora的解决方案,放到我的GNOME/Wayland/Ubuntu环境下也不生效。
有没有大佬知道在Ubuntu 22.04+的Wayland环境下,该怎么配置才能让Emacs守护进程开机后自动正确启动,不需要手动重启呢?
备注:内容来源于stack exchange,提问作者donatello




