Subject: bug#35300: 27.0.50; emacsclient on remote sessions no longer works

From: Paul Eggert <[email-masked]>
Date: Sat, 20 Apr 2019 12:31:10 -0700

I installed into master the attached patch, which should cause emacsclient to 
output something like the following in your situation:

emacsclient: Should XDG_RUNTIME_DIR='/run/user/1000' be in the environment?
emacsclient: (Be careful: XDG_RUNTIME_DIR is security-related.)

I hope this helps.
>From b3a12c62c9085171866256f00dada4326a4a3084 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Sat, 20 Apr 2019 09:31:47 -0700
Subject: [PATCH] Improve XDG_RUNTIME_DIR diagnostic

* lib-src/emacsclient.c (set_local_socket):
If there appears to be an XDG runtime directory for the user
but XDG_RUNTIME_DIR is unset, suggest setting it while warning
about potential security issues (Bug#35300).
---
 lib-src/emacsclient.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index f476840898..5871a18ce6 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1357,6 +1357,7 @@ set_local_socket (char const *server_name)
   int tmpdirlen = -1;
   int socknamelen = -1;
   uid_t uid = geteuid ();
+  bool tmpdir_used = false;
 
   if (strchr (server_name, '/')
       || (ISSLASH ('\\') && strchr (server_name, '\\')))
@@ -1389,6 +1390,7 @@ set_local_socket (char const *server_name)
 	    }
 	  socknamelen = local_sockname (sockname, socknamesize, tmpdirlen,
 					uid, server_name);
+	  tmpdir_used = true;
 	}
     }
 
@@ -1462,11 +1464,27 @@ set_local_socket (char const *server_name)
   if (sock_status < 0)
     message (true, "%s: Invalid socket owner\n", progname);
   else if (sock_status == ENOENT)
-    message (true,
-	     ("%s: can't find socket; have you started the server?\n"
-	      "%s: To start the server in Emacs,"
-	      " type \"M-x server-start\".\n"),
-	     progname, progname);
+    {
+      if (tmpdir_used)
+	{
+	  uintmax_t id = uid;
+	  char sockdirname[socknamesize];
+	  int sockdirnamelen = snprintf (sockdirname, sizeof sockdirname,
+					 "/run/user/%"PRIuMAX, id);
+	  if (0 <= sockdirnamelen && sockdirnamelen < sizeof sockdirname
+	      && euidaccess (sockdirname, X_OK) == 0)
+	    message
+	      (true,
+	       ("%s: Should XDG_RUNTIME_DIR='%s' be in the environment?\n"
+		"%s: (Be careful: XDG_RUNTIME_DIR is security-related.)\n"),
+	       progname, sockdirname, progname);
+	}
+      message (true,
+	       ("%s: can't find socket; have you started the server?\n"
+		"%s: To start the server in Emacs,"
+		" type \"M-x server-start\".\n"),
+	       progname, progname);
+    }
   else
     message (true, "%s: can't stat %s: %s\n",
 	     progname, sockname, strerror (sock_status));
-- 
2.17.1