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.
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.
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
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?