Subject: Re: bug#51327: 28.0.60; emacsclient warns about XDG_RUNTIME_DIR when starting daemon on-demand

From: Paul Eggert <[email-masked]>
Date: Wed, 8 Dec 2021 15:44:39 -0800

On 12/8/21 13:56, Ulrich Mueller wrote:
> So, can we please think about a better solution, and not knee-jerk
> something half-baked into Emacs 28, like checking for yet another
> environment variable?

Agreed, now is not the time for significant innovation. It could be that 
any significant improvement will have to wait for Emacs 29.

> Even reverting to the Emacs 27 behaviour would be better than what has
> been suggested above: In Emacs 27, you can set EMACS_SOCKET_NAME to make
> things work.

Setting EMACS_SOCKET_NAME to an absolute file name should work just as 
well in emacs-28 as it did in Emacs 27, because in that case the code 
doesn't consult either XDG_RUNTIME_DIR or TMPDIR. So if that's an 
adequate solution, we should be able to continue with that.

> Given the goal to release Emacs 28.1 soon, I'm not sure there's time to come up with (and be confident in) a better solution for 28. In that case, I guess the available options are:
> 
> * If the security issue is considered minor enough, keep the current Emacs 28 behavior and silence the warning.

I'd rather not silence the warning as there is a real issue here 
(admittedly obscure...).

> * Otherwise, revert to the Emacs 27 behavior and come up with a better solution for Emacs 29. 

That sounds better, if the EMACS_SOCKET_NAME approach is good enough. 
Proposed patch attached. This patch attempts to be reasonably minimal vs 
what's in emacs-28 now (as opposed to cleaning up this somewhat-messy area).
From 2cb6087f2b797d4ec21d27bc531998e07848797f Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Wed, 8 Dec 2021 15:37:39 -0800
Subject: [PATCH] emacsclient takes more care about XDG_RUNTIME_DIR

* lib-src/emacsclient.c (set_local_socket): Revert to the Emacs 27
behavior of not trying TMPDIR if XDG_RUNTIME_DIR is set.
This is one of the suggestions made by Jim Porter and
independently by Ulrich Mueller in Bug#51327.
---
 lib-src/emacsclient.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index cff3cec2a7..d11fd88c45 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1456,7 +1456,6 @@ set_local_socket (char const *server_name)
   else
     {
       /* socket_name is a file name component.  */
-      sock_status = ENOENT;
       char const *xdg_runtime_dir = egetenv ("XDG_RUNTIME_DIR");
       if (xdg_runtime_dir)
 	{
@@ -1466,7 +1465,7 @@ set_local_socket (char const *server_name)
 			 ? connect_socket (AT_FDCWD, sockname, s, 0)
 			 : ENAMETOOLONG);
 	}
-      if (sock_status == ENOENT)
+      else
 	{
 	  char const *tmpdir = egetenv ("TMPDIR");
 	  if (tmpdir)
-- 
2.32.0