Bug 1174534

Summary: emacsclient -c fails with xauth problem: "*ERROR*: Display :0 can't be opened"
Product: [openSUSE] openSUSE Tumbleweed Reporter: Tristan Miller <psychonaut>
Component: GNOMEAssignee: E-mail List <gnome-bugs>
Status: RESOLVED NORESPONSE QA Contact: E-mail List <qa-bugs>
Severity: Minor    
Priority: P5 - None CC: dleuenberger, fabian, fvogt, georg.grauberger, psychonaut, werner, xiaoguang.wang
Version: CurrentFlags: georg.grauberger: needinfo?
Target Milestone: ---   
Hardware: Other   
OS: Other   
See Also: http://bugzilla.opensuse.org/show_bug.cgi?id=1174592
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: Systemd unit configuration file for emacs daemon

Description Tristan Miller 2020-07-27 11:21:32 UTC
My user account has emacs running as a daemon and I use emacsclient -c to connect to it.  This setup has worked for years.  Today I updated from Tumbleweed 20200708 to 20200724 and now whenever I run emacsclient -c, it fails with the following message:

*ERROR*: Display :0 can’t be opened

A workaround is to first issue the following command:

xauth extract - $DISPLAY | xauth -f ~/.Xauthority merge -

A problem with the same symptoms and same workaround was previously reported for Gentoo: <https://bugs.gentoo.org/555346>  According to that report, the problem was with sddm.  Perhaps the culprit in this case is the <https://build.opensuse.org/request/show/819685>, which added some patches related to xauth.
Comment 1 Fabian Vogt 2020-07-27 11:31:22 UTC
Apparently emacs/emacsclient don't honour $XAUTHORITY, reassigning.
Comment 2 Tristan Miller 2020-07-27 14:02:58 UTC
I branched the openSUSE:Factory/sddm package at Revision 49 <https://build.opensuse.org/package/show/openSUSE:Factory/sddm?rev=49> (which is just before the suspicious commits) and built and installed the package.  Now emacsclient is working again.  So the problem definitely has something to do with the recent changes to sddm (or to emacsclient's incompatibility with them).
Comment 3 Dr. Werner Fink 2020-08-19 12:07:30 UTC
I'm using an older Tumblweed with new GNU Emacs and use emacsclient (restarted!) as well and it does wotk
Comment 4 Fabian Vogt 2020-08-19 12:09:28 UTC
(In reply to Dr. Werner Fink from comment #3)
> I'm using an older Tumblweed with new GNU Emacs and use emacsclient
> (restarted!) as well and it does wotk

With recent enough sddm?
Comment 5 Dr. Werner Fink 2020-08-19 12:13:16 UTC
The only difference I have done is to modify my ~/bin/emacs script in such a way the now both wit hand without frame the emacsclient is started now with -c
Comment 6 Dr. Werner Fink 2020-08-19 12:13:47 UTC
(In reply to Fabian Vogt from comment #4)
> (In reply to Dr. Werner Fink from comment #3)
> > I'm using an older Tumblweed with new GNU Emacs and use emacsclient
> > (restarted!) as well and it does wotk
> 
> With recent enough sddm?

werner/emacs> rpm -q sddm
sddm-0.18.1-3.1.x86_64
Comment 7 Dr. Werner Fink 2020-08-19 12:17:59 UTC
Ahhh ... here I have

 echo $XAUTHORITY 
 /run/user/223/xauth_tAtOOg

 werner/emacs> xauth list
 noether/unix:0  MIT-MAGIC-COOKIE-1  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 #ffff##:0  MIT-MAGIC-COOKIE-1  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

(key replaced)
Comment 8 Dr. Werner Fink 2020-08-19 12:20:57 UTC
This is IMHO a bug in sddm ... or one of the login scripts used by the user/reporter which overrides XAUTHORITY of the X session (even only partly)
Comment 9 Fabian Vogt 2020-08-19 12:26:47 UTC
I don't know what emacsclient -c is or does. As xauth extract works, both $XAUTHORITY and its content are correct. So I don't think this is an issue in sddm. If it connects to a "server", maybe that "server" needs to be started with the right $XAUTHORITY already?
Comment 10 Dr. Werner Fink 2020-08-19 12:33:13 UTC
(In reply to Fabian Vogt from comment #9)
> I don't know what emacsclient -c is or does. As xauth extract works, both
> $XAUTHORITY and its content are correct. So I don't think this is an issue
> in sddm. If it connects to a "server", maybe that "server" needs to be
> started with the right $XAUTHORITY already?

The emacs server needs the correct MIT-MAGIC-COOKIE-1 for the current DISPLAY ... which Xauthority file is used therefore should not matter  ... the X server gets its Xauthority information from its command line with

    -auth /run/sddm/{......}
Comment 11 Dr. Werner Fink 2020-08-19 12:37:14 UTC
The only problem could be if there is NO XAUTHORITY variable set at start time of emacs server/daemon of if XAUTHORITY is set to ~/.Xauthority then the content should be the same as in later XAUTHORITY file

Maybe a

  ps aex | grep /usr/bin/emacs | grep -v grep | tr ' ' '\n' | grep AUTH

does show more
Comment 12 Dr. Werner Fink 2020-08-19 12:51:27 UTC
It should also noted that emacsclient its self does not use X nor Xauthority ... only the emacs server/daemon does
Comment 13 Tristan Miller 2020-08-19 13:28:57 UTC
I just did a distribution upgrade of Tumbleweed (including sddm) from 20200724 to 20200817 and now I can no longer reproduce the "Display :0 can't be opened" problem.

I am, however, experiencing a different problem with Emacs in that it can no longer access any of my system fonts, leaving me with an ugly bitmap as default.  Attempting to change the font back to one of the system fonts (via Options->Set Default Font…) results in a "Font not available" error in the status bar.

I'm not sure if this font problem is related to the xauth issue.  If not, then the current report can probably be closed (though I would appreciate advice on the font issue, including whether to file a separate bug for it).
Comment 14 Tristan Miller 2020-08-19 13:30:57 UTC
(In reply to Tristan Miller from comment #13)
> I am, however, experiencing a different problem with Emacs in that it can no
> longer access any of my system fonts, leaving me with an ugly bitmap as
> default.  Attempting to change the font back to one of the system fonts (via
> Options->Set Default Font…) results in a "Font not available" error in the
> status bar.
> 
> I'm not sure if this font problem is related to the xauth issue.  If not,
> then the current report can probably be closed (though I would appreciate
> advice on the font issue, including whether to file a separate bug for it).

Never mind; it seems this issue was already reported as Bug 1175372.
Comment 15 Fabian Vogt 2020-08-19 13:31:57 UTC
(In reply to Tristan Miller from comment #13)
> I just did a distribution upgrade of Tumbleweed (including sddm) from
> 20200724 to 20200817 and now I can no longer reproduce the "Display :0 can't
> be opened" problem.

Great, then it might've been fixed by the Apparmor profile change as well.
Comment 16 Dr. Werner Fink 2020-08-20 09:58:06 UTC
Btw: if /usr/lib/systemd/user/emacs.service is used ... e.g. by linking into ~/.config/systemd/user/ and enabling it, then a restart might help the current emacs server/daemon to find a new DISPLAY entry in the Xauthority file.  Only if DISPALY :0 on local console is found in a different Xauthority file than e.g. DISPLAY :3 (e.g. as a VNC screen), the export into the Xauthority file used by system service unit helps out.
Comment 17 Tristan Miller 2020-11-05 11:15:44 UTC
(In reply to Fabian Vogt from comment #15)
> (In reply to Tristan Miller from comment #13)
> > I just did a distribution upgrade of Tumbleweed (including sddm) from
> > 20200724 to 20200817 and now I can no longer reproduce the "Display :0 can't
> > be opened" problem.
> 
> Great, then it might've been fixed by the Apparmor profile change as well.

The problem has been recurring for me.  In fact, I think it never really went away; it's just unpredictable as to whether or not the service successfully starts on any given boot.  If it does fail to start, then issuing a "systemctl restart --user emacs.service" will fix the problem.

The unit configuration file I'm using isn't much different from the one in /usr/lib/systemd/user/emacs.service.  The only differences are that my file sets a couple environment variables (SSH_AUTH_SOCK and PATH) and uses Type=simple instead of Type=notify.  (But even if I change this to Type=notify, the problem still occurs.)
Comment 18 Dr. Werner Fink 2020-11-05 11:41:04 UTC
(In reply to Tristan Miller from comment #17)
> (In reply to Fabian Vogt from comment #15)
> > (In reply to Tristan Miller from comment #13)
> > > I just did a distribution upgrade of Tumbleweed (including sddm) from
> > > 20200724 to 20200817 and now I can no longer reproduce the "Display :0 can't
> > > be opened" problem.
> > 
> > Great, then it might've been fixed by the Apparmor profile change as well.
> 
> The problem has been recurring for me.  In fact, I think it never really
> went away; it's just unpredictable as to whether or not the service
> successfully starts on any given boot.  If it does fail to start, then
> issuing a "systemctl restart --user emacs.service" will fix the problem.
> 
> The unit configuration file I'm using isn't much different from the one in
> /usr/lib/systemd/user/emacs.service.  The only differences are that my file
> sets a couple environment variables (SSH_AUTH_SOCK and PATH) and uses
> Type=simple instead of Type=notify.  (But even if I change this to
> Type=notify, the problem still occurs.)

I'm also using user based emacs.service and I *never* ever had this issue. Never on Tumblweed nor on any Leap. It simply works.
Comment 19 Dr. Werner Fink 2020-11-05 11:50:32 UTC
I'm doubt that this is an emacs problem, this looks more like a timing and/or access problem with the (default) xauthority file.  Beside this I do not use apparmor
Comment 20 Tristan Miller 2020-11-05 12:12:04 UTC
(In reply to Dr. Werner Fink from comment #19)
> I'm doubt that this is an emacs problem, this looks more like a timing
> and/or access problem with the (default) xauthority file.  Beside this I do
> not use apparmor

Is there anything else I can try then?  Maybe some way of introducing a delay before the emacs service starts, to give the system time to establish the Xauthority file?
Comment 21 Dr. Werner Fink 2020-11-05 12:32:32 UTC
Maybe it is more a problem with the used desktop.  I'm using my own ~/.xsession file with fvwm2 and lxsession. And for X Vnc sessions (home office) I'm sourcing the file as well /etc/X11/xinit/xinitrc.common which loads some extensions.
Comment 22 Stefan Dirsch 2020-11-05 15:44:53 UTC
Ok. Which displaymanager, which desktop? How to start emacs Deamon? Once I know this I can try to reproduce on current TW.
Comment 23 Tristan Miller 2020-11-08 16:08:11 UTC
Created attachment 843386 [details]
Systemd unit configuration file for emacs daemon

(In reply to Stefan Dirsch from comment #22)
> Ok. Which displaymanager, which desktop? How to start emacs Deamon? Once I
> know this I can try to reproduce on current TW.

I'm using SDDM 0.18.1 to log into KDE Plasma 5.20.2.  The Emacs daemon is started automatically with the attached unit configuration file in $HOME/.config/systemd/user/emacs.service, which I had enabled by invoking "systemctl enable --user emacs".  Note that the problem occurs only when the daemon is started automatically; starting or restarting it manually, once I've already logged in, with "systemctl restart --user emacs.service", always works fine.
Comment 24 Stefan Dirsch 2020-11-08 22:07:08 UTC
Indeed I can reproduce this issue with your emacs.service file in ~/.config/systemd/user/emacs.service - with ssdm, but also with gdm

tux@tw:~> emacsclient -c
Waiting for Emacs...
*ERROR*: Display :1 can’t be opened
tux@tw:~> systemctl stop --user emacs.service
tux@tw:~> systemctl start --user emacs.service
tux@tw:~> emacsclient -c
Waiting for Emacs...
< emacs is starting >
Comment 25 Stefan Dirsch 2020-11-08 22:44:42 UTC
> xauth extract - $DISPLAY | xauth -f ~/.Xauthority merge -

Indeed this also helps. No idea why. Is emacs-server/client hardcoded to use values of ~/.Xauthority somehow? 

And yes, neither sddm nor gdm use ~/.Xauthority  Check $XAUTHORITY

I think, removing ~/.Xauthority also fixes the issue permanently. Not 100% sure. I had mixed results when doing this.
Comment 26 Dr. Werner Fink 2020-11-09 07:41:39 UTC
(In reply to Stefan Dirsch from comment #25)
> > xauth extract - $DISPLAY | xauth -f ~/.Xauthority merge -
> 
> Indeed this also helps. No idea why. Is emacs-server/client hardcoded to use
> values of ~/.Xauthority somehow? 
> 
> And yes, neither sddm nor gdm use ~/.Xauthority  Check $XAUTHORITY
> 
> I think, removing ~/.Xauthority also fixes the issue permanently. Not 100%
> sure. I had mixed results when doing this.

AFAIK GNU Emacs behave as all X clients, with XAUTHORITY set in environment this is used, without set the default ~/.Xauthority is used.  Looks like a race as I guess (or better hope) that the environment variable XAUTHORITY is set.

If it is a race then a line like

  ExecStartPre=/bin/bash -c "echo $XAUTHORITY; /usr/bin/sleep 5"

before starting Emacs might help.
Comment 27 Stefan Dirsch 2020-11-09 09:59:16 UTC
Indeed. This would make sense, but it's interesting that this broke for gdm and sddm at the same time.

So, Tristan,  could you please try the workaround in previous comment #26? 

In the end I think it's a corner case. It's the first time I hear anything about systemd User Units ...
Comment 29 Tristan Miller 2020-11-09 10:54:16 UTC
(In reply to Stefan Dirsch from comment #27)
> So, Tristan,  could you please try the workaround in previous comment #26? 

No, I'm afraid the workaround from Comment 26 doesn't work for me.
Comment 30 Stefan Dirsch 2020-11-09 12:59:22 UTC
Oh, well. For some reason the emcas systemd User Unit is no longer started for me automatically during login, so I can't investigate this any longer (tried also with freshly created user). Maybe you want to give this line a try

ExecStartPre=/bin/bash -c "echo \"before 5s sleep: XAUTHORITY = $XAUTHORITY\" > $HOME/xauth.txt; /usr/bin/sleep 5; echo \"after 5s sleep: XAUTHORITY = $XAUTHORITY\" >> $HOME/xauth.txt"

And check afterwards the content of your ~/xauth.txt.

Anyway, I think such things, which in the end need a DISPLAY shouldn't be done by a systemd User Unit. Instead better try to use autostart mechanism of your desktop.
Comment 31 Dr. Werner Fink 2020-11-09 13:00:10 UTC
Try this little script below in your personal ~/bin/ directory.
Give it the name emacs and do nto forget to run

  chmod u+x ~/bin/emacs

this should do the job. If the daemon is already running
as well if not.

------------------------* snip *------------------------------------------------------
#!/bin/bash
while ! frame=$(emacsclient -n -e "(if (> (length (frame-list)) 1) 't)" 2>/dev/null)
do
    /usr/bin/emacs --daemon 2>/dev/null
    sleep 1
done
for socket in /tmp/emacs${UID}/server /run/user/${UID}/emacs/server
do
    test -n "$DISPLAY" || break
    test -S $socket || continue
    pid=$(fuser $socket 2>/dev/null)
    if test -n "$pid"
    then
        xauth=$(ps e $pid | tr ' ' '\n' | sed -rn 's/XAUTHORITY=//p')
        if test -e "$xauth" -a \( -z "$XAUTHORITY" -o "$XAUTHORITY" != "$xauth" \)
        then
            entry=$(xauth list $DISPLAY)
            xauth -f "$xauth" add $entry
        fi
    fi
done
exec -a emacs /usr/bin/emacsclient -n ${DISPLAY+-d $DISPLAY} -c ${1+"$@"}
Comment 32 Stefan Dirsch 2020-11-09 13:02:27 UTC
Reassigning back to desktop. Let's use GNOME this time, since it's affected as well.
Comment 33 Tristan Miller 2020-11-09 13:56:57 UTC
(In reply to Stefan Dirsch from comment #30)
> Oh, well. For some reason the emcas systemd User Unit is no longer started
> for me automatically during login, so I can't investigate this any longer
> (tried also with freshly created user). Maybe you want to give this line a
> try
> 
> ExecStartPre=/bin/bash -c "echo \"before 5s sleep: XAUTHORITY =
> $XAUTHORITY\" > $HOME/xauth.txt; /usr/bin/sleep 5; echo \"after 5s sleep:
> XAUTHORITY = $XAUTHORITY\" >> $HOME/xauth.txt"
> 
> And check afterwards the content of your ~/xauth.txt.

Unfortunately, it seems the variable isn't set even after five seconds:

before 5s sleep: XAUTHORITY = 
after 5s sleep: XAUTHORITY = 

> Anyway, I think such things, which in the end need a DISPLAY shouldn't be
> done by a systemd User Unit. Instead better try to use autostart mechanism
> of your desktop.

If this is true, and sound arguments can be made in support of it, then maybe this should be reported upstream, since running the Emacs daemon as a systemd service has been officially supported since Emacs 26.1 -- this version onwards includes a unit configuration file and documentation on how to use it.  (I'm loath to make any such report myself, since I had been running Emacs this way on openSUSE without a problem for several years, and other GNU/Linux distributions also seem to support or advise running Emacs this way.)
Comment 34 Tristan Miller 2020-11-09 14:04:04 UTC
(In reply to Tristan Miller from comment #33)
> Unfortunately, it seems the variable isn't set even after five seconds:

Even using a delay of 20 seconds (by which time my desktop environment has been fully loaded) doesn't work around the problem.  So maybe this is not a race condition after all, but rather something else?
Comment 35 Tristan Miller 2020-12-01 09:58:56 UTC
Also reproducible for me with Leap 15.2.
Comment 36 Dr. Werner Fink 2020-12-01 11:50:09 UTC
(In reply to Tristan Miller from comment #35)
> Also reproducible for me with Leap 15.2.

Please give the script in comment #31 a try as ~/bin/emacs (don't forget the chmod 755), then call emacs not emacsclient
Comment 37 Tristan Miller 2021-01-05 09:56:02 UTC
(In reply to Dr. Werner Fink from comment #36)
> Please give the script in comment #31 a try as ~/bin/emacs (don't forget the
> chmod 755), then call emacs not emacsclient

The script doesn't work for me:

$ ~/bin/emacs
*ERROR*: Display :0 can’t be opened
Comment 38 Dr. Werner Fink 2021-01-12 09:15:52 UTC
*** Bug 1179854 has been marked as a duplicate of this bug. ***
Comment 39 Georg Grauberger 2021-01-13 15:51:25 UTC
I have some more input on this.

GDM creates a static xauthority file in
`XAUTHORITY=/run/user/1000/gdm/Xauthority`.

If I run the user service in a Session which was launched in GNOME it will work
in all consecutive calls emacs, even after restart.

This is thanks to the emacs distribution I am using, Spacemacs. It creates
a ~/.spacemacs.env File which will be loaded upon start by emacs. It contains the XAUTHORITY variable with the static path.

If I am using sddm however, the path to the XAUTHORITY file is changing on each new login. Hence the environment file is not working because the Path to the xauthority file is not the same.
e.g.

First Login with sddm:
XAUTHORITY=/run/user/1000/xauth_xpMWCc

Second Login sddm:
XAUTHORITY=/run/user/1000/xauth_bhgNcT


Now I assume that sddm is responsible for creating the right environment for
the programs and passing it to the GUI applications.
It does so for traditional apps.

But let's compare the environment for the emacsdaemon and a Konsole window.

```
regrau@tumblevm:~> tr '\0' '\n' < /proc/$PID_OF_KONSOLE/environ | wc -l
87
regrau@tumblevm:~> tr '\0' '\n' < /proc/$PID_OF_KONSOLE/environ | grep XAUTH
XAUTHORITY=/run/user/1000/gdm/Xauthority
XAUTHLOCALHOSTNAME=tumblevm

```

```
regrau@tumblevm:~> tr '\0' '\n' < /proc/$PID_OF_EMACSDAEMON/environ | wc -l
18
regrau@tumblevm:~> tr '\0' '\n' < /proc/$PID_OF_EMACSDAEMON/environ | grep XAUTH
```

As one can see the EMACSDAEMON environment does not get the right environment vars
from sddm.

It's not a race condition as adding waiting time to emacsdaemon service unit does
help. I've gone up as high as 5 Minutes before starting up the service. It did
not help.


So there has to be a way to start the unit after the initialization of the
environment is completed or to pass the environment to the emacs daemon afterwards.
Comment 40 xiaoguang wang 2021-01-14 03:03:06 UTC
My TW is 20201119. I works on GNOME, the displaymanager is gdm.
After I installed emacs, and run 'systemctl --user enable emace.service', restart system. Then I can run 'emacsclient -c' without issue.

You can try this: before run 'emacsclient -c', run command
dbus-update-activation-environment --systemd --all
Comment 41 Dr. Werner Fink 2021-01-14 08:33:17 UTC
(In reply to xiaoguang wang from comment #40)
> My TW is 20201119. I works on GNOME, the displaymanager is gdm.
> After I installed emacs, and run 'systemctl --user enable emace.service',
> restart system. Then I can run 'emacsclient -c' without issue.
> 
> You can try this: before run 'emacsclient -c', run command
> dbus-update-activation-environment --systemd --all

For my VNC sessions I use

```
if test -n "$VNCDESKTOP" -a -z "$RESTART"; then
    exec > "$HOME/.vnc/${VNCDESKTOP}.log" 2>&1
    unset SESSION_MANAGER
    unset DBUS_SESSION_BUS_ADDRESS
    test -e /etc/X11/xinit/xinitrc.common && . /etc/X11/xinit/xinitrc.common
fi
```

in my personal ~/.xsession used as VNC xstartup and this xinitrc.common will also load

```
/etc/X11/xinit/xinitrc.d/50-systemd-user.sh
```

which does use dbus-update-activation-environment ...
Comment 42 Dr. Werner Fink 2021-03-08 14:40:22 UTC
I've added a patch to GNU Emacs which does start the GNU Emacs server with the environment variable XAUTHORITY set to /run/user/<UID>/emacs/xauth in emacs.service as well as an extended server.el to extract the Xauth cookie of the current Display and merge this to the new XAUTHORITY file. This should work not only for default ~/.Xauthority but also for gdm and sddm with their session value of XAUTHORITY 

Testers are welcome, see OBS editors/emacs
Comment 43 Georg Grauberger 2021-03-08 14:58:46 UTC
(In reply to Dr. Werner Fink from comment #42)
> I've added a patch to GNU Emacs which does start the GNU Emacs server with
> the environment variable XAUTHORITY set to /run/user/<UID>/emacs/xauth in
> emacs.service as well as an extended server.el to extract the Xauth cookie
> of the current Display and merge this to the new XAUTHORITY file. This
> should work not only for default ~/.Xauthority but also for gdm and sddm
> with their session value of XAUTHORITY 
> 
> Testers are welcome, see OBS editors/emacs

So I tried it right now, unfortunately no changes of the behaviour.

Is there any input I can provide to aid?
Comment 44 Dr. Werner Fink 2021-03-08 15:45:58 UTC
(In reply to Georg Grauberger from comment #43)
> (In reply to Dr. Werner Fink from comment #42)
> > I've added a patch to GNU Emacs which does start the GNU Emacs server with
> > the environment variable XAUTHORITY set to /run/user/<UID>/emacs/xauth in
> > emacs.service as well as an extended server.el to extract the Xauth cookie
> > of the current Display and merge this to the new XAUTHORITY file. This
> > should work not only for default ~/.Xauthority but also for gdm and sddm
> > with their session value of XAUTHORITY 
> > 
> > Testers are welcome, see OBS editors/emacs
> 
> So I tried it right now, unfortunately no changes of the behaviour.
> 
> Is there any input I can provide to aid?

Does the ~/.config/systemd/user/emacs.service file include the line

  Environment=XAUTHORITY=%t/emacs/xauth

if not it can not work.  Also check changelog ...

 * Mon Mar 08 2021 Dr. Werner Fink <werner@suse.de>
 - Add patch emacs-27.1-Xauthority4server.patch
   * Allow GNU Emacs server to open X Display even if the Xauthority
     file is not the default expected by XCloseDisplay()
   * Hopefully fix boo#1174534 and boo#1179854
Comment 45 Georg Grauberger 2021-03-08 16:04:06 UTC
(In reply to Dr. Werner Fink from comment #44)
> (In reply to Georg Grauberger from comment #43)
> > (In reply to Dr. Werner Fink from comment #42)
> > > I've added a patch to GNU Emacs which does start the GNU Emacs server with
> > > the environment variable XAUTHORITY set to /run/user/<UID>/emacs/xauth in
> > > emacs.service as well as an extended server.el to extract the Xauth cookie
> > > of the current Display and merge this to the new XAUTHORITY file. This
> > > should work not only for default ~/.Xauthority but also for gdm and sddm
> > > with their session value of XAUTHORITY 
> > > 
> > > Testers are welcome, see OBS editors/emacs
> > 
> > So I tried it right now, unfortunately no changes of the behaviour.
> > 
> > Is there any input I can provide to aid?
> 
> Does the ~/.config/systemd/user/emacs.service file include the line
> 
>   Environment=XAUTHORITY=%t/emacs/xauth
> 
> if not it can not work.  Also check changelog ...
> 
>  * Mon Mar 08 2021 Dr. Werner Fink <werner@suse.de>
>  - Add patch emacs-27.1-Xauthority4server.patch
>    * Allow GNU Emacs server to open X Display even if the Xauthority
>      file is not the default expected by XCloseDisplay()
>    * Hopefully fix boo#1174534 and boo#1179854

You're right the line was missing. I added it but the error is still the same.
Waiting for Emacs...
*ERROR*: Display :0 can’t be opened


For an installation on latest tumbleweed with KDE and default sddm.
Comment 46 Tristan Miller 2021-03-08 20:59:08 UTC
(In reply to Dr. Werner Fink from comment #42)
> I've added a patch to GNU Emacs which does start the GNU Emacs server with
> the environment variable XAUTHORITY set to /run/user/<UID>/emacs/xauth in
> emacs.service as well as an extended server.el to extract the Xauth cookie
> of the current Display and merge this to the new XAUTHORITY file. This
> should work not only for default ~/.Xauthority but also for gdm and sddm
> with their session value of XAUTHORITY 
> 
> Testers are welcome, see OBS editors/emacs

This version seems works for me on Tumbleweed; thanks!

(In reply to Georg Grauberger from comment #45)
> (In reply to Dr. Werner Fink from comment #44)
> > Does the ~/.config/systemd/user/emacs.service file include the line
> > 
> >   Environment=XAUTHORITY=%t/emacs/xauth
> 
> You're right the line was missing. I added it but the error is still the
> same.
> Waiting for Emacs...
> *ERROR*: Display :0 can’t be opened

Perhaps a stupid question, but did you reboot after making the change to your emacs.service file?
Comment 47 Georg Grauberger 2021-03-08 21:03:19 UTC
(In reply to Tristan Miller from comment #46)

> Perhaps a stupid question, but did you reboot after making the change to
> your emacs.service file?

Not stupid at all :) that's the troubleshooting 101.

I did, but the restart did not help.

I have multiple ways to test with prepared VM's. So I will investigate further and see if I get it running.
Comment 48 Dr. Werner Fink 2021-03-09 08:03:38 UTC
(In reply to Georg Grauberger from comment #47)
> (In reply to Tristan Miller from comment #46)
> 
> > Perhaps a stupid question, but did you reboot after making the change to
> > your emacs.service file?
> 
> Not stupid at all :) that's the troubleshooting 101.
> 
> I did, but the restart did not help.
> 
> I have multiple ways to test with prepared VM's. So I will investigate
> further and see if I get it running.

Guess only: You might have caught the emacs before the changed version had finished its builds ...

 /suse/werner> ll -G ~/.config/systemd/user/emacs.service
 lrwxrwxrwx 1 werner 35 May  8  2019 /suse/werner/.config/systemd/user/emacs.service -> /usr/lib/systemd/user/emacs.service
 /suse/werner> rpm -q --changelog -f /usr/lib/systemd/user/emacs.service | head -n 4
 * Mon Mar 08 2021 Dr. Werner Fink <werner@suse.de>
 - Add patch emacs-27.1-Xauthority4server.patch
   * Allow GNU Emacs server to open X Display even if the Xauthority
     file is not the default expected by XCloseDisplay()
Comment 49 Dr. Werner Fink 2021-03-10 09:17:10 UTC
For debugging I suggest to see which service is active

  systemctl --user status emacs.service

make sure to use latest /usr/lib/systemd/user/emacs.service
then you might restart it

  systemctl --user restart emacs.service

then have a look at the process table (or redo status) to get major pid
of the emacs daemon

  pidof emacs

with this pid you can attach a strace with

  strace -o emacs.trace -s 256 -f -p $(pidof emacs)

and then start in an other kconsole/xterm/gnome-terminal

  emacsclient -c

then stop the strace command with Ctrl-C ... you might attach this trace
Comment 50 Dr. Werner Fink 2021-07-26 12:29:14 UTC
No answer yet