Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 555346 - app-editors/emacs: emacsclient -c: xauth problems when connecting to daemon (*ERROR*: Display :0 can't be opened)
Summary: app-editors/emacs: emacsclient -c: xauth problems when connecting to daemon (...
Status: RESOLVED CANTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Emacs project
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-19 14:28 UTC by Manuel Ullmann
Modified: 2015-11-09 09:54 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel Ullmann 2015-07-19 14:28:44 UTC
When emacs-daemon is invoked for user root, emacsclient -c fails to use the available display.


Reproducible: Always

Steps to Reproduce:
0. emerge -q emacs-root
1. cd /etc/init.d/
2. ln -s emacs.root emacs
3. rc-service emacs.root start # assuming non-systemd profile
4. emacsclient -c /path/to/arbitrary/file
Actual Results:  
root # emacsclient -c emacs-root.sh 
Waiting for Emacs...
*ERROR*: Display :0 can't be opened


Expected Results:  
root # emacsclient -c emacs-root.sh 
Waiting for Emacs...

Invoking it for a normal user has not this issue. Also running emacs --daemon as root from terminal generates a server aware of X. It does not matter whether X was running during emacs.root startup or not. Simplifying the startup script does not help either:
#!/bin/bash                                                                                                
logfile=$(mktemp ${TMPDIR:-/tmp}/emacs.log.XXXXXX)
trap "rm -f '${logfile}'" EXIT
exec emacs --daemon &>${logfile}

My system is a plain Gentoo again (cleanly reinstalled). No use of binary servers anymore. The calculate overlay is masked. I needed it just to lookup a few plymouth-openrc-plugin patches.

emerge --info
Portage 2.2.20 (python 2.7.9-final-0, default/linux/amd64/13.0/desktop/kde, gcc-4.8.4, glibc-2.20-r2, 4.1.2-gentoo x86_64)
=================================================================
System uname: Linux-4.1.2-gentoo-x86_64-AMD_Turion-tm-X2_Ultra_DualCore_Mobile_ZM-84-with-gentoo-2.2
KiB Mem:     3787808 total,   1893848 free
KiB Swap:    5242876 total,   5242876 free
Timestamp of repository gentoo: Sat, 18 Jul 2015 14:30:01 +0000
Timestamp of repository poly-c: Thu, 16 Jul 2015 11:55:42 +0000
sh bash 4.3_p33-r2
ld GNU ld (Gentoo 2.24 p1.4) 2.24
app-shells/bash:          4.3_p33-r2::gentoo
dev-java/java-config:     2.2.0::gentoo
dev-lang/perl:            5.20.2::gentoo
dev-lang/python:          2.7.9-r1::gentoo, 3.3.5-r1::gentoo
dev-util/cmake:           3.2.2::gentoo
dev-util/pkgconfig:       0.28-r2::gentoo
sys-apps/baselayout:      2.2::gentoo
sys-apps/openrc:          0.17::gentoo
sys-apps/sandbox:         2.6-r1::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69::gentoo
sys-devel/automake:       1.11.6-r1::gentoo, 1.14.1::gentoo, 1.15::gentoo
sys-devel/binutils:       2.24-r3::gentoo
sys-devel/gcc:            4.8.4::gentoo
sys-devel/gcc-config:     1.7.3::gentoo
sys-devel/libtool:        2.4.6::gentoo
sys-devel/make:           4.1-r1::gentoo
sys-kernel/linux-headers: 3.18::gentoo (virtual/os-headers)
sys-libs/glibc:           2.20-r2::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

fluendo
    location: /usr/local/portage
    masters: gentoo
    priority: 0

calculate
    location: /var/lib/layman/calculate
    sync-type: laymansync
    sync-uri: git://git.calculate.ru/calculate/overlay.git
    masters: gentoo
    priority: 50

gnu-elpa
    location: /var/lib/layman/gnu-elpa
    sync-type: laymansync
    sync-uri: gs-elpa gnu-elpa
    masters: gentoo
    priority: 50

grub2-themes
    location: /var/lib/layman/grub2-themes
    sync-type: laymansync
    sync-uri: https://github.com/gentoo/grub2-themes-overlay.git
    masters: gentoo
    priority: 50

melpa-stable
    location: /var/lib/layman/melpa-stable
    sync-type: laymansync
    sync-uri: gs-elpa melpa-stable
    masters: gnu-elpa gentoo
    priority: 50

poly-c
    location: /var/lib/layman/poly-c
    sync-type: laymansync
    sync-uri: rsync://gentoofan.no-ip.org/poly-c
    masters: gentoo
    priority: 50

steam-overlay
    location: /var/lib/layman/steam-overlay
    sync-type: laymansync
    sync-uri: git://github.com/anyc/steam-overlay.git
    masters: gentoo
    priority: 50

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=native -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe"
DISTDIR="/usr/portage//distfiles/"
EMERGE_DEFAULT_OPTS=" --load-average=8.0"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs collision-protect config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch parallel-install preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="ftp://ftp.uni-erlangen.de/pub/mirrors/gentoo"
LANG="de_DE.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j3 -l 8.0"
PKGDIR="/usr/portage//packages/"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
USE="X a52 aac acl acpi alsa amd64 audiofile avi berkdb bluetooth branding bzip2 cairo cdda cddb cdparanoia cdr cli consolekit cracklib crypt css cue cups cxx dbus declarative djvu dri dts dv dvd dvdr dvdread emboss encode exif faac ffmpeg firefox flac foomaticdb fortran ftp gd gdbm gif glamor gpm gstreamer gtk iconv id3tag imagemagick ipv6 irc jpeg jpeg2k kde kipi lcms ldap libass libnotify libwww lm_sensors logrotate lzo mad matroska mbox mmx mmxext mng modules mp3 mp4 mpeg multilib ncurses networkmanager nfs nls nptl nsplugin ogg oggvorbis openal openexr opengl openmp oscar pam pango pcre pdf phonon plasma png policykit portaudio ppds qt3support qt4 quicktime raw readline samba sasl sdl session smp spell sse sse2 ssl startup-notification svg tcpd theora threads tiff truetype udev udisks unicode upower usb v4l v4l2 vaapi vcd vdpau vhosts vorbis wavpack wimax wmf wxwidgets x264 x265 xanim xcb xcomposite xinerama xml xpm xscreensaver xv xvid zlib" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="3dnow 3dnowext mmx mmxext sse sse2 sse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ublox ubx" GRUB_PLATFORMS="pc efi-64" INPUT_DEVICES="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="de en" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_3" RUBY_TARGETS="ruby19 ruby20" USERLAND="GNU" VIDEO_CARDS="r600 radeon" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON
Comment 1 Ulrich Müller gentoo-dev 2015-07-25 11:56:09 UTC
I cannot reproduce the bug, everything works as expected for me.

(In reply to Manuel Ullmann from comment #0)
> Actual Results:  
> root # emacsclient -c emacs-root.sh 
> Waiting for Emacs...
> *ERROR*: Display :0 can't be opened

What happens when you start /usr/bin/emacs instead? Does it open an X window?
Comment 2 Manuel Ullmann 2015-07-26 14:42:45 UTC
/usr/bin/emacs opens a window, always reproducible.

Please note, that the emacs-daemon scripts do not seem to be responsible. I switched to systemd in the meantime, and reproduced it with the systemd unit, provided at http://www.emacswiki.org/emacs/EmacsAsDaemon#toc8.

Still it might be nice to get a reason for this one and I assume, the GNU Emacs Team would still be assigned to app-editors/emacs.

I tested this further and would say, the root emacs daemon does not recognize :0 anymore, when the XSession was restarted. This is also reproducible in Failsafe, not only in Plasma. I think, I had already reproduced this in openrc, while systemd/plasma were still compiling. Not sure, though.
I removed the emacs root configuration to check for bad lisp karma, but to no avail. As usual the ncurses interface works fine all the time.

Of course you get now a new emerge --info:
Portage 2.2.20 (python 2.7.9-final-0, default/linux/amd64/13.0/desktop/plasma/systemd, gcc-4.8.4, glibc-2.20-r2, 4.1.2-gentoo x86_64)
=================================================================
System uname: Linux-4.1.2-gentoo-x86_64-AMD_Turion-tm-X2_Ultra_DualCore_Mobile_ZM-84-with-gentoo-2.2
KiB Mem:     3785128 total,   1872508 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Tue, 21 Jul 2015 22:00:01 +0000
Timestamp of repository poly-c: Thu, 16 Jul 2015 11:55:42 +0000
sh bash 4.3_p33-r2
ld GNU ld (Gentoo 2.24 p1.4) 2.24
app-shells/bash:          4.3_p33-r2::gentoo
dev-java/java-config:     2.2.0::gentoo
dev-lang/perl:            5.20.2::gentoo
dev-lang/python:          2.7.9-r1::gentoo, 3.3.5-r1::gentoo
dev-util/cmake:           3.2.2::gentoo
dev-util/pkgconfig:       0.28-r2::gentoo
sys-apps/baselayout:      2.2::gentoo
sys-apps/openrc:          0.17::gentoo
sys-apps/sandbox:         2.6-r1::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69::gentoo
sys-devel/automake:       1.11.6-r1::gentoo, 1.14.1::gentoo, 1.15::gentoo
sys-devel/binutils:       2.24-r3::gentoo
sys-devel/gcc:            4.8.4::gentoo
sys-devel/gcc-config:     1.7.3::gentoo
sys-devel/libtool:        2.4.6::gentoo
sys-devel/make:           4.1-r1::gentoo
sys-kernel/linux-headers: 3.18::gentoo (virtual/os-headers)
sys-libs/glibc:           2.20-r2::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

fluendo
    location: /usr/local/portage
    masters: gentoo
    priority: 0

bar
    location: /var/lib/layman/bar
    sync-type: laymansync
    sync-uri: git://github.com/tokiclover/bar-overlay.git
    masters: gentoo
    priority: 50

calculate
    location: /var/lib/layman/calculate
    sync-type: laymansync
    sync-uri: git://git.calculate.ru/calculate/overlay.git
    masters: gentoo
    priority: 50

gnu-elpa
    location: /var/lib/layman/gnu-elpa
    sync-type: laymansync
    sync-uri: gs-elpa gnu-elpa
    masters: gentoo
    priority: 50

grub2-themes
    location: /var/lib/layman/grub2-themes
    sync-type: laymansync
    sync-uri: https://github.com/gentoo/grub2-themes-overlay.git
    masters: gentoo
    priority: 50

kde
    location: /var/lib/layman/kde
    sync-type: laymansync
    sync-uri: git://anongit.gentoo.org/proj/kde.git
    masters: gentoo
    priority: 50

melpa-stable
    location: /var/lib/layman/melpa-stable
    sync-type: laymansync
    sync-uri: gs-elpa melpa-stable
    masters: gnu-elpa gentoo
    priority: 50

poly-c
    location: /var/lib/layman/poly-c
    sync-type: laymansync
    sync-uri: rsync://gentoofan.no-ip.org/poly-c
    masters: gentoo
    priority: 50

steam-overlay
    location: /var/lib/layman/steam-overlay
    sync-type: laymansync
    sync-uri: git://github.com/anyc/steam-overlay.git
    masters: gentoo
    priority: 50

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=native -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe"
DISTDIR="/usr/portage//distfiles/"
EMERGE_DEFAULT_OPTS=" --load-average=8.0"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs collision-protect config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch parallel-install preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="ftp://ftp.fau.de/pub/mirrors/gentoo"
LANG="de_DE.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j3 -l 8.0"
PKGDIR="/usr/portage//packages/"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
USE="X a52 aac acl acpi alsa amd64 audiofile avi berkdb bluetooth branding bzip2 cairo cdda cddb cdparanoia cdr cli cracklib crypt css cue cups cxx dbus declarative djvu dri dts dv dvd dvdr dvdread emboss encode exif faac ffmpeg firefox flac foomaticdb fortran ftp gd gdbm gif glamor gpm gstreamer gtk iconv id3tag imagemagick ipv6 irc jpeg jpeg2k kde kipi lcms ldap libass libnotify libwww lm_sensors logrotate lzo mad matroska mbox mmx mmxext mng modules mp3 mp4 mpeg multilib ncurses networkmanager nfs nls nptl nsplugin ogg oggvorbis openal openexr opengl openmp oscar pam pango pcre pdf phonon plasma png policykit portaudio ppds qml qt3support qt4 qt5 quicktime raw readline samba sasl sdl session smp spell sse sse2 ssl startup-notification svg systemd tcpd theora threads tiff truetype udev udisks unicode upower usb v4l v4l2 vaapi vcd vdpau vhosts vorbis wavpack widgets wimax wmf wxwidgets x264 x265 xanim xcb xcomposite xinerama xml xpm xscreensaver xv xvid zlib" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="3dnow 3dnowext mmx mmxext sse sse2 sse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ublox ubx" GRUB_PLATFORMS="pc efi-64" INPUT_DEVICES="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="de en" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_3" RUBY_TARGETS="ruby19 ruby20" USERLAND="GNU" VIDEO_CARDS="r600 radeon" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON
Comment 3 Ulrich Müller gentoo-dev 2015-07-26 19:24:43 UTC
(In reply to Manuel Ullmann from comment #2)
> Please note, that the emacs-daemon scripts do not seem to be responsible. I
> switched to systemd in the meantime, and reproduced it with the systemd
> unit, provided at http://www.emacswiki.org/emacs/EmacsAsDaemon#toc8.

> [...]
> I think, I had already reproduced this in openrc, while systemd/plasma were
> still compiling. Not sure, though.

Using third-party systemd units is not a supported configuration, therefore closing. Feel free to reopen if you can reproduce the bug with openrc and the init scripts provided by app-emacs/emacs-daemon.
Comment 4 Manuel Ullmann 2015-07-27 17:01:00 UTC
Hi again,

actually I was just not sure about the reproducibility by running emacsclient -c -a '' twice. When I was reporting this, I had a clean openrc profile and was running your scripts in default runlevel. Maybe a misunderstanding, but never mind.
Of course, openrc is still installed, so it is a matter of concatenating init=/sbin/openrc to kernel parameters for switching over.
Actually this behavior was reproduced in the only other opened emacs-daemon bug (the gtk one):
https://bugs.gentoo.org/show_bug.cgi?id=292471#c10 (just this comment)

So it has most likely something to do with xauth. I already found a lead.
Running “su -l -c 'env | grep XAUTHORITY' <myuser>” reveals, that it is not set for su sessions invoked for my user. In that case xauth will default to .Xauthority, which is present and therefore the same for all subsequent invocations. XAUTHORITY points for my user to /tmp/xauth-1000-_0, but mixing those in emacsclient invocations does not seem to reproduce it.

For root, the situation is different:
.xauth[a-zA-Z0-9]+ seem to be dynamically created by most likely xinit. If I run “su -l -c 'env | grep XAUTHORITY'” repeatedly, I get a different xauth cookie on every run. So it seems reasonable, that the second run fails, especially if untrusted xauth cookies would be generated (could be also the timeout; see below).

I have never fiddled with the xauth configuration for root, so it should be the default configuration. The root partition was cleanly reinstalled, but /home is Gentoo Hardened → Debian Wheezy → Calculate Linux → Gentoo (yeah, you get always back to the good ones), so the .Xauthority of my user is a remain.

Actually I can’t imagine, how the cookies can be created, since ”xauth -f .Xauthority -v generate :0 . trusted timeout 300” keeps telling me, that the Xsecurity extension is not loaded. I could not find the appropriate package/USE Flag, which would install it (and I’d rather stick to xorg-server).
Could be, that this is the reason, since the cookie of my user most likely does not expire until login (see below).

So back to the reasons, why this still is not only a X11 issue.
— If this is caused by default X configurations for root and the X11 Team refuses to change it, at least an ewarn in emacs-daemon ebuild would be appropriate.

— If this is caused by the wrapper script not reading the XAUTHORITY variable correctly, this would definitely have to be fixed.

The reason, why I wanted to generate my own xauth cookie and probably set it in root’s .bashrc is, that xauth generates by default cookies expiring after one minute. So, if emacs.root starts up and sddm/plasma take more than a minute to load, like they usually do, the cookie has expired once I am able to invoke emacsclient.
Duh! Ok, bad theory since starting emacs.root directly before invoking emacsclient in a terminal emulator also reproduces the issue.

So I hope you don’t deem this as invalid anymore, although other project teams could be involved and just a small configuration change might be required to fix this.

kind regards

PS: Since systemd is officially supported, packages providing init scripts gradually have to offer also units anyway. If I have time I’ll eventually port the functionality and report a bug for merging them. Maybe another user is kind enough to test them.
Comment 5 Ulrich Müller gentoo-dev 2015-07-27 22:58:39 UTC
Looks like the same problem as in this upstream report:
http://debbugs.gnu.org/cgi-bin/bugreport.cgi?bug=1467

In a nutshell, the emacs daemon needs to read X authentication information from the ~/.Xauthority file. Storing this information in a different place and pointing XAUTHORITY to it won't work, because the daemon cannot see this XAUTHORITY variable in its environment.

Please try if executing one of the following commands before calling emacsclient works around the problem:

# xauth extract - $DISPLAY | xauth -f ~/.Xauthority merge -
# xauth -f ~/.Xauthority merge $XAUTHORITY
Comment 6 Manuel Ullmann 2015-07-28 15:20:22 UTC
Thank you, this indeed temporary resolves the issue until a session restart. To make it permanant I added it to my existing emacs bashrc, which reads now:

#/etc/bash/bashrc.d/emacs
xauth extract - $DISPLAY | xauth -f ~/.Xauthority merge -
xauth -f ~/.Xauthority merge $XAUTHORITY
export ALTERNATE_EDITOR="" EDITOR=emacsclient VISUAL="emacsclient -c"

Is there something I could do about my xauth configuration to make that unnecessary?
Comment 7 Ulrich Müller gentoo-dev 2015-07-28 16:21:18 UTC
(In reply to Manuel Ullmann from comment #6)
> xauth extract - $DISPLAY | xauth -f ~/.Xauthority merge -
> xauth -f ~/.Xauthority merge $XAUTHORITY

Hm, I thought that one of these lines would be sufficient, since they do similar things. Do you really need both?

> Is there something I could do about my xauth configuration to make that
> unnecessary?

Not sure. For "su", things are normally handled by pam, i.e. the pam_xauth module. /etc/pam.d/su should contain a line like this:
session    optional             pam_xauth.so
pam_xauth will then create a temporary cookie file and point the XAUTHORITY variable to it. AFAICS, there is no way to configure it such that it will update .Xauthority instead. (For my part, I often use "ssh -Y" even for the localhost, because it avoids these xauth problems.)

Can this bug be closed? It really is a conceptual problem that multi-tty emacs can only use the ~/.Xauthority file, but not the client's XAUTHORITY variable. Therefore I don't see any possible fix in app-editors/emacs or app-emacs/emacs-daemon.
Comment 8 Manuel Ullmann 2015-07-28 17:19:25 UTC
> Hm, I thought that one of these lines would be sufficient, since they do
> similar things. Do you really need both?

Oops. ;-) I guess, I overread the ‘one of’. One command is of course sufficient.

> Can this bug be closed? It really is a conceptual problem that multi-tty
> emacs can only use the ~/.Xauthority file, but not the client's XAUTHORITY
> variable. Therefore I don't see any possible fix in app-editors/emacs or
> app-emacs/emacs-daemon.

In fact, there is nothing, which you could do in those ebuilds. On the other hand a note in the Gentoo GNU Emacs Wiki would possibly save your time from marking duplicates and quickly help users with the same issue.

I assume, you have access to the wiki and it is perfectly fine, if you close the bug and queue the note up for now. At least, if it gets done until, say, next year.

Kind regards

PS:
Changed the addition to

if [[ -n "${DISPLAY}" ]]; then
    xauth -f ~/.Xauthority merge $XAUTHORITY
fi

to avoid error messages in non-X consoles.
Comment 9 Ulrich Müller gentoo-dev 2015-08-07 09:58:05 UTC
I've raised the issue in the upstream developers' ML:
https://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00049.html
Comment 10 Manuel Ullmann 2015-08-10 17:17:22 UTC
Thank you very much for your commitment.

After reading the thread, is my assumption correct, that display managers create both the root and user xauth cookies?

Since I experienced the issue with both kdm and now sddm (plasma/systemd profile, while running openrc), I guess there can’t be done much about kdm, but sddm is still under heavy development.
So would it be appropriate to create a ticket on https://github.com/sddm/sddm/issues linking this report and the thread and asking for defaulting to ~/.Xauthority?
I guess they wouldn’t mind such a minor change at the current state of development.
Comment 11 Ulrich Müller gentoo-dev 2015-08-10 17:26:35 UTC
(In reply to Manuel Ullmann from comment #10)
> So would it be appropriate to create a ticket on
> https://github.com/sddm/sddm/issues linking this report and the thread and
> asking for defaulting to ~/.Xauthority?

Yes, please go ahead.
Comment 12 Manuel Ullmann 2015-11-09 09:54:55 UTC
Bug should be fixed in sddm with pull request 541:
https://github.com/sddm/sddm/pull/541
https://github.com/plfiorini/sddm/commit/9d9159faebec1c900f2332be708665f63abf4407

Thanks again for your time and evaluating the root of the problem. Have a nice day.