Bug 1222172 - emacsclient -n -c fails to start when emacs daemon is started early
Summary: emacsclient -n -c fails to start when emacs daemon is started early
Status: RESOLVED FIXED
Alias: None
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Other (show other bugs)
Version: Current
Hardware: Other Other
: P5 - None : Normal (vote)
Target Milestone: ---
Assignee: Dr. Werner Fink
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-29 20:06 UTC by Gabriel Krisman Bertazi
Modified: 2024-07-19 09:01 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Krisman Bertazi 2024-03-29 20:06:02 UTC
TW includes emacs.service to start an emacs server through systemd. I enable the unit file:
  systemctl enable --user emacs

after log out/log in, the server is started properly within the user session. But any attempt to start a client with a frame (-c) disconnected from the shell (-n) fails silently: 

  emacsclient -n -c   // fails immediately and returns 1.

journald shows:
 29 15:54:29 cartola emacs[29953]: xauth: (argv):1:  bad display name "wayland-0" in "extract" command
 29 15:54:29 cartola emacs[29953]: No matches found, authority file "-" not written
 29 15:54:29 cartola emacs[29953]: xauth: (argv):1:  unable to read any entries from file "(stdin)"

Curiously, if I omit the -n parameter, it kind of works. A tiny window gets created.  It seems the frame is misconfigured  as it ignored the window setting:
  emacsclient -c

Now...

If, from a shell, I restart the service:
    systemctl restart --user emacs

Then, both:
  emacsclient -n -c 
  emacsclient -c

work fine, and respect the window sizes previously set.

I suspect the problem is some missing wayland environment variable that is not configured when emacsd is first started.  After restart, when everything works, I see the /proc/<pid>/environ is much longer. In particular these are now  set in the emacs daemon environment:

XAUTHORITY=/run/user/1000/emacs/xauth
XAUTHLOCALHOSTNAME=mylaptop

I'm using the distro provided unit file:

 [0:krisman@cartola ~]$ systemctl status --user emacs
● emacs.service - Emacs text editor
     Loaded: loaded (/usr/lib/systemd/user/emacs.service; enabled; preset: disa>
     Active: active (running) since Fri 2024-03-29 15:56:04 EDT; 8min ago
       Docs: info:emacs
             man:emacs(1)
Comment 1 Dr. Werner Fink 2024-04-02 07:02:50 UTC
Usr REAL X not broken wayland ... does this work?
Comment 2 Dr. Werner Fink 2024-04-02 07:07:33 UTC
Btw: HOW should a already running emacs daemon know about size of a not stared display?
Comment 3 Dr. Werner Fink 2024-04-02 11:50:13 UTC
https://www.emacswiki.org/emacs/EmacsAsDaemon
Comment 4 Gabriel Krisman Bertazi 2024-04-06 23:41:35 UTC
(In reply to Dr. Werner Fink from comment #2)

Should emacs (In reply to Dr. Werner Fink from comment #1)
> Usr REAL X not broken wayland ... does this work?

Not really. considering wayland is becoming a default everywhere and I need stuff like per-display scaling,  X is becoming a worse option everyday, no matter how crappy wayland is... Also, isn't gnome over wayland the default installation on TW?

(In reply to Dr. Werner Fink from comment #2)
> Btw: HOW should a already running emacs daemon know about size of a not
> stared display?

Perhaps the emacs daemon service unit should depend on the graphical environment:

[unit]
After=gnome-session-manager@gnome.service

It's been a PITA debugging this because logout-login seems to be preserving some environment somehow, and I simply cannot reproduce without a full reboot.  But I'll test this.
Comment 5 Dr. Werner Fink 2024-04-11 06:46:24 UTC
I've added

After=graphical-session.target

in the [Unit] section as this should work with GNOME/KDE as well as with X11 and Wayland
Comment 6 OBSbugzilla Bot 2024-04-11 07:55:02 UTC
This is an autogenerated message for OBS integration:
This bug (1222172) was mentioned in
https://build.opensuse.org/request/show/1166776 Factory / emacs
Comment 7 Dr. Werner Fink 2024-04-12 07:14:19 UTC
(In reply to OBSbugzilla Bot from comment #6)
> This is an autogenerated message for OBS integration:
> This bug (1222172) was mentioned in
> https://build.opensuse.org/request/show/1166776 Factory / emacs

Please test this version to see if the emacs.service in the systemd user serives solve the problem ... be aware to remove any self edited version to really use the new emacs.service
Comment 9 Dr. Werner Fink 2024-07-19 09:01:21 UTC
Fixed IMHO