Subject: Re: bug#62938: 30.0.50; Emacsclient -nc can fail with to many arguments under Wayland

From: Björn Bidar <[email-masked]>
Date: Thu, 20 Apr 2023 08:57:20 +0300

Robert Pluim <[email-masked]> writes:

>>>>>> On Tue, 18 Apr 2023 19:08:19 +0300, Björn Bidar via "Bug reports
> for GNU Emacs, the Swiss army knife of text editors"
> <[email-masked]> said:
>
>     Björn> I start emacsclient -nc using a global shortcut in KDE (S-e in my case)
>     Björn> start by the included Emacsclient desktop file.
>     Björn> (exec emacsclient --alternate-editor= --display="\$DISPLAY" "\$@"; else exec emacsclient --alternate-editor= --create-frame; fi' sh %F)
>
>     Björn> The command fails silently visually but in the logs there's:
>     Björn> Apr 18 18:47:46 odin kwin_wayland_wrapper[22013]: *ERROR*: Assertion failed: (eq (match-end 0)
>
>     Björn> The bug only happens on Wayland, on X11 the issue isn't present.
>     Björn> I believe the issue was present before Emacs 29 was branched off.
>
>     Björn> My WM/Compositor is Kwin.
>
>     Björn> Enabling toggle-debug-error shows this backtrace:
>     Björn> Debugger entered--Lisp error: (cl-assertion-failed ((eq (match-end 0) (length string)) nil))
>     Björn>   cl--assertion-failed((eq (match-end 0) (length string)))
>
>     Björn> I assume the arguments passed to the daemon process are to long because
>     Björn> of the amount of environment variables that I set.
>
> How are you starting the daemon emacs? Does this still happen if you
> start the daemon as 'emacs --fg-daemon' instead.

I'm starting it using systemd --user:

~/:systemctl --user cat emacs.service  
# /home/bidar/.local/etc/systemd/user/emacs.service

[Unit]
Description=Emacs: the extensible, self-documenting text editor
Wants=graphical.target
Wants=environment.target

[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=always
TimeoutStartSec=0
[Install]
WantedBy=default.target

# /home/bidar/.local/etc/systemd/user/emacs.service.d/gdkenv.conf
[Service]
Environment=GDK_DPI_SCALE=0.8
Environment=GDK_SCALE=2

# /home/bidar/.local/etc/systemd/user/emacs.service.d/override.conf
[Service]
TimeoutStopSec=600

I don't think using fg-daemon should make a difference.

> The issue is that emacsclient is sending 'Waiting for Emacs...' to the
> emacs server socket instead of stdout. Are you using the
> EMACS_SOCKET_NAME environment variable or the '--socket-name' option
> somehow?

No that's not set.

> Could you also check which emacsclient is being invoked (eg
> emacsclient -V) and ensure it corresponds to your version of Emacs?

There's only one Emacs installed.

> Robert