0

Problem

I am running Emacs daemon as a user service using Systemd, following the documentation in EmacsWiki. I configured it while using Fedora-36, and everything was working as expected. Once I upgraded to Fedora-37, emacsclient -c started failing with error *ERROR*: Display :0 can't be opened; the Emacs daemon also added Authorization required, but no authorization protocol specified to the systemctl --user status emacs.service output.

Temporary solution.

First I figured out that simply restarting the service using systemctl --user restart emacs.service fixed the problem until I reboot the machine again. But having to restart the service manually every time I start the machine defeated the point of starting it automatically using Systemd.

Debugging attempt.

After some research on the topic, I figured out that the emacs daemon is not getting the XAUTHORITY environment variable when started automatically. Running ps -C emacs eww after a reboot, I can see that the following 14 environment variables are set.

HOME, LANG, LOGNAME, PATH, SHELL, SYSTEMD_EXEC_PID, USER, 
XDG_DATA_DIRS, XDG_RUNTIME_DIR, DBUS_SESSION_BUS_ADDRESS, 
NOTIFY_SOCKET, MANAGERPID, INVOCATION_ID, JOURNAL_STREAM

After restarting the service, I see 43 environment variables. Amount the 29 new variables, there is DISPLAY, GNOME_SETUP_DISPLAY, WAYLAND_DISPLAY, and XAUTHORITY.

So one possibility is that Systemd is starting user services before these variables are available, which causes the problem. If this is the case, how can I fix it?

But I also found that I could just create a soft link named .Xauthority file in my home directory, which points to the actual one, and Emacs seems to work without these environment variables. So maybe these environment variables are not needed and what changed from fedora-36 to fedora-37 is not having the .Xauthority file in the home directory any more. If this is the case, how should I fix this?

1 Answer 1

1

Solved this problem by creating /usr/lib/systemd/user/gnome-emacs.service, which is a copy of emacs.service with changes:

[root@fedora user]# diff -uw emacs.service gnome-emacs.service 
--- emacs.service   2023-02-25 14:08:10.623902447 +0300
+++ gnome-emacs.service 2023-02-25 14:08:47.735165962 +0300
@@ -1,6 +1,7 @@
 [Unit]
 Description=Emacs text editor
 Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
+After=gnome-session-x11-services.target
 
 [Service]
 Type=notify
@@ -16,4 +17,4 @@
 Restart=on-failure
 
 [Install]
-WantedBy=default.target
+WantedBy=graphical-session.target

and enable this service (after removing all installed before):

$ systemctl --user enable gnome-emacs.service
$ systemctl --user start gnome-emacs.service

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.