Subject: bug#68255: 28.2; Can't connect to emacs daemon after logging out and back in.

From: Jeremy Phelps <[email-masked]>
Date: Thu, 4 Jan 2024 14:52:17 -0500

1. Configure your session manager not to kill leftover user processes
   after logging out. If you're using elogind, this can be done by
   editing /etc/elogind/logind.conf and setting KillUserProcesses=no.
   Same process for systemd-logind, except the file is located
   at /etc/systemd/logind.conf.
2. Log into a new session and run "emacs --daemon".
3. Log out of all sessions for that user. This causes the directory
   named in $XDG_RUNTIME_DIR to be deleted, and with it, the Emacs
   daemon's socket.
4. Log back in.
5. Observe that the emacs daemon's process is still there, and that
   its socket is gone.

Working around this problem is difficult because the XDG_RUNTIME_DIR
variable whose use causes this problem is referenced in two places:

1. The "server-socket-dir" variable in Elisp. This is fairly easy to
   change because Emacs can take you right to the definition.
2. The emacsclient binary. Changing the behavior here requires
   editing emacsclient.c, recompiling, and installing the resulting
   binary. Except it's too hard to get Emacs to build on modern
   Linux distros, so I hex-edited the emacsclient binary instead,
   NUL-ing out all strings containing "XDG_RUNTIME_DIR".

In GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.37,
cairo version 1.16.0)
 of 2023-05-13, modified by Debian built on x86-ubc-01
Windowing system distributor 'The X.Org Foundation', version 11.0.12101007
System Description: Devuan GNU/Linux 5 (daedalus)

Configured using:
 'configure --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/libexec
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-libsystemd --with-pop=yes
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/28.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/28.2/site-lisp:/usr/share/emacs/site-lisp
 --with-sound=alsa --without-gconf --with-mailutils
 --with-native-compilation --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/libexec
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-libsystemd --with-pop=yes
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/28.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/28.2/site-lisp:/usr/share/emacs/site-lisp
 --with-sound=alsa --without-gconf --with-mailutils
 --with-native-compilation --with-cairo --with-x=yes
 --with-x-toolkit=gtk3 --with-toolkit-scroll-bars 'CFLAGS=-g -O2
 -ffile-prefix-map=/build/emacs-mPr7Vr/emacs-28.2+1=. -fstack-protector-strong
 -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time
 -D_FORTIFY_SOURCE=2' LDFLAGS=-Wl,-z,relro'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  shell-dirtrack-mode: t
  iswitchb-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
/usr/share/emacs/site-lisp/elpa/slime-2.27/slime-tests hides
/usr/share/emacs/site-lisp/elpa-src/slime-2.27/slime-tests
/usr/share/emacs/site-lisp/elpa/slime-2.27/slime hides
/usr/share/emacs/site-lisp/elpa-src/slime-2.27/slime
/usr/share/emacs/site-lisp/elpa/slime-2.27/slime-pkg hides
/usr/share/emacs/site-lisp/elpa-src/slime-2.27/slime-pkg
/usr/share/emacs/site-lisp/elpa/slime-2.27/slime-autoloads hides
/usr/share/emacs/site-lisp/elpa-src/slime-2.27/slime-autoloads
/home/jlp/.emacs.d/elpa/transient-20200107.2156/transient hides
/usr/share/emacs/28.2/lisp/transient

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa epg rfc6068 epg-config gnus-util rmail
rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils misearch multi-isearch apropos face-remap
cus-edit cus-start cus-load wid-edit ob-ruby ob-lisp ob-clojure ob-awk
ob-python python tramp-sh tramp tramp-loaddefs trampver
tramp-integration files-x tramp-compat parse-time ls-lisp ob-scheme
ob-shell shell org ob ob-tangle ob-ref ob-lob ob-table ob-exp org-macro
org-footnote org-src ob-comint org-pcomplete pcomplete org-list
org-faces org-entities org-version ob-emacs-lisp ob-core ob-eval
org-table oc-basic bibtex iso8601 time-date ol org-keys oc org-compat
org-macs org-loaddefs format-spec find-func cal-menu calendar
cal-loaddefs iswitchb slime-fancy slime-indentation slime-cl-indent
cl-indent slime-trace-dialog slime-fontifying-fu slime-package-fu
slime-references slime-compiler-notes-tree slime-scratch
slime-presentations bridge slime-macrostep macrostep slime-mdot-fu
slime-enclosing-context slime-fuzzy slime-fancy-trace
slime-fancy-inspector slime-c-p-c slime-editing-commands slime-autodoc
slime-repl elp slime-parse slime compile text-property-search etags
fileloop generator xref project arc-mode archive-mode noutline outline
pp comint ansi-color ring hyperspec thingatpt image+ image-file
image-converter unicode-math-input quail comp comp-cstr rx git-blame
amber-theme cl-extra help-mode cyberpunk-theme rainbow-delimiters
easy-mmode yaml-mode derived edmacro kmacro warnings advice cl
finder-inf info slime-autoloads package browse-url url url-proxy
url-privacy url-expand url-methods url-history url-cookie url-domsuf
url-util mailcap url-handlers url-parse auth-source cl-seq eieio
eieio-core cl-macs eieio-loaddefs password-cache json subr-x map
url-vars seq byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib
iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 480397 22320)
 (symbols 48 28109 1)
 (strings 32 128262 12974)
 (string-bytes 1 4201587)
 (vectors 16 44072)
 (vector-slots 8 750050 47045)
 (floats 8 200 256)
 (intervals 56 760 0)
 (buffers 992 13))